public abstract class ConditionalCommand extends Command
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
Command.initialize() and then 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.
| Constructor and Description |
|---|
ConditionalCommand(Command onTrue)
Creates a new ConditionalCommand with given onTrue and onFalse Commands.
|
ConditionalCommand(Command onTrue,
Command onFalse)
Creates a new ConditionalCommand with given onTrue and onFalse Commands.
|
ConditionalCommand(java.lang.String name,
Command onTrue)
Creates a new ConditionalCommand with given name and onTrue and onFalse Commands.
|
ConditionalCommand(java.lang.String name,
Command onTrue,
Command onFalse)
Creates a new ConditionalCommand with given name and onTrue and onFalse Commands.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
_cancel()
This works like cancel(), except that it doesn't throw an exception if it is a part of a
command group.
|
protected void |
_initialize()
Calls
condition() and runs the proper command. |
protected void |
_interrupted()
A shadow method called after
interrupted(). |
protected abstract boolean |
condition()
The Condition to test to determine which Command to run.
|
protected boolean |
isFinished()
Returns whether this command is finished.
|
cancel, clearRequirements, doesRequire, end, execute, getGroup, initialize, initSendable, interrupted, isCanceled, isCompleted, isInterruptible, isRunning, isTimedOut, requires, setInterruptible, setRunWhenDisabled, setTimeout, start, timeSinceInitialized, toString, willRunWhenDisabledaddChild, free, getName, getSubsystem, setName, setName, setName, setSubsystemclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetName, getSubsystem, setName, setName, setSubsystempublic ConditionalCommand(Command onTrue)
Users of this constructor should also override condition().
onTrue - The Command to execute if condition() returns truepublic ConditionalCommand(Command onTrue, Command onFalse)
Users of this constructor should also override condition().
onTrue - The Command to execute if condition() returns trueonFalse - The Command to execute if condition() returns falsepublic ConditionalCommand(java.lang.String name, Command onTrue)
Users of this constructor should also override condition().
name - the name for this command grouponTrue - The Command to execute if condition() returns truepublic ConditionalCommand(java.lang.String name, Command onTrue, Command onFalse)
Users of this constructor should also override condition().
name - the name for this command grouponTrue - The Command to execute if condition() returns trueonFalse - The Command to execute if condition() returns falseprotected abstract boolean condition()
protected void _initialize()
condition() and runs the proper command.protected void _cancel()
Commandprotected boolean isFinished()
Commandend() 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.
isFinished in class CommandisTimedOut()protected void _interrupted()
Commandinterrupted().