Skip to content

Commit

Permalink
Fix potential division by zero when calculating FF (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansen4857 authored Jan 27, 2025
1 parent 47a765f commit 4fb3a1c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pathplannerlib-python/pathplannerlib/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __init__(self, path: Union[PathPlannerPath, None], starting_speeds: Union[Ch
v0 = prevState.linearVelocity
v = state.linearVelocity
sumV = v + v0
if abs(sumV) < 1e-6:
if abs(sumV) < 1e-6 or abs(state.deltaPos) < 1e-6:
state.timeSeconds = prevState.timeSeconds
if i != 1:
prevState.feedforwards = self._states[i - 2].feedforwards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public PathPlannerTrajectory(
double v0 = prevState.linearVelocity;
double v = state.linearVelocity;
double sumV = v + v0;
if (Math.abs(sumV) < 1e-6) {
if (Math.abs(sumV) < 1e-6 || Math.abs(state.deltaPos) < 1e-6) {
state.timeSeconds = prevState.timeSeconds;
if (i != 1) {
prevState.feedforwards = states.get(i - 2).feedforwards;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ PathPlannerTrajectory::PathPlannerTrajectory(
units::meters_per_second_t v0 = prevState.linearVelocity;
units::meters_per_second_t v = state.linearVelocity;
units::meters_per_second_t sumV = v + v0;
if (units::math::abs(sumV) < 1e-6_mps) {
if (units::math::abs(sumV) < 1e-6_mps
|| units::math::abs(state.deltaPos) < 1e-6_m) {
state.time = prevState.time;
if (i != 1) {
prevState.feedforwards = m_states[i - 2].feedforwards;
Expand Down

0 comments on commit 4fb3a1c

Please sign in to comment.