Package org.chsrobotics.lib.commands
Class ConditionalConsumerCommand<T>
java.lang.Object
edu.wpi.first.wpilibj2.command.CommandBase
org.chsrobotics.lib.commands.ConditionalConsumerCommand<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 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.
-
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
ConstructorsConstructorDescriptionConditionalConsumerCommand(BiConsumer<T, T> biConsumer, Tuple2<T> onTrue, Tuple2<T> onFalse, double durationSeconds, Supplier<Boolean> conditional, edu.wpi.first.wpilibj2.command.Subsystem... toRequire) Constructs a ConditionalConsumerCommand for a method with two parameter.ConditionalConsumerCommand(BiConsumer<T, T> consumer, Tuple2<T> onTrue, Tuple2<T> onFalse, Supplier<Boolean> conditional, edu.wpi.first.wpilibj2.command.Subsystem... toRequire) Constructs a ConditionalConsumerCommand for a method with two parameter which never ends.ConditionalConsumerCommand(Consumer<T> consumer, T onTrue, T onFalse, Supplier<Boolean> conditional, double durationSeconds, edu.wpi.first.wpilibj2.command.Subsystem... toRequire) Constructs a ConditionalConsumerCommand for a method with one parameter.ConditionalConsumerCommand(Consumer<T> consumer, T onTrue, T onFalse, Supplier<Boolean> conditional, edu.wpi.first.wpilibj2.command.Subsystem... toRequire) Constructs a ConditionalConsumerCommand for a method with one parameter which never ends. -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()voidbooleanbooleanvoidsetRunsWhileDisabled(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, setSubsystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Command
alongWith, andThen, andThen, asProxy, beforeStarting, beforeStarting, cancel, deadlineWith, end, finallyDo, getInterruptionBehavior, handleInterrupt, hasRequirement, ignoringDisable, isScheduled, perpetually, raceWith, repeatedly, schedule, unless, until, withInterrupt, withInterruptBehavior, withName, withTimeout
-
Constructor Details
-
ConditionalConsumerCommand
public ConditionalConsumerCommand(Consumer<T> consumer, T onTrue, T onFalse, Supplier<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(Consumer<T> consumer, T onTrue, T onFalse, Supplier<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(BiConsumer<T, T> biConsumer, Tuple2<T> onTrue, Tuple2<T> onFalse, double durationSeconds, Supplier<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.durationSeconds- Time that this command should expire after.conditional- A lambda of a boolean.toRequire- Any subsystems required to be freed for method execution.
-
ConditionalConsumerCommand
public ConditionalConsumerCommand(BiConsumer<T, T> consumer, Tuple2<T> onTrue, Tuple2<T> onFalse, Supplier<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 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() -
execute
public void execute() -
initialize
public void initialize() -
isFinished
public boolean isFinished()
-