Commands
KEY CONCEPT
Commands - Coordinating Robot Actions
Commands are the actions that your robot performs. They use subsystems to accomplish tasks and can be triggered by user input, sensors, or automated sequences.
↳ TAKEAWAY
Commands tell subsystems what action to run.
Command Structure & Examples
Inline Command Methods Example
Command Methods
Create commands using factory methods like runOnce() to execute actions once when the command is triggered.
return runOnce(() -> action);Command Requirements
Commands must declare which subsystems they use to prevent conflicts and ensure proper scheduling.
addRequirements(subsystem);Command Lifecycle
Commands have a clear lifecycle: start, run continuously, then clean up when finished.
initialize() → execute() → end()Workshop Implementation
Before & After: Implementation
Before
- Arm subsystem with basic voltage control
- No user input integration
- No commands to coordinate actions
- Manual method calls only
After
- Enhanced Arm subsystem methods
- Commands for moveUp(), moveDown()
- Ready for user input integration
Loading file...
Code Walkthrough
New Subsystem Methods:
- moveUp(): Positive voltage for upward movement
- moveDown(): Negative voltage for downward movement
Command Benefits:
- Encapsulation: Actions wrapped in reusable commands
- Safety: Automatic stop when command ends
- Flexibility: Ready for trigger integration
Enhanced Arm subsystem with command methods! Next, we'll learn about Triggers to bind user input before verifying mechanism setup.
CHECKPOINT · 4 ITEMS
Next Steps
You now have reusable command factories on each mechanism. Before moving on, confirm that every command declares its subsystem requirements and stops motors safely in end().
- Bind new commands to controller inputs in a sandbox branch.
- Verify telemetry shows commands interrupting each other safely.
- Document command naming conventions in your team codebase.