Consider checking out Pathfinding | PathPlanner Docs for more in-depth information about pathplanning, but here’s an example from their website (This exampel assumes you are using swerve and have set up AutoBuilder:
/ Since we are using a holonomic drivetrain, the rotation component of this pose
// represents the goal holonomic rotation
Pose2d targetPose = new Pose2d(10, 5, Rotation2d.fromDegrees(180));
// Create the constraints to use while pathfinding
PathConstraints constraints = new PathConstraints(
3.0, 4.0,
Units.degreesToRadians(540), Units.degreesToRadians(720));
// Since AutoBuilder is configured, we can use it to build pathfinding commands
Command pathfindingCommand = AutoBuilder.pathfindToPose(
targetPose,
constraints,
0.0, // Goal end velocity in meters/sec
0.0 // Rotation delay distance in meters. This is how far the robot should travel before attempting to rotate.
);
Then simply execute it as you would any other command.
Do you have reliable vision? Your auto driving feature can only be as accurate as your vision. If you want to hold a button and have the robot autonomously drive itself from say the source to the amp there will be two parts involved.
Drive from the current pose to a new pose while avoiding obstacles. This can be done with path planners pathfinding (not on the fly trajectory).
The pathfinding from path planner will only get you to roughly the correct position but there will still be error at the end. To eliminate this error you have two options:
Option 1: have a predefined path that the pathfinder drives to. This predefined path will be able to have much higher accuracy.
Options 2(my choice): run a pid controller for the X, Y, theta of the robot and pass those values into the drivetrain for fine tune alignment. This options works better if you want to be able to change the end location without having lots of pre defined paths for stage, speaker, amp, source, etc…
This can be two separate commands ran in a sequential command. Let me know if you have any questions.
The first step to create something like this, is having a accurate pose estimation of your robot (ideally combining sensor like vision, gyro and odometry.
once you have this working well, it should be relatively easy to do it using path planner, but it depends of your definision of “auto pilot”,
do you want the bot to drive automaticaly from the source to the AMP or SPEAKER?
or do something like 3015 and run the robot without touching the controls at all?