Lesson 6.16: Advanced PathPlanner
🎯 What You’ll Learn
By the end of this lesson you will be able to:
- Generate paths on-the-fly from code instead of the PathPlanner GUI
- Apply custom constraints to control speed and acceleration in specific path segments
- Configure zone behaviors that change robot actions based on field position
- Compose complex autonomous routines using AutoBuilder
- Understand when to use GUI-designed paths vs. code-generated paths
Beyond GUI-Designed Paths
In Unit 4 you learned to read PathPlanner paths. In Unit 5 you created paths in the GUI and registered Named Commands. Now it’s time to go further.
The PathPlanner GUI is great for designing paths you know ahead of time. But what about:
- Dynamic scoring — generating a path to the nearest game piece based on vision data
- Adaptive autos — choosing different paths based on alliance partner positions
- Recovery paths — generating a return-to-path if the robot gets bumped off course
These scenarios require generating paths from code at runtime. PathPlanner’s API makes this possible.
Reference: pathplanner.dev — the official PathPlanner documentation covers all features discussed in this lesson.
On-the-Fly Path Generation
PathPlanner lets you create paths programmatically using PathPlannerPath and waypoints defined in code.
Creating a Path from Poses
import com.pathplanner.lib.path.*;import edu.wpi.first.math.geometry.*;
// Generate a path from current position to a targetpublic Command driveToTarget(Pose2d targetPose) { Pose2d currentPose = drivetrain.getPose();
List<Waypoint> waypoints = PathPlannerPath.waypointsFromPoses( currentPose, targetPose );
PathPlannerPath path = new PathPlannerPath( waypoints, new PathConstraints( 3.0, // max velocity (m/s) 3.0, // max acceleration (m/s²) 2 * Math.PI, // max angular velocity (rad/s) 2 * Math.PI // max angular acceleration (rad/s²) ), null, // ideal starting state (null = use current) new GoalEndState(0.0, targetPose.getRotation()) // stop at target );
return AutoBuilder.followPath(path);}When to Use On-the-Fly Paths
| Scenario | GUI Path | On-the-Fly Path |
|---|---|---|
| Fixed auto routine (same every match) | ✅ Best choice | Unnecessary complexity |
| Drive to nearest game piece (vision-based) | ❌ Can’t predict position | ✅ Generate from vision data |
| Return to path after being bumped | ❌ Can’t predict bump | ✅ Generate recovery path |
| Adaptive auto based on game state | ❌ Too many variations | ✅ Generate based on conditions |
The rule of thumb: if you know the path before the match starts, design it in the GUI. If the path depends on runtime data, generate it from code.
Your robot uses vision to detect game pieces on the field. You want to drive to the nearest one during autonomous. Should you use a GUI-designed path or an on-the-fly path?
Path Constraints
Constraints control how fast and aggressively the robot moves along a path. You can set global constraints for the entire path or apply different constraints to specific segments.
Global Constraints
PathConstraints globalConstraints = new PathConstraints( 4.0, // max velocity: 4 m/s 3.5, // max acceleration: 3.5 m/s² 2 * Math.PI, // max angular velocity 2 * Math.PI // max angular acceleration);Constraint Zones (Per-Segment Constraints)
In the PathPlanner GUI, you can define constraint zones — regions of the path where different speed limits apply. This is useful for:
- Slowing down near scoring positions — precision matters more than speed
- Speeding up on straightaways — maximize time efficiency
- Reducing acceleration near game pieces — smoother pickup
// In code, constraint zones are defined as part of the pathConstraintsZone slowZone = new ConstraintsZone( 0.7, // start position (0.0 to 1.0 along path) 1.0, // end position new PathConstraints(1.5, 2.0, Math.PI, Math.PI) // slower near the end);Choosing Constraint Values
| Parameter | Conservative | Moderate | Aggressive |
|---|---|---|---|
| Max velocity | 2.0 m/s | 3.5 m/s | 5.0 m/s |
| Max acceleration | 2.0 m/s² | 3.0 m/s² | 4.5 m/s² |
| Max angular velocity | π rad/s | 2π rad/s | 3π rad/s |
Start conservative and increase gradually. Aggressive constraints look great in simulation but can cause wheel slip, overshoot, or tipping on a real robot.
Zone Behaviors
PathPlanner supports event markers and zone-based triggers that fire commands when the robot enters specific regions of the field or reaches specific points along a path.
Event Markers
Event markers trigger a Named Command at a specific point along the path:
// In the PathPlanner GUI, you place event markers on the path// In code, you register the Named Commands they reference
NamedCommands.registerCommand("startIntake", intake.runOnce(() -> intake.deploy()) .andThen(intake.run(() -> intake.runRollers())));
NamedCommands.registerCommand("prepareShooter", shooter.runOnce(() -> shooter.spinUp(4000)));When the robot reaches the marker position on the path, the associated command starts automatically.
Combining Markers with Path Segments
A well-designed auto uses markers to overlap actions with driving:
Path: Start → Game Piece → Scoring Position ├── At 30%: startIntake (deploy intake before arriving at game piece) ├── At 60%: retractIntake (retract after pickup) └── At 80%: prepareShooter (spin up before arriving at scoring position)This parallelism — doing things while driving — is what separates good autos from great ones.
AutoBuilder Composition
AutoBuilder is PathPlanner’s tool for composing complex autonomous routines from multiple paths and commands.
Basic AutoBuilder Setup
// In RobotContainer constructor — configure AutoBuilder onceAutoBuilder.configure( drivetrain::getPose, // Pose supplier drivetrain::resetPose, // Pose reset consumer drivetrain::getChassisSpeeds, // ChassisSpeeds supplier drivetrain::drive, // Drive consumer new PPHolonomicDriveController( new PIDConstants(5.0, 0.0, 0.0), // Translation PID new PIDConstants(5.0, 0.0, 0.0) // Rotation PID ), robotConfig, // Robot configuration () -> isRedAlliance(), // Alliance flip supplier drivetrain // Drive subsystem);Composing Multi-Path Autos
// Build a complex auto from multiple paths and commandspublic Command fourPieceAuto() { return Commands.sequence( // Score preloaded piece AutoBuilder.followPath(PathPlannerPath.fromPathFile("ScorePreload")), shootCommand(),
// Pick up piece 2 and score AutoBuilder.followPath(PathPlannerPath.fromPathFile("ToGamePiece2")), intakeCommand().withTimeout(1.5), AutoBuilder.followPath(PathPlannerPath.fromPathFile("ToScoring2")), shootCommand(),
// Pick up piece 3 and score AutoBuilder.followPath(PathPlannerPath.fromPathFile("ToGamePiece3")), intakeCommand().withTimeout(1.5), AutoBuilder.followPath(PathPlannerPath.fromPathFile("ToScoring3")), shootCommand() );}Conditional Autos
// Choose paths based on runtime conditionspublic Command adaptiveAuto() { return Commands.sequence( AutoBuilder.followPath(PathPlannerPath.fromPathFile("ScorePreload")), shootCommand(),
// Decide based on what the vision system sees Commands.either( // If game piece detected at position A Commands.sequence( AutoBuilder.followPath(PathPlannerPath.fromPathFile("ToPositionA")), intakeCommand().withTimeout(1.5) ), // Otherwise go to position B Commands.sequence( AutoBuilder.followPath(PathPlannerPath.fromPathFile("ToPositionB")), intakeCommand().withTimeout(1.5) ), () -> vision.seesGamePieceAtA() // Condition ),
AutoBuilder.followPath(PathPlannerPath.fromPathFile("ReturnToScore")), shootCommand() );}You're building a 3-piece auto. The robot scores a preloaded piece, picks up two more, and scores each. Between the second and third pickup, you want the robot to spin up the shooter while driving. How do you achieve this?
Debugging Autonomous Routines
Advanced autos have more things that can go wrong. Here’s a debugging toolkit:
Common Issues and Fixes
| Symptom | Likely Cause | Fix |
|---|---|---|
| Robot drives the wrong direction | Alliance flipping not configured | Check isRedAlliance() supplier in AutoBuilder |
| Robot overshoots waypoints | Constraints too aggressive | Reduce max velocity and acceleration |
| Robot stops mid-path | Named Command throws exception | Check DS console for errors, verify command registration |
| Path doesn’t match GUI preview | Pose estimation drift | Calibrate odometry, check gyro, tune vision fusion |
| Robot jerks at path transitions | Discontinuous velocity between paths | Ensure end velocity of one path matches start of next |
Logging for Auto Debugging
// Log useful data during autonomousLogger.recordOutput("Auto/CurrentPath", currentPathName);Logger.recordOutput("Auto/TargetPose", targetPose);Logger.recordOutput("Auto/PoseError", poseError);Logger.recordOutput("Auto/IsFollowingPath", isFollowing);Review these logs in AdvantageScope after each auto run to identify where things go wrong.
Strong answers include:
-
On-the-fly scenario — e.g., “During autonomous, our vision system detects a game piece that’s been knocked to an unexpected position. We generate a path from our current pose to the detected position, since we couldn’t have predicted this location when designing paths in the GUI.”
-
Slowing down — “Use a constraint zone on the last 30% of the path with reduced max velocity (e.g., 1.5 m/s instead of 3.5 m/s). In the PathPlanner GUI, drag a constraint zone over the approach segment and set lower velocity limits.”
-
Overlapping actions — “Place an event marker on the path at the point where the intake should start deploying (before the robot arrives at the game piece). Register a Named Command called ‘deployIntake’ that runs the intake deploy. The intake deploys while the robot is still driving, saving time.”
Key Terms
📖 All terms below are also in the full glossary for quick reference.
| Term | Definition |
|---|---|
| On-the-Fly Path Generation | Creating PathPlanner paths programmatically at runtime based on current robot state or sensor data, rather than pre-designing them in the GUI |
| Path Constraints | Speed and acceleration limits applied to a path, controlling how fast and aggressively the robot moves |
| Constraint Zone | A region of a path where different constraints apply, allowing variable speed along the route |
| Event Marker | A point on a path that triggers a Named Command when the robot reaches it, enabling action overlap with driving |
| AutoBuilder | PathPlanner’s utility for configuring path following and composing complex autonomous routines from paths and commands |
| Alliance Flipping | Automatically mirroring paths for the opposite alliance side so the same auto works from both sides of the field |
| Goal End State | The desired velocity and heading when the robot reaches the end of a path |
What’s Next?
You now understand PathPlanner’s advanced features. In Activity 6.17: Implement an Advanced Auto Feature, you’ll put one of these techniques into practice — building an on-the-fly path, adding constraint zones, or composing a multi-path auto with event markers.