mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Clean up unit UDL usage (#6961)
This commit is contained in:
@@ -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};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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{});
|
||||
}
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user