mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
[wpilib] Use RKDP in DifferentialDrivetrainSim (#5931)
This commit is contained in:
@@ -58,7 +58,7 @@ void DifferentialDrivetrainSim::SetGearing(double newGearing) {
|
||||
}
|
||||
|
||||
void DifferentialDrivetrainSim::Update(units::second_t dt) {
|
||||
m_x = RK4([this](auto& x, auto& u) { return Dynamics(x, u); }, m_x, m_u, dt);
|
||||
m_x = RKDP([this](auto& x, auto& u) { return Dynamics(x, u); }, m_x, m_u, dt);
|
||||
m_y = m_x + frc::MakeWhiteNoiseVector<7>(m_measurementStdDevs);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ TEST(DifferentialDrivetrainSimTest, Convergence) {
|
||||
sim.Update(20_ms);
|
||||
|
||||
// Update ground truth.
|
||||
groundTruthX = frc::RK4(
|
||||
groundTruthX = frc::RKDP(
|
||||
[&sim](const auto& x, const auto& u) -> frc::Vectord<7> {
|
||||
return sim.Dynamics(x, u);
|
||||
},
|
||||
@@ -63,7 +63,7 @@ TEST(DifferentialDrivetrainSimTest, Convergence) {
|
||||
}
|
||||
|
||||
// 2 inch tolerance is OK since our ground truth is an approximation of the
|
||||
// ODE solution using RK4 anyway
|
||||
// ODE solution using RKDP anyway
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user