mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[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:
@@ -122,7 +122,11 @@ T RKDP(F&& f, T x, U u, units::second_t dt, double maxError = 1e-6) {
|
||||
(b1[6] - b2[6]) * k7))
|
||||
.norm();
|
||||
|
||||
h *= 0.9 * std::pow(maxError / truncationError, 1.0 / 5.0);
|
||||
if (truncationError == 0.0) {
|
||||
h = dt.value() - dtElapsed;
|
||||
} else {
|
||||
h *= 0.9 * std::pow(maxError / truncationError, 1.0 / 5.0);
|
||||
}
|
||||
} while (truncationError > maxError);
|
||||
|
||||
dtElapsed += h;
|
||||
|
||||
Reference in New Issue
Block a user