Package org.chsrobotics.lib.commands
Class ConsumerCommand<T>
- java.lang.Object
-
- edu.wpi.first.wpilibj2.command.CommandBase
-
- org.chsrobotics.lib.commands.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.CommandBaseSimple class to allow calling methods with one or two parameters (of the same type) in the command-based structure.
-
-
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 voidend(boolean interrupted)voidinitialize()booleanisFinished()booleanrunsWhenDisabled()voidsetRunsWhileDisabled(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
-
-
-
-
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 typeT.init- The value ofTto feed to the consumer when this command is initialized. Ifnull, will not be fed.end- The value ofTto feed to the consumer when this command ends. Ifnull, 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 typeT.init- A value of typeTto feed to the consumer when this command is initialized. Ifnull, 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 typeT.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 typeT.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()
-
-