Clean up unit UDL usage (#6961)

This commit is contained in:
Tyler Veness
2024-08-14 10:44:00 -07:00
committed by GitHub
parent 70fa41c69e
commit 8e0d9ac805
25 changed files with 57 additions and 77 deletions

View File

@@ -25,8 +25,8 @@ TEST(ControlAffinePlantInversionFeedforwardTest, Calculate) {
std::function<Vectord<2>(const Vectord<2>&, const Vectord<1>&)>
modelDynamics = [](auto& x, auto& u) { return Dynamics(x, u); };
frc::ControlAffinePlantInversionFeedforward<2, 1> feedforward{
modelDynamics, units::second_t{0.02}};
frc::ControlAffinePlantInversionFeedforward<2, 1> feedforward{modelDynamics,
20_ms};
Vectord<2> r{2, 2};
Vectord<2> nextR{3, 3};

View File

@@ -36,7 +36,7 @@ TEST(HolonomicDriveControllerTest, ReachesReference) {
auto trajectory = frc::TrajectoryGenerator::GenerateTrajectory(
waypoints, {8.0_mps, 4.0_mps_sq});
constexpr auto kDt = 0.02_s;
constexpr units::second_t kDt = 20_ms;
auto totalTime = trajectory.TotalTime();
for (size_t i = 0; i < (totalTime / kDt).value(); ++i) {
auto state = trajectory.Sample(kDt * i);

View File

@@ -62,7 +62,7 @@ frc::Vectord<5> Dynamics(const frc::Vectord<5>& x, const frc::Vectord<2>& u) {
}
TEST(LTVDifferentialDriveControllerTest, ReachesReference) {
constexpr auto kDt = 0.02_s;
constexpr units::second_t kDt = 20_ms;
frc::LTVDifferentialDriveController controller{
plant, kTrackwidth, {0.0625, 0.125, 2.5, 0.95, 0.95}, {12.0, 12.0}, kDt};

View File

@@ -17,7 +17,7 @@ static constexpr units::radian_t kAngularTolerance{2.0 * std::numbers::pi /
180.0};
TEST(LTVUnicycleControllerTest, ReachesReference) {
constexpr auto kDt = 0.02_s;
constexpr units::second_t kDt = 20_ms;
frc::LTVUnicycleController controller{{0.0625, 0.125, 2.5}, {4.0, 4.0}, kDt};
frc::Pose2d robotPose{2.7_m, 23_m, 0_deg};

View File

@@ -180,9 +180,9 @@ TEST(LinearQuadraticRegulatorTest, LatencyCompensate) {
return frc::LinearSystemId::ElevatorSystem(motors, m, r, G).Slice(0);
}();
LinearQuadraticRegulator<2, 1> controller{plant, {0.1, 0.2}, {12.0}, 0.02_s};
LinearQuadraticRegulator<2, 1> controller{plant, {0.1, 0.2}, {12.0}, 20_ms};
controller.LatencyCompensate(plant, 0.02_s, 0.01_s);
controller.LatencyCompensate(plant, 20_ms, 10_ms);
EXPECT_NEAR(8.97115941, controller.K(0, 0), 1e-3);
EXPECT_NEAR(0.07904881, controller.K(0, 1), 1e-3);

View File

@@ -29,7 +29,7 @@ TEST(RamseteControllerTest, ReachesReference) {
auto trajectory = frc::TrajectoryGenerator::GenerateTrajectory(
waypoints, {8.8_mps, 0.1_mps_sq});
constexpr auto kDt = 0.02_s;
constexpr units::second_t kDt = 20_ms;
auto totalTime = trajectory.TotalTime();
for (size_t i = 0; i < (totalTime / kDt).value(); ++i) {
auto state = trajectory.Sample(kDt * i);

View File

@@ -167,8 +167,8 @@ TEST(DifferentialDrivePoseEstimatorTest, Accuracy) {
state.velocity * state.curvature};
},
[&](frc::Trajectory::State& state) { return state.pose; },
trajectory.InitialPose(), {0_m, 0_m, frc::Rotation2d{45_deg}}, 0.02_s,
0.1_s, 0.25_s, true, false);
trajectory.InitialPose(), {0_m, 0_m, frc::Rotation2d{45_deg}}, 20_ms,
100_ms, 250_ms, true, false);
}
TEST(DifferentialDrivePoseEstimatorTest, BadInitialPose) {
@@ -205,8 +205,8 @@ TEST(DifferentialDrivePoseEstimatorTest, BadInitialPose) {
state.velocity * state.curvature};
},
[&](frc::Trajectory::State& state) { return state.pose; },
initial_pose, {0_m, 0_m, frc::Rotation2d{45_deg}}, 0.02_s, 0.1_s,
0.25_s, false, false);
initial_pose, {0_m, 0_m, frc::Rotation2d{45_deg}}, 20_ms, 100_ms,
250_ms, false, false);
}
}
}
@@ -275,7 +275,7 @@ TEST(DifferentialDrivePoseEstimatorTest, TestDiscardStaleVisionMeasurements) {
{0.1, 0.1, 0.1}, {0.45, 0.45, 0.45}};
// Add enough measurements to fill up the buffer
for (auto time = 0.0_s; time < 4_s; time += 0.02_s) {
for (auto time = 0_s; time < 4_s; time += 20_ms) {
estimator.UpdateWithTime(time, frc::Rotation2d{}, 0_m, 0_m);
}

View File

@@ -162,8 +162,8 @@ TEST(MecanumDrivePoseEstimatorTest, AccuracyFacingTrajectory) {
state.velocity * state.curvature};
},
[&](frc::Trajectory::State& state) { return state.pose; },
trajectory.InitialPose(), {0_m, 0_m, frc::Rotation2d{45_deg}}, 0.02_s,
0.1_s, 0.25_s, true, false);
trajectory.InitialPose(), {0_m, 0_m, frc::Rotation2d{45_deg}}, 20_ms,
100_ms, 250_ms, true, false);
}
TEST(MecanumDrivePoseEstimatorTest, BadInitialPose) {
@@ -204,8 +204,8 @@ TEST(MecanumDrivePoseEstimatorTest, BadInitialPose) {
state.velocity * state.curvature};
},
[&](frc::Trajectory::State& state) { return state.pose; },
initial_pose, {0_m, 0_m, frc::Rotation2d{45_deg}}, 0.02_s, 0.1_s,
0.25_s, false, false);
initial_pose, {0_m, 0_m, frc::Rotation2d{45_deg}}, 20_ms, 100_ms,
250_ms, false, false);
}
}
}
@@ -276,7 +276,7 @@ TEST(MecanumDrivePoseEstimatorTest, TestDiscardStaleVisionMeasurements) {
frc::Pose2d{}, {0.1, 0.1, 0.1}, {0.45, 0.45, 0.45}};
// Add enough measurements to fill up the buffer
for (auto time = 0.0_s; time < 4_s; time += 0.02_s) {
for (auto time = 0_s; time < 4_s; time += 20_ms) {
estimator.UpdateWithTime(time, frc::Rotation2d{},
frc::MecanumDriveWheelPositions{});
}

View File

@@ -169,7 +169,7 @@ TEST(SwerveDrivePoseEstimatorTest, AccuracyFacingTrajectory) {
},
[&](frc::Trajectory::State& state) { return state.pose; },
{0_m, 0_m, frc::Rotation2d{45_deg}}, {0_m, 0_m, frc::Rotation2d{45_deg}},
0.02_s, 0.1_s, 0.25_s, true, false);
20_ms, 100_ms, 250_ms, true, false);
}
TEST(SwerveDrivePoseEstimatorTest, BadInitialPose) {
@@ -213,8 +213,8 @@ TEST(SwerveDrivePoseEstimatorTest, BadInitialPose) {
state.velocity * state.curvature};
},
[&](frc::Trajectory::State& state) { return state.pose; },
initial_pose, {0_m, 0_m, frc::Rotation2d{45_deg}}, 0.02_s, 0.1_s,
0.25_s, false, false);
initial_pose, {0_m, 0_m, frc::Rotation2d{45_deg}}, 20_ms, 100_ms,
250_ms, false, false);
}
}
}
@@ -293,7 +293,7 @@ TEST(SwerveDrivePoseEstimatorTest, TestDiscardStaleVisionMeasurements) {
frc::Pose2d{}, {0.1, 0.1, 0.1}, {0.45, 0.45, 0.45}};
// Add enough measurements to fill up the buffer
for (auto time = 0.0_s; time < 4_s; time += 0.02_s) {
for (auto time = 0_s; time < 4_s; time += 20_ms) {
estimator.UpdateWithTime(time, frc::Rotation2d{}, {fl, fr, bl, br});
}

View File

@@ -97,7 +97,7 @@ TEST_F(MecanumDriveOdometryTest, AccuracyFacingTrajectory) {
std::default_random_engine generator;
std::normal_distribution<double> distribution(0.0, 1.0);
units::second_t dt = 0.02_s;
units::second_t dt = 20_ms;
units::second_t t = 0_s;
double maxError = -std::numeric_limits<double>::max();
@@ -160,7 +160,7 @@ TEST_F(MecanumDriveOdometryTest, AccuracyFacingXAxis) {
std::default_random_engine generator;
std::normal_distribution<double> distribution(0.0, 1.0);
units::second_t dt = 0.02_s;
units::second_t dt = 20_ms;
units::second_t t = 0_s;
double maxError = -std::numeric_limits<double>::max();

View File

@@ -93,7 +93,7 @@ TEST_F(SwerveDriveOdometryTest, AccuracyFacingTrajectory) {
std::default_random_engine generator;
std::normal_distribution<double> distribution(0.0, 1.0);
units::second_t dt = 0.02_s;
units::second_t dt = 20_ms;
units::second_t t = 0_s;
double maxError = -std::numeric_limits<double>::max();
@@ -157,7 +157,7 @@ TEST_F(SwerveDriveOdometryTest, AccuracyFacingXAxis) {
std::default_random_engine generator;
std::normal_distribution<double> distribution(0.0, 1.0);
units::second_t dt = 0.02_s;
units::second_t dt = 20_ms;
units::second_t t = 0_s;
double maxError = -std::numeric_limits<double>::max();

View File

@@ -9,17 +9,10 @@
using namespace frc;
namespace {
using ProtoType = wpi::Protobuf<frc::DCMotor>;
const DCMotor kExpectedData = DCMotor{units::volt_t{1.91},
units::newton_meter_t{19.1},
units::ampere_t{1.74},
units::ampere_t{2.29},
units::radians_per_second_t{2.2},
2};
} // namespace
inline constexpr DCMotor kExpectedData =
DCMotor{1.91_V, 19.1_Nm, 1.74_A, 2.29_A, 2.2_rad_per_s, 2};
TEST(DCMotorProtoTest, Roundtrip) {
google::protobuf::Arena arena;

View File

@@ -8,16 +8,10 @@
using namespace frc;
namespace {
using StructType = wpi::Struct<frc::DCMotor>;
const DCMotor kExpectedData = DCMotor{units::volt_t{1.91},
units::newton_meter_t{19.1},
units::ampere_t{1.74},
units::ampere_t{2.29},
units::radians_per_second_t{2.2},
2};
} // namespace
inline constexpr DCMotor kExpectedData =
DCMotor{1.91_V, 19.1_Nm, 1.74_A, 2.29_A, 2.2_rad_per_s, 2};
TEST(DCMotorStructTest, Roundtrip) {
uint8_t buffer[StructType::GetSize()];

View File

@@ -306,7 +306,7 @@ TEST(ExponentialProfileTest, TimingToGoal) {
for (int i = 0; i < 900; ++i) {
state = CheckDynamics(profile, constraints, feedforward, state, goal);
if (!reachedGoal && state == goal) {
EXPECT_NEAR_UNITS(prediction, i * 0.01_s, 0.25_s);
EXPECT_NEAR_UNITS(prediction, i * 10_ms, 250_ms);
reachedGoal = true;
}
}
@@ -329,7 +329,7 @@ TEST(ExponentialProfileTest, TimingToNegativeGoal) {
for (int i = 0; i < 900; ++i) {
state = CheckDynamics(profile, constraints, feedforward, state, goal);
if (!reachedGoal && state == goal) {
EXPECT_NEAR_UNITS(prediction, i * 0.01_s, 0.25_s);
EXPECT_NEAR_UNITS(prediction, i * 10_ms, 250_ms);
reachedGoal = true;
}
}