WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
frc::ConditionalCommand Class Referenceabstract

A ConditionalCommand is a Command that starts one of two commands. More...

#include <ConditionalCommand.h>

Inheritance diagram for frc::ConditionalCommand:
frc::Command frc::ErrorBase frc::NamedSendable ITableListener frc::Sendable

Public Member Functions

 ConditionalCommand (Command *onTrue, Command *onFalse=new InstantCommand())
 Creates a new ConditionalCommand with given onTrue and onFalse Commands. More...
 
 ConditionalCommand (const std::string &name, Command *onTrue, Command *onFalse=new InstantCommand())
 Creates a new ConditionalCommand with given onTrue and onFalse Commands. More...
 
- Public Member Functions inherited from frc::Command
 Command ()
 Creates a new command. More...
 
 Command (const std::string &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 std::string &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 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 Subsystems 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...
 
std::string GetName () const override
 
void InitTable (std::shared_ptr< ITable > subtable) override
 Initializes a table for this sendable object. More...
 
std::shared_ptr< ITableGetTable () const override
 
std::string GetSmartDashboardType () const override
 
void ValueChanged (ITable *source, llvm::StringRef key, std::shared_ptr< nt::Value > value, bool isNew) override
 Called when a key-value pair is changed in a ITable. 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 (llvm::StringRef 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, llvm::StringRef 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, llvm::StringRef 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, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (llvm::StringRef errorMessage, Error::Code code, llvm::StringRef 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 ITableListener
virtual void ValueChangedEx (ITable *source, llvm::StringRef key, std::shared_ptr< nt::Value > value, unsigned int flags)
 Extended version of ValueChanged. More...
 

Protected Member Functions

virtual bool Condition ()=0
 The Condition to test to determine which Command to run. More...
 
void _Initialize () override
 
void _Cancel () override
 This works like cancel(), except that it doesn't throw an exception if it is a part of a command group. More...
 
bool IsFinished () override
 Returns whether this command is finished. More...
 
void Interrupted () override
 Called when the command ends because somebody called cancel() or another command shared the same requirements as this one, and booted it out. More...
 
- 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...
 
void ClearRequirements ()
 Clears list of subsystem requirements. More...
 
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 void End ()
 Called when the command ended peacefully. More...
 
virtual void _Interrupted ()
 
virtual void _Execute ()
 
virtual void _End ()
 

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, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, int lineNumber)
 
static ErrorGetGlobalError ()
 Retrieve the current global error.
 
- Protected Attributes inherited from frc::Command
std::shared_ptr< ITablem_table
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 
- Static Protected Attributes inherited from frc::ErrorBase
static priority_mutex _globalErrorMutex
 
static Error _globalError
 

Detailed Description

A ConditionalCommand is a Command that starts one of two commands.

A ConditionalCommand uses m_condition to determine whether it should run m_onTrue or m_onFalse.

A ConditionalCommand adds the proper Command to the Scheduler during ConditionalCommand#initialize() and then ConditionalCommand#isFinished() will return true once that Command has finished executing.

If no Command is specified for m_onFalse, the occurrence of that condition will be a no-op.

See Also
Command
Scheduler

Constructor & Destructor Documentation

ConditionalCommand::ConditionalCommand ( Command onTrue,
Command onFalse = new InstantCommand() 
)
explicit

Creates a new ConditionalCommand with given onTrue and onFalse Commands.

Parameters
onTrueThe Command to execute if ConditionalCommand#Condition() returns true
onFalseThe Command to execute if ConditionalCommand#Condition() returns false
ConditionalCommand::ConditionalCommand ( const std::string &  name,
Command onTrue,
Command onFalse = new InstantCommand() 
)

Creates a new ConditionalCommand with given onTrue and onFalse Commands.

Parameters
namethe name for this command group
onTrueThe Command to execute if ConditionalCommand#Condition() returns true
onFalseThe Command to execute if ConditionalCommand#Condition() returns false

Member Function Documentation

void ConditionalCommand::_Cancel ( )
overrideprotectedvirtual

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.

Reimplemented from frc::Command.

virtual bool frc::ConditionalCommand::Condition ( )
protectedpure virtual

The Condition to test to determine which Command to run.

Returns
true if m_onTrue should be run or false if m_onFalse should be run.
void ConditionalCommand::Interrupted ( )
overrideprotectedvirtual

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 ConditionalCommand::IsFinished ( )
overrideprotectedvirtual

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
Command::isTimedOut() isTimedOut()

Implements frc::Command.


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