Replace .to<double>() and .template to<double>() with .value() (#3667)

It's a less verbose way to do the same thing.
This commit is contained in:
Tyler Veness
2021-10-25 08:58:12 -07:00
committed by GitHub
parent 6bc1db44bc
commit 181723e573
134 changed files with 782 additions and 826 deletions

View File

@@ -25,8 +25,8 @@ TEST(ADXRS450GyroSimTest, SetAttributes) {
sim.SetAngle(TEST_ANGLE);
sim.SetRate(TEST_RATE);
EXPECT_EQ(TEST_ANGLE.to<double>(), gyro.GetAngle());
EXPECT_EQ(TEST_RATE.to<double>(), gyro.GetRate());
EXPECT_EQ(TEST_ANGLE.value(), gyro.GetAngle());
EXPECT_EQ(TEST_RATE.value(), gyro.GetRate());
gyro.Reset();
EXPECT_EQ(0, gyro.GetAngle());

View File

@@ -20,8 +20,8 @@ TEST(AnalogEncoderSimTest, Basic) {
frc::sim::AnalogEncoderSim encoderSim{encoder};
encoderSim.SetPosition(180_deg);
EXPECT_NEAR(encoder.Get().to<double>(), 0.5, 1E-8);
EXPECT_NEAR(encoderSim.GetTurns().to<double>(), 0.5, 1E-8);
EXPECT_NEAR(encoderSim.GetPosition().Radians().to<double>(), wpi::numbers::pi,
EXPECT_NEAR(encoder.Get().value(), 0.5, 1E-8);
EXPECT_NEAR(encoderSim.GetTurns().value(), 0.5, 1E-8);
EXPECT_NEAR(encoderSim.GetPosition().Radians().value(), wpi::numbers::pi,
1E-8);
}

View File

@@ -43,7 +43,7 @@ TEST(AnalogGyroSimTest, SetAngle) {
sim.SetAngle(kTestAngle);
EXPECT_EQ(kTestAngle, sim.GetAngle());
EXPECT_EQ(kTestAngle, gyro.GetAngle());
EXPECT_EQ(-kTestAngle, gyro.GetRotation2d().Degrees().to<double>());
EXPECT_EQ(-kTestAngle, gyro.GetRotation2d().Degrees().value());
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(kTestAngle, callback.GetLastValue());
}

View File

@@ -43,13 +43,13 @@ TEST(DifferentialDriveSimTest, Convergence) {
frc::Pose2d(), {}, frc::Pose2d(2_m, 2_m, 0_rad), config);
// NOLINTNEXTLINE
for (double t = 0; t < trajectory.TotalTime().to<double>(); t += 0.02) {
for (double t = 0; t < trajectory.TotalTime().value(); t += 0.02) {
auto state = trajectory.Sample(20_ms);
auto ramseteOut = ramsete.Calculate(sim.GetPose(), state);
auto [l, r] = kinematics.ToWheelSpeeds(ramseteOut);
auto voltages = feedforward.Calculate(
Eigen::Vector<double, 2>{l.to<double>(), r.to<double>()});
auto voltages =
feedforward.Calculate(Eigen::Vector<double, 2>{l.value(), r.value()});
// Sim periodic code.
sim.SetInputs(units::volt_t(voltages(0, 0)), units::volt_t(voltages(1, 0)));
@@ -65,10 +65,9 @@ TEST(DifferentialDriveSimTest, Convergence) {
// 2 inch tolerance is OK since our ground truth is an approximation of the
// ODE solution using RK4 anyway
EXPECT_NEAR(groundTruthX(0, 0), sim.GetPose().X().to<double>(), 0.05);
EXPECT_NEAR(groundTruthX(1, 0), sim.GetPose().Y().to<double>(), 0.05);
EXPECT_NEAR(groundTruthX(2, 0), sim.GetHeading().Radians().to<double>(),
0.01);
EXPECT_NEAR(groundTruthX(0, 0), sim.GetPose().X().value(), 0.05);
EXPECT_NEAR(groundTruthX(1, 0), sim.GetPose().Y().value(), 0.05);
EXPECT_NEAR(groundTruthX(2, 0), sim.GetHeading().Radians().value(), 0.01);
}
TEST(DifferentialDriveSimTest, Current) {

View File

@@ -41,7 +41,7 @@ TEST(ElevatorSimTest, StateSpaceSim) {
encoderSim.SetDistance(y(0));
}
EXPECT_NEAR(controller.GetSetpoint(), sim.GetPosition().to<double>(), 0.2);
EXPECT_NEAR(controller.GetSetpoint(), sim.GetPosition().value(), 0.2);
}
TEST(ElevatorSimTest, MinMax) {

View File

@@ -91,7 +91,7 @@ TEST(EncoderSimTest, Period) {
auto cb = sim.RegisterPeriodCallback(callback.GetCallback(), false);
sim.SetPeriod(123.456);
EXPECT_EQ(123.456, sim.GetPeriod());
EXPECT_EQ(123.456, encoder.GetPeriod().to<double>());
EXPECT_EQ(123.456, encoder.GetPeriod().value());
EXPECT_EQ(kDefaultDistancePerPulse / 123.456, encoder.GetRate());
EXPECT_TRUE(callback.WasTriggered());

View File

@@ -50,13 +50,13 @@ TEST(RoboRioSimTest, SetVin) {
RoboRioSim::SetVInVoltage(units::volt_t{kTestVoltage});
EXPECT_TRUE(voltageCallback.WasTriggered());
EXPECT_EQ(kTestVoltage, voltageCallback.GetLastValue());
EXPECT_EQ(kTestVoltage, RoboRioSim::GetVInVoltage().to<double>());
EXPECT_EQ(kTestVoltage, RoboRioSim::GetVInVoltage().value());
EXPECT_EQ(kTestVoltage, RobotController::GetInputVoltage());
RoboRioSim::SetVInCurrent(units::ampere_t{kTestCurrent});
EXPECT_TRUE(currentCallback.WasTriggered());
EXPECT_EQ(kTestCurrent, currentCallback.GetLastValue());
EXPECT_EQ(kTestCurrent, RoboRioSim::GetVInCurrent().to<double>());
EXPECT_EQ(kTestCurrent, RoboRioSim::GetVInCurrent().value());
EXPECT_EQ(kTestCurrent, RobotController::GetInputCurrent());
}
@@ -71,8 +71,8 @@ TEST(RoboRioSimTest, SetBrownout) {
RoboRioSim::SetBrownoutVoltage(units::volt_t{kTestVoltage});
EXPECT_TRUE(voltageCallback.WasTriggered());
EXPECT_EQ(kTestVoltage, voltageCallback.GetLastValue());
EXPECT_EQ(kTestVoltage, RoboRioSim::GetBrownoutVoltage().to<double>());
EXPECT_EQ(kTestVoltage, RobotController::GetBrownoutVoltage().to<double>());
EXPECT_EQ(kTestVoltage, RoboRioSim::GetBrownoutVoltage().value());
EXPECT_EQ(kTestVoltage, RobotController::GetBrownoutVoltage().value());
}
TEST(RoboRioSimTest, Set6V) {
@@ -97,13 +97,13 @@ TEST(RoboRioSimTest, Set6V) {
RoboRioSim::SetUserVoltage6V(units::volt_t{kTestVoltage});
EXPECT_TRUE(voltageCallback.WasTriggered());
EXPECT_EQ(kTestVoltage, voltageCallback.GetLastValue());
EXPECT_EQ(kTestVoltage, RoboRioSim::GetUserVoltage6V().to<double>());
EXPECT_EQ(kTestVoltage, RoboRioSim::GetUserVoltage6V().value());
EXPECT_EQ(kTestVoltage, RobotController::GetVoltage6V());
RoboRioSim::SetUserCurrent6V(units::ampere_t{kTestCurrent});
EXPECT_TRUE(currentCallback.WasTriggered());
EXPECT_EQ(kTestCurrent, currentCallback.GetLastValue());
EXPECT_EQ(kTestCurrent, RoboRioSim::GetUserCurrent6V().to<double>());
EXPECT_EQ(kTestCurrent, RoboRioSim::GetUserCurrent6V().value());
EXPECT_EQ(kTestCurrent, RobotController::GetCurrent6V());
RoboRioSim::SetUserActive6V(false);
@@ -141,13 +141,13 @@ TEST(RoboRioSimTest, Set5V) {
RoboRioSim::SetUserVoltage5V(units::volt_t{kTestVoltage});
EXPECT_TRUE(voltageCallback.WasTriggered());
EXPECT_EQ(kTestVoltage, voltageCallback.GetLastValue());
EXPECT_EQ(kTestVoltage, RoboRioSim::GetUserVoltage5V().to<double>());
EXPECT_EQ(kTestVoltage, RoboRioSim::GetUserVoltage5V().value());
EXPECT_EQ(kTestVoltage, RobotController::GetVoltage5V());
RoboRioSim::SetUserCurrent5V(units::ampere_t{kTestCurrent});
EXPECT_TRUE(currentCallback.WasTriggered());
EXPECT_EQ(kTestCurrent, currentCallback.GetLastValue());
EXPECT_EQ(kTestCurrent, RoboRioSim::GetUserCurrent5V().to<double>());
EXPECT_EQ(kTestCurrent, RoboRioSim::GetUserCurrent5V().value());
EXPECT_EQ(kTestCurrent, RobotController::GetCurrent5V());
RoboRioSim::SetUserActive5V(false);
@@ -185,13 +185,13 @@ TEST(RoboRioSimTest, Set3V3) {
RoboRioSim::SetUserVoltage3V3(units::volt_t{kTestVoltage});
EXPECT_TRUE(voltageCallback.WasTriggered());
EXPECT_EQ(kTestVoltage, voltageCallback.GetLastValue());
EXPECT_EQ(kTestVoltage, RoboRioSim::GetUserVoltage3V3().to<double>());
EXPECT_EQ(kTestVoltage, RoboRioSim::GetUserVoltage3V3().value());
EXPECT_EQ(kTestVoltage, RobotController::GetVoltage3V3());
RoboRioSim::SetUserCurrent3V3(units::ampere_t{kTestCurrent});
EXPECT_TRUE(currentCallback.WasTriggered());
EXPECT_EQ(kTestCurrent, currentCallback.GetLastValue());
EXPECT_EQ(kTestCurrent, RoboRioSim::GetUserCurrent3V3().to<double>());
EXPECT_EQ(kTestCurrent, RoboRioSim::GetUserCurrent3V3().value());
EXPECT_EQ(kTestCurrent, RobotController::GetCurrent3V3());
RoboRioSim::SetUserActive3V3(false);

View File

@@ -18,5 +18,5 @@ TEST(SingleJointedArmTest, Disabled) {
}
// The arm should swing down.
EXPECT_NEAR(sim.GetAngle().to<double>(), -wpi::numbers::pi / 2, 0.01);
EXPECT_NEAR(sim.GetAngle().value(), -wpi::numbers::pi / 2, 0.01);
}

View File

@@ -51,7 +51,7 @@ TEST(StateSpaceSimTest, FlywheelSim) {
sim.SetInput(Eigen::Vector<double, 1>{
motor.Get() * frc::RobotController::GetInputVoltage()});
sim.Update(20_ms);
encoderSim.SetRate(sim.GetAngularVelocity().to<double>());
encoderSim.SetRate(sim.GetAngularVelocity().value());
}
ASSERT_TRUE(std::abs(200 - encoder.GetRate()) < 0.1);