Package edu.wpi.first.wpilibj2.command
Class Commands
java.lang.Object
edu.wpi.first.wpilibj2.command.Commands
Namespace for command factory methods.
For convenience, you might want to static import the members of this class.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Command
Runs a group of commands at the same time.static Command
Runs the command supplied by the supplier.static Command
deferredProxy
(Supplier<Command> supplier) Deprecated, for removal: This API element is subject to removal in a future version.static Command
either
(Command onTrue, Command onFalse, BooleanSupplier selector) Runs one of two commands, based on the boolean selector function.static Command
Constructs a command that does nothing until interrupted.static Command
none()
Constructs a command that does nothing, finishing immediately.static Command
Runs a group of commands at the same time.static Command
Constructs a command that prints a message and finishes.static Command
Runs a group of commands at the same time.static Command
repeatingSequence
(Command... commands) Runs a group of commands in series, one after the other.static Command
Constructs a command that runs an action every iteration until interrupted.static Command
Constructs a command that runs an action every iteration until interrupted, and then runs a second action.static Command
Constructs a command that runs an action once and finishes.static <K> Command
Runs one of several commands, based on the selector function.static Command
Runs a group of commands in series, one after the other.static Command
Constructs a command that runs an action once and another action when the command is interrupted.static Command
Constructs a command that runs an action once, and then runs an action every iteration until interrupted.static Command
waitSeconds
(double seconds) Constructs a command that does nothing, finishing after a specified duration.static Command
Constructs a command that does nothing, finishing after a specified duration.static Command
waitUntil
(BooleanSupplier condition) Constructs a command that does nothing, finishing once a condition becomes true.
-
Method Details
-
none
Constructs a command that does nothing, finishing immediately.- Returns:
- the command
-
idle
Constructs a command that does nothing until interrupted.- Parameters:
requirements
- Subsystems to require- 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:
-
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:
-
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:
-
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
-
startRun
Constructs a command that runs an action once, and then runs an action every iteration until interrupted.- Parameters:
start
- the action to run on startrun
- the action to run every iterationrequirements
- 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:
-
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:
-
waitTime
Constructs a command that does nothing, finishing after a specified duration.- Parameters:
time
- after how long the command finishes- Returns:
- the command
- See Also:
-
waitUntil
Constructs a command that does nothing, finishing once a condition becomes true.- Parameters:
condition
- the condition- Returns:
- the command
- See Also:
-
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:
-
select
Runs one of several commands, based on the selector function.- Type Parameters:
K
- The type of key used to select the command- Parameters:
selector
- the selector functioncommands
- map of commands to select from- Returns:
- the command
- See Also:
-
defer
Runs the command supplied by the supplier.- Parameters:
supplier
- the command supplierrequirements
- the set of requirements for this command- Returns:
- the command
- See Also:
-
deferredProxy
@Deprecated(since="2025", forRemoval=true) public static Command deferredProxy(Supplier<Command> supplier) Deprecated, for removal: This API element is subject to removal in a future version.The ProxyCommand supplier constructor has been deprecated in favor of directly proxying aDeferredCommand
, see ProxyCommand documentaion for more details. As a replacement, consider using `defer(supplier).asProxy()`.Constructs a command that schedules the command returned from the supplier when initialized, and ends when it is no longer scheduled. The supplier is called when the command is initialized.- Parameters:
supplier
- the command supplier- Returns:
- the command
- See Also:
-
sequence
Runs a group of commands in series, one after the other.- Parameters:
commands
- the commands to include- Returns:
- the command group
- See Also:
-
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:
-
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:
-
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:
-
deadline
Runs a group of commands at the same time. Ends once a specific command finishes, and cancels the others.- Parameters:
deadline
- the deadline commandotherCommands
- the other commands to include- Returns:
- the command group
- Throws:
IllegalArgumentException
- if the deadline command is also in the otherCommands argument- See Also:
-
DeferredCommand
, see ProxyCommand documentaion for more details.