RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
org.wpilib.command3.Trigger Class Reference
Inheritance diagram for org.wpilib.command3.Trigger:
org.wpilib.command3.button.InternalButton org.wpilib.command3.button.JoystickButton org.wpilib.command3.button.NetworkButton org.wpilib.command3.button.POVButton

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)

Detailed Description

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.

Positive trigger command bindings
MethodSchedulesCancels on false
onTrue(Command)On a rising edgeNo
ifTrue(Command)On every true pollNo
whileTrue(Command)On a rising edgeYes
retryWhileTrue(Command)On every true pollYes

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.

Constructor & Destructor Documentation

◆ Trigger() [1/3]

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.

Parameters
schedulerThe scheduler that should execute triggered commands.
conditionthe condition represented by this trigger

Definition at line 109 of file Trigger.java.

◆ Trigger() [2/3]

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.

Parameters
conditionthe condition represented by this trigger

Definition at line 124 of file Trigger.java.

◆ Trigger() [3/3]

org.wpilib.command3.Trigger.Trigger ( Scheduler scheduler,
EventLoop loop,
BooleanSupplier condition )

Creates a new trigger based on the given condition.

Parameters
schedulerThe scheduler that should execute triggered commands.
loopThe event loop to poll the trigger.
conditionthe condition represented by this trigger

Definition at line 136 of file Trigger.java.

Member Function Documentation

◆ and()

Trigger org.wpilib.command3.Trigger.and ( BooleanSupplier trigger)

Composes two triggers with logical AND.

Parameters
triggerthe condition to compose with
Returns
A trigger which is active when both component triggers are active.

Definition at line 310 of file Trigger.java.

◆ debounce() [1/2]

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.

Parameters
durationThe debounce period.
Returns
The debounced trigger (rising edges debounced only)

Definition at line 341 of file Trigger.java.

◆ debounce() [2/2]

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.

Parameters
durationThe debounce period.
typeThe debounce type.
Returns
The debounced trigger.

Definition at line 353 of file Trigger.java.

◆ fallingEdge()

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.

Returns
A falling edge trigger.

Definition at line 383 of file Trigger.java.

◆ getAsBoolean()

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.

Returns
The state of the trigger.

Definition at line 300 of file Trigger.java.

◆ ifTrue()

Trigger org.wpilib.command3.Trigger.ifTrue ( Command command)

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.

Parameters
commandthe command to start
Returns
this trigger, so calls can be chained

Definition at line 180 of file Trigger.java.

◆ multiPress()

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.

Parameters
pressCountThe number of rising edges to require. If this is non-positive, the trigger will always be active.
durationThe duration within which the rising edges must occur. If this is non-positive, the trigger will never activate.
Returns
A trigger that activates on multiple presses

Definition at line 398 of file Trigger.java.

◆ negate()

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.

Returns
the negated trigger

Definition at line 330 of file Trigger.java.

◆ onFalse()

Trigger org.wpilib.command3.Trigger.onFalse ( Command command)

Starts the given command whenever the condition changes from true to false.

Parameters
commandthe command to start
Returns
this trigger, so calls can be chained

Definition at line 192 of file Trigger.java.

◆ onTrue()

Trigger org.wpilib.command3.Trigger.onTrue ( Command command)

Starts the given command whenever the condition changes from false to true.

Parameters
commandthe command to start
Returns
this trigger, so calls can be chained

Definition at line 164 of file Trigger.java.

◆ or()

Trigger org.wpilib.command3.Trigger.or ( BooleanSupplier trigger)

Composes two triggers with logical OR.

Parameters
triggerthe condition to compose with
Returns
A trigger which is active when either component trigger is active.

Definition at line 320 of file Trigger.java.

◆ retryWhileFalse()

Trigger org.wpilib.command3.Trigger.retryWhileFalse ( Command command)

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).

Parameters
commandthe command to start
Returns
this trigger, so calls can be chained

Definition at line 258 of file Trigger.java.

◆ retryWhileTrue()

Trigger org.wpilib.command3.Trigger.retryWhileTrue ( Command command)

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).

Parameters
commandthe command to start
Returns
this trigger, so calls can be chained

Definition at line 241 of file Trigger.java.

◆ risingEdge()

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.

Returns
A rising edge trigger.

Definition at line 368 of file Trigger.java.

◆ toggleOnFalse()

Trigger org.wpilib.command3.Trigger.toggleOnFalse ( Command command)

Toggles a command when the condition changes from true to false.

Parameters
commandthe command to toggle
Returns
this trigger, so calls can be chained

Definition at line 282 of file Trigger.java.

◆ toggleOnTrue()

Trigger org.wpilib.command3.Trigger.toggleOnTrue ( Command command)

Toggles a command when the condition changes from false to true.

Parameters
commandthe command to toggle
Returns
this trigger, so calls can be chained

Definition at line 270 of file Trigger.java.

◆ whileFalse()

Trigger org.wpilib.command3.Trigger.whileFalse ( Command command)

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.

Parameters
commandthe command to start
Returns
this trigger, so calls can be chained

Definition at line 224 of file Trigger.java.

◆ whileTrue()

Trigger org.wpilib.command3.Trigger.whileTrue ( Command command)

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.

Parameters
commandthe command to start
Returns
this trigger, so calls can be chained

Definition at line 208 of file Trigger.java.


The documentation for this class was generated from the following file: