Pathfinding
PathPlannerLib now includes a set of commands that will automatically plan a path between two points while avoiding obstacles on the field. They can also be used to generate a path to another path, allowing you to chain together a generated and pre-planned path for finer control.
A few important considerations to note before attempting to use these commands:
There must be a
navgrid.json
file present in yourdeploy/pathplanner
directory in order for the system to know where obstacles are. This file will be created automatically when opening the project in pathplanner. You can edit the navgrid in the GUI, but you probably shouldn't have to.You have no control of the robot's heading at the start and end points. In other words, you can't attempt to pathfind to a position to the left of the robot, but have it arrive at that point while moving to the right. The shortest path from A to B will be used.
Because of the above, this is more difficult to get great results with a differential drivetrain. It will still be possible, you just need to take more care with it. For example, doing a turn in place command if your robot is not facing the direction it will travel when pathfinding.
Even with a holonomic drive train, it's not that great at lining up with things (for example, a human player station) because of the heading restriction. This is why the ability to chain paths together exists. It is recommended to create a pre-planned path for doing the final line up with something, then pathfind to that path if precision is required.
The AD* algorithm used for pathfinding does not just produce one path, it produces a few as it further refines the path in the background. In some rare cases, the robot could start moving in one direction, then switch to the other direction when AD* figures out that direction is more optimal.
Compared to the normal path following commands, pathfinding commands have a couple of additional optional parameters:
- Goal end velocity
The velocity the robot should be moving at when reaching the goal position. If pathfinding to a predefined path, this will be automatically set based on the max velocity of that path
- Rotation delay distance
This parameter controls the distance that the robot should move before attempting to rotate to the goal rotation while pathfinding. This is useful in cases where you are pathfinding out of a cramped area, avoiding possible collisions from rotation
AdvantageKit Compatibility
Pathfind to Pose
Using AutoBuilder
The easiest way to create a pathfinding command is by using AutoBuilder
. See Build an Auto to configure AutoBuilder.
Manually
Pathfind Then Follow Path
Using AutoBuilder
The easiest way to create a pathfinding command is by using AutoBuilder
. See Build an Auto to configure AutoBuilder.
Manually
Custom Pathfinders
PathPlannerLib supports the ability to use a custom pathfinder implementation for pathfinding commands. In order to do so, your pathfinder must implement the methods in the Pathfinder
interface.
After creating your pathfinder, you must tell PathPlannerLib to use it for pathfinding commands. This should be done at the beginning of your robotInit
method, before any pathfinding commands are created.