Search lessons

Suggested searches

Browse

Making commands

Prerequisites: subsystems, lambdas. A command is scheduled, initialized, executed across scheduler iterations, and ended either normally or by interruption. The scheduler resolves conflicting subsystem requirements. The starter uses:

Commands.runEnd(() -> intake.setSpeed(0.5), () -> intake.setSpeed(0), intake)
    .withTimeout(2);

The last argument reserves the intake; runEnd also provides a stop action when interrupted. This is an excerpt from the starter, not a standalone class. Avoid blocking loops or sleeps in commands. withTimeout ends the decorated command when the time expires; disabling the robot cancels ordinary commands.

Exercise: start the command and disable early. Expected: output returns to zero. Start another command requiring the same subsystem and explain why the scheduler interrupts the first. If a motor would keep running, inspect end/runEnd and requirements. See WPILib commands.

Interactive lab · AI-assisted teaching model

Command scheduler lab

Step a simplified scheduler and observe ownership of one motor subsystem.

Archived original lesson (historical APIs; unverified).