mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Discard stale pose estimates (#5045)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
@@ -263,3 +263,31 @@ TEST(DifferentialDrivePoseEstimatorTest, SimultaneousVisionMeasurements) {
|
||||
EXPECT_TRUE(dx > 0.08_m || dy > 0.08_m || dtheta > 0.08_rad);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DifferentialDrivePoseEstimatorTest, TestDiscardStaleVisionMeasurements) {
|
||||
frc::DifferentialDriveKinematics kinematics{1_m};
|
||||
|
||||
frc::DifferentialDrivePoseEstimator estimator{
|
||||
kinematics, frc::Rotation2d{}, 0_m, 0_m, frc::Pose2d{},
|
||||
{0.1, 0.1, 0.1}, {0.45, 0.45, 0.45}};
|
||||
|
||||
// Add enough measurements to fill up the bufer
|
||||
for (auto time = 0.0_s; time < 4_s; time += 0.02_s) {
|
||||
estimator.UpdateWithTime(time, frc::Rotation2d{}, 0_m, 0_m);
|
||||
}
|
||||
|
||||
auto odometryPose = estimator.GetEstimatedPosition();
|
||||
|
||||
// Apply a vision measurement from 3 seconds ago
|
||||
estimator.AddVisionMeasurement(
|
||||
frc::Pose2d{frc::Translation2d{10_m, 10_m}, frc::Rotation2d{0.1_rad}},
|
||||
1_s, {0.1, 0.1, 0.1});
|
||||
|
||||
EXPECT_NEAR(odometryPose.X().value(),
|
||||
estimator.GetEstimatedPosition().X().value(), 1e-6);
|
||||
EXPECT_NEAR(odometryPose.Y().value(),
|
||||
estimator.GetEstimatedPosition().Y().value(), 1e-6);
|
||||
EXPECT_NEAR(odometryPose.Rotation().Radians().value(),
|
||||
estimator.GetEstimatedPosition().Rotation().Radians().value(),
|
||||
1e-6);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user