the video version
The same lesson as a narrated video. Watch it on YouTube
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.
the part worth keeping
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
Getting Started with FRCWorked Examples & Mini-Projectslesson 5 of 5
Keep going
Take the quiz+10 XP with an accountwhere this came from
Sources and 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, in public, in the corrections log.
sources and further reading
- docs.wpilib.orgCommand Compositions (WPILib)
- docs.wpilib.orgOrganizing Command-Based Robot Projects
- docs.wpilib.orgWPILib Example Projects
clipped to this lesson
Articles that go further on this
The lesson gets you through the topic. These go wider on it, and they read in one sitting.
- 8 min readFRC Autonomous with PathPlanner: A Beginner's Guide to Auto RoutinesLearn how FRC teams build autonomous routines with PathPlanner (PPLib): paths vs autos, AutoBuilder, named commands, odometry, tuning, and Choreo./blogread it
- 9 min readFRC Command-Based Programming: Subsystems, Commands, and the SchedulerA beginner-friendly guide to WPILib command-based programming in Java: subsystems, commands, the CommandScheduler, triggers, and composing commands./blogread it
- 13 min readFRC Code Structure Best Practices: Command-Based Project ArchitectureHow to structure an FRC command-based robot project the right way — subsystems, commands, RobotContainer, and Constants — verified against official WPILib docs./blogread it
answer sheet
Lesson quiz
All 3 right completes the lesson. Miss one and only that question comes back, anything you already answered correctly stays banked.
0 of 3 answered
01In a command-based project, which RobotContainer method returns the command to run during autonomous?
02Where does the Robot class actually start (schedule) the autonomous command?
03Why must every timed auto command (like shoot) carry a withTimeout end condition?
Answer every question to submit.
All 28 lessons in Getting Started with FRCopenclose
01 / what-first-and-frc-are
02 / the-season-and-the-game
03 / culture-teams-and-roles
04 / getting-started-your-first-steps
05 / worked-examples-mini-projects
- Not read yet:Project 1 — Make a NEO Spin with the REV Hardware Client
- Not read yet:Project 2 — Deploy a Real Arcade-Drive Program
- Not read yet:Project 3 — Refactor into a Command-Based Drive Subsystem
- Not read yet:Project 4 — Build a Fuel Launcher for REBUILT
- Not read yet:Project 5 — A One-Button Autonomous Routine
06 / common-mistakes-troubleshooting
- Not read yet:The Connection Chain: When the Driver Station Won't Connect
- Not read yet:Brownouts: Why the Robot Goes Limp Mid-Match
- Not read yet:CAN Bus Gremlins: Missing and Conflicting Devices
- Not read yet:Software Gotchas: Inverted Drives, Scheduler Stalls, and Reading the RioLog
- Not read yet:Inspection-Day Failures: Bumpers, Size, and Weight
07 / advanced-techniques-case-studies
- Not read yet:Closed-Loop Control: PID + Feedforward for a Consistent Shot
- Not read yet:Swerve Drive: Omnidirectional Movement with YAGSL
- Not read yet:AprilTag Vision: Knowing Where You Are with PhotonVision
- Not read yet:Data-Driven Strategy: Scouting, EPA/OPR, and Alliance Selection
- Not read yet:Choosing Your Hardware Ecosystem: REV vs CTRE