Robot Core Documentation
Loading...
Searching...
No Matches
edu.wpi.first.wpilibj2.command.button.Trigger Class Reference
Inheritance diagram for edu.wpi.first.wpilibj2.command.button.Trigger:
edu.wpi.first.wpilibj2.command.button.InternalButton edu.wpi.first.wpilibj2.command.button.JoystickButton edu.wpi.first.wpilibj2.command.button.POVButton

Public Member Functions

 Trigger (EventLoop loop, BooleanSupplier condition)
 
 Trigger (BooleanSupplier condition)
 
Trigger onTrue (Command command)
 
Trigger onFalse (Command command)
 
Trigger whileTrue (Command command)
 
Trigger whileFalse (Command command)
 
Trigger toggleOnTrue (Command command)
 
Trigger toggleOnFalse (Command command)
 
Trigger and (BooleanSupplier trigger)
 
Trigger or (BooleanSupplier trigger)
 
Trigger negate ()
 
Trigger debounce (double seconds)
 
Trigger debounce (double seconds, Debouncer.DebounceType type)
 

Detailed Description

This class provides an easy way to link commands to conditions.

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.

This class is provided by the NewCommands VendorDep

Constructor & Destructor Documentation

◆ Trigger() [1/2]

edu.wpi.first.wpilibj2.command.button.Trigger.Trigger ( EventLoop loop,
BooleanSupplier condition )

Creates a new trigger based on the given condition.

Parameters
loopThe loop instance that polls this trigger.
conditionthe condition represented by this trigger

◆ Trigger() [2/2]

edu.wpi.first.wpilibj2.command.button.Trigger.Trigger ( BooleanSupplier condition)

Creates a new trigger based on the given condition.

Polled by the default scheduler button loop.

Parameters
conditionthe condition represented by this trigger

Member Function Documentation

◆ and()

Trigger edu.wpi.first.wpilibj2.command.button.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.

◆ debounce() [1/2]

Trigger edu.wpi.first.wpilibj2.command.button.Trigger.debounce ( double seconds)

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
secondsThe debounce period.
Returns
The debounced trigger (rising edges debounced only)

◆ debounce() [2/2]

Trigger edu.wpi.first.wpilibj2.command.button.Trigger.debounce ( double seconds,
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
secondsThe debounce period.
typeThe debounce type.
Returns
The debounced trigger.

◆ negate()

Trigger edu.wpi.first.wpilibj2.command.button.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

◆ onFalse()

Trigger edu.wpi.first.wpilibj2.command.button.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

◆ onTrue()

Trigger edu.wpi.first.wpilibj2.command.button.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

◆ or()

Trigger edu.wpi.first.wpilibj2.command.button.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.

◆ toggleOnFalse()

Trigger edu.wpi.first.wpilibj2.command.button.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

◆ toggleOnTrue()

Trigger edu.wpi.first.wpilibj2.command.button.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

◆ whileFalse()

Trigger edu.wpi.first.wpilibj2.command.button.Trigger.whileFalse ( Command command)

Starts the given command when the condition changes to false and cancels it when the condition changes to true.

Doesn't re-start the command if it ends while the condition is still false. If the command should restart, see edu.wpi.first.wpilibj2.command.RepeatCommand.

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

◆ whileTrue()

Trigger edu.wpi.first.wpilibj2.command.button.Trigger.whileTrue ( Command command)

Starts the given command when the condition changes to true and cancels it when the condition changes to false.

Doesn't re-start the command if it ends while the condition is still true. If the command should restart, see edu.wpi.first.wpilibj2.command.RepeatCommand.

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

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