Class ConditionalRunnableCommand

  • All Implemented Interfaces:
    edu.wpi.first.util.sendable.Sendable, edu.wpi.first.wpilibj2.command.Command

    public class ConditionalRunnableCommand
    extends edu.wpi.first.wpilibj2.command.CommandBase
    Class to allow execution of methods (with no parameters) upon boolean state change, in the command-based structure.
    • Field Summary

      • Fields inherited from class edu.wpi.first.wpilibj2.command.CommandBase

        m_requirements
    • Constructor Summary

      Constructors 
      Constructor Description
      ConditionalRunnableCommand​(java.lang.Runnable onTrue, java.lang.Runnable onFalse, java.util.function.Supplier<java.lang.Boolean> conditional, double durationSeconds, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
      Constructs a ConditionalRunnableCommand.
      ConditionalRunnableCommand​(java.lang.Runnable onTrue, java.lang.Runnable onFalse, java.util.function.Supplier<java.lang.Boolean> conditional, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
      Constructs a ConditionalRunnableCommand that does not end.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void execute()  
      void initialize()  
      boolean isFinished()  
      boolean runsWhenDisabled()  
      void setRunsWhileDisabled​(boolean runsWhileDisabled)
      Sets whether this command should continue to run even while the robot is in a disabled state.
      • Methods inherited from class edu.wpi.first.wpilibj2.command.CommandBase

        addRequirements, getName, getRequirements, getSubsystem, initSendable, setName, setSubsystem, withName
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface edu.wpi.first.wpilibj2.command.Command

        alongWith, andThen, andThen, asProxy, beforeStarting, beforeStarting, cancel, deadlineWith, end, hasRequirement, isScheduled, perpetually, raceWith, schedule, schedule, until, withInterrupt, withTimeout
    • Constructor Detail

      • ConditionalRunnableCommand

        public ConditionalRunnableCommand​(java.lang.Runnable onTrue,
                                          java.lang.Runnable onFalse,
                                          java.util.function.Supplier<java.lang.Boolean> conditional,
                                          double durationSeconds,
                                          edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
        Constructs a ConditionalRunnableCommand.
        Parameters:
        onTrue - Method to be called when conditional changes from false to true. If null, will not be called.
        onFalse - Method to be called when conditional changes from true to false. If null, will not be called.
        conditional - Lambda of a boolean state dictating when the runnables should be called.
        durationSeconds - Time that this command should be active for; if less than zero, this command will not end; if zero, this command will start and end in the same command scheduler loop.
        toRequire - Any subsystems required to be freed for the method.
      • ConditionalRunnableCommand

        public ConditionalRunnableCommand​(java.lang.Runnable onTrue,
                                          java.lang.Runnable onFalse,
                                          java.util.function.Supplier<java.lang.Boolean> conditional,
                                          edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
        Constructs a ConditionalRunnableCommand that does not end.
        Parameters:
        onTrue - Method to be called when conditional changes from false to true. If null, will not be called.
        onFalse - Method to be called when conditional changes from true to false. If null, will not be called.
        conditional - Lambda of a boolean state dictating when the runnables should be called.
        toRequire - Any subsystems required to be freed for the method.
    • Method Detail

      • setRunsWhileDisabled

        public void setRunsWhileDisabled​(boolean runsWhileDisabled)
        Sets whether this command should continue to run even while the robot is in a disabled state.
        Parameters:
        runsWhileDisabled - True if this command should continue in the disabled state.
      • runsWhenDisabled

        public boolean runsWhenDisabled()
      • initialize

        public void initialize()
      • execute

        public void execute()
      • isFinished

        public boolean isFinished()