Skip to content

Commit

Permalink
Fix path snapping bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nab138 committed Feb 28, 2024
1 parent 018e6f6 commit a5be7c3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Pathfinding/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'me.nabdev.pathfinding'
version '0.9.19SNAPSHOT'
version '0.9.20'

java {
withSourcesJar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ public void periodic() {
if (shouldInvalidate) {
for (Obstacle obs : obstacles) {
obs.modifiers.invalidateCache();
obs.iHateProgramming();
}
map.calculateStaticNeighbors();
}
Expand Down Expand Up @@ -419,6 +418,7 @@ private Path generatePathInner(Vertex start, ArrayList<Vertex> waypoints, Pathfi
private Path generatePathInner(Vertex start, Vertex target, PathfindSnapMode snapMode,
ArrayList<Vertex> dynamicVertices, boolean processPath) throws ImpossiblePathException {
long startTime = System.nanoTime();
periodic();
// Snapping is done because the center of the robot can be inside of the
// inflated obstacle edges
// In the case where this happened the start needs to be snapped outside
Expand Down Expand Up @@ -492,8 +492,7 @@ private Path generatePathInner(Vertex start, Vertex target, PathfindSnapMode sna
* @return
*/
private Vertex snap(Vertex point) throws ImpossiblePathException {
ArrayList<Obstacle> targetObs = Obstacle.isRobotInObstacle(obstacles, point);
targetObs.removeIf(obs -> obs.modifiers.hasModifier(ObstacleModifierTypes.ZONE_MODIFIER));
ArrayList<Obstacle> targetObs = Obstacle.isRobotInObstacle(obstacles, point, true);
Vertex tempNearestVertex = point;
int i = 0;
while (targetObs.size() > 0) {
Expand All @@ -503,7 +502,7 @@ private Vertex snap(Vertex point) throws ImpossiblePathException {
for (Obstacle obs : targetObs) {
tempNearestVertex = obs.calculateNearestPointFromInside(tempNearestVertex);
}
targetObs = Obstacle.isRobotInObstacle(obstacles, tempNearestVertex);
targetObs = Obstacle.isRobotInObstacle(obstacles, tempNearestVertex, true);
i++;
}
return tempNearestVertex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public boolean isActive() {
boolean hasRequired = true;
for (ObstacleModifier mod : requiredModifiers) {
if (!mod.isActive())
isActive = false;
hasRequired = false;
}
boolean hasOptional = false;
for (ObstacleModifier mod : optionalModifiers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import org.json.JSONArray;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import me.nabdev.pathfinding.modifiers.ModifierCollection;
import me.nabdev.pathfinding.modifiers.ObstacleModifier.ObstacleModifierTypes;

Expand Down Expand Up @@ -300,11 +299,4 @@ public ArrayList<Vertex> getVertices() {
public ArrayList<Edge> getEdges() {
return edges;
}

public void iHateProgramming() {
if (id.contains("Barrier")) {
System.out.println("I hate programming");
SmartDashboard.putBoolean(id, modifiers.isActive());
}
}
}

0 comments on commit a5be7c3

Please sign in to comment.