Major formatting changes (breaks diffs). No code changes.

The changes made in this commit do not affect any actual code,
    they are purely aesthetic. I ran clang-format with google style
    over all .h/.cpp files in wpilibc that weren't in wpilibC++Sim
    or gtest, and the eclipse formatter over all of the Java files
    using the Google eclipse formatting configuration.

Change-Id: I9627bca0bc103c398ecc1c5ba17467193291ae63
This commit is contained in:
James Kuszmaul
2015-06-25 15:07:55 -04:00
parent bd64d9a7ef
commit 7eb8550bdb
470 changed files with 89798 additions and 77287 deletions

View File

@@ -12,13 +12,19 @@
enum MotorEncoderTestType { TEST_VICTOR, TEST_JAGUAR, TEST_TALON };
std::ostream &operator<<(std::ostream &os, MotorEncoderTestType const &type) {
switch(type) {
case TEST_VICTOR: os << "Victor"; break;
case TEST_JAGUAR: os << "Jaguar"; break;
case TEST_TALON: os << "Talon"; break;
}
switch (type) {
case TEST_VICTOR:
os << "Victor";
break;
case TEST_JAGUAR:
os << "Jaguar";
break;
case TEST_TALON:
os << "Talon";
break;
}
return os;
return os;
}
static constexpr double kMotorTime = 0.5;
@@ -29,124 +35,121 @@ static constexpr double kMotorTime = 0.5;
* @author Thomas Clark
*/
class MotorEncoderTest : public testing::TestWithParam<MotorEncoderTestType> {
protected:
SpeedController *m_speedController;
Encoder *m_encoder;
protected:
SpeedController *m_speedController;
Encoder *m_encoder;
virtual void SetUp() override {
switch(GetParam()) {
case TEST_VICTOR:
m_speedController = new Victor(TestBench::kVictorChannel);
m_encoder = new Encoder(TestBench::kVictorEncoderChannelA,
TestBench::kVictorEncoderChannelB);
break;
virtual void SetUp() override {
switch (GetParam()) {
case TEST_VICTOR:
m_speedController = new Victor(TestBench::kVictorChannel);
m_encoder = new Encoder(TestBench::kVictorEncoderChannelA,
TestBench::kVictorEncoderChannelB);
break;
case TEST_JAGUAR:
m_speedController = new Jaguar(TestBench::kJaguarChannel);
m_encoder = new Encoder(TestBench::kJaguarEncoderChannelA,
TestBench::kJaguarEncoderChannelB);
break;
case TEST_JAGUAR:
m_speedController = new Jaguar(TestBench::kJaguarChannel);
m_encoder = new Encoder(TestBench::kJaguarEncoderChannelA,
TestBench::kJaguarEncoderChannelB);
break;
case TEST_TALON:
m_speedController = new Talon(TestBench::kTalonChannel);
m_encoder = new Encoder(TestBench::kTalonEncoderChannelA,
TestBench::kTalonEncoderChannelB);
break;
}
case TEST_TALON:
m_speedController = new Talon(TestBench::kTalonChannel);
m_encoder = new Encoder(TestBench::kTalonEncoderChannelA,
TestBench::kTalonEncoderChannelB);
break;
}
}
}
virtual void TearDown() override {
delete m_speedController;
delete m_encoder;
}
virtual void TearDown() override {
delete m_speedController;
delete m_encoder;
}
void Reset() {
m_speedController->Set(0.0f);
m_encoder->Reset();
}
void Reset() {
m_speedController->Set(0.0f);
m_encoder->Reset();
}
};
/**
* Test if the encoder value increments after the motor drives forward
*/
TEST_P(MotorEncoderTest, Increment) {
Reset();
Reset();
/* Drive the speed controller briefly to move the encoder */
m_speedController->Set(1.0);
Wait(kMotorTime);
m_speedController->Set(0.0);
/* Drive the speed controller briefly to move the encoder */
m_speedController->Set(1.0);
Wait(kMotorTime);
m_speedController->Set(0.0);
/* The encoder should be positive now */
EXPECT_GT(m_encoder->Get(), 0)
<< "Encoder should have incremented after the motor moved";
/* The encoder should be positive now */
EXPECT_GT(m_encoder->Get(), 0)
<< "Encoder should have incremented after the motor moved";
}
/**
* Test if the encoder value decrements after the motor drives backwards
*/
TEST_P(MotorEncoderTest, Decrement) {
Reset();
Reset();
/* Drive the speed controller briefly to move the encoder */
m_speedController->Set(-1.0f);
Wait(kMotorTime);
m_speedController->Set(0.0f);
/* Drive the speed controller briefly to move the encoder */
m_speedController->Set(-1.0f);
Wait(kMotorTime);
m_speedController->Set(0.0f);
/* The encoder should be positive now */
EXPECT_LT(m_encoder->Get(), 0.0f)
<< "Encoder should have decremented after the motor moved";
/* The encoder should be positive now */
EXPECT_LT(m_encoder->Get(), 0.0f)
<< "Encoder should have decremented after the motor moved";
}
/**
* Test if motor speeds are clamped to [-1,1]
*/
TEST_P(MotorEncoderTest, ClampSpeed) {
Reset();
Reset();
m_speedController->Set(2.0f);
Wait(kMotorTime);
m_speedController->Set(2.0f);
Wait(kMotorTime);
EXPECT_FLOAT_EQ(1.0f, m_speedController->Get());
EXPECT_FLOAT_EQ(1.0f, m_speedController->Get());
m_speedController->Set(-2.0f);
Wait(kMotorTime);
m_speedController->Set(-2.0f);
Wait(kMotorTime);
EXPECT_FLOAT_EQ(-1.0f, m_speedController->Get());
EXPECT_FLOAT_EQ(-1.0f, m_speedController->Get());
}
/**
* Test if PID loops work
*/
TEST_P(MotorEncoderTest, PIDController) {
Reset();
Reset();
PIDController pid(0.001f, 0.0005f, 0.0f, m_encoder, m_speedController);
pid.SetAbsoluteTolerance(20.0f);
pid.SetOutputRange(-0.3f, 0.3f);
pid.SetSetpoint(2500);
PIDController pid(0.001f, 0.0005f, 0.0f, m_encoder, m_speedController);
pid.SetAbsoluteTolerance(20.0f);
pid.SetOutputRange(-0.3f, 0.3f);
pid.SetSetpoint(2500);
/* 10 seconds should be plenty time to get to the setpoint */
pid.Enable();
Wait(10.0);
pid.Disable();
/* 10 seconds should be plenty time to get to the setpoint */
pid.Enable();
Wait(10.0);
pid.Disable();
RecordProperty("PIDError", pid.GetError());
RecordProperty("PIDError", pid.GetError());
EXPECT_TRUE(pid.OnTarget()) << "PID loop did not converge within 10 seconds.";
EXPECT_TRUE(pid.OnTarget()) << "PID loop did not converge within 10 seconds.";
}
/**
* Test resetting encoders
*/
TEST_P(MotorEncoderTest, Reset) {
Reset();
Reset();
EXPECT_EQ(0, m_encoder->Get()) << "Encoder did not reset to 0";
EXPECT_EQ(0, m_encoder->Get()) << "Encoder did not reset to 0";
}
INSTANTIATE_TEST_CASE_P(Test, MotorEncoderTest,
testing::Values(TEST_VICTOR, TEST_JAGUAR, TEST_TALON));
testing::Values(TEST_VICTOR, TEST_JAGUAR, TEST_TALON));