Skip to content

Commit

Permalink
Update wpimath/src/main/native/include/frc/MathUtil.h
Browse files Browse the repository at this point in the history
Co-authored-by: Joseph Eng <[email protected]>
  • Loading branch information
OhmV-IR and KangarooKoala authored Feb 21, 2025
1 parent 5852c95 commit f8481ec
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions wpimath/src/main/native/include/frc/MathUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ constexpr Translation2d SlewRateLimit(const Translation2d& current,
if (dist < 1e-9_m) {
return next;
}
units::meters_per_second_t velocity = units::math::min(dist / dt, maxVelocity);
return current + diff * (velocity / dist).value();
if (dist > maxVelocity * dt) {
// Move maximum allowed amount in direction of the difference
return current + maxVelocity * dt * diff / dist;
}
return next;
}

/**
Expand Down

0 comments on commit f8481ec

Please sign in to comment.