Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid division by zero in python #982

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions pathplannerlib-python/pathplannerlib/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,13 @@ def _forwardAccelPass(states: List[PathPlannerTrajectoryState], config: RobotCon
for m in range(config.numModules):
prevRotDelta = state.moduleStates[m].angle - prevState.moduleStates[m].angle
modVel = state.moduleStates[m].speed
dt = nextState.moduleStates[m].deltaPos / modVel
if modVel != 0.0:
dt = nextState.moduleStates[m].deltaPos / modVel

if math.isfinite(dt):
realMaxDT = max(realMaxDT, dt)
if abs(prevRotDelta.degrees()) < 60:
maxDT = max(maxDT, dt)
if math.isfinite(dt):
realMaxDT = max(realMaxDT, dt)
if abs(prevRotDelta.degrees()) < 60:
maxDT = max(maxDT, dt)

if maxDT == 0.0:
maxDT = realMaxDT
Expand Down Expand Up @@ -674,13 +675,14 @@ def _reverseAccelPass(states: List[PathPlannerTrajectoryState], config: RobotCon
for m in range(config.numModules):
prevRotDelta = state.moduleStates[m].angle - states[i - 1].moduleStates[m].angle
modVel = state.moduleStates[m].speed
dt = nextState.moduleStates[m].deltaPos / modVel
if modVel != 0.0:
dt = nextState.moduleStates[m].deltaPos / modVel

if math.isfinite(dt):
realMaxDT = max(realMaxDT, dt)
if math.isfinite(dt):
realMaxDT = max(realMaxDT, dt)

if abs(prevRotDelta.degrees()) < 60:
maxDT = max(maxDT, dt)
if abs(prevRotDelta.degrees()) < 60:
maxDT = max(maxDT, dt)

if maxDT == 0.0:
maxDT = realMaxDT
Expand Down
Loading