41 explicit Trigger(std::function<
bool()> condition)
43 std::move(condition)} {}
52 : m_loop{loop}, m_condition{
std::move(condition)} {}
227 return Trigger(m_loop, [condition = m_condition, rhs = std::move(rhs)] {
228 return condition() && rhs();
238 return Trigger(m_loop, [condition = m_condition, rhs] {
239 return condition() && rhs.m_condition();
249 return Trigger(m_loop, [condition = m_condition, rhs = std::move(rhs)] {
250 return condition() || rhs();
260 return Trigger(m_loop, [condition = m_condition, rhs] {
261 return condition() || rhs.m_condition();
272 return Trigger(m_loop, [condition = m_condition] {
return !condition(); });
303 std::function<bool()> m_condition;
A state machine representing a complete action to be performed by the robot.
Definition Command.h:41
A wrapper around std::unique_ptr<Command> so commands have move-only semantics.
Definition CommandPtr.h:28
The scheduler responsible for running Commands.
Definition CommandScheduler.h:38
This class provides an easy way to link commands to conditions.
Definition Trigger.h:32
bool Get() const
Returns the current state of this trigger.
Trigger OnFalse(CommandPtr &&command)
Starts the given command whenever the condition changes from true to false.
Trigger()
Create a new trigger that is always false.
Definition Trigger.h:57
Trigger operator&&(std::function< bool()> rhs)
Composes two triggers with logical AND.
Definition Trigger.h:226
Trigger WhileTrue(CommandPtr &&command)
Starts the given command when the condition changes to true and cancels it when the condition changes...
Trigger operator!()
Composes a trigger with logical NOT.
Definition Trigger.h:271
Trigger WhileFalse(Command *command)
Starts the given command when the condition changes to false and cancels it when the condition change...
Trigger OnFalse(Command *command)
Starts the given command whenever the condition changes from true to false.
Trigger operator&&(Trigger rhs)
Composes two triggers with logical AND.
Definition Trigger.h:237
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 ...
Trigger OnTrue(CommandPtr &&command)
Starts the given command whenever the condition changes from false to true.
Trigger OnTrue(Command *command)
Starts the given command whenever the condition changes from false to true.
Trigger OnChange(Command *command)
Starts the command when the condition changes.
Trigger WhileFalse(CommandPtr &&command)
Starts the given command when the condition changes to false and cancels it when the condition change...
Trigger(const Trigger &other)
Trigger ToggleOnTrue(Command *command)
Toggles a command when the condition changes from false to true.
Trigger operator||(Trigger rhs)
Composes two triggers with logical OR.
Definition Trigger.h:259
Trigger operator||(std::function< bool()> rhs)
Composes two triggers with logical OR.
Definition Trigger.h:248
Trigger OnChange(CommandPtr &&command)
Starts the command when the condition changes.
Trigger ToggleOnFalse(CommandPtr &&command)
Toggles a command when the condition changes from true to false.
Trigger WhileTrue(Command *command)
Starts the given command when the condition changes to true and cancels it when the condition changes...
Trigger ToggleOnTrue(CommandPtr &&command)
Toggles a command when the condition changes from false to true.
Trigger(frc::EventLoop *loop, std::function< bool()> condition)
Creates a new trigger based on the given condition.
Definition Trigger.h:51
Trigger(std::function< bool()> condition)
Creates a new trigger based on the given condition.
Definition Trigger.h:41
Trigger ToggleOnFalse(Command *command)
Toggles a command when the condition changes from true to the low state.
DebounceType
Type of debouncing to perform.
Definition Debouncer.h:23
@ kRising
Rising edge.
Definition Debouncer.h:25
A declarative way to bind a set of actions to a loop and execute them when the loop is polled.
Definition EventLoop.h:15
unique_function is a type-erasing functor similar to std::function.
Definition FunctionExtras.h:57
Definition FunctionalCommand.h:13
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280