Trigger
- class commands2.button.Trigger(condition: Callable[[], bool] = lambda : ...)[source]
- class commands2.button.Trigger(loop: EventLoop, condition: Callable[[], bool])
Bases:
object
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.
- and_(other: Callable[[], bool]) Trigger [source]
Composes two triggers with logical AND.
- Parameters:
trigger – the condition to compose with
- Returns:
A trigger which is active when both component triggers are active.
- debounce(seconds: float, debounce_type: ~wpimath.filter._filter.Debouncer.DebounceType = <DebounceType.kRising: 0>) Trigger [source]
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:
seconds – The debounce period.
type – The debounce type.
- Returns:
The debounced trigger.
- negate() Trigger [source]
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(command: Command) Self [source]
Starts the given command whenever the condition changes from True to False.
- Parameters:
command – the command to start
- Returns:
this trigger, so calls can be chained
- onTrue(command: Command) Self [source]
Starts the given command whenever the condition changes from False to True.
- Parameters:
command – the command to start
- Returns:
this trigger, so calls can be chained
- or_(other: Callable[[], bool]) Trigger [source]
Composes two triggers with logical OR.
- Parameters:
trigger – the condition to compose with
- Returns:
A trigger which is active when either component trigger is active.
- toggleOnFalse(command: Command) Self [source]
Toggles a command when the condition changes from True to False.
- Parameters:
command – the command to toggle
- Returns:
this trigger, so calls can be chained
- toggleOnTrue(command: Command) Self [source]
Toggles a command when the condition changes from False to True.
- Parameters:
command – the command to toggle
- Returns:
this trigger, so calls can be chained
- whileFalse(command: Command) Self [source]
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
commands2.RepeatCommand
.- Parameters:
command – the command to start
- Returns:
this trigger, so calls can be chained
- whileTrue(command: Command) Self [source]
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
commands2.RepeatCommand
.- Parameters:
command – the command to start
- Returns:
this trigger, so calls can be chained