Package lib.util
Class CmdUtil
java.lang.Object
lib.util.CmdUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcancelConflicting(edu.wpi.first.wpilibj2.command.Subsystem... requirements) Cancels all commands that conflict with the given subsystemsstatic edu.wpi.first.wpilibj2.command.Commanddelayed(double delaySeconds, edu.wpi.first.wpilibj2.command.Command command) static edu.wpi.first.wpilibj2.command.CommandnonNull(edu.wpi.first.wpilibj2.command.Command cmd) Replacenulls with ano-opcommand insteadstatic voidschedule(edu.wpi.first.wpilibj2.command.Command... commands) static booleantryCancelConflicting(edu.wpi.first.wpilibj2.command.Subsystem... requirements) Attempts to cancel all commands that conflict with the given subsystems.static <T> edu.wpi.first.wpilibj2.command.CommandwithState(Supplier<T> getState, Function<Supplier<T>, edu.wpi.first.wpilibj2.command.Command> getCommand, edu.wpi.first.wpilibj2.command.Subsystem... addedRequirements) Useful for creating complicated functional commands with multiple lambdas that reference the same state, and where the state needs to be updated every iteration.
-
Method Details
-
schedule
public static void schedule(edu.wpi.first.wpilibj2.command.Command... commands) -
cancelConflicting
public static void cancelConflicting(edu.wpi.first.wpilibj2.command.Subsystem... requirements) Cancels all commands that conflict with the given subsystems -
tryCancelConflicting
public static boolean tryCancelConflicting(edu.wpi.first.wpilibj2.command.Subsystem... requirements) Attempts to cancel all commands that conflict with the given subsystems. Commands will only be canceled if none of the conflicting commands have theirinterruption behaviorset tokCancelIncoming.For example:
if (CmdUtil.tryCancelConflicting(Component.elevator)) { Component.elevator.setVoltage(2); // not command-based }- Returns:
trueif conflicting commands were canceled
-
nonNull
public static edu.wpi.first.wpilibj2.command.Command nonNull(edu.wpi.first.wpilibj2.command.Command cmd) Replacenulls with ano-opcommand instead- Parameters:
cmd- Command ornull- Returns:
- Non-null command
-
delayed
public static edu.wpi.first.wpilibj2.command.Command delayed(double delaySeconds, edu.wpi.first.wpilibj2.command.Command command) -
withState
public static <T> edu.wpi.first.wpilibj2.command.Command withState(Supplier<T> getState, Function<Supplier<T>, edu.wpi.first.wpilibj2.command.Command> getCommand, edu.wpi.first.wpilibj2.command.Subsystem... addedRequirements) Useful for creating complicated functional commands with multiple lambdas that reference the same state, and where the state needs to be updated every iteration.For example:
return CmdUtil.<Pose2d>withState( this::getNextPose, state -> new ParallelCommandGroup( c_moveTo(() -> state.get().getTranslation())), c_rotateTo(() -> state.get().getRotation()) ) )- Type Parameters:
T- The type of the state- Parameters:
getState- Supplier of the current stategetCommand- Lambda that takes in a state supplier for usage in the functional command(s), and returns a command. Usestate.get()to retrieve the current state within this lambda. Callingstate.get()does not recompute the state - it returns the state that was already computed this iterationaddedRequirements- Additional requirements to add- Returns:
- The constructed command
-