Class ConditionalCommand
- All Implemented Interfaces:
Sendable
,AutoCloseable
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.
A ConditionalCommand will require the superset of subsystems of the onTrue and onFalse commands.
-
Constructor Summary
Constructors Constructor 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(String name, Command onTrue)
Creates a new ConditionalCommand with given name and onTrue and onFalse Commands.ConditionalCommand(String name, Command onTrue, Command onFalse)
Creates a new ConditionalCommand with given name and onTrue and onFalse Commands. -
Method Summary
Modifier and Type Method Description protected void
_cancel()
protected void
_initialize()
Callscondition()
and runs the proper command.protected void
_interrupted()
protected abstract boolean
condition()
The Condition to test to determine which Command to run.protected boolean
isFinished()
Returns whether this command is finished.Methods inherited from class edu.wpi.first.wpilibj.command.Command
cancel, clearRequirements, close, doesRequire, end, execute, getGroup, getName, getSubsystem, initialize, initSendable, interrupted, isCanceled, isCompleted, isInterruptible, isRunning, isTimedOut, requires, setInterruptible, setName, setRunWhenDisabled, setSubsystem, setTimeout, start, timeSinceInitialized, toString, willRunWhenDisabled
-
Constructor Details
-
ConditionalCommand
Creates a new ConditionalCommand with given onTrue and onFalse Commands.Users of this constructor should also override condition().
- Parameters:
onTrue
- The Command to execute ifcondition()
returns true
-
ConditionalCommand
Creates a new ConditionalCommand with given onTrue and onFalse Commands.Users of this constructor should also override condition().
- Parameters:
onTrue
- The Command to execute ifcondition()
returns trueonFalse
- The Command to execute ifcondition()
returns false
-
ConditionalCommand
Creates a new ConditionalCommand with given name and onTrue and onFalse Commands.Users of this constructor should also override condition().
- Parameters:
name
- the name for this command grouponTrue
- The Command to execute ifcondition()
returns true
-
ConditionalCommand
Creates a new ConditionalCommand with given name and onTrue and onFalse Commands.Users of this constructor should also override condition().
- Parameters:
name
- the name for this command grouponTrue
- The Command to execute ifcondition()
returns trueonFalse
- The Command to execute ifcondition()
returns false
-
-
Method Details
-
condition
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.
-
_initialize
Callscondition()
and runs the proper command. -
_cancel
-
isFinished
Description copied from class:Command
Returns whether this command is finished. If it is, then the command will be removed andend()
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 canceled manually or interrupted by another command. Returning true will result in the command executing once and finishing immediately. We recommend using
InstantCommand
for this.- Specified by:
isFinished
in classCommand
- Returns:
- whether this command is finished.
- See Also:
isTimedOut()
-
_interrupted
-