#include <Command.h>
Public Types | |
typedef std::set< Subsystem * > | SubsystemSet |
Public Member Functions | |
Command () | |
Command (const char *name) | |
Command (double timeout) | |
Command (const char *name, double timeout) | |
double | TimeSinceInitialized () |
void | Requires (Subsystem *s) |
bool | IsCanceled () |
void | Start () |
bool | Run () |
void | Cancel () |
bool | IsRunning () |
bool | IsInterruptible () |
void | SetInterruptible (bool interruptible) |
bool | DoesRequire (Subsystem *subsystem) |
SubsystemSet | GetRequirements () |
CommandGroup * | GetGroup () |
void | SetRunWhenDisabled (bool run) |
bool | WillRunWhenDisabled () |
int | GetID () |
virtual std::string | GetName () |
virtual void | InitTable (ITable *table) |
virtual ITable * | GetTable () |
virtual std::string | GetSmartDashboardType () |
virtual void | ValueChanged (ITable *source, const std::string &key, EntryValue value, bool isNew) |
Public Member Functions inherited from ErrorBase | |
virtual Error & | GetError () |
Retrieve the current error. Get the current error information associated with this sensor. | |
virtual const Error & | GetError () const |
virtual void | SetErrnoError (const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set error information associated with a C library call that set an error to the "errno" global variable. More... | |
virtual void | SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated from the nivision Imaq API. More... | |
virtual void | SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const |
Set the current error information associated with this sensor. More... | |
virtual void | CloneError (ErrorBase *rhs) const |
virtual void | ClearError () const |
Clear the current error information associated with this sensor. | |
virtual bool | StatusIsFatal () const |
Check if the current error code represents a fatal error. More... | |
Protected Member Functions | |
void | SetTimeout (double timeout) |
bool | IsTimedOut () |
bool | AssertUnlocked (const char *message) |
void | SetParent (CommandGroup *parent) |
virtual void | Initialize ()=0 |
virtual void | Execute ()=0 |
virtual bool | IsFinished ()=0 |
virtual void | End ()=0 |
virtual void | Interrupted ()=0 |
virtual void | _Initialize () |
virtual void | _Interrupted () |
virtual void | _Execute () |
virtual void | _End () |
virtual void | _Cancel () |
Protected Member Functions inherited from ErrorBase | |
ErrorBase () | |
Initialize the instance status to 0 for now. | |
Protected Attributes | |
ITable * | m_table |
Protected Attributes inherited from ErrorBase | |
Error | m_error |
Friends | |
class | CommandGroup |
class | Scheduler |
Additional Inherited Members | |
Static Public Member Functions inherited from ErrorBase | |
static void | SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) |
static void | SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) |
static Error & | GetGlobalError () |
Static Protected Attributes inherited from ErrorBase | |
static SEM_ID | _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE) |
static Error | _globalError |
The Command class is at the very core of the entire command framework. Every command can be started with a call to Start(). Once a command is started it will call Initialize(), and then will repeatedly call Execute() until the IsFinished() returns true. Once it does, End() will be called.
However, if at any point while it is running Cancel() is called, then the command will be stopped and Interrupted() will be called.
If a command uses a Subsystem, then it should specify that it does so by calling the Requires(...) method in its constructor. Note that a Command may have multiple requirements, and Requires(...) should be called for each one.
If a command is running and a new command with shared requirements is started, then one of two things will happen. If the active command is interruptible, then Cancel() will be called and the command will be removed to make way for the new one. If the active command is not interruptible, the other one will not even be started, and the active one will continue functioning.
Command::Command | ( | ) |
Creates a new command. The name of this command will be default.
Definition at line 50 of file Command.cpp.
Command::Command | ( | const char * | name | ) |
Creates a new command with the given name and no timeout.
name | the name for this command |
Definition at line 59 of file Command.cpp.
Command::Command | ( | double | timeout | ) |
Creates a new command with the given timeout and a default name.
timeout | the time (in seconds) before this command "times out" |
Definition at line 71 of file Command.cpp.
Command::Command | ( | const char * | name, |
double | timeout | ||
) |
Creates a new command with the given name and timeout.
name | the name of the command |
timeout | the time (in seconds) before this command "times out" |
Definition at line 84 of file Command.cpp.
|
protectedvirtual |
This works like cancel(), except that it doesn't throw an exception if it is a part of a command group. Should only be called by the parent command group.
Definition at line 365 of file Command.cpp.
|
protected |
If changes are locked, then this will generate a CommandIllegalUse error.
message | the message to report on error (it is appended by a default message) |
Definition at line 278 of file Command.cpp.
void Command::Cancel | ( | ) |
This will cancel the current command.
This will cancel the current command eventually. It can be called multiple times. And it can be called when the command is not running. If the command is running though, then the command will be marked as canceled and eventually removed.
A command can not be canceled if it is a part of a command group, you must cancel the command group instead.
Definition at line 353 of file Command.cpp.
bool Command::DoesRequire | ( | Subsystem * | system | ) |
Checks if the command requires the given Subsystem.
system | the system |
Definition at line 403 of file Command.cpp.
|
protectedpure virtual |
Called when the command ended peacefully. This is where you may want to wrap up loose ends, like shutting off a motor that was being used in the command.
Implemented in CommandGroup, PrintCommand, WaitCommand, WaitForChildren, WaitUntilCommand, and StartCommand.
|
protectedpure virtual |
The execute method is called repeatedly until this Command either finishes or is canceled.
Implemented in CommandGroup, PrintCommand, WaitCommand, WaitForChildren, WaitUntilCommand, and StartCommand.
CommandGroup * Command::GetGroup | ( | ) |
Returns the CommandGroup that this command is a part of. Will return null if this Command is not in a group.
Definition at line 413 of file Command.cpp.
int Command::GetID | ( | ) |
Get the ID (sequence number) for this command The ID is a unique sequence number that is incremented for each command.
Definition at line 105 of file Command.cpp.
|
virtual |
Implements NamedSendable.
Definition at line 438 of file Command.cpp.
Command::SubsystemSet Command::GetRequirements | ( | ) |
Returns the requirements (as an std::set of Subsystems pointers) of this command
Definition at line 260 of file Command.cpp.
|
virtual |
Implements Sendable.
Reimplemented in PIDCommand.
Definition at line 443 of file Command.cpp.
|
virtual |
Implements Sendable.
Definition at line 461 of file Command.cpp.
|
protectedpure virtual |
The initialize method is called the first time this Command is run after being started.
Implemented in CommandGroup, PrintCommand, WaitCommand, WaitForChildren, WaitUntilCommand, and StartCommand.
|
virtual |
Initializes a table for this sendable object.
subtable | The table to put the values in. |
Implements Sendable.
Reimplemented in PIDCommand.
Definition at line 448 of file Command.cpp.
|
protectedpure virtual |
Called when the command ends because somebody called cancel() or another command shared the same requirements as this one, and booted it out.
This is where you may want to wrap up loose ends, like shutting off a motor that was being used in the command.
Generally, it is useful to simply call the end() method within this method
Implemented in CommandGroup, PrintCommand, WaitCommand, WaitForChildren, WaitUntilCommand, and StartCommand.
bool Command::IsCanceled | ( | ) |
Returns whether or not this has been canceled.
Definition at line 375 of file Command.cpp.
|
protectedpure virtual |
Returns whether this command is finished. If it is, then the command will be removed and end() will be called.
It may be useful for a team to reference the isTimedOut() method for time-sensitive commands.
Implemented in CommandGroup, PrintCommand, WaitCommand, WaitForChildren, WaitUntilCommand, and StartCommand.
bool Command::IsInterruptible | ( | ) |
Returns whether or not this command can be interrupted.
Definition at line 384 of file Command.cpp.
bool Command::IsRunning | ( | ) |
Returns whether or not the command is running. This may return true even if the command has just been canceled, as it may not have yet called Command#interrupted().
Definition at line 340 of file Command.cpp.
|
protected |
Returns whether or not the timeSinceInitialized() method returns a number which is greater than or equal to the timeout for the command. If there is no timeout, this will always return false.
Definition at line 251 of file Command.cpp.
void Command::Requires | ( | Subsystem * | subsystem | ) |
This method specifies that the given Subsystem is used by this command. This method is crucial to the functioning of the Command System in general.
Note that the recommended way to call this method is in the constructor.
subsystem | the Subsystem required |
Definition at line 144 of file Command.cpp.
bool Command::Run | ( | ) |
The run method is used internally to actually run the commands.
Definition at line 199 of file Command.cpp.
void Command::SetInterruptible | ( | bool | interruptible | ) |
Sets whether or not this command can be interrupted.
interruptible | whether or not this command can be interrupted |
Definition at line 393 of file Command.cpp.
|
protected |
Sets the parent of this command. No actual change is made to the group.
parent | the parent |
Definition at line 294 of file Command.cpp.
void Command::SetRunWhenDisabled | ( | bool | run | ) |
Sets whether or not this Command should run when the robot is disabled.
By default a command will not run when the robot is disabled, and will in fact be canceled.
run | whether or not this command should run when the robot is disabled |
Definition at line 424 of file Command.cpp.
|
protected |
Sets the timeout of this command.
timeout | the timeout (in seconds) |
Definition at line 114 of file Command.cpp.
void Command::Start | ( | ) |
Starts up the command. Gets the command ready to start.
Note that the command will eventually start, however it will not necessarily do so immediately, and may in fact be canceled before initialize is even called.
Definition at line 186 of file Command.cpp.
double Command::TimeSinceInitialized | ( | ) |
Returns the time since this command was initialized (in seconds). This function will work even if there is no specified timeout.
Definition at line 127 of file Command.cpp.
|
virtual |
Called when a key-value pair is changed in a ITable WARNING: If a new key-value is put in this method value changed will immediatly be called which could lead to recursive code
source | the table the key-value pair exists in |
key | the key associated with the value that changed |
value | the new value |
isNew | true if the key did not previously exist in the table, otherwise it is false |
Implements ITableListener.
Definition at line 465 of file Command.cpp.
bool Command::WillRunWhenDisabled | ( | ) |
Returns whether or not this Command will run when the robot is disabled, or if it will cancel itself.
Definition at line 433 of file Command.cpp.