mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[wpimath] Fix dt type in C++ tests (#8179)
The UKF test was calling `.value()` on an implicit `units::millisecond_t` type assuming it was `units::second_t`. I normalized the rest of the dt declarations while I was at it.
This commit is contained in:
@@ -12,7 +12,7 @@ namespace frc {
|
||||
|
||||
TEST(DifferentialDriveAccelerationLimiterTest, LowLimits) {
|
||||
constexpr auto trackwidth = 0.9_m;
|
||||
constexpr auto dt = 5_ms;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
constexpr auto maxA = 2_mps_sq;
|
||||
constexpr auto maxAlpha = 2_rad_per_s_sq;
|
||||
|
||||
@@ -105,7 +105,7 @@ TEST(DifferentialDriveAccelerationLimiterTest, LowLimits) {
|
||||
|
||||
TEST(DifferentialDriveAccelerationLimiterTest, HighLimits) {
|
||||
constexpr auto trackwidth = 0.9_m;
|
||||
constexpr auto dt = 5_ms;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
|
||||
using Kv_t = decltype(1_V / 1_mps);
|
||||
using Ka_t = decltype(1_V / 1_mps_sq);
|
||||
@@ -173,7 +173,7 @@ TEST(DifferentialDriveAccelerationLimiterTest, HighLimits) {
|
||||
|
||||
TEST(DifferentialDriveAccelerationLimiterTest, SeparateMinMaxLowLimits) {
|
||||
constexpr auto trackwidth = 0.9_m;
|
||||
constexpr auto dt = 5_ms;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
constexpr auto minA = -1_mps_sq;
|
||||
constexpr auto maxA = 2_mps_sq;
|
||||
constexpr auto maxAlpha = 2_rad_per_s_sq;
|
||||
|
||||
@@ -20,7 +20,7 @@ TEST(DifferentialDriveFeedforwardTest, CalculateWithTrackwidth) {
|
||||
constexpr auto kVAngular = 1_V / 1_rad_per_s;
|
||||
constexpr auto kAAngular = 1_V / 1_rad_per_s_sq;
|
||||
constexpr auto trackwidth = 1_m;
|
||||
constexpr auto dt = 20_ms;
|
||||
constexpr units::second_t dt = 20_ms;
|
||||
|
||||
frc::DifferentialDriveFeedforward differentialDriveFeedforward{
|
||||
kVLinear, kALinear, kVAngular, kAAngular, trackwidth};
|
||||
@@ -54,7 +54,7 @@ TEST(DifferentialDriveFeedforwardTest, CalculateWithoutTrackwidth) {
|
||||
constexpr auto kALinear = 1_V / 1_mps_sq;
|
||||
constexpr auto kVAngular = 1_V / 1_mps;
|
||||
constexpr auto kAAngular = 1_V / 1_mps_sq;
|
||||
constexpr auto dt = 20_ms;
|
||||
constexpr units::second_t dt = 20_ms;
|
||||
|
||||
frc::DifferentialDriveFeedforward differentialDriveFeedforward{
|
||||
kVLinear, kALinear, kVAngular, kAAngular};
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
namespace frc {
|
||||
|
||||
TEST(ImplicitModelFollowerTest, SameModel) {
|
||||
constexpr auto dt = 5_ms;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
|
||||
using Kv_t = decltype(1_V / 1_mps);
|
||||
using Ka_t = decltype(1_V / 1_mps_sq);
|
||||
@@ -54,7 +54,7 @@ TEST(ImplicitModelFollowerTest, SameModel) {
|
||||
}
|
||||
|
||||
TEST(ImplicitModelFollowerTest, SlowerRefModel) {
|
||||
constexpr auto dt = 5_ms;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
|
||||
using Kv_t = decltype(1_V / 1_mps);
|
||||
using Ka_t = decltype(1_V / 1_mps_sq);
|
||||
|
||||
@@ -31,10 +31,10 @@ TEST(LinearQuadraticRegulatorTest, ElevatorGains) {
|
||||
return frc::LinearSystemId::ElevatorSystem(motors, m, r, G).Slice(0);
|
||||
}();
|
||||
Matrixd<1, 2> K =
|
||||
LinearQuadraticRegulator<2, 1>{plant, {0.02, 0.4}, {12.0}, 5.05_ms}.K();
|
||||
LinearQuadraticRegulator<2, 1>{plant, {0.02, 0.4}, {12.0}, 5_ms}.K();
|
||||
|
||||
EXPECT_NEAR(522.15314269, K(0, 0), 1e-6);
|
||||
EXPECT_NEAR(38.20138596, K(0, 1), 1e-6);
|
||||
EXPECT_NEAR(522.87006795347486, K(0, 0), 1e-6);
|
||||
EXPECT_NEAR(38.239878385020411, K(0, 1), 1e-6);
|
||||
}
|
||||
|
||||
TEST(LinearQuadraticRegulatorTest, ArmGains) {
|
||||
@@ -56,11 +56,11 @@ TEST(LinearQuadraticRegulatorTest, ArmGains) {
|
||||
}();
|
||||
|
||||
Matrixd<1, 2> K =
|
||||
LinearQuadraticRegulator<2, 1>{plant, {0.01745, 0.08726}, {12.0}, 5.05_ms}
|
||||
LinearQuadraticRegulator<2, 1>{plant, {0.01745, 0.08726}, {12.0}, 5_ms}
|
||||
.K();
|
||||
|
||||
EXPECT_NEAR(19.16, K(0, 0), 1e-1);
|
||||
EXPECT_NEAR(3.32, K(0, 1), 1e-1);
|
||||
EXPECT_NEAR(19.339349883583761, K(0, 0), 1e-6);
|
||||
EXPECT_NEAR(3.3542559517421582, K(0, 1), 1e-6);
|
||||
}
|
||||
|
||||
TEST(LinearQuadraticRegulatorTest, FourMotorElevator) {
|
||||
|
||||
@@ -61,7 +61,7 @@ frc::Vectord<5> GlobalMeasurementModel(
|
||||
} // namespace
|
||||
|
||||
TEST(ExtendedKalmanFilterTest, Init) {
|
||||
constexpr auto dt = 0.00505_s;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
|
||||
frc::ExtendedKalmanFilter<5, 2, 3> observer{Dynamics,
|
||||
LocalMeasurementModel,
|
||||
@@ -80,7 +80,7 @@ TEST(ExtendedKalmanFilterTest, Init) {
|
||||
}
|
||||
|
||||
TEST(ExtendedKalmanFilterTest, Convergence) {
|
||||
constexpr auto dt = 0.00505_s;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
constexpr auto rb = 0.8382_m / 2.0; // Robot radius
|
||||
|
||||
frc::ExtendedKalmanFilter<5, 2, 3> observer{Dynamics,
|
||||
|
||||
@@ -68,7 +68,7 @@ frc::Vectord<5> DriveGlobalMeasurementModel(
|
||||
}
|
||||
|
||||
TEST(UnscentedKalmanFilterTest, DriveInit) {
|
||||
constexpr auto dt = 5_ms;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
|
||||
frc::UnscentedKalmanFilter<5, 2, 3> observer{DriveDynamics,
|
||||
DriveLocalMeasurementModel,
|
||||
@@ -94,7 +94,7 @@ TEST(UnscentedKalmanFilterTest, DriveInit) {
|
||||
}
|
||||
|
||||
TEST(UnscentedKalmanFilterTest, DriveConvergence) {
|
||||
constexpr auto dt = 5_ms;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
constexpr auto rb = 0.8382_m / 2.0; // Robot radius
|
||||
|
||||
frc::UnscentedKalmanFilter<5, 2, 3> observer{DriveDynamics,
|
||||
@@ -206,7 +206,7 @@ TEST(UnscentedKalmanFilterTest, LinearUKF) {
|
||||
}
|
||||
|
||||
TEST(UnscentedKalmanFilterTest, RoundTripP) {
|
||||
constexpr auto dt = 5_ms;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
|
||||
frc::UnscentedKalmanFilter<2, 2, 2> observer{
|
||||
[](const frc::Vectord<2>& x, const frc::Vectord<2>& u) { return x; },
|
||||
|
||||
@@ -56,7 +56,7 @@ TEST(DiscretizationTest, DiscretizeSlowModelAQ) {
|
||||
frc::Matrixd<2, 2> contA{{0, 1}, {0, 0}};
|
||||
frc::Matrixd<2, 2> contQ{{1, 0}, {0, 1}};
|
||||
|
||||
constexpr auto dt = 1_s;
|
||||
constexpr units::second_t dt = 1_s;
|
||||
|
||||
// T
|
||||
// Q_d ≈ ∫ e^(Aτ) Q e^(Aᵀτ) dτ
|
||||
@@ -88,7 +88,7 @@ TEST(DiscretizationTest, DiscretizeFastModelAQ) {
|
||||
frc::Matrixd<2, 2> contA{{0, 1}, {0, -1406.29}};
|
||||
frc::Matrixd<2, 2> contQ{{0.0025, 0}, {0, 1}};
|
||||
|
||||
constexpr auto dt = 5_ms;
|
||||
constexpr units::second_t dt = 5_ms;
|
||||
|
||||
// T
|
||||
// Q_d = ∫ e^(Aτ) Q e^(Aᵀτ) dτ
|
||||
|
||||
Reference in New Issue
Block a user