REBUILT gives robots a 20-second autonomous period at the start of each match. A reliable auto that scores even one preloaded Fuel and then leaves its starting zone is worth more than a fancy one that fails. We will compose the commands you already wrote into a sequence.
Command-based shines here because you build complex routines by composing simple commands. The key compositions are andThen (sequential), withTimeout (stop a command after N seconds), and Commands.sequence(...).
Add a factory to DriveSubsystem:
public Command driveForTime(double fwd, double seconds) {
return run(() -> arcade(fwd, 0)).withTimeout(seconds)
.andThen(runOnce(() -> arcade(0, 0)));
}
Now assemble the routine in RobotContainer:
import edu.wpi.first.wpilibj2.command.Commands;
public Command getAutonomousCommand() {
return Commands.sequence(
m_launcher.shoot().withTimeout(2.5), // spin up & fire preload
m_drive.driveForTime(0.4, 1.5) // leave the starting zone
);
}
And schedule it in Robot.java:
@Override public void autonomousInit() {
Command auto = m_robotContainer.getAutonomousCommand();
if (auto != null) auto.schedule();
}
@Override public void teleopInit() {
// cancel any leftover auto command when teleop starts
CommandScheduler.getInstance().cancelAll();
}
Why this scores points: firing the preload aims at the Hub for Fuel points (each Fuel in the active Hub is worth 1 point in auto), and driveForTime moves the robot off its starting line. Driving forward at 40% for 1.5s is gentle enough not to overshoot. The withTimeout on the shoot command is essential — without an end condition, an auto command can run forever and block the sequence.
Make it selectable: real teams put a SendableChooser<Command> on the dashboard so drivers pick 'Score + Leave', 'Just Leave', or 'Do Nothing' before the match. Add it later; the composition pattern above is the engine.
Test methodically: run auto on blocks first, confirm the launcher fires and the wheels turn the right direction, then floor-test in an open space. A simple, repeatable 20-second auto that works every match is a genuine competitive advantage — many rookie alliances are decided by who scored in auto and who sat still.
Key takeaways
- Compose autos from simple commands using Commands.sequence, andThen, and withTimeout
- Every timed auto command needs an end condition (withTimeout) or it blocks the rest of the sequence
- A boring, reliable 'score preload + leave the zone' auto beats a flashy one that fails — auto often decides rookie matches
Keep going
Take the quiz · +10 XP with an accountSources & corrections
This lesson is AI-assisted: drafted from primary sources, then reviewed and edited by hand. Errors still get through. When one is reported we fix it and write down what changed — publicly, in the corrections log.
Sources and further reading
- Command Compositions (WPILib)docs.wpilib.org
- Organizing Command-Based Robot Projectsdocs.wpilib.org
- WPILib Example Projectsdocs.wpilib.org
Read next
Articles on this, for competition day
The lesson covers how it works. These cover what to do when it breaks.
- 8 min read
FRC Autonomous with PathPlanner: A Beginner's Guide to Auto Routines
Learn how FRC teams build autonomous routines with PathPlanner (PPLib): paths vs autos, AutoBuilder, named commands, odometry, tuning, and Choreo.
Read - 9 min read
FRC Command-Based Programming: Subsystems, Commands, and the Scheduler
A beginner-friendly guide to WPILib command-based programming in Java: subsystems, commands, the CommandScheduler, triggers, and composing commands.
Read - 13 min read
FRC Code Structure Best Practices: Command-Based Project Architecture
How to structure an FRC command-based robot project the right way — subsystems, commands, RobotContainer, and Constants — verified against official WPILib docs.
Read
Lesson quiz
RequiredAll 3 right completes the lesson. Miss one and only that question comes back — anything you already answered correctly stays banked.
0 of 3 answered
01.In a command-based project, which RobotContainer method returns the command to run during autonomous?
02.Where does the Robot class actually start (schedule) the autonomous command?
03.Why must every timed auto command (like shoot) carry a withTimeout end condition?
Answer every question to submit.
All 28 lessons in Getting Started with FRC
- Not started:Project 1 — Make a NEO Spin with the REV Hardware Client
- Not started:Project 2 — Deploy a Real Arcade-Drive Program
- Not started:Project 3 — Refactor into a Command-Based Drive Subsystem
- Not started:Project 4 — Build a Fuel Launcher for REBUILT
- Not started:Project 5 — A One-Button Autonomous Routine
- Not started:The Connection Chain: When the Driver Station Won't Connect
- Not started:Brownouts: Why the Robot Goes Limp Mid-Match
- Not started:CAN Bus Gremlins: Missing and Conflicting Devices
- Not started:Software Gotchas: Inverted Drives, Scheduler Stalls, and Reading the RioLog
- Not started:Inspection-Day Failures: Bumpers, Size, and Weight
- Not started:Closed-Loop Control: PID + Feedforward for a Consistent Shot
- Not started:Swerve Drive: Omnidirectional Movement with YAGSL
- Not started:AprilTag Vision: Knowing Where You Are with PhotonVision
- Not started:Data-Driven Strategy: Scouting, EPA/OPR, and Alliance Selection
- Not started:Choosing Your Hardware Ecosystem: REV vs CTRE