14#include "wpi/units/time.hpp"
68 virtual void End(
bool interrupted);
404 [[deprecated(
"Use CommandScheduler::GetInstance().Schedule() instead.")]]
486 std::optional<std::string> m_previousComposition;
This file defines the SmallSet class.
@ name
Definition base.h:690
A state machine representing a complete action to be performed by the robot.
Definition Command.hpp:41
Command & operator=(const Command &rhs)
virtual bool RunsWhenDisabled() const
Whether the given command should run when the robot is disabled.
Definition Command.hpp:459
CommandPtr Unless(std::function< bool()> condition) &&
Decorates this command to only run if this condition is not met.
friend class CommandPtr
Definition Command.hpp:185
void SetComposed(bool isComposed)
Sets whether the command is currently composed in a command composition.
std::optional< std::string > GetPreviousCompositionSite() const
Get the stacktrace of where this command was composed, or an empty optional.
CommandPtr WithTimeout(wpi::units::second_t duration) &&
Decorates this command with a timeout.
CommandPtr AsProxy() &&
Decorates this command to run "by proxy" by wrapping it in a ProxyCommand.
CommandPtr BeforeStarting(std::function< void()> toRun, Requirements requirements={}) &&
Decorates this command with a runnable to run before this command starts.
CommandPtr WithInterruptBehavior(Command::InterruptionBehavior interruptBehavior) &&
Decorates this command to have a different interrupt behavior.
Command(const Command &)=default
void AddRequirements(wpi::util::SmallSet< Subsystem *, 4 > requirements)
Adds the specified Subsystem requirements to the command.
bool IsScheduled() const
Whether or not the command is currently scheduled.
bool HasRequirement(Subsystem *requirement) const
Whether the command requires a given subsystem.
bool IsComposed() const
Whether the command is currently grouped in a command group.
CommandPtr OnlyIf(std::function< bool()> condition) &&
Decorates this command to only run if this condition is met.
virtual void End(bool interrupted)
The action to take when the command ends.
CommandPtr FinallyDo(std::function< void(bool)> end) &&
Decorates this command with a lambda to call on interrupt or end, following the command's inherent Co...
std::string GetName() const
Gets the name of this Command.
InterruptionBehavior
An enum describing the command's behavior when another command with a shared requirement is scheduled...
Definition Command.hpp:173
@ kCancelSelf
This command ends, End(true) is called, and the incoming command is scheduled normally.
Definition Command.hpp:180
@ kCancelIncoming
This command continues, and the incoming command is not scheduled.
Definition Command.hpp:182
CommandPtr AndThen(CommandPtr &&next) &&
Decorates this command with a set of commands to run after it in sequence.
CommandPtr DeadlineFor(CommandPtr &¶llel) &&
Decorates this command with a set of commands to run parallel to it, ending when the calling command ...
virtual InterruptionBehavior GetInterruptionBehavior() const
How the command behaves when another command with a shared requirement is scheduled.
Definition Command.hpp:467
std::string GetSubsystem() const
Gets the subsystem name of this Command.
CommandPtr AndThen(std::function< void()> toRun, Requirements requirements={}) &&
Decorates this command with a runnable to run after the command finishes.
void Cancel()
Cancels this command.
CommandPtr RaceWith(CommandPtr &¶llel) &&
Decorates this command with a set of commands to run parallel to it, ending when the first command en...
void AddRequirements(Requirements requirements)
Adds the specified Subsystem requirements to the command.
virtual void Execute()
The main body of a command.
CommandPtr BeforeStarting(CommandPtr &&before) &&
Decorates this command with another command to run before this command starts.
CommandPtr WithName(std::string_view name) &&
Decorates this Command with a name.
void InitSendable(wpi::util::SendableBuilder &builder) override
Initializes this Sendable object.
void Schedule()
Schedules this command.
CommandPtr AlongWith(CommandPtr &¶llel) &&
Decorates this command with a set of commands to run parallel to it, ending when the last command end...
CommandPtr WithDeadline(CommandPtr &&deadline) &&
Creates a new command that runs this command and the deadline in parallel, finishing (and interruptin...
void SetSubsystem(std::string_view subsystem)
Sets the subsystem name of this Command.
Command & operator=(Command &&)=default
virtual CommandPtr ToPtr() &&=0
Transfers ownership of this command to a unique pointer.
virtual void Initialize()
The initial subroutine of a command.
CommandPtr OnlyWhile(std::function< bool()> condition) &&
Decorates this command with a run condition.
CommandPtr HandleInterrupt(std::function< void()> handler) &&
Decorates this command with a lambda to call on interrupt, following the command's inherent Command::...
CommandPtr Repeatedly() &&
Decorates this command to run repeatedly, restarting it when it ends, until this command is interrupt...
void SetName(std::string_view name)
Sets the name of this Command.
CommandPtr IgnoringDisable(bool doesRunWhenDisabled) &&
Decorates this command to run or stop when disabled.
CommandPtr Until(std::function< bool()> condition) &&
Decorates this command with an interrupt condition.
Command(Command &&)=default
CommandPtr FinallyDo(std::function< void()> end) &&
Decorates this command with a lambda to call on interrupt or end, following the command's inherent Co...
virtual bool IsFinished()
Whether the command has finished.
Definition Command.hpp:76
void AddRequirements(Subsystem *requirement)
Adds the specified Subsystem requirement to the command.
virtual wpi::util::SmallSet< Subsystem *, 4 > GetRequirements() const
Specifies the set of subsystems used by this command.
Represents requirements for a command, which is a set of (pointers to) subsystems.
Definition Requirements.hpp:20
A robot subsystem.
Definition Subsystem.hpp:42
Helper class for building Sendable dashboard representations.
Definition SendableBuilder.hpp:21
A helper class for use with objects that add themselves to SendableRegistry.
Definition SendableHelper.hpp:21
Interface for Sendable objects.
Definition Sendable.hpp:16
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.hpp:132
Definition CommandNiDsStadiaController.hpp:15
bool RequirementsDisjoint(Command *first, Command *second)
Checks if two commands have disjoint requirement sets.