8#include <initializer_list>
44 explicit Trigger(std::function<
bool()> condition)
46 std::move(condition)} {}
55 : m_loop{loop}, m_condition{
std::move(condition)} {}
216 WPI_DEPRECATED(
"Use OnTrue(Command) instead")
233 m_loop->
Bind([condition = m_condition, previous = m_condition(),
234 command = std::make_unique<std::remove_reference_t<T>>(
235 std::forward<T>(command))]()
mutable {
236 bool current = condition();
238 if (!previous && current) {
256 "Use OnTrue(Command) instead and construct the InstantCommand manually")
284 "Use WhileTrue(Command) with RepeatCommand, or bind command::Schedule "
285 "with IfHigh(std::function<void()>).")
303 "with IfHigh(
std::function<
void()>).")
305 m_loop->
Bind([condition = m_condition, previous = m_condition(),
306 command = std::make_unique<std::remove_reference_t<T>>(
307 std::forward<T>(command))]()
mutable {
308 bool current = condition();
312 }
else if (previous && !current) {
329 WPI_DEPRECATED(
"Use WhileTrue(Command) and construct a RunCommand manually")
353 WPI_DEPRECATED(
"Use WhileTrue(Command) instead.")
370 m_loop->
Bind([condition = m_condition, previous = m_condition(),
371 command = std::make_unique<std::remove_reference_t<T>>(
372 std::forward<T>(command))]()
mutable {
373 bool current = condition();
375 if (!previous && current) {
377 }
else if (previous && !current) {
395 WPI_DEPRECATED(
"Use OnFalse(Command) instead.")
412 m_loop->
Bind([condition = m_condition, previous = m_condition(),
413 command = std::make_unique<std::remove_reference_t<T>>(
414 std::forward<T>(command))]()
mutable {
415 bool current = condition();
417 if (previous && !current) {
435 "Use OnFalse(Command) instead and construct the InstantCommand manually")
461 WPI_DEPRECATED(
"Use ToggleOnTrue(Command) instead.")
478 m_loop->
Bind([condition = m_condition, previous = m_condition(),
479 command = std::make_unique<std::remove_reference_t<T>>(
480 std::forward<T>(command))]()
mutable {
481 bool current = condition();
483 if (!previous && current) {
484 if (command->IsScheduled()) {
506 WPI_DEPRECATED(
"Pass this as a command end condition with Until() instead.")
515 return Trigger(m_loop, [condition = m_condition, rhs = std::move(rhs)] {
516 return condition() && rhs();
526 return Trigger(m_loop, [condition = m_condition, rhs] {
527 return condition() && rhs.m_condition();
537 return Trigger(m_loop, [condition = m_condition, rhs = std::move(rhs)] {
538 return condition() || rhs();
548 return Trigger(m_loop, [condition = m_condition, rhs] {
549 return condition() || rhs.m_condition();
560 return Trigger(m_loop, [condition = m_condition] {
return !condition(); });
573 frc::Debouncer::DebounceType::kRising);
577 std::function<bool()> m_condition;
and(b) You must cause any modified files to carry prominent notices stating that You changed the files
or
Definition: ThirdPartyNotices.txt:199
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:47
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:36
A Command that runs instantly; it will initialize, execute once, and end on the same iteration of the...
Definition: InstantCommand.h:22
A command that runs another command repeatedly, restarting it when it ends, until this command is int...
Definition: RepeatCommand.h:31
A command that runs a Runnable continuously.
Definition: RunCommand.h:23
A robot subsystem.
Definition: Subsystem.h:39
This class provides an easy way to link commands to conditions.
Definition: Trigger.h:35
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:60
Trigger CancelWhenActive(Command *command)
Binds a command to be canceled when the trigger becomes active.
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:559
Trigger WhenInactive(Command *command)
Binds a command to start when the trigger becomes inactive.
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:525
Trigger ToggleWhenActive(Command *command)
Binds a command to start when the trigger becomes active, and be canceled when it again becomes activ...
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 WhileActiveContinous(Command *command)
Binds a command to be started repeatedly while the trigger is active, and canceled when it becomes in...
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:547
Trigger operator||(std::function< bool()> rhs)
Composes two triggers with logical OR.
Definition: Trigger.h:536
Trigger WhenActive(Command *command)
Binds a command to start when the trigger becomes active.
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:54
Trigger WhileActiveOnce(Command *command)
Binds a command to be started when the trigger becomes active, and canceled when it becomes inactive.
Trigger(std::function< bool()> condition)
Creates a new trigger based on the given condition.
Definition: Trigger.h:44
Trigger ToggleOnFalse(Command *command)
Toggles a command when the condition changes from true to the low state.
DebounceType
Definition: Debouncer.h:20
The loop polling BooleanEvent objects and executing the actions bound to them.
Definition: EventLoop.h:15
void Bind(wpi::unique_function< void()> action)
Bind a new action to run.
typename std::enable_if< B, T >::type enable_if_t
Definition: core.h:298
typename std::remove_reference< T >::type remove_reference_t
Definition: core.h:303
type
Definition: core.h:575
Definition: InstantCommand.h:14
Definition: StdDeque.h:50