Class ConditionalConsumerCommand<T>

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

    public class ConditionalConsumerCommand<T>
    extends edu.wpi.first.wpilibj2.command.CommandBase
    Class to allow calling methods with one or two parameters (of the same type), in the command-based structure, upon state change of a boolean conditional.
    • Field Summary

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

        m_requirements
    • Constructor Summary

      Constructors 
      Constructor Description
      ConditionalConsumerCommand​(java.util.function.BiConsumer<T,​T> biConsumer, Tuple2<T> onTrue, Tuple2<T> onFalse, double durationSeconds, java.util.function.Supplier<java.lang.Boolean> conditional, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
      Constructs a ConditionalConsumerCommand for a method with two parameter.
      ConditionalConsumerCommand​(java.util.function.BiConsumer<T,​T> consumer, Tuple2<T> onTrue, Tuple2<T> onFalse, java.util.function.Supplier<java.lang.Boolean> conditional, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
      Constructs a ConditionalConsumerCommand for a method with two parameter which never ends.
      ConditionalConsumerCommand​(java.util.function.Consumer<T> consumer, T onTrue, T onFalse, java.util.function.Supplier<java.lang.Boolean> conditional, double durationSeconds, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
      Constructs a ConditionalConsumerCommand for a method with one parameter.
      ConditionalConsumerCommand​(java.util.function.Consumer<T> consumer, T onTrue, T onFalse, java.util.function.Supplier<java.lang.Boolean> conditional, edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
      Constructs a ConditionalConsumerCommand for a method with one parameter which never ends.
    • 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

      • ConditionalConsumerCommand

        public ConditionalConsumerCommand​(java.util.function.Consumer<T> consumer,
                                          T onTrue,
                                          T onFalse,
                                          java.util.function.Supplier<java.lang.Boolean> conditional,
                                          double durationSeconds,
                                          edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
        Constructs a ConditionalConsumerCommand for a method with one parameter.
        Parameters:
        consumer - A method which takes one parameter of type T.
        onTrue - A value of T to feed to the consumer upon conditional change from false to true.
        onFalse - A value of T to feed to the consumer upon conditional change from true to false.
        conditional - A lambda of a boolean.
        durationSeconds - Time that this command should expire after.
        toRequire - Any subsystems required to be freed for method execution.
      • ConditionalConsumerCommand

        public ConditionalConsumerCommand​(java.util.function.Consumer<T> consumer,
                                          T onTrue,
                                          T onFalse,
                                          java.util.function.Supplier<java.lang.Boolean> conditional,
                                          edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
        Constructs a ConditionalConsumerCommand for a method with one parameter which never ends.
        Parameters:
        consumer - A method which takes one parameter of type T.
        onTrue - A value of T to feed to the consumer upon conditional change from false to true.
        onFalse - A value of T to feed to the consumer upon conditional change from true to false.
        conditional - A lambda of a boolean.
        toRequire - Any subsystems required to be freed for method execution.
      • ConditionalConsumerCommand

        public ConditionalConsumerCommand​(java.util.function.BiConsumer<T,​T> biConsumer,
                                          Tuple2<T> onTrue,
                                          Tuple2<T> onFalse,
                                          double durationSeconds,
                                          java.util.function.Supplier<java.lang.Boolean> conditional,
                                          edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
        Constructs a ConditionalConsumerCommand for a method with two parameter.
        Parameters:
        biConsumer - A method which takes two parameters of type T.
        onTrue - A Tuple2 of Ts to feed to the consumer upon conditional change from false to true. Should be in the same order as in the actual method.
        onFalse - A Tuple2 of Ts to feed to the consumer upon conditional change from true to false. Should be in the same order as in the actual method.
        conditional - A lambda of a boolean.
        durationSeconds - Time that this command should expire after.
        toRequire - Any subsystems required to be freed for method execution.
      • ConditionalConsumerCommand

        public ConditionalConsumerCommand​(java.util.function.BiConsumer<T,​T> consumer,
                                          Tuple2<T> onTrue,
                                          Tuple2<T> onFalse,
                                          java.util.function.Supplier<java.lang.Boolean> conditional,
                                          edu.wpi.first.wpilibj2.command.Subsystem... toRequire)
        Constructs a ConditionalConsumerCommand for a method with two parameter which never ends.
        Parameters:
        consumer - A method which takes one parameters of type T.
        onTrue - A Tuple2 of T to feed to the consumer upon conditional change from false to true.
        onFalse - A Tuple2 of T to feed to the consumer upon conditional change from true to false.
        conditional - A lambda of a boolean.
        toRequire - Any subsystems required to be freed for method execution.
    • 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()
      • execute

        public void execute()
      • initialize

        public void initialize()
      • isFinished

        public boolean isFinished()