Commands
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.
🎯 Key Concept: Commands tell subsystems what action to run.
Command Structure & Examples
🎮 Inline Command Methods Example
Subsystem Command MethodsJAVA
1// In your Arm subsystem - add these command methods:
2
3public Command moveUp() {
4 return runOnce(() -> setVoltage(6));
5}
6
7public Command moveDown() {
8 return runOnce(() -> setVoltage(-6));
9}
10
11public Command stopArm() {
12 return runOnce(() -> stop());
13}
14
15⚡ 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
💡 Next Step: Enhanced Arm subsystem with command methods! Next, we'll learn about Triggers to bind user input before verifying mechanism setup.