Class Command

Inheritance Relationships

Derived Types

Class Documentation

class Command

A generic extendable class for implementing a command. Each command is attached to a subsystem. To create a new command, extend the Command class and instantiate the virtual functions in this class. See example_command.hpp for example of this.

Subclassed by tap::control::ComprisedCommand, tap::control::ConcurrentTemplateCommand< COMMANDS, RACE >, tap::control::SequentialCommand< COMMANDS >, tap::control::governor::GovernorLimitedCommand< NUM_CONDITIONS >, tap::control::governor::GovernorWithFallbackCommand< NUM_CONDITIONS >, tap::control::setpoint::CalibrateCommand, tap::control::setpoint::MoveAbsoluteCommand, tap::control::setpoint::MoveCommand, tap::control::setpoint::MoveIntegralCommand, tap::control::setpoint::UnjamCommand, tap::control::setpoint::UnjamCommandInterface

Public Functions

Command()
virtual ~Command()
inline subsystem_scheduler_bitmap_t getRequirementsBitwise() const

Specifies the encoded set of subsystems used by this command. Two commands cannot use the same subsystem at the same time. If another command is scheduled that shares a requirement, the command will be interrupted. If no subsystems are required, return an empty set.

The generic Command class contains a list of the requrements. The user should add requirements to this list accordingly (typically in the constructor of a class extending the Command class). If a Command does not specify any requirements, the Command cannot be added to the CommandScheduler.

See also

CommandScheduler

Returns:

the set of subsystems that are required.

inline int getGlobalIdentifier() const
void addSubsystemRequirement(Subsystem *requirement)

Adds the required subsystem to a list of required subsystems.

Parameters:

requirement[in] the requirement to add to the list of requirements. If the requirement is nullptr or if the requirement is already in the set, nothing is added.

virtual const char *getName() const = 0
Returns:

the name of the command, to be implemented by derived classes.

virtual bool isReady()

A check called right before a command is scheduled to determine whether or not a command should be scheduled. If return is true then the command is scheduled, if false then the command is not scheduled.

Not forced to be overridden, returns true by default.

virtual void initialize() = 0

The initial subroutine of a command. Called once when the command is initially scheduled by a CommandScheduler.

Note that command instances are re-used: a single command could be initialized, run, finished, then later initialized again. Ensure that initialize() resets any state stored in the command!

virtual void execute() = 0

The main body of a command. Called repeatedly while the command is scheduled by a CommandScheduler.

virtual void end(bool interrupted) = 0

The action to take when the command ends. Called when either the command finishes normally, or when it interrupted/canceled.

Parameters:

interrupted[in] whether the command was interrupted/canceled.

virtual bool isFinished() const = 0

Whether the command has finished. Once a Command finishes, the scheduler will call the end() function and un-schedule it. If a Command is naturally finished (i.e. isFinished() == true), then the CommandScheduler will pass in false to end(). If, for example, another Command is added that in turn stops the Command from executing, then the CommandScheduler will pass in true to end().

Returns:

whether the command has finished.

Protected Attributes

command_scheduler_bitmap_t commandRequirementsBitwise = 0