WPILibC++ 2023.4.3-108-ge5452e3
|
This class provides an easy way to link commands to conditions. More...
#include <frc2/command/button/Trigger.h>
Public Member Functions | |
Trigger (std::function< bool()> condition) | |
Creates a new trigger based on the given condition. More... | |
Trigger (frc::EventLoop *loop, std::function< bool()> condition) | |
Creates a new trigger based on the given condition. More... | |
Trigger () | |
Create a new trigger that is always false . More... | |
Trigger (const Trigger &other) | |
Trigger | OnTrue (Command *command) |
Starts the given command whenever the condition changes from false to true . More... | |
Trigger | OnTrue (CommandPtr &&command) |
Starts the given command whenever the condition changes from false to true . More... | |
Trigger | OnFalse (Command *command) |
Starts the given command whenever the condition changes from true to false . More... | |
Trigger | OnFalse (CommandPtr &&command) |
Starts the given command whenever the condition changes from true to false . More... | |
Trigger | WhileTrue (Command *command) |
Starts the given command when the condition changes to true and cancels it when the condition changes to false . More... | |
Trigger | WhileTrue (CommandPtr &&command) |
Starts the given command when the condition changes to true and cancels it when the condition changes to false . More... | |
Trigger | WhileFalse (Command *command) |
Starts the given command when the condition changes to false and cancels it when the condition changes to true . More... | |
Trigger | WhileFalse (CommandPtr &&command) |
Starts the given command when the condition changes to false and cancels it when the condition changes to true . More... | |
Trigger | ToggleOnTrue (Command *command) |
Toggles a command when the condition changes from false to true . More... | |
Trigger | ToggleOnTrue (CommandPtr &&command) |
Toggles a command when the condition changes from false to true . More... | |
Trigger | ToggleOnFalse (Command *command) |
Toggles a command when the condition changes from true to the low state. More... | |
Trigger | ToggleOnFalse (CommandPtr &&command) |
Toggles a command when the condition changes from true to false . More... | |
Trigger | operator&& (std::function< bool()> rhs) |
Composes two triggers with logical AND. More... | |
Trigger | operator&& (Trigger rhs) |
Composes two triggers with logical AND. More... | |
Trigger | operator|| (std::function< bool()> rhs) |
Composes two triggers with logical OR. More... | |
Trigger | operator|| (Trigger rhs) |
Composes two triggers with logical OR. More... | |
Trigger | operator! () |
Composes a trigger with logical NOT. More... | |
Trigger | Debounce (units::second_t debounceTime, frc::Debouncer::DebounceType type=frc::Debouncer::DebounceType::kRising) |
Creates a new debounced trigger from this trigger - it will become active when this trigger has been active for longer than the specified period. More... | |
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 operator!
, operator||
, operator&&
operators.
This class is provided by the NewCommands VendorDep
|
inlineexplicit |
Creates a new trigger based on the given condition.
Polled by the default scheduler button loop.
condition | the condition represented by this trigger |
|
inline |
Creates a new trigger based on the given condition.
loop | The loop instance that polls this trigger. |
condition | the condition represented by this trigger |
|
inline |
Create a new trigger that is always false
.
frc2::Trigger::Trigger | ( | const Trigger & | other | ) |
Trigger frc2::Trigger::Debounce | ( | units::second_t | debounceTime, |
frc::Debouncer::DebounceType | type = frc::Debouncer::DebounceType::kRising |
||
) |
Creates a new debounced trigger from this trigger - it will become active when this trigger has been active for longer than the specified period.
debounceTime | The debounce period. |
type | The debounce type. |
Starts the given command whenever the condition changes from true
to false
.
Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.
command | the command to start |
Trigger frc2::Trigger::OnFalse | ( | CommandPtr && | command | ) |
Starts the given command whenever the condition changes from true
to false
.
command | The command to bind. |
Starts the given command whenever the condition changes from false
to true
.
Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.
command | the command to start |
Trigger frc2::Trigger::OnTrue | ( | CommandPtr && | command | ) |
Starts the given command whenever the condition changes from false
to true
.
Moves command ownership to the button scheduler.
command | The command to bind. |
|
inline |
Composes a trigger with logical NOT.
|
inline |
Composes two triggers with logical AND.
Composes two triggers with logical AND.
|
inline |
Composes two triggers with logical OR.
Composes two triggers with logical OR.
Toggles a command when the condition changes from true
to the low state.
Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.
command | the command to toggle |
Trigger frc2::Trigger::ToggleOnFalse | ( | CommandPtr && | command | ) |
Toggles a command when the condition changes from true
to false
.
Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.
command | the command to toggle |
Toggles a command when the condition changes from false
to true
.
Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.
command | the command to toggle |
Trigger frc2::Trigger::ToggleOnTrue | ( | CommandPtr && | command | ) |
Toggles a command when the condition changes from false
to true
.
Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.
command | the command to toggle |
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 true
. If the command should restart, see RepeatCommand.
Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.
command | the command to start |
Trigger frc2::Trigger::WhileFalse | ( | CommandPtr && | command | ) |
Starts the given command when the condition changes to false
and cancels it when the condition changes to true
.
Moves command ownership to the button scheduler.
Doesn't re-start the command if it ends while the condition is still false
. If the command should restart, see RepeatCommand.
command | The command to bind. |
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 RepeatCommand.
Takes a raw pointer, and so is non-owning; users are responsible for the lifespan of the command.
command | the command to start |
Trigger frc2::Trigger::WhileTrue | ( | CommandPtr && | command | ) |
Starts the given command when the condition changes to true
and cancels it when the condition changes to false
.
Moves command ownership to the button scheduler.
Doesn't re-start the command if it ends while the condition is still true
. If the command should restart, see RepeatCommand.
command | The command to bind. |