Package org.chsrobotics.lib.commands
Class ConditionalRunnableCommand
java.lang.Object
edu.wpi.first.wpilibj2.command.CommandBase
org.chsrobotics.lib.commands.ConditionalRunnableCommand
- All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable,edu.wpi.first.wpilibj2.command.Command
public class ConditionalRunnableCommand
extends edu.wpi.first.wpilibj2.command.CommandBase
Class to allow execution of methods (with no parameters) upon boolean state change, 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
ConstructorsConstructorDescriptionConditionalRunnableCommand(Runnable onTrue, Runnable onFalse, Supplier<Boolean> conditional, double durationSeconds, edu.wpi.first.wpilibj2.command.Subsystem... toRequire) Constructs a ConditionalRunnableCommand.ConditionalRunnableCommand(Runnable onTrue, Runnable onFalse, Supplier<Boolean> conditional, edu.wpi.first.wpilibj2.command.Subsystem... toRequire) Constructs a ConditionalRunnableCommand that does not end. -
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
-
ConditionalRunnableCommand
public ConditionalRunnableCommand(Runnable onTrue, Runnable onFalse, Supplier<Boolean> conditional, double durationSeconds, edu.wpi.first.wpilibj2.command.Subsystem... toRequire) Constructs a ConditionalRunnableCommand.- Parameters:
onTrue- Method to be called whenconditionalchanges fromfalsetotrue. Ifnull, will not be called.onFalse- Method to be called whenconditionalchanges fromtruetofalse. Ifnull, will not be called.conditional- Lambda of a boolean state dictating when the runnables should be called.durationSeconds- Time that this command should be active for; if less than zero, this command will not end; if zero, this command will start and end in the same command scheduler loop.toRequire- Any subsystems required to be freed for the method.
-
ConditionalRunnableCommand
public ConditionalRunnableCommand(Runnable onTrue, Runnable onFalse, Supplier<Boolean> conditional, edu.wpi.first.wpilibj2.command.Subsystem... toRequire) Constructs a ConditionalRunnableCommand that does not end.- Parameters:
onTrue- Method to be called whenconditionalchanges fromfalsetotrue. Ifnull, will not be called.onFalse- Method to be called whenconditionalchanges fromtruetofalse. Ifnull, will not be called.conditional- Lambda of a boolean state dictating when the runnables should be called.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() -
execute
public void execute() -
isFinished
public boolean isFinished()
-