Package edu.wpi.first.wpilibj2.command
Class Commands
java.lang.Object
edu.wpi.first.wpilibj2.command.Commands
public final class Commands extends Object
Namespace for command factory methods.
For convenience, you might want to static import the members of this class.
-
Method Summary
Modifier and Type Method Description static CommandBase
deadline(Command deadline, Command... commands)
Runs a group of commands at the same time.static CommandBase
either(Command onTrue, Command onFalse, BooleanSupplier selector)
Runs one of two commands, based on the boolean selector function.static CommandBase
none()
Constructs a command that does nothing, finishing immediately.static CommandBase
parallel(Command... commands)
Runs a group of commands at the same time.static CommandBase
print(String message)
Constructs a command that prints a message and finishes.static CommandBase
race(Command... commands)
Runs a group of commands at the same time.static CommandBase
repeatingSequence(Command... commands)
Runs a group of commands in series, one after the other.static CommandBase
run(Runnable action, Subsystem... requirements)
Constructs a command that runs an action every iteration until interrupted.static CommandBase
runEnd(Runnable run, Runnable end, Subsystem... requirements)
Constructs a command that runs an action every iteration until interrupted, and then runs a second action.static CommandBase
runOnce(Runnable action, Subsystem... requirements)
Constructs a command that runs an action once and finishes.static CommandBase
select(Map<Object,Command> commands, Supplier<Object> selector)
Runs one of several commands, based on the selector function.static CommandBase
sequence(Command... commands)
Runs a group of commands in series, one after the other.static CommandBase
startEnd(Runnable start, Runnable end, Subsystem... requirements)
Constructs a command that runs an action once and another action when the command is interrupted.static CommandBase
waitSeconds(double seconds)
Constructs a command that does nothing, finishing after a specified duration.static CommandBase
waitUntil(BooleanSupplier condition)
Constructs a command that does nothing, finishing once a command becomes true.
-
Method Details
-
none
Constructs a command that does nothing, finishing immediately.- Returns:
- the command
-
runOnce
Constructs a command that runs an action once and finishes.- Parameters:
action
- the action to runrequirements
- subsystems the action requires- Returns:
- the command
- See Also:
InstantCommand
-
run
Constructs a command that runs an action every iteration until interrupted.- Parameters:
action
- the action to runrequirements
- subsystems the action requires- Returns:
- the command
- See Also:
RunCommand
-
startEnd
Constructs a command that runs an action once and another action when the command is interrupted.- Parameters:
start
- the action to run on startend
- the action to run on interruptrequirements
- subsystems the action requires- Returns:
- the command
- See Also:
StartEndCommand
-
runEnd
Constructs a command that runs an action every iteration until interrupted, and then runs a second action.- Parameters:
run
- the action to run every iterationend
- the action to run on interruptrequirements
- subsystems the action requires- Returns:
- the command
-
print
Constructs a command that prints a message and finishes.- Parameters:
message
- the message to print- Returns:
- the command
- See Also:
PrintCommand
-
waitSeconds
Constructs a command that does nothing, finishing after a specified duration.- Parameters:
seconds
- after how long the command finishes- Returns:
- the command
- See Also:
WaitCommand
-
waitUntil
Constructs a command that does nothing, finishing once a command becomes true.- Parameters:
condition
- the condition- Returns:
- the command
- See Also:
WaitUntilCommand
-
either
Runs one of two commands, based on the boolean selector function.- Parameters:
onTrue
- the command to run if the selector function returns trueonFalse
- the command to run if the selector function returns falseselector
- the selector function- Returns:
- the command
- See Also:
ConditionalCommand
-
select
Runs one of several commands, based on the selector function.- Parameters:
selector
- the selector functioncommands
- map of commands to select from- Returns:
- the command
- See Also:
SelectCommand
-
sequence
Runs a group of commands in series, one after the other.- Parameters:
commands
- the commands to include- Returns:
- the command group
- See Also:
SequentialCommandGroup
-
repeatingSequence
Runs a group of commands in series, one after the other. Once the last command ends, the group is restarted.- Parameters:
commands
- the commands to include- Returns:
- the command group
- See Also:
SequentialCommandGroup
,Command.repeatedly()
-
parallel
Runs a group of commands at the same time. Ends once all commands in the group finish.- Parameters:
commands
- the commands to include- Returns:
- the command
- See Also:
ParallelCommandGroup
-
race
Runs a group of commands at the same time. Ends once any command in the group finishes, and cancels the others.- Parameters:
commands
- the commands to include- Returns:
- the command group
- See Also:
ParallelRaceGroup
-
deadline
Runs a group of commands at the same time. Ends once a specific command finishes, and cancels the others.- Parameters:
deadline
- the deadline commandcommands
- the commands to include- Returns:
- the command group
- See Also:
ParallelDeadlineGroup
-