|
RobotCore 1.0
WPILib port to raspberry Pi
|
Classes | |
| enum | Signal |
Public Member Functions | |
| Trigger (Scheduler scheduler, BooleanSupplier condition) | |
| Trigger (BooleanSupplier condition) | |
| Trigger (Scheduler scheduler, EventLoop loop, BooleanSupplier condition) | |
| Trigger | onTrue (Command command) |
| Trigger | ifTrue (Command command) |
| Trigger | onFalse (Command command) |
| Trigger | whileTrue (Command command) |
| Trigger | whileFalse (Command command) |
| Trigger | retryWhileTrue (Command command) |
| Trigger | retryWhileFalse (Command command) |
| Trigger | toggleOnTrue (Command command) |
| Trigger | toggleOnFalse (Command command) |
| boolean | getAsBoolean () |
| Trigger | and (BooleanSupplier trigger) |
| Trigger | or (BooleanSupplier trigger) |
| Trigger | negate () |
| Trigger | debounce (Time duration) |
| Trigger | debounce (Time duration, Debouncer.DebounceType type) |
| Trigger | risingEdge () |
| Trigger | fallingEdge () |
| Trigger | multiPress (int pressCount, Time duration) |
Triggers allow users to specify conditions for when commands should run. Triggers can be set up to read from joystick and controller buttons (eg org.wpilib.command3.button.CommandGamepad#faceDown()) or be customized to read sensor values or any other arbitrary true/false condition.
It is very easy to link a button to a command. For instance, you could link the trigger button of a joystick to a "score" command.
Triggers can easily be composed for advanced functionality using the and(BooleanSupplier), or(BooleanSupplier), negate() operators.
| Method | Schedules | Cancels on false |
|---|---|---|
onTrue(Command) | On a rising edge | No |
ifTrue(Command) | On every true poll | No |
whileTrue(Command) | On a rising edge | Yes |
retryWhileTrue(Command) | On every true poll | Yes |
Trigger bindings created inside a running command will only be active while that command is running. This is useful for defining trigger-based behavior only in a certain scope and avoids needing to create dozens of global triggers. Any commands scheduled by these triggers will be canceled when the enclosing command exits.
Command shootWhileAiming = Command.noRequirements(co -> {
turret.atTarget.onTrue(shooter.shootOnce());
co.await(turret.lockOnGoal());
}).named("Shoot While Aiming");
controller.rightBumper().whileTrue(shootWhileAiming);
Definition at line 76 of file Trigger.java.
| org.wpilib.command3.Trigger.Trigger | ( | Scheduler | scheduler, |
| BooleanSupplier | condition ) |
Creates a new trigger based on the given condition. Polled by the scheduler's default event loop.
| scheduler | The scheduler that should execute triggered commands. |
| condition | the condition represented by this trigger |
Definition at line 109 of file Trigger.java.
| org.wpilib.command3.Trigger.Trigger | ( | BooleanSupplier | condition | ) |
Creates a new trigger based on the given condition. Triggered commands are executed by the default scheduler.
Polled by the default scheduler button loop.
| condition | the condition represented by this trigger |
Definition at line 124 of file Trigger.java.
| org.wpilib.command3.Trigger.Trigger | ( | Scheduler | scheduler, |
| EventLoop | loop, | ||
| BooleanSupplier | condition ) |
Creates a new trigger based on the given condition.
| scheduler | The scheduler that should execute triggered commands. |
| loop | The event loop to poll the trigger. |
| condition | the condition represented by this trigger |
Definition at line 136 of file Trigger.java.
| Trigger org.wpilib.command3.Trigger.and | ( | BooleanSupplier | trigger | ) |
Composes two triggers with logical AND.
| trigger | the condition to compose with |
Definition at line 310 of file Trigger.java.
| Trigger org.wpilib.command3.Trigger.debounce | ( | Time | duration | ) |
Creates a new debounced trigger from this trigger - it will become active when this trigger has been active for longer than the specified period.
| duration | The debounce period. |
Definition at line 341 of file Trigger.java.
| Trigger org.wpilib.command3.Trigger.debounce | ( | Time | duration, |
| Debouncer.DebounceType | type ) |
Creates a new debounced trigger from this trigger - it will become active when this trigger has been active for longer than the specified period.
| duration | The debounce period. |
| type | The debounce type. |
Definition at line 353 of file Trigger.java.
| Trigger org.wpilib.command3.Trigger.fallingEdge | ( | ) |
Creates a trigger that activates on a falling edge of this trigger's signal. The falling edge trigger is active in the same cycle that this trigger's condition is false while its condition in the previous cycle was true. The resulting trigger will only be active for that single cycle before going inactive again; therefore, onTrue(Command) should be used instead of whileTrue(Command), as commands bound using the latter method will be immediately canceled after a single scheduler cycle.
Definition at line 383 of file Trigger.java.
| boolean org.wpilib.command3.Trigger.getAsBoolean | ( | ) |
Gets the boolean state of the trigger. Because triggers are checked when their event loop is polled, which by default occurs when Scheduler#run() is called in user code, but may differ for custom event loops, the state is only valid immediately after the event loop is polled. If the underlying signal changes without a subsequent event loop poll, the return value from getAsBoolean() may not agree with the result of checking the signal directly.
This method will always return false before being polled by an event loop.
Definition at line 300 of file Trigger.java.
Starts the given command on every event-loop poll where the condition is true.
This does not cancel the command when the condition becomes false; use whileTrue(Command) for that behavior. Scheduling an already-running command follows ordinary scheduler behavior and does not restart it.
| command | the command to start |
Definition at line 180 of file Trigger.java.
| Trigger org.wpilib.command3.Trigger.multiPress | ( | int | pressCount, |
| Time | duration ) |
Creates a trigger that activates when this trigger has at least pressCount rising edges within the specified duration.
| pressCount | The number of rising edges to require. If this is non-positive, the trigger will always be active. |
| duration | The duration within which the rising edges must occur. If this is non-positive, the trigger will never activate. |
Definition at line 398 of file Trigger.java.
| Trigger org.wpilib.command3.Trigger.negate | ( | ) |
Creates a new trigger that is active when this trigger is inactive, i.e. that acts as the negation of this trigger.
Definition at line 330 of file Trigger.java.
Starts the given command whenever the condition changes from true to false.
| command | the command to start |
Definition at line 192 of file Trigger.java.
Starts the given command whenever the condition changes from false to true.
| command | the command to start |
Definition at line 164 of file Trigger.java.
| Trigger org.wpilib.command3.Trigger.or | ( | BooleanSupplier | trigger | ) |
Composes two triggers with logical OR.
| trigger | the condition to compose with |
Definition at line 320 of file Trigger.java.
Starts the given command when the condition changes to false and cancels it when the condition changes to true.
Unlike whileFalse(Command), the command is restarted if it ends while the condition is still false. If the command stopped because it was interrupted, restarting it will immediately interrupt the would-be interrupting command (if they have the same priority).
| command | the command to start |
Definition at line 258 of file Trigger.java.
Starts the given command when the condition changes to true and cancels it when the condition changes to false.
Unlike whileTrue(Command), the command is restarted if it ends while the condition is still true. If the command stopped because it was interrupted, restarting it will immediately interrupt the would-be interrupting command (if they have the same priority).
| command | the command to start |
Definition at line 241 of file Trigger.java.
| Trigger org.wpilib.command3.Trigger.risingEdge | ( | ) |
Creates a trigger that activates on a rising edge of this trigger's signal. The rising edge trigger is active in the same cycle that this trigger's condition is true while its condition in the previous cycle was false. The resulting trigger will only be active for that single cycle before going inactive again; therefore, onTrue(Command) should be used instead of whileTrue(Command), as commands bound using the latter method will be immediately canceled after a single scheduler cycle.
Definition at line 368 of file Trigger.java.
Toggles a command when the condition changes from true to false.
| command | the command to toggle |
Definition at line 282 of file Trigger.java.
Toggles a command when the condition changes from false to true.
| command | the command to toggle |
Definition at line 270 of file Trigger.java.
Starts the given command when the condition changes to false and cancels it when the condition changes to true.
Unlike retryWhileFalse(Command), this does not restart the command if it ends while the condition is still false.
| command | the command to start |
Definition at line 224 of file Trigger.java.
Starts the given command when the condition changes to true and cancels it when the condition changes to false.
Unlike retryWhileTrue(Command), this does not restart the command if it ends while the condition is still true.
| command | the command to start |
Definition at line 208 of file Trigger.java.