68 virtual void End(
bool interrupted);
436 [[deprecated(
"Use ToPtr() instead")]]
This file defines the SmallSet class.
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:41
bool IsScheduled() const
Whether or not the command is currently scheduled.
void Cancel()
Cancels this command.
std::string GetSubsystem() const
Gets the subsystem name of this Command.
CommandPtr AsProxy() &&
Decorates this command to run "by proxy" by wrapping it in a ProxyCommand.
virtual void End(bool interrupted)
The action to take when the command ends.
void InitSendable(wpi::SendableBuilder &builder) override
Initializes this Sendable object.
void AddRequirements(Requirements requirements)
Adds the specified Subsystem requirements to the command.
Command(Command &&)=default
CommandPtr HandleInterrupt(std::function< void()> handler) &&
Decorates this command with a lambda to call on interrupt, following the command's inherent Command::...
CommandPtr FinallyDo(std::function< void()> end) &&
Decorates this command with a lambda to call on interrupt or end, following the command's inherent Co...
CommandPtr WithTimeout(units::second_t duration) &&
Decorates this command with a timeout.
void AddRequirements(Subsystem *requirement)
Adds the specified Subsystem requirement to the command.
CommandPtr Repeatedly() &&
Decorates this command to run repeatedly, restarting it when it ends, until this command is interrupt...
std::optional< std::string > GetPreviousCompositionSite() const
Get the stacktrace of where this command was composed, or an empty optional.
void SetName(std::string_view name)
Sets the name of this Command.
virtual bool RunsWhenDisabled() const
Whether the given command should run when the robot is disabled.
Definition: Command.h:406
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.
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...
CommandPtr WithName(std::string_view name) &&
Decorates this Command with a name.
bool IsComposed() const
Whether the command is currently grouped in a command group.
Command(const Command &)=default
virtual wpi::SmallSet< Subsystem *, 4 > GetRequirements() const
Specifies the set of subsystems used by this command.
CommandPtr Until(std::function< bool()> condition) &&
Decorates this command with an interrupt condition.
virtual void Execute()
The main body of a command.
void AddRequirements(wpi::SmallSet< Subsystem *, 4 > requirements)
Adds the specified Subsystem requirements to the command.
CommandPtr OnlyWhile(std::function< bool()> condition) &&
Decorates this command with a run condition.
CommandPtr OnlyIf(std::function< bool()> condition) &&
Decorates this command to only run if this condition is met.
Command & operator=(const Command &rhs)
virtual InterruptionBehavior GetInterruptionBehavior() const
How the command behaves when another command with a shared requirement is scheduled.
Definition: Command.h:414
std::string GetName() const
Gets the name of this Command.
wpi::SmallSet< Subsystem *, 4 > m_requirements
Requirements set.
Definition: Command.h:430
virtual CommandPtr ToPtr() &&=0
Transfers ownership of this command to a unique pointer.
CommandPtr IgnoringDisable(bool doesRunWhenDisabled) &&
Decorates this command to run or stop when disabled.
void SetComposed(bool isComposed)
Sets whether the command is currently composed in a command composition.
bool HasRequirement(Subsystem *requirement) const
Whether the command requires a given subsystem.
virtual void Initialize()
The initial subroutine of a command.
void Schedule()
Schedules this command.
void SetSubsystem(std::string_view subsystem)
Sets the subsystem name of this Command.
InterruptionBehavior
An enum describing the command's behavior when another command with a shared requirement is scheduled...
Definition: Command.h:173
@ kCancelSelf
This command ends, End(true) is called, and the incoming command is scheduled normally.
Command & operator=(Command &&)=default
CommandPtr AndThen(std::function< void()> toRun, Requirements requirements={}) &&
Decorates this command with a runnable to run after the command finishes.
std::optional< std::string > m_previousComposition
Definition: Command.h:439
virtual std::unique_ptr< Command > TransferOwnership() &&=0
Transfers ownership of this command to a unique pointer.
virtual bool IsFinished()
Whether the command has finished.
Definition: Command.h:76
CommandPtr Unless(std::function< bool()> condition) &&
Decorates this command to only run if this condition is not met.
A wrapper around std::unique_ptr<Command> so commands have move-only semantics.
Definition: CommandPtr.h:29
Represents requirements for a command, which is a set of (pointers to) subsystems.
Definition: Requirements.h:20
A robot subsystem.
Definition: Subsystem.h:43
Helper class for building Sendable dashboard representations.
Definition: SendableBuilder.h:21
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:19
Interface for Sendable objects.
Definition: Sendable.h:16
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:135
basic_string_view< char > string_view
Definition: core.h:501
const T & first(const T &value, const Tail &...)
Definition: compile.h:60
Definition: TrapezoidProfileSubsystem.h:12
bool RequirementsDisjoint(Command *first, Command *second)
Checks if two commands have disjoint requirement sets.
constexpr const char * name(const T &)