Triggers
Triggers - Connecting User Input to Commands
Triggers link user inputs (buttons, joysticks, sensors) to commands. They define when and how commands should run based on controller input or robot state.
Key Concept: Use onTrue() to run commands when buttons are pressed, and onFalse() to run commands when buttons are released.
Trigger Implementation & Examples
🎯 Trigger Examples - Binding Input to Commands
🎮 onTrue() Trigger
controller.a()
.onTrue(command);🔽 onFalse() Trigger
controller.a()
.onFalse(command);🔄 Chaining Triggers
.onTrue(cmd1)
.onFalse(cmd2);🎯 Sensor Triggers
new Trigger(
() => sensor.get())
.onTrue(cmd);🔄 Before → After: Implementation
📋 Before
- • Empty RobotContainer constructor
- • No controller declared
- • No configureBindings() method
- • Commands exist but can't be triggered
✅ After
- • CommandXboxController instantiated
- • configureBindings() method created
- • Button triggers bound to commands
- • Robot responds to controller input
🎯 Final Implementation & GitHub Changes
Loading file...
🚀 Advanced Command Patterns
ℹ️ Advanced Topics - Beyond This Workshop
This workshop uses simplified patterns (runOnce(), onTrue(), and onFalse()) for easier learning. The examples below show advanced command patterns that are powerful for competition but not required for this workshop's scope.
💡 Feel free to explore these after completing the workshop fundamentals!
Extending WPILib Command
For more complex commands, extend Command directly instead of using inline methods.See WPILib documentation →
Complex Command Groups
Combine sequences and parallel actions to coordinate subsystems.
Composition Strategies
Use fluent helpers to assemble commands from smaller pieces.
Common Pitfalls
Always declare subsystem requirements to avoid unexpected conflicts.
Advanced Triggers
Create triggers from sensor conditions or button combinations.
Real-World Scenario
Combine patterns to build robust autonomous routines.