Replaced floats with doubles (#355)

This makes our APIs more consistent. With optimizations enabled, doubles are just as efficient as floats on ARMv7, so we should take advantage of the extra precision.
This commit is contained in:
Tyler Veness
2016-11-20 07:25:03 -08:00
committed by Peter Johnson
parent 7bcd243ec3
commit 69422dc063
129 changed files with 643 additions and 639 deletions

View File

@@ -43,11 +43,11 @@ class AnalogLoopTest : public testing::Test {
TEST_F(AnalogLoopTest, AnalogInputWorks) {
// Set the output voltage and check if the input measures the same voltage
for (int32_t i = 0; i < 50; i++) {
m_output->SetVoltage(i / 10.0f);
m_output->SetVoltage(i / 10.0);
Wait(kDelayTime);
EXPECT_NEAR(m_output->GetVoltage(), m_input->GetVoltage(), 0.01f);
EXPECT_NEAR(m_output->GetVoltage(), m_input->GetVoltage(), 0.01);
}
}
@@ -57,23 +57,23 @@ TEST_F(AnalogLoopTest, AnalogInputWorks) {
*/
TEST_F(AnalogLoopTest, AnalogTriggerWorks) {
AnalogTrigger trigger(m_input);
trigger.SetLimitsVoltage(2.0f, 3.0f);
trigger.SetLimitsVoltage(2.0, 3.0);
m_output->SetVoltage(1.0f);
m_output->SetVoltage(1.0);
Wait(kDelayTime);
EXPECT_FALSE(trigger.GetInWindow())
<< "Analog trigger is in the window (2V, 3V)";
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
m_output->SetVoltage(2.5f);
m_output->SetVoltage(2.5);
Wait(kDelayTime);
EXPECT_TRUE(trigger.GetInWindow())
<< "Analog trigger is not in the window (2V, 3V)";
EXPECT_FALSE(trigger.GetTriggerState()) << "Analog trigger is on";
m_output->SetVoltage(4.0f);
m_output->SetVoltage(4.0);
Wait(kDelayTime);
EXPECT_FALSE(trigger.GetInWindow())
@@ -87,7 +87,7 @@ TEST_F(AnalogLoopTest, AnalogTriggerWorks) {
*/
TEST_F(AnalogLoopTest, AnalogTriggerCounterWorks) {
AnalogTrigger trigger(m_input);
trigger.SetLimitsVoltage(2.0f, 3.0f);
trigger.SetLimitsVoltage(2.0, 3.0);
Counter counter(trigger);
@@ -111,7 +111,7 @@ static void InterruptHandler(uint32_t interruptAssertedMask, void* param) {
TEST_F(AnalogLoopTest, AsynchronusInterruptWorks) {
int32_t param = 0;
AnalogTrigger trigger(m_input);
trigger.SetLimitsVoltage(2.0f, 3.0f);
trigger.SetLimitsVoltage(2.0, 3.0);
// Given an interrupt handler that sets an int32_t to 12345
std::shared_ptr<AnalogTriggerOutput> triggerOutput =

View File

@@ -51,9 +51,9 @@ class CounterTest : public testing::Test {
m_talonCounter->Reset();
m_victorCounter->Reset();
m_jaguarCounter->Reset();
m_talon->Set(0.0f);
m_victor->Set(0.0f);
m_jaguar->Set(0.0f);
m_talon->Set(0.0);
m_victor->Set(0.0);
m_jaguar->Set(0.0);
}
};
@@ -64,44 +64,44 @@ class CounterTest : public testing::Test {
TEST_F(CounterTest, CountTalon) {
Reset();
/* Run the motor forward and determine if the counter is counting. */
m_talon->Set(1.0f);
m_talon->Set(1.0);
Wait(0.5);
EXPECT_NE(0.0f, m_talonCounter->Get()) << "The counter did not count (talon)";
EXPECT_NE(0.0, m_talonCounter->Get()) << "The counter did not count (talon)";
/* Set the motor to 0 and determine if the counter resets to 0. */
m_talon->Set(0.0f);
m_talon->Set(0.0);
Wait(0.5);
m_talonCounter->Reset();
EXPECT_FLOAT_EQ(0.0f, m_talonCounter->Get())
EXPECT_FLOAT_EQ(0.0, m_talonCounter->Get())
<< "The counter did not restart to 0 (talon)";
}
TEST_F(CounterTest, CountVictor) {
Reset();
/* Run the motor forward and determine if the counter is counting. */
m_victor->Set(1.0f);
m_victor->Set(1.0);
Wait(0.5);
EXPECT_NE(0.0f, m_victorCounter->Get())
EXPECT_NE(0.0, m_victorCounter->Get())
<< "The counter did not count (victor)";
/* Set the motor to 0 and determine if the counter resets to 0. */
m_victor->Set(0.0f);
m_victor->Set(0.0);
Wait(0.5);
m_victorCounter->Reset();
EXPECT_FLOAT_EQ(0.0f, m_victorCounter->Get())
EXPECT_FLOAT_EQ(0.0, m_victorCounter->Get())
<< "The counter did not restart to 0 (jaguar)";
}
TEST_F(CounterTest, CountJaguar) {
Reset();
/* Run the motor forward and determine if the counter is counting. */
m_jaguar->Set(1.0f);
m_jaguar->Set(1.0);
Wait(0.5);
EXPECT_NE(0.0f, m_jaguarCounter->Get())
EXPECT_NE(0.0, m_jaguarCounter->Get())
<< "The counter did not count (jaguar)";
/* Set the motor to 0 and determine if the counter resets to 0. */
m_jaguar->Set(0.0f);
m_jaguar->Set(0.0);
Wait(0.5);
m_jaguarCounter->Reset();
EXPECT_FLOAT_EQ(0.0f, m_jaguarCounter->Get())
EXPECT_FLOAT_EQ(0.0, m_jaguarCounter->Get())
<< "The counter did not restart to 0 (jaguar)";
}
@@ -113,11 +113,11 @@ TEST_F(CounterTest, TalonGetStopped) {
Reset();
/* Set the Max Period of the counter and run the motor */
m_talonCounter->SetMaxPeriod(kMaxPeriod);
m_talon->Set(1.0f);
m_talon->Set(1.0);
Wait(0.5);
EXPECT_FALSE(m_talonCounter->GetStopped()) << "The counter did not count.";
/* Stop the motor and wait until the Max Period is exceeded */
m_talon->Set(0.0f);
m_talon->Set(0.0);
Wait(kMotorDelay);
EXPECT_TRUE(m_talonCounter->GetStopped())
<< "The counter did not stop counting.";
@@ -127,11 +127,11 @@ TEST_F(CounterTest, VictorGetStopped) {
Reset();
/* Set the Max Period of the counter and run the motor */
m_victorCounter->SetMaxPeriod(kMaxPeriod);
m_victor->Set(1.0f);
m_victor->Set(1.0);
Wait(0.5);
EXPECT_FALSE(m_victorCounter->GetStopped()) << "The counter did not count.";
/* Stop the motor and wait until the Max Period is exceeded */
m_victor->Set(0.0f);
m_victor->Set(0.0);
Wait(kMotorDelay);
EXPECT_TRUE(m_victorCounter->GetStopped())
<< "The counter did not stop counting.";
@@ -141,11 +141,11 @@ TEST_F(CounterTest, JaguarGetStopped) {
Reset();
/* Set the Max Period of the counter and run the motor */
m_jaguarCounter->SetMaxPeriod(kMaxPeriod);
m_jaguar->Set(1.0f);
m_jaguar->Set(1.0);
Wait(0.5);
EXPECT_FALSE(m_jaguarCounter->GetStopped()) << "The counter did not count.";
/* Stop the motor and wait until the Max Period is exceeded */
m_jaguar->Set(0.0f);
m_jaguar->Set(0.0);
Wait(kMotorDelay);
EXPECT_TRUE(m_jaguarCounter->GetStopped())
<< "The counter did not stop counting.";

View File

@@ -83,7 +83,7 @@ class FakeEncoderTest : public testing::Test {
* Test the encoder by reseting it to 0 and reading the value.
*/
TEST_F(FakeEncoderTest, TestDefaultState) {
EXPECT_FLOAT_EQ(0.0f, m_encoder->Get()) << "The encoder did not start at 0.";
EXPECT_FLOAT_EQ(0.0, m_encoder->Get()) << "The encoder did not start at 0.";
}
/**
@@ -93,7 +93,7 @@ TEST_F(FakeEncoderTest, TestCountUp) {
m_encoder->Reset();
Simulate100QuadratureTicks();
EXPECT_FLOAT_EQ(100.0f, m_encoder->Get()) << "Encoder did not count to 100.";
EXPECT_FLOAT_EQ(100.0, m_encoder->Get()) << "Encoder did not count to 100.";
}
/**

View File

@@ -73,7 +73,7 @@ class MotorEncoderTest : public testing::TestWithParam<MotorEncoderTestType> {
}
void Reset() {
m_speedController->Set(0.0f);
m_speedController->Set(0.0);
m_encoder->Reset();
}
};
@@ -101,12 +101,12 @@ TEST_P(MotorEncoderTest, Decrement) {
Reset();
/* Drive the speed controller briefly to move the encoder */
m_speedController->Set(-0.2f);
m_speedController->Set(-0.2);
Wait(kMotorTime);
m_speedController->Set(0.0f);
m_speedController->Set(0.0);
/* The encoder should be positive now */
EXPECT_LT(m_encoder->Get(), 0.0f)
EXPECT_LT(m_encoder->Get(), 0.0)
<< "Encoder should have decremented after the motor moved";
}
@@ -116,15 +116,15 @@ TEST_P(MotorEncoderTest, Decrement) {
TEST_P(MotorEncoderTest, ClampSpeed) {
Reset();
m_speedController->Set(2.0f);
m_speedController->Set(2.0);
Wait(kMotorTime);
EXPECT_FLOAT_EQ(1.0f, m_speedController->Get());
EXPECT_FLOAT_EQ(1.0, m_speedController->Get());
m_speedController->Set(-2.0f);
m_speedController->Set(-2.0);
Wait(kMotorTime);
EXPECT_FLOAT_EQ(-1.0f, m_speedController->Get());
EXPECT_FLOAT_EQ(-1.0, m_speedController->Get());
}
/**
@@ -134,9 +134,9 @@ TEST_P(MotorEncoderTest, PositionPIDController) {
Reset();
double goal = 1000;
m_encoder->SetPIDSourceType(PIDSourceType::kDisplacement);
PIDController pid(0.001f, 0.0005f, 0.0f, m_encoder, m_speedController);
pid.SetAbsoluteTolerance(50.0f);
pid.SetOutputRange(-0.2f, 0.2f);
PIDController pid(0.001, 0.0005, 0.0, m_encoder, m_speedController);
pid.SetAbsoluteTolerance(50.0);
pid.SetOutputRange(-0.2, 0.2);
pid.SetSetpoint(goal);
/* 10 seconds should be plenty time to get to the setpoint */
@@ -158,10 +158,10 @@ TEST_P(MotorEncoderTest, VelocityPIDController) {
Reset();
m_encoder->SetPIDSourceType(PIDSourceType::kRate);
PIDController pid(1e-5, 0.0f, 3e-5, 8e-5, m_encoder, m_speedController);
pid.SetAbsoluteTolerance(200.0f);
PIDController pid(1e-5, 0.0, 3e-5, 8e-5, m_encoder, m_speedController);
pid.SetAbsoluteTolerance(200.0);
pid.SetToleranceBuffer(50);
pid.SetOutputRange(-0.3f, 0.3f);
pid.SetOutputRange(-0.3, 0.3);
pid.SetSetpoint(600);
/* 10 seconds should be plenty time to get to the setpoint */

View File

@@ -66,7 +66,7 @@ class MotorInvertingTest
void Reset() {
m_speedController->SetInverted(false);
m_speedController->Set(0.0f);
m_speedController->Set(0.0);
m_encoder->Reset();
}
};

View File

@@ -27,7 +27,7 @@ class PIDToleranceTest : public testing::Test {
double PIDGet() { return val; }
};
class fakeOutput : public PIDOutput {
void PIDWrite(float output) {}
void PIDWrite(double output) {}
};
fakeInput inp;
fakeOutput out;

View File

@@ -51,7 +51,7 @@ class TiltPanCameraTest : public testing::Test {
m_spiAccel = new ADXL345_SPI(SPI::kOnboardCS1);
m_tilt->Set(kTiltSetpoint45);
m_pan->SetAngle(0.0f);
m_pan->SetAngle(0.0);
Wait(kServoResetTime);
@@ -75,7 +75,7 @@ AnalogGyro* TiltPanCameraTest::m_gyro = nullptr;
* Test if the gyro angle defaults to 0 immediately after being reset.
*/
void TiltPanCameraTest::DefaultGyroAngle() {
EXPECT_NEAR(0.0f, m_gyro->GetAngle(), 1.0f);
EXPECT_NEAR(0.0, m_gyro->GetAngle(), 1.0);
}
/**
@@ -109,7 +109,7 @@ void TiltPanCameraTest::GyroAngle() {
*/
void TiltPanCameraTest::GyroCalibratedParameters() {
uint32_t cCenter = m_gyro->GetCenter();
float cOffset = m_gyro->GetOffset();
double cOffset = m_gyro->GetOffset();
delete m_gyro;
m_gyro = new AnalogGyro(TestBench::kCameraGyroChannel, cCenter, cOffset);
m_gyro->SetSensitivity(kSensitivity);
@@ -117,8 +117,8 @@ void TiltPanCameraTest::GyroCalibratedParameters() {
// Default gyro angle test
// Accumulator needs a small amount of time to reset before being tested
m_gyro->Reset();
Wait(.001);
EXPECT_NEAR(0.0f, m_gyro->GetAngle(), 1.0f);
Wait(0.001);
EXPECT_NEAR(0.0, m_gyro->GetAngle(), 1.0);
// Gyro angle test
// Make sure that the gyro doesn't get jerked when the servo goes to zero.