Trigger

class wpilib.buttons.Trigger(addLiveWindow=True)[source]

Bases: wpilib.SendableBase

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.

Creates an instance of the sensor base.

Parameters:addLiveWindow – if true, add this Sendable to LiveWindow
cancelWhenActive(command)[source]

Cancels a command when the trigger becomes active.

Parameters:command (Command) – the command to cancel
Return type:None
get()[source]

Returns whether or not the trigger is active

This method will be called repeatedly a command is linked to the Trigger.

Return type:bool
Returns:whether or not the trigger condition is active.
grab()[source]

Returns whether get() returns True or the internal table for SmartDashboard use is pressed.

Return type:bool
initSendable(builder)[source]
toggleWhenActive(command)[source]

Toggles a command when the trigger becomes active.

Parameters:command (Command) – the command to toggle
whenActive(command)[source]

Starts the given command whenever the trigger just becomes active.

Parameters:command (Command) – the command to start
Return type:None
whenInactive(command)[source]

Starts the command when the trigger becomes inactive.

Parameters:command (Command) – the command to start
whileActive(command)[source]

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