Skip to content

Commit

Permalink
prevent possible pathfinding crash (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansen4857 authored Jan 16, 2024
1 parent 07ff0d6 commit 78917be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pathplannerlib-python/pathplannerlib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def initialize(self):
if self._shouldFlipPath():
self._targetPose = flipFieldPose(self._targetPose)

if currentPose.translation().distance(self._targetPose.translation()) < 0.35:
if currentPose.translation().distance(self._targetPose.translation()) < 0.5:
self._output(ChassisSpeeds())
self.cancel()
else:
Pathfinding.setStartPosition(currentPose.translation())
Expand Down Expand Up @@ -383,7 +384,7 @@ def execute(self):
# Find the two closest states in front of and behind robot
closestState1Idx = 0
closestState2Idx = 1
while True:
while closestState2Idx < len(self._currentTrajectory.getStates()) - 1:
closest2Dist = self._currentTrajectory.getState(closestState2Idx).positionMeters.distance(
currentPose.translation())
nextDist = self._currentTrajectory.getState(closestState2Idx + 1).positionMeters.distance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public void initialize() {
}
}

if (currentPose.getTranslation().getDistance(targetPose.getTranslation()) < 0.35) {
if (currentPose.getTranslation().getDistance(targetPose.getTranslation()) < 0.5) {
output.accept(new ChassisSpeeds());
this.cancel();
} else {
Pathfinding.setStartPosition(currentPose.getTranslation());
Expand Down Expand Up @@ -207,7 +208,7 @@ public void execute() {
// Find the two closest states in front of and behind robot
int closestState1Idx = 0;
int closestState2Idx = 1;
while (true) {
while (closestState2Idx < currentTrajectory.getStates().size() - 1) {
double closest2Dist =
currentTrajectory
.getState(closestState2Idx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ void PathfindingCommand::Initialize() {
}

if (currentPose.Translation().Distance(m_targetPose.Translation())
< 0.35_m) {
< 0.5_m) {
m_output(frc::ChassisSpeeds());
Cancel();
} else {
Pathfinding::setStartPosition(currentPose.Translation());
Expand Down Expand Up @@ -126,7 +127,7 @@ void PathfindingCommand::Execute() {
// Find the two closest states in front of and behind robot
size_t closestState1Idx = 0;
size_t closestState2Idx = 1;
while (true) {
while (closestState2Idx < m_currentTrajectory.getStates().size() - 1) {
auto closest2Dist = m_currentTrajectory.getState(
closestState2Idx).position.Distance(
currentPose.Translation());
Expand Down

0 comments on commit 78917be

Please sign in to comment.