Class ConsumerCommand<T>

  • 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.
    • Field Summary

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

        m_requirements
    • Constructor Summary

      Constructors 
      Constructor Description
      ConsumerCommand​(java.util.function.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​(java.util.function.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​(java.util.function.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​(java.util.function.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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void end​(boolean interrupted)  
      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, execute, hasRequirement, isScheduled, perpetually, raceWith, schedule, schedule, until, withInterrupt, withTimeout
    • Constructor Detail

      • ConsumerCommand

        public ConsumerCommand​(java.util.function.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​(java.util.function.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​(java.util.function.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​(java.util.function.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 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()
      • end

        public void end​(boolean interrupted)
      • isFinished

        public boolean isFinished()