WPILibC++  unspecified
frc::CommandGroup Class Reference

A CommandGroup is a list of commands which are executed in sequence. More...

#include <CommandGroup.h>

Inheritance diagram for frc::CommandGroup:
Collaboration diagram for frc::CommandGroup:

Public Member Functions

 CommandGroup (const llvm::Twine &name)
 Creates a new CommandGroup with the given name. More...
 
void AddSequential (Command *command)
 Adds a new Command to the group. More...
 
void AddSequential (Command *command, double timeout)
 Adds a new Command to the group with a given timeout. More...
 
void AddParallel (Command *command)
 Adds a new child Command to the group. More...
 
void AddParallel (Command *command, double timeout)
 Adds a new child Command to the group with the given timeout. More...
 
bool IsInterruptible () const
 
int GetSize () const
 
- Public Member Functions inherited from frc::Command
 Command ()
 Creates a new command. More...
 
 Command (const llvm::Twine &name)
 Creates a new command with the given name and no timeout. More...
 
 Command (double timeout)
 Creates a new command with the given timeout and a default name. More...
 
 Command (const llvm::Twine &name, double timeout)
 Creates a new command with the given name and timeout. More...
 
double TimeSinceInitialized () const
 Returns the time since this command was initialized (in seconds). More...
 
void Requires (Subsystem *s)
 This method specifies that the given Subsystem is used by this command. More...
 
bool IsCanceled () const
 Returns whether or not this has been canceled. More...
 
void Start ()
 Starts up the command. More...
 
bool Run ()
 The run method is used internally to actually run the commands. More...
 
void Cancel ()
 This will cancel the current command. More...
 
bool IsRunning () const
 Returns whether or not the command is running. More...
 
bool IsInitialized () const
 Returns whether or not the command has been initialized. More...
 
bool IsCompleted () const
 Returns whether or not the command has completed running. More...
 
bool IsInterruptible () const
 Returns whether or not this command can be interrupted. More...
 
void SetInterruptible (bool interruptible)
 Sets whether or not this command can be interrupted. More...
 
bool DoesRequire (Subsystem *subsystem) const
 Checks if the command requires the given Subsystem. More...
 
SubsystemSet GetRequirements () const
 Returns the requirements (as an std::set of Subsystem pointers) of this command. More...
 
CommandGroupGetGroup () const
 Returns the CommandGroup that this command is a part of. More...
 
void SetRunWhenDisabled (bool run)
 Sets whether or not this Command should run when the robot is disabled. More...
 
bool WillRunWhenDisabled () const
 Returns whether or not this Command will run when the robot is disabled, or if it will cancel itself. More...
 
int GetID () const
 Get the ID (sequence number) for this command. More...
 
void InitSendable (SendableBuilder &builder) override
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (const ErrorBase &)=delete
 
ErrorBaseoperator= (const ErrorBase &)=delete
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (const llvm::Twine &contextMessage, llvm::StringRef filename, llvm::StringRef function, int 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 llvm::Twine &contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const llvm::Twine &contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const llvm::Twine &contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const llvm::Twine &errorMessage, Error::Code code, const llvm::Twine &contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const 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...
 
- Public Member Functions inherited from frc::SendableBase
 SendableBase (bool addLiveWindow=true)
 Creates an instance of the sensor base. More...
 
 ~SendableBase () override
 Free the resources used by this object.
 
std::string GetName () const final
 Gets the name of this Sendable object. More...
 
void SetName (const llvm::Twine &name) final
 Sets the name of this Sendable object. More...
 
std::string GetSubsystem () const final
 Gets the subsystem name of this Sendable object. More...
 
void SetSubsystem (const llvm::Twine &subsystem) final
 Sets the subsystem name of this Sendable object. More...
 
- Public Member Functions inherited from frc::Sendable
void SetName (const llvm::Twine &subsystem, const llvm::Twine &name)
 Sets both the subsystem name and device name of this Sendable object. More...
 

Protected Member Functions

virtual void Initialize ()
 The initialize method is called the first time this Command is run after being started.
 
virtual void Execute ()
 The execute method is called repeatedly until this Command either finishes or is canceled.
 
virtual bool IsFinished ()
 Returns whether this command is finished. More...
 
virtual void End ()
 Called when the command ended peacefully. More...
 
virtual void Interrupted ()
 Called when the command ends because somebody called Cancel() or another command shared the same requirements as this one, and booted it out. More...
 
virtual void _Initialize ()
 
virtual void _Interrupted ()
 
virtual void _Execute ()
 
virtual void _End ()
 
- Protected Member Functions inherited from frc::Command
void SetTimeout (double timeout)
 Sets the timeout of this command. More...
 
bool IsTimedOut () const
 Returns whether or not the TimeSinceInitialized() method returns a number which is greater than or equal to the timeout for the command. More...
 
bool AssertUnlocked (const std::string &message)
 If changes are locked, then this will generate a CommandIllegalUse error. More...
 
void SetParent (CommandGroup *parent)
 Sets the parent of this command. More...
 
bool IsParented () const
 Returns whether the command has a parent. More...
 
void ClearRequirements ()
 Clears list of subsystem requirements. More...
 
virtual void _Cancel ()
 This works like Cancel(), except that it doesn't throw an exception if it is a part of a command group. More...
 
- Protected Member Functions inherited from frc::SendableBase
void AddChild (std::shared_ptr< Sendable > child)
 Add a child component. More...
 
void AddChild (void *child)
 Add a child component. More...
 
void SetName (const llvm::Twine &moduleType, int channel)
 Sets the name of the sensor with a channel number. More...
 
void SetName (const llvm::Twine &moduleType, int moduleNumber, int channel)
 Sets the name of the sensor with a module and channel number. More...
 

Additional Inherited Members

- Public Types inherited from frc::Command
typedef std::set< Subsystem * > SubsystemSet
 
- Static Public Member Functions inherited from frc::ErrorBase
static void SetGlobalError (Error::Code code, const llvm::Twine &contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (const llvm::Twine &errorMessage, const llvm::Twine &contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber)
 
static ErrorGetGlobalError ()
 Retrieve the current global error.
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 
- Static Protected Attributes inherited from frc::ErrorBase
static wpi::mutex _globalErrorMutex
 
static Error _globalError
 

Detailed Description

A CommandGroup is a list of commands which are executed in sequence.

Commands in a CommandGroup are added using the AddSequential() method and are called sequentially. CommandGroups are themselves Commands and can be given to other CommandGroups.

CommandGroups will carry all of the requirements of their Command subcommands. Additional requirements can be specified by calling Requires() normally in the constructor.

CommandGroups can also execute commands in parallel, simply by adding them using AddParallel().

See also
Command
Subsystem

Constructor & Destructor Documentation

CommandGroup::CommandGroup ( const llvm::Twine name)
explicit

Creates a new CommandGroup with the given name.

Parameters
nameThe name for this command group

Member Function Documentation

void CommandGroup::AddParallel ( Command command)

Adds a new child Command to the group.

The Command will be started after all the previously added Commands.

Instead of waiting for the child to finish, a CommandGroup will have it run at the same time as the subsequent Commands. The child will run until either it finishes, a new child with conflicting requirements is started, or the main sequence runs a Command with conflicting requirements. In the latter two cases, the child will be canceled even if it says it can't be interrupted.

Note that any requirements the given Command has will be added to the group. For this reason, a Command's requirements can not be changed after being added to a group.

It is recommended that this method be called in the constructor.

Parameters
commandThe command to be added
void CommandGroup::AddParallel ( Command command,
double  timeout 
)

Adds a new child Command to the group with the given timeout.

The Command will be started after all the previously added Commands.

Once the Command is started, it will run until it finishes, is interrupted, or the time expires, whichever is sooner. Note that the given Command will have no knowledge that it is on a timer.

Instead of waiting for the child to finish, a CommandGroup will have it run at the same time as the subsequent Commands. The child will run until either it finishes, the timeout expires, a new child with conflicting requirements is started, or the main sequence runs a Command with conflicting requirements. In the latter two cases, the child will be canceled even if it says it can't be interrupted.

Note that any requirements the given Command has will be added to the group. For this reason, a Command's requirements can not be changed after being added to a group.

It is recommended that this method be called in the constructor.

Parameters
commandThe command to be added
timeoutThe timeout (in seconds)
void CommandGroup::AddSequential ( Command command)

Adds a new Command to the group.

The Command will be started after all the previously added Commands.

Note that any requirements the given Command has will be added to the group. For this reason, a Command's requirements can not be changed after being added to a group.

It is recommended that this method be called in the constructor.

Parameters
commandThe Command to be added
void CommandGroup::AddSequential ( Command command,
double  timeout 
)

Adds a new Command to the group with a given timeout.

The Command will be started after all the previously added commands.

Once the Command is started, it will be run until it finishes or the time expires, whichever is sooner. Note that the given Command will have no knowledge that it is on a timer.

Note that any requirements the given Command has will be added to the group. For this reason, a Command's requirements can not be changed after being added to a group.

It is recommended that this method be called in the constructor.

Parameters
commandThe Command to be added
timeoutThe timeout (in seconds)
void CommandGroup::End ( )
protectedvirtual

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.

Reimplemented from frc::Command.

void CommandGroup::Interrupted ( )
protectedvirtual

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, as done here.

Reimplemented from frc::Command.

bool CommandGroup::IsFinished ( )
protectedvirtual

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.

Returning false will result in the command never ending automatically. It may still be cancelled manually or interrupted by another command. Returning true will result in the command executing once and finishing immediately. We recommend using InstantCommand for this.

Returns
Whether this command is finished.
See also
IsTimedOut()

Implements frc::Command.


The documentation for this class was generated from the following files: