Scoring multiple game pieces during the 15-second autonomous period requires synchronizing holonomic path following with mechanism commands.
PathPlanner is the standard tool for designing trajectories and sequencing commands in FRC.
1. Setting Up AutoBuilder in Java
Section titled “1. Setting Up AutoBuilder in Java”PathPlannerLib requires configuring an AutoBuilder in your swerve subsystem. This connects PathPlanner’s path-following algorithms to your physical drivetrain:
package frc.robot.subsystems;
import com.pathplanner.lib.auto.AutoBuilder;import com.pathplanner.lib.config.PIDConstants;import com.pathplanner.lib.config.RobotConfig;import com.pathplanner.lib.controllers.PPHolonomicDriveController;
public class CommandSwerveDrivetrain extends SubsystemBase { // ... swerve hardware handles ...
public void configurePathPlanner() { try { RobotConfig config = RobotConfig.fromGUISettings();
AutoBuilder.configure( this::getPose, // Pose2d supplier this::resetPose, // Pose2d consumer to reset odometry this::getRobotRelativeSpeeds, // Current ChassisSpeeds supplier (speeds, feedforwards) -> driveRobotRelative(speeds), // Output consumer new PPHolonomicDriveController( new PIDConstants(5.0, 0.0, 0.0), // Translation PID (meters) new PIDConstants(5.0, 0.0, 0.0) // Rotation PID (radians) ), config, () -> isRedAlliance(), // Flips paths for Red Alliance this ); } catch (Exception e) { e.printStackTrace(); } }}2. Registering Named Commands
Section titled “2. Registering Named Commands”To trigger mechanism actions (like deploying an intake or firing a shooter) along a path, you must register Named Commands in Java:
// Inside RobotContainer.javapublic void configureNamedCommands() { // Map text strings in the PathPlanner GUI to Java commands NamedCommands.registerCommand("IntakePiece", m_intake.intakeCommand()); NamedCommands.registerCommand("ShootHigh", m_shooter.shootCommand()); NamedCommands.registerCommand("StowArm", m_arm.moveToAngleCommand(Degrees.of(0.0))); NamedCommands.registerCommand("PrepareScore", m_arm.moveToAngleCommand(Degrees.of(80.0)));}Always call configureNamedCommands() before building any autonomous routines from files. If PathPlanner encounters a named command during auto construction that has not been registered in Java, it throws a runtime exception and aborts autonomous mode.
3. Designing Paths in the PathPlanner GUI
Section titled “3. Designing Paths in the PathPlanner GUI”- Open the PathPlanner application.
- Select your robot project directory (PathPlanner loads settings from
src/main/deploy/pathplanner/). - Click New Path:
- Set the initial waypoint: X, Y, and robot heading.
- Add end waypoints to form a smooth Bézier curve.
- Adjust control points to navigate around field obstacles.
- Insert Event Markers:
- Click along the curve to add an event marker at a specific timestamp or position.
- Assign a Named Command (e.g.,
IntakePiece). The command will trigger while the robot is driving at full speed!
- Create an Auto Routine:
- In the Autos tab, create a new auto (e.g.,
FourPieceCenter). - Sequence paths and commands:
[ScorePreload] -> [PathToPiece1] -> [ScorePiece1].
- In the Autos tab, create a new auto (e.g.,
4. Loading Autos into SendableChooser
Section titled “4. Loading Autos into SendableChooser”Expose your PathPlanner routines to the Driver Station dashboard:
public class RobotContainer { private final SendableChooser<Command> m_autoChooser;
public RobotContainer() { // Register named commands FIRST configureNamedCommands();
// Build auto chooser from PathPlanner project files m_autoChooser = AutoBuilder.buildAutoChooser(); SmartDashboard.putData("Auto Mode", m_autoChooser); }
public Command getAutonomousCommand() { return m_autoChooser.getSelected(); }}Common Failure Modes
Section titled “Common Failure Modes”1. Alliance Color Inversion Errors
Section titled “1. Alliance Color Inversion Errors”- Symptom: On the blue alliance, the robot drives forward; on red alliance, the robot drives backward or off the field.
- Cause: The alliance flip supplier was implemented improperly or flipped gyro angles twice.
- Fix: Verify
() -> isRedAlliance()accurately reflectsDriverStation.getAlliance().
2. Robot Drifts Off Path
Section titled “2. Robot Drifts Off Path”- Symptom: Robot begins tracking the path, but gradually drifts 20-30 cm off course.
- Cause: Translation PID constants are too low (
PIDConstants(1.0, 0, 0)), or wheel scrub is not compensated. - Fix: Increase translation
kPto5.0or6.0to tighten trajectory tracking.
Check Your Work
Section titled “Check Your Work”- Create a simple 2-meter straight path in PathPlanner GUI (
TestStraight2M). - Run simulation (F5) and select
TestStraight2Min SmartDashboard. - Enable Autonomous in SimGUI.
- Verify the robot drives exactly 2 meters on the simulated field map and stops cleanly.
Verified Sources & Standards
- PathPlanner Documentation & Trajectory Generationpathplanner.devHardware Vendor
- WPILib Path Planning & Autonomous Routinesdocs.wpilib.orgWPILib Standard