Class ConsumerCommand<T>

java.lang.Object
edu.wpi.first.wpilibj2.command.CommandBase
org.chsrobotics.lib.commands.ConsumerCommand<T>
Type Parameters:
T - Data type of the method parameter or parameters.
All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable, edu.wpi.first.wpilibj2.command.Command

public class ConsumerCommand<T> extends edu.wpi.first.wpilibj2.command.CommandBase
Simple class to allow calling methods with one or two parameters (of the same type) in the command-based structure.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface edu.wpi.first.wpilibj2.command.Command

    edu.wpi.first.wpilibj2.command.Command.InterruptionBehavior
  • Field Summary

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

    m_requirements
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConsumerCommand(BiConsumer<T,T> biConsumer, Tuple2<T> init, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
    Constructs a ConsumerCommand for a method with two parameters of the same type that ends instantly.
    ConsumerCommand(BiConsumer<T,T> biConsumer, Tuple2<T> init, Tuple2<T> end, double durationSeconds, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
    Constructs a ConsumerCommand for a method with two parameters.
    ConsumerCommand(Consumer<T> consumer, T init, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
    Constructs a ConsumerCommand for a method with a single parameter that instantly ends.
    ConsumerCommand(Consumer<T> consumer, T init, T end, double durationSeconds, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
    Constructs a ConsumerCommand for a method with one parameter.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    end(boolean interrupted)
     
    void
     
    boolean
     
    boolean
     
    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

    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, execute, finallyDo, getInterruptionBehavior, handleInterrupt, hasRequirement, ignoringDisable, isScheduled, perpetually, raceWith, repeatedly, schedule, unless, until, withInterrupt, withInterruptBehavior, withName, withTimeout
  • Constructor Details

    • ConsumerCommand

      public ConsumerCommand(Consumer<T> consumer, T init, T end, double durationSeconds, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
      Constructs a ConsumerCommand for a method with one parameter.
      Parameters:
      consumer - A method with a single parameter of type T.
      init - The value of T to feed to the consumer when this command is initialized. If null, will not be fed.
      end - The value of T to feed to the consumer when this command ends. If null, will not be fed.
      durationSeconds - Time that this command should be active; if less than zero, this command will not end; if zero, this command will end in the first command scheduler loop.
      toRequire - Any subsystems that need to be freed for the method.
    • ConsumerCommand

      public ConsumerCommand(Consumer<T> consumer, T init, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
      Constructs a ConsumerCommand for a method with a single parameter that instantly ends.
      Parameters:
      consumer - A method with a single parameter of type T.
      init - A value of type T to feed to the consumer when this command is initialized. If null, will not be fed.
      toRequire - Any subsystems that need to be freed for the method.
    • ConsumerCommand

      public ConsumerCommand(BiConsumer<T,T> biConsumer, Tuple2<T> init, Tuple2<T> end, double durationSeconds, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
      Constructs a ConsumerCommand for a method with two parameters.
      Parameters:
      biConsumer - A method with two parameters of type T.
      init - A Tuple2 of Ts to feed to the consumer when the command is initialized. The order should match the order of parameters in the actual method.
      end - A Tuple2 of Ts to feed to the consumer when the command ends. The order should match the order of parameters in the actual method.
      durationSeconds - How long this command should be active; if less than zero, this command won't end; if zero, this command will begin and end on the same command scheduler loop.
      toRequire - Any subsystems required to be freed for the method.
    • ConsumerCommand

      public ConsumerCommand(BiConsumer<T,T> biConsumer, Tuple2<T> init, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
      Constructs a ConsumerCommand for a method with two parameters of the same type that ends instantly.
      Parameters:
      biConsumer - A method with exactly two parameters of type T.
      init - A Tuple2 of Ts to feed to the consumer upon command initializaiton. The order should match the order of parameters in the actual method.
      toRequire - Any subsystems required to be freed for the method.
  • Method Details

    • 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()
    • end

      public void end(boolean interrupted)
    • isFinished

      public boolean isFinished()