PathPlanner Lesson

PathPlanner: Advanced Autonomous Motion

Welcome to the cutting edge of FRC autonomous programming. PathPlanner is a powerful tool that allows us to design, visualize, and execute complex, curved autonomous paths with incredible precision, and it's a standard for top teams like ours.

What is PathPlanner?

PathPlanner is a third-party tool with two key components:

  • A Graphical Path Editor: A visual tool where you draw the exact path you want your robot to follow on a diagram of the FRC field.
  • A WPILib-compatible Library: A library you add to our robot code that provides commands to make the robot follow those paths accurately.

Why We Use PathPlanner: The 2910 Advantage

Instead of simple "drive forward, then turn" routines, PathPlanner allows for:

  • Smooth and Efficient Motion: It generates continuous, curved paths. A robot that never stops moving is a faster robot.
  • Decoupled Actions (Event Markers): We can place markers along the path that trigger other commands, like running an intake or aiming a shooter, allowing the robot to perform multiple actions while fluidly driving.
  • Rapid Visualization and Iteration: We can design and tweak complex paths in the editor without writing a single line of code, drastically speeding up development.

How it Works in Our Code

Integrating PathPlanner into our command-based robot code involves a few key steps in `RobotContainer.java`.

// In RobotContainer.java

public class RobotContainer {
    // ... subsystems and controllers ...
    private final SendableChooser<Command> autoChooser;

    public RobotContainer() {
        // ... other setup ...

        // 1. Link Command Names to Actual Command Objects
        // In the PathPlanner GUI, we can create an event marker named "intake".
        // This line tells our code that when it sees that marker, it should run an IntakeCommand.
        NamedCommands.registerCommand("intake", new IntakeCommand(m_intake));
        NamedCommands.registerCommand("shoot", new ShootCommand(m_shooter, m_leds));

        // 2. Build the Autonomous Chooser Automatically
        // This magical method finds all the autonomous routines you created in the
        // PathPlanner app and automatically creates a SendableChooser for them.
        autoChooser = AutoBuilder.buildAutoChooser();
        SmartDashboard.putData("Auto Mode", autoChooser);

        configureButtonBindings();
    }

    /**
     * @return the command to run in autonomous
     */
    public Command getAutonomousCommand() {
        // 3. Return the selected command
        // This returns the complex, pre-built command group from PathPlanner.
        return autoChooser.getSelected();
    }
}
    

Test Your Knowledge

Question: What is the most powerful feature of PathPlanner that allows us to run commands like an intake or a shooter while the robot is still driving along a path?