Package edu.wpi.first.wpilibj.buttons
Class Trigger
java.lang.Object
edu.wpi.first.wpilibj.buttons.Trigger
- All Implemented Interfaces:
Sendable
- Direct Known Subclasses:
Button
public abstract class Trigger extends Object implements Sendable
This class provides an easy way to link commands to inputs.
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.
It is encouraged that teams write a subclass of Trigger if they want to have something unusual
(for instance, if they want to react to the user holding a button while the robot is reading a
certain sensor input). For this, they only have to write the get() method to get
the full functionality of the Trigger class.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTrigger.ButtonSchedulerAn internal class ofTrigger. -
Constructor Summary
Constructors Constructor Description Trigger() -
Method Summary
Modifier and Type Method Description voidcancelWhenActive(Command command)Cancels a command when the trigger becomes active.abstract booleanget()Returns whether or not the trigger is active.voidinitSendable(SendableBuilder builder)Initializes thisSendableobject.voidtoggleWhenActive(Command command)Toggles a command when the trigger becomes active.voidwhenActive(Command command)Starts the given command whenever the trigger just becomes active.voidwhenInactive(Command command)Starts the command when the trigger becomes inactive.voidwhileActive(Command command)Constantly starts the given command while the button is held.
-
Constructor Details
-
Method Details
-
get
Returns whether or not the trigger is active.This method will be called repeatedly a command is linked to the Trigger.
- Returns:
- whether or not the trigger condition is active.
-
whenActive
Starts the given command whenever the trigger just becomes active.- Parameters:
command- the command to start
-
whileActive
Constantly starts the given command while the button is held.Command.start()will be called repeatedly while the trigger is active, and will be canceled when the trigger becomes inactive.- Parameters:
command- the command to start
-
whenInactive
Starts the command when the trigger becomes inactive.- Parameters:
command- the command to start
-
toggleWhenActive
Toggles a command when the trigger becomes active.- Parameters:
command- the command to toggle
-
cancelWhenActive
Cancels a command when the trigger becomes active.- Parameters:
command- the command to cancel
-
initSendable
Description copied from interface:SendableInitializes thisSendableobject.- Specified by:
initSendablein interfaceSendable- Parameters:
builder- sendable builder
-