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
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 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.

This class is provided by the OldCommands VendorDep

See Also:
Command, Scheduler
  • Constructor Details

    • 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 if condition() 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 if condition() returns true
      onFalse - The Command to execute if condition() 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 group
      onTrue - The Command to execute if condition() 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 group
      onTrue - The Command to execute if condition() returns true
      onFalse - The Command to execute if condition() returns false
  • Method Details

    • 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()
      Calls condition() 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 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 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 class Command
      Returns:
      whether this command is finished.
      See Also:
      isTimedOut()
    • _interrupted

      protected void _interrupted()