Package me.nabdev.pathfinding
Class Pathfinder
java.lang.Object
me.nabdev.pathfinding.Pathfinder
The main pathfinder class, and the only one you should need to interact with.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Determines how vertices will be snapped to the nearest obstacle edge if they are inside of an obstacle. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPathfinder
(FieldLoader.FieldData field, double pointSpacing, double cornerPointSpacing, double cornerDist, double clearance, double cornerSplitPercent, boolean injectPoints, boolean normalizeCorners, SearchAlgorithm.SearchAlgorithmType searchAlgorithmType, boolean profiling, double endgameTime) Create a new pathfinder. -
Method Summary
Modifier and TypeMethodDescriptionfinal double
How far to inflate obstaclesgeneratePath
(edu.wpi.first.math.geometry.Pose2d start, edu.wpi.first.math.geometry.Pose2d target) Snaps the start and target poses to be outside of obstacles and generates the best path.generatePath
(edu.wpi.first.math.geometry.Pose2d start, edu.wpi.first.math.geometry.Pose2d target, Pathfinder.PathfindSnapMode snapMode) Snaps the start and target poses according to the snap mode and generates the best path.generatePath
(edu.wpi.first.math.geometry.Pose2d start, ArrayList<edu.wpi.first.math.geometry.Pose2d> target) Snaps the start and target vertices to be outside of obstacles and generates the best path that passes through all waypoints.generatePath
(Vertex start, Vertex target) Snaps the start and target vertices to be outside of obstacles and generates the best path.generatePath
(Vertex start, Vertex target, Pathfinder.PathfindSnapMode snapMode) Snaps the start and target vertices according to the snap mode and generates the best path.generatePath
(Vertex start, Vertex target, Pathfinder.PathfindSnapMode snapMode, ArrayList<Vertex> dynamicVertices) Snaps the start and target vertices according to the snap mode, calculates visibility graph for dynamic elements, and generates the best path.edu.wpi.first.math.trajectory.Trajectory
generateTrajectory
(edu.wpi.first.math.geometry.Pose2d start, edu.wpi.first.math.geometry.Pose2d target, edu.wpi.first.math.trajectory.TrajectoryConfig config) Snaps the start and target vertices to be outside of obstacles and generates the best path as a wpilib trajectory.edu.wpi.first.math.trajectory.Trajectory
generateTrajectory
(edu.wpi.first.math.geometry.Pose2d start, edu.wpi.first.math.geometry.Pose2d target, Pathfinder.PathfindSnapMode snapMode, edu.wpi.first.math.trajectory.TrajectoryConfig config) Snaps the start and target vertices according to the snap mode and generates the best path a wpilib trajectory.edu.wpi.first.math.trajectory.Trajectory
generateTrajectory
(edu.wpi.first.math.geometry.Pose2d start, edu.wpi.first.math.geometry.Pose2d target, Pathfinder.PathfindSnapMode snapMode, ArrayList<Vertex> dynamicVertices, edu.wpi.first.math.trajectory.TrajectoryConfig config) Snaps the start and target vertices according to the snap mode, calculates visibility graph for dynamic elements, and generates the best path as a wpilib trajectory.edu.wpi.first.math.trajectory.Trajectory
generateTrajectory
(edu.wpi.first.math.geometry.Pose2d start, ArrayList<edu.wpi.first.math.geometry.Pose2d> target, edu.wpi.first.math.trajectory.TrajectoryConfig config) Snaps the start and target vertices to be outside of obstacles and generates the best path that passes through all waypoints as a wpilib trajectory.edu.wpi.first.math.trajectory.Trajectory
generateTrajectory
(edu.wpi.first.math.geometry.Pose2d start, ArrayList<edu.wpi.first.math.geometry.Pose2d> target, Pathfinder.PathfindSnapMode snapMode, edu.wpi.first.math.trajectory.TrajectoryConfig config) Snaps the start and target vertices accoridng to the snap mode the best path that passes through all waypoints as a wpilib trajectory.double
How far back along the straightaway to dedicate to making cornersdouble
Space between points on corners of the path (percent of the curve length)double
How far each corner should move towards the other point if the distance is too short to allow both corners the full corner distancestatic double
Time in seconds when the robot should start to consider endgame obstacles.boolean
Whether or not to inject points on straightawaysboolean
Whether or not to normalize distance between corner pointsdouble
Space between injected points on straightaways in the path (meters)boolean
Whether or not to profile the pathfinding processThe search algorithm to usevoid
periodic()
Updates the modifier cache based on data from the driver station and wpilib.void
setCornerDist
(double newCornerDist) How far back along the straightaway to dedicate to making cornersvoid
setCornerPointSpacing
(double newCornerPointSpacing) Space between points on corners of the path (percent of the curve length)void
setCornerSplitPercent
(double newCornerSplitPercent) How far each corner should move towards the other point if the distance is too short to allow both corners the full corner distancestatic void
setEndgameTime
(double newEndgameTime) Time in seconds when the robot should start to consider endgame obstacles.void
setInjectPoints
(boolean newInjectPoints) Whether or not to inject points on straightawaysvoid
setNormalizeCorners
(boolean newNormalizeCorners) Whether or not to normalize distance between corner pointsvoid
setPointSpacing
(double newPointSpacing) Space between injected points on straightaways in the path (meters)void
setProfiling
(boolean newProfiling) Whether or not to profile the pathfinding processvoid
setSearchAlgorithmType
(SearchAlgorithm.SearchAlgorithmType newSearchAlgorithm) The search algorithm to useIntended for use with our custom advantagescope fork for debugging new fields.Intended for use with our custom advantagescope fork for debugging new fields.Intended for use with our custom advantagescope fork for debugging the visibility graph.Intended for use with our custom advantagescope fork for debugging the visibility graph.Intended for use with our custom advantagescope fork for debugging new fields.
-
Field Details
-
map
The map this pathfinder will use
-
-
Constructor Details
-
Pathfinder
public Pathfinder(FieldLoader.FieldData field, double pointSpacing, double cornerPointSpacing, double cornerDist, double clearance, double cornerSplitPercent, boolean injectPoints, boolean normalizeCorners, SearchAlgorithm.SearchAlgorithmType searchAlgorithmType, boolean profiling, double endgameTime) Create a new pathfinder. Should only be done once, at the start of the program.- Parameters:
field
- The field json object to usepointSpacing
- The distance between points on the straightawayscornerPointSpacing
- The distance between points on the cornerscornerDist
- How far back along the straightaway to dedicate to cornersclearance
- The clearance to use when inflating obstaclescornerSplitPercent
- How far back along the straightaway to dedicate to a corner when the straightaway is too small to fit both corners (percentage, should be less than 0.5)injectPoints
- Whether or not to inject points on straightawaysnormalizeCorners
- Whether or not to normalize distance between corner pointssearchAlgorithmType
- The search algorithm to useprofiling
- Whether or not to profile the pathfinding processendgameTime
- The time in seconds when the robot should start to consider endgame obstacles
-
-
Method Details
-
periodic
public void periodic()Updates the modifier cache based on data from the driver station and wpilib. Should be called in robotPeriodic. -
generatePath
public Path generatePath(Vertex start, Vertex target, Pathfinder.PathfindSnapMode snapMode, ArrayList<Vertex> dynamicVertices) throws ImpossiblePathException Snaps the start and target vertices according to the snap mode, calculates visibility graph for dynamic elements, and generates the best path.- Parameters:
start
- The starting vertextarget
- The target vertexsnapMode
- The snap mode to usedynamicVertices
- An ArrayList of dynamic vertices- Returns:
- The shortest path from the starting vertex to the target vertex that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
generatePath
Snaps the start and target vertices to be outside of obstacles and generates the best path. Defaults to PathfindSnapMode.SNAP_ALL- Parameters:
start
- The starting vertextarget
- The target vertex- Returns:
- The shortest path from the starting vertex to the target vertex that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
generatePath
public Path generatePath(edu.wpi.first.math.geometry.Pose2d start, edu.wpi.first.math.geometry.Pose2d target) throws ImpossiblePathException Snaps the start and target poses to be outside of obstacles and generates the best path. Defaults to PathfindSnapMode.SNAP_ALL- Parameters:
start
- The starting posestarget
- The target poses- Returns:
- The shortest path from the starting vertex to the target vertex that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
generatePath
public Path generatePath(Vertex start, Vertex target, Pathfinder.PathfindSnapMode snapMode) throws ImpossiblePathException Snaps the start and target vertices according to the snap mode and generates the best path.- Parameters:
start
- The starting vertextarget
- The target vertexsnapMode
- The snap mode to use- Returns:
- The shortest path from the starting vertex to the target vertex that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
generatePath
public Path generatePath(edu.wpi.first.math.geometry.Pose2d start, edu.wpi.first.math.geometry.Pose2d target, Pathfinder.PathfindSnapMode snapMode) throws ImpossiblePathException Snaps the start and target poses according to the snap mode and generates the best path.- Parameters:
start
- The starting posetarget
- The target posesnapMode
- The snap mode to use- Returns:
- The shortest path from the starting pose to the target pose that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
generatePath
public Path generatePath(edu.wpi.first.math.geometry.Pose2d start, ArrayList<edu.wpi.first.math.geometry.Pose2d> target) throws ImpossiblePathException Snaps the start and target vertices to be outside of obstacles and generates the best path that passes through all waypoints. Defaults to PathfindSnapMode.SNAP_ALL- Parameters:
start
- The starting posetarget
- The target waypoints- Returns:
- A trajectory from the starting vertex passing through all waypoints that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
generateTrajectory
public edu.wpi.first.math.trajectory.Trajectory generateTrajectory(edu.wpi.first.math.geometry.Pose2d start, edu.wpi.first.math.geometry.Pose2d target, Pathfinder.PathfindSnapMode snapMode, edu.wpi.first.math.trajectory.TrajectoryConfig config) throws ImpossiblePathException Snaps the start and target vertices according to the snap mode and generates the best path a wpilib trajectory.- Parameters:
start
- The starting posetarget
- The target posesnapMode
- The snap mode to useconfig
- The trajectory config to use when generating the trajectory- Returns:
- A trajectory from the starting vertex to the target vertex that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
generateTrajectory
public edu.wpi.first.math.trajectory.Trajectory generateTrajectory(edu.wpi.first.math.geometry.Pose2d start, edu.wpi.first.math.geometry.Pose2d target, Pathfinder.PathfindSnapMode snapMode, ArrayList<Vertex> dynamicVertices, edu.wpi.first.math.trajectory.TrajectoryConfig config) throws ImpossiblePathException Snaps the start and target vertices according to the snap mode, calculates visibility graph for dynamic elements, and generates the best path as a wpilib trajectory.- Parameters:
start
- The starting posetarget
- The target posesnapMode
- The snap mode to usedynamicVertices
- An ArrayList of dynamic verticesconfig
- The trajectory config to use when generating the trajectory- Returns:
- A trajectory from the starting vertex to the target vertex that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
generateTrajectory
public edu.wpi.first.math.trajectory.Trajectory generateTrajectory(edu.wpi.first.math.geometry.Pose2d start, edu.wpi.first.math.geometry.Pose2d target, edu.wpi.first.math.trajectory.TrajectoryConfig config) throws ImpossiblePathException Snaps the start and target vertices to be outside of obstacles and generates the best path as a wpilib trajectory. Defaults to PathfindSnapMode.SNAP_ALL- Parameters:
start
- The starting posetarget
- The target poseconfig
- The trajectory config to use when generating the trajectory- Returns:
- A trajectory from the starting vertex to the target vertex that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
generateTrajectory
public edu.wpi.first.math.trajectory.Trajectory generateTrajectory(edu.wpi.first.math.geometry.Pose2d start, ArrayList<edu.wpi.first.math.geometry.Pose2d> target, edu.wpi.first.math.trajectory.TrajectoryConfig config) throws ImpossiblePathException Snaps the start and target vertices to be outside of obstacles and generates the best path that passes through all waypoints as a wpilib trajectory. Defaults to PathfindSnapMode.SNAP_ALL- Parameters:
start
- The starting posetarget
- The target poseconfig
- The trajectory config to use when generating the trajectory- Returns:
- A trajectory from the starting vertex passing through all waypoints that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
generateTrajectory
public edu.wpi.first.math.trajectory.Trajectory generateTrajectory(edu.wpi.first.math.geometry.Pose2d start, ArrayList<edu.wpi.first.math.geometry.Pose2d> target, Pathfinder.PathfindSnapMode snapMode, edu.wpi.first.math.trajectory.TrajectoryConfig config) throws ImpossiblePathException Snaps the start and target vertices accoridng to the snap mode the best path that passes through all waypoints as a wpilib trajectory.- Parameters:
start
- The starting posetarget
- The target posesnapMode
- The snap mode to useconfig
- The trajectory config to use when generating the trajectory- Returns:
- A trajectory from the starting vertex passing through all waypoints that does not intersect any obstacles
- Throws:
ImpossiblePathException
- If no path can be found
-
visualizeNeighbors
Intended for use with our custom advantagescope fork for debugging the visibility graph.- Returns:
- An arraylist containing edges to represent all neighbors, showing the visibility graph
-
visualizePathVertices
Intended for use with our custom advantagescope fork for debugging the visibility graph.- Returns:
- An arraylist containing vertices to represent all vertices in the visibility graph. This is the same as visualizeVertices, but includes dynamic vertices like the start and end points.
-
visualizeEdges
Intended for use with our custom advantagescope fork for debugging new fields.- Returns:
- An arraylist containing edges to represent all defined field edges
-
visualizeVertices
Intended for use with our custom advantagescope fork for debugging new fields.- Returns:
- An arraylist containing vertices to represent all defined, uninflated obstacle vertices
-
visualizeInflatedVertices
Intended for use with our custom advantagescope fork for debugging new fields.- Returns:
- An arraylist containing vertices to represent all uninflated obstacle vertices
-
getPointSpacing
public double getPointSpacing()Space between injected points on straightaways in the path (meters)- Returns:
- The space between injected points on straightaways (meters)
-
getCornerPointSpacing
public double getCornerPointSpacing()Space between points on corners of the path (percent of the curve length)- Returns:
- The space between points on corners of the path (percent of the curve
-
getCornerDist
public double getCornerDist()How far back along the straightaway to dedicate to making corners- Returns:
- The distance back along the straightaway dedicated to making corners
-
clearance
public final double clearance()How far to inflate obstacles- Returns:
- The clearance to use when inflating obstacles
-
getInjectPoints
public boolean getInjectPoints()Whether or not to inject points on straightaways- Returns:
- Whether or not to inject points on straightaways
-
getNormalizeCorners
public boolean getNormalizeCorners()Whether or not to normalize distance between corner points- Returns:
- Whether or not to normalize distance between corner points
-
getCornerSplitPercent
public double getCornerSplitPercent()How far each corner should move towards the other point if the distance is too short to allow both corners the full corner distance- Returns:
- The corner split percentage
-
getSearchAlgorithmType
The search algorithm to use- Returns:
- The search algorithm to use
-
getProfiling
public boolean getProfiling()Whether or not to profile the pathfinding process- Returns:
- Whether or not to profile the pathfinding process
-
getEndgameTime
public static double getEndgameTime()Time in seconds when the robot should start to consider endgame obstacles.- Returns:
- The time in seconds when the robot should start to consider endgame
-
setPointSpacing
public void setPointSpacing(double newPointSpacing) Space between injected points on straightaways in the path (meters)- Parameters:
newPointSpacing
- The new space between injected points on straightaways (meters)
-
setCornerPointSpacing
public void setCornerPointSpacing(double newCornerPointSpacing) Space between points on corners of the path (percent of the curve length)- Parameters:
newCornerPointSpacing
- The new space between points on corners of the path (percent of the curve length)
-
setCornerDist
public void setCornerDist(double newCornerDist) How far back along the straightaway to dedicate to making corners- Parameters:
newCornerDist
- The new distance back along the straightaway dedicated to making corners
-
setInjectPoints
public void setInjectPoints(boolean newInjectPoints) Whether or not to inject points on straightaways- Parameters:
newInjectPoints
- Whether or not to inject points on straightaways
-
setNormalizeCorners
public void setNormalizeCorners(boolean newNormalizeCorners) Whether or not to normalize distance between corner points- Parameters:
newNormalizeCorners
- Whether or not to normalize distance between corner points
-
setCornerSplitPercent
public void setCornerSplitPercent(double newCornerSplitPercent) How far each corner should move towards the other point if the distance is too short to allow both corners the full corner distance- Parameters:
newCornerSplitPercent
- The new corner split percentage
-
setSearchAlgorithmType
The search algorithm to use- Parameters:
newSearchAlgorithm
- The new search algorithm to use
-
setProfiling
public void setProfiling(boolean newProfiling) Whether or not to profile the pathfinding process- Parameters:
newProfiling
- Whether or not to profile the pathfinding process
-
setEndgameTime
public static void setEndgameTime(double newEndgameTime) Time in seconds when the robot should start to consider endgame obstacles.- Parameters:
newEndgameTime
- The new time in seconds when the robot should start to consider endgame obstacles
-