Class ConditionalCommand
- java.lang.Object
-
- edu.wpi.first.wpilibj.command.Command
-
- edu.wpi.first.wpilibj.command.ConditionalCommand
-
- All Implemented Interfaces:
Sendable
,AutoCloseable
public abstract class ConditionalCommand extends Command
AConditionalCommand
is aCommand
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 properCommand
to theScheduler
duringCommand.initialize()
and thenisFinished()
will return true once thatCommand
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
All Methods Instance Methods Abstract Methods Concrete Methods 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 Detail
-
ConditionalCommand
public ConditionalCommand(Command onTrue)
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
public ConditionalCommand(Command onTrue, Command onFalse)
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
public ConditionalCommand(String name, Command onTrue)
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
public ConditionalCommand(String name, Command onTrue, Command onFalse)
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 Detail
-
condition
protected abstract boolean 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
protected void _initialize()
Callscondition()
and runs the proper command.
-
_cancel
protected void _cancel()
-
isFinished
protected boolean 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
protected void _interrupted()
-
-