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
AConditionalCommandis aCommandthat starts one of two commands.A
ConditionalCommanduses m_condition to determine whether it should run m_onTrue or m_onFalse.A
ConditionalCommandadds the properCommandto theSchedulerduringCommand.initialize()and thenisFinished()will return true once thatCommandhas finished executing.If no
Commandis 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 booleancondition()The Condition to test to determine which Command to run.protected booleanisFinished()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:CommandReturns 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 cancelled manually or interrupted by another command. Returning true will result in the command executing once and finishing immediately. We recommend using
InstantCommandfor this.- Specified by:
isFinishedin classCommand- Returns:
- whether this command is finished.
- See Also:
isTimedOut()
-
_interrupted
protected void _interrupted()
-
-