Skip to content

Commit f8481ec

Browse files
Update wpimath/src/main/native/include/frc/MathUtil.h
Co-authored-by: Joseph Eng <[email protected]>
1 parent 5852c95 commit f8481ec

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

wpimath/src/main/native/include/frc/MathUtil.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,11 @@ constexpr Translation2d SlewRateLimit(const Translation2d& current,
234234
if (dist < 1e-9_m) {
235235
return next;
236236
}
237-
units::meters_per_second_t velocity = units::math::min(dist / dt, maxVelocity);
238-
return current + diff * (velocity / dist).value();
237+
if (dist > maxVelocity * dt) {
238+
// Move maximum allowed amount in direction of the difference
239+
return current + maxVelocity * dt * diff / dist;
240+
}
241+
return next;
239242
}
240243

241244
/**

0 commit comments

Comments
 (0)