Lesson 40: Autonomous Routines

Autonomous code runs without driver control, so it needs to be planned and tested carefully. A good autonomous routine is a sequence of clear steps with safe exit conditions.

Write the Routine in English First

Before writing Java, describe the routine:

  1. Reset encoders and gyro.
  2. Drive forward 60 inches while holding zero degrees.
  3. Stop the drive train.
  4. Run the shooter until it reaches speed.
  5. Feed the game piece.

If you cannot explain the routine in English, the code will probably be hard to debug.

Every Step Needs an Exit

A step can end because it reached a sensor target, because a timer finished, or because a fault happened. Never write an autonomous step that can run forever if a sensor fails.

Use an Auto Chooser

Teams often need multiple autonomous routines. A dashboard chooser lets the drive team pick the routine before the match.

SendableChooser<Command> autoChooser = new SendableChooser<>();
autoChooser.setDefaultOption("Taxi", taxiAuto);
autoChooser.addOption("Score and Taxi", scoreAndTaxiAuto);
SmartDashboard.putData("Auto", autoChooser);

Test in Layers

Test the drive step by itself. Then test the shooter step by itself. Then put them together. If you only test the full routine, you will spend more time guessing which step failed.

Practice

Write three autonomous routines for the same robot: a safe mobility routine, a scoring routine, and a fallback routine that does the least risky useful thing.