[wpimath] Fix potential divide-by-zero in RKDP (#5242)

If f(x, u) has no dynamics, the truncation error can be zero.
This commit is contained in:
Tyler Veness
2023-03-26 17:00:09 -07:00
committed by GitHub
parent 9227b2166e
commit 63512bbbb8
6 changed files with 36 additions and 4 deletions

View File

@@ -30,6 +30,16 @@ TEST(NumericalIntegrationTest, ExponentialWithU) {
EXPECT_NEAR(y1(0), std::exp(0.1) - std::exp(0), 1e-3);
}
// Tests that integrating dx/dt = 0 works with RKDP
TEST(NumericalIntegrationTest, ZeroRKDP) {
frc::Vectord<1> y1 = frc::RKDP(
[](const frc::Vectord<1>& x, const frc::Vectord<1>& u) {
return frc::Vectord<1>::Zero();
},
frc::Vectord<1>{0.0}, frc::Vectord<1>{0.0}, 0.1_s);
EXPECT_NEAR(y1(0), 0.0, 1e-3);
}
// Tests that integrating dx/dt = e^x works with RKDP
TEST(NumericalIntegrationTest, ExponentialRKDP) {
frc::Vectord<1> y0{0.0};