Skip to content

Building Autonomous Routines

learnfrc.com
learnfrc.comAuthor
Veer Bajaj
Veer BajajMaintainer

The first ~15 seconds of an FRC match are autonomous : the robot runs with no driver input. A good auto combines driving (trajectories) with mechanism actions (intake, score) and finishes reliably. In command-based code, an entire auto is just one big composed command.

In the command-based template, Robot.autonomousInit() schedules whatever RobotContainer.getAutonomousCommand() returns:

public Command getAutonomousCommand() {
return Commands.sequence(
drivetrain.followPath("ToReef"), // a trajectory
arm.raiseToScore(), // mechanism action
intake.eject().withTimeout(1.0), // score
drivetrain.followPath("BackToStart"));
}

Sequences run steps in order; parallel groups let you, say, raise the arm while driving to save time:

Commands.deadline(
drivetrain.followPath("ToReef"), // deadline: ends when the drive ends
arm.raiseToScore()); // runs alongside

Matches need different autos depending on alliance strategy and starting position. Use a SendableChooser to expose options on the dashboard (Elastic, Glass, or Shuffleboard):

private final SendableChooser<Command> m_chooser = new SendableChooser<>();
public RobotContainer() {
m_chooser.setDefaultOption("Score + Leave", scoreAndLeaveAuto());
m_chooser.addOption("Just Leave", justLeaveAuto());
SmartDashboard.putData("Auto", m_chooser);
}
public Command getAutonomousCommand() { return m_chooser.getSelected(); }

If you’re using PathPlanner, AutoBuilder.buildAutoChooser() can populate a chooser with every auto you built in the GUI automatically. With ChoreoLib, prefer its AutoChooser.

A few hard-won principles:

  • Add timeouts. Wrap risky commands with .withTimeout(...) so a stuck mechanism can’t hang the whole auto.
  • Set the starting pose. Reset odometry to the path’s start pose in the auto’s first step, or your trajectory follower starts from a wrong belief about position. (PathPlanner/Choreo helpers can do this for you.)
  • Test the exact starting position you’ll use on the field; a few centimeters of offset compounds over a path.
  • Prefer a simple auto that always works over a complex one that sometimes fails. A reliable “score one and leave” outscores an ambitious auto that no-shows half the time.

A complete auto module typically: resets odometry → follows a path (optionally doing mechanism work in parallel) → scores → repositions. Wired to a chooser and tested in simulation (next lesson) and on the practice field, this is what separates teams that reliably bank autonomous points from those that gamble on them.

  • Autonomous is one composed command returned from getAutonomousCommand().
  • Use sequences for ordered steps and parallel/deadline groups to save time.
  • Expose multiple autos with SendableChooser (or PathPlanner/Choreo choosers) on the dashboard.
  • Reset odometry to the path’s start pose and add timeouts to risky commands.
  • A simple, reliable auto beats a complex one that fails — and always test the exact start position.

This lesson was adapted from learnfrc.com.