Space Academy 3.0 is open — want to become a project contributor?Join in

Programming

Command-Based Programming

Structuring robot code as subsystems and commands instead of one giant loop.

1 min readUpdated Jul 27, 2026

A monolithic TeleOp loop works until three mechanisms need to move at once. Command-based programming separates what a mechanism can do (subsystem) from what the robot is doing right now (command).

The three conceptsLink to this section

  • Subsystem — owns hardware, exposes intent, runs periodic().
  • Command — a small unit of behaviour with initialize, execute, end, isFinished.
  • Scheduler — runs commands, enforcing that two commands never own the same subsystem.

A commandLink to this section

java
public class RaiseLift extends CommandBase {
    private final Lift lift;
    private final int target;

    public RaiseLift(Lift lift, int target) {
        this.lift = lift;
        this.target = target;
        addRequirements(lift);
    }

    @Override public void initialize() { lift.setTarget(target); }
    @Override public boolean isFinished() { return lift.atTarget(); }
    @Override public void end(boolean interrupted) { lift.hold(); }
}

Composing autonomousLink to this section

java
new SequentialCommandGroup(
    new FollowPath(drive, toBackboard),
    new ParallelCommandGroup(new RaiseLift(lift, HIGH), new AimArm(arm)),
    new ScoreSample(claw),
    new FollowPath(drive, toPark)
);