In basic autonomous programming, teams often execute a sequence of discrete steps: drive to location, stop, deploy intake, run rollers, retract intake, drive to goal, stop, spin up shooter, shoot. This stop-and-go architecture limits scoring throughput to 2 or 3 game pieces in 15 seconds.
Top-tier teams use Event Markers and NamedCommands to run mechanisms concurrently with drivetrain translation, saving 0.5 to 1.5 seconds on every game piece cycle.
1. What to Learn First
Section titled “1. What to Learn First”Before configuring event markers:
- Ensure individual mechanism commands have well-defined termination criteria (
isFinished()) and safe interrupt handling (end(boolean interrupted)) as covered in Writing Commands. - Verify mechanism current limits to prevent stalling when deploying intakes at high transit speeds.
2. Registering NamedCommands
Section titled “2. Registering NamedCommands”PathPlanner allows paths to reference commands by string identifier (such as "deployIntake" or "spinUpFlywheel"). These string names are mapped to actual WPILib command factories in code using NamedCommands.registerCommand():
package frc.robot;
import com.pathplanner.lib.auto.NamedCommands;import edu.wpi.first.wpilibj2.command.Commands;import frc.robot.subsystems.IntakeSubsystem;import frc.robot.subsystems.ShooterSubsystem;import frc.robot.subsystems.ElevatorSubsystem;import static edu.wpi.first.units.Units.*;
public class AutonomousCommandRegistrar { public static void registerAll( IntakeSubsystem intake, ShooterSubsystem shooter, ElevatorSubsystem elevator ) { // Register intake command: runs rollers until game piece trips internal beam break NamedCommands.registerCommand( "intakePiece", intake.intakeUntilAcquiredCommand() );
// Register shooter pre-spool: spins wheels up to 4500 RPM NamedCommands.registerCommand( "preSpoolShooter", shooter.spinUpCommand(RPM.of(4500)) );
// Register scoring sequence: feeds piece into shooter once up to speed NamedCommands.registerCommand( "scorePiece", Commands.sequence( shooter.waitUntilAtSpeedCommand(RPM.of(4500), RPM.of(50)), intake.feedToShooterCommand().withTimeout(0.35) ) );
// Register elevator preset position NamedCommands.registerCommand( "elevatorToMid", elevator.setHeightCommand(Meters.of(0.75)) ); }}All NamedCommands.registerCommand() calls must execute before any PathPlannerAuto or PathPlannerPath is loaded. If an auto references an unregistered command name, PathPlanner throws an exception or substitutes a dummy command.
3. Spatial vs Timestamp Event Markers
Section titled “3. Spatial vs Timestamp Event Markers”In the PathPlanner GUI, event markers can be placed along any trajectory:
1. Position-Based Markers (Waypoint Offsets)
Section titled “1. Position-Based Markers (Waypoint Offsets)”- Placed relative to a specific waypoint (e.g., 0.5 meters before Waypoint 2).
- Use Case: Lowering the intake right before reaching a note, regardless of actual velocity or acceleration.
2. Time-Based Markers (Timestamp Offsets)
Section titled “2. Time-Based Markers (Timestamp Offsets)”- Placed relative to time elapsed or time remaining (e.g., 0.8 seconds before reaching the end of the path).
- Use Case: Spooling up a heavy flywheel shooter. If a flywheel requires 0.75 seconds to accelerate from idle to 5000 RPM, trigger
"preSpoolShooter"attimeRemaining <= 0.80sso the shooter reaches full speed the exact instant the drivetrain stops at the scoring position.
4. Building Safe Non-Blocking Compositions
Section titled “4. Building Safe Non-Blocking Compositions”When mechanisms run concurrently with swerve drive commands, commands must not block the drivetrain if a mechanism fails:
// Example: Safe intake command with timeout guardpublic Command intakeUntilAcquiredCommand() { return Commands.sequence( deployIntakeCommand(), runRollersCommand() .raceWith(Commands.waitUntil(this::hasGamePiece)) .withTimeout(2.5), // Safety guard: abort if piece not acquired in 2.5s retractIntakeCommand() );}By wrapping the sensor wait in withTimeout(2.5), the robot will not remain frozen on the field if a game piece was bumped away by another robot during the match.
How Success is Checked
Section titled “How Success is Checked”- Continuous Drivetrain Motion in AdvantageScope:
- Check the swerve chassis velocity graph. The robot should not decelerate to zero while deploying the intake or raising the elevator.
- Flywheel Ready at Arrival:
- In AdvantageScope, plot
Shooter/RPMandSwerve/LinearVelocity. - The flywheel RPM must reach the setpoint tolerance band within of the robot coming to a stop at the goal pose.
- In AdvantageScope, plot
- Sensor-Triggered Advance:
- When the beam break detects a game piece, the intake must retract immediately without waiting for a fixed timer.
Where to Go Next
Section titled “Where to Go Next”Now proceed to Field Pose Correction & Terminal Alignment to learn how to keep trajectories repeatable under carpet wear and wheel scrub.
Verified Sources & Standards
- PathPlanner NamedCommands Documentationpathplanner.devCommunity Reference
- WPILib Command Compositionsdocs.wpilib.orgWPILib Standard