Interface Command
- All Known Implementing Classes:
CommandBase,CommandGroupBase,ConditionalCommand,FunctionalCommand,InstantCommand,MecanumControllerCommand,NotifierCommand,ParallelCommandGroup,ParallelDeadlineGroup,ParallelRaceGroup,PerpetualCommand,PIDCommand,PrintCommand,ProfiledPIDCommand,ProxyScheduleCommand,RamseteCommand,RunCommand,ScheduleCommand,SelectCommand,SequentialCommandGroup,StartEndCommand,SwerveControllerCommand,TrapezoidProfileCommand,WaitCommand,WaitUntilCommand
public interface Command
CommandScheduler, and can be composed into CommandGroups to allow users to build
complicated multi-step actions without the need to roll the state machine logic themselves.
Commands are run synchronously from the main robot loop; no multithreading is used, unless specified explicitly from the command implementation.
-
Method Summary
Modifier and Type Method Description default ParallelCommandGroupalongWith(Command... parallel)Decorates this command with a set of commands to run parallel to it, ending when the last command ends.default SequentialCommandGroupandThen(Command... next)Decorates this command with a set of commands to run after it in sequence.default SequentialCommandGroupandThen(Runnable toRun, Subsystem... requirements)Decorates this command with a runnable to run after the command finishes.default ProxyScheduleCommandasProxy()Decorates this command to run "by proxy" by wrapping it in aProxyScheduleCommand.default SequentialCommandGroupbeforeStarting(Command before)Decorates this command with another command to run before this command starts.default SequentialCommandGroupbeforeStarting(Runnable toRun, Subsystem... requirements)Decorates this command with a runnable to run before this command starts.default voidcancel()Cancels this command.default ParallelDeadlineGroupdeadlineWith(Command... parallel)Decorates this command with a set of commands to run parallel to it, ending when the calling command ends and interrupting all the others.default voidend(boolean interrupted)The action to take when the command ends.default voidexecute()The main body of a command.default StringgetName()Gets the name of this Command.Set<Subsystem>getRequirements()Specifies the set of subsystems used by this command.default booleanhasRequirement(Subsystem requirement)Whether the command requires a given subsystem.default voidinitialize()The initial subroutine of a command.default booleanisFinished()Whether the command has finished.default booleanisScheduled()Whether or not the command is currently scheduled.default PerpetualCommandperpetually()Decorates this command to run perpetually, ignoring its ordinary end conditions.default ParallelRaceGroupraceWith(Command... parallel)Decorates this command with a set of commands to run parallel to it, ending when the first command ends.default booleanrunsWhenDisabled()Whether the given command should run when the robot is disabled.default voidschedule()Schedules this command, defaulting to interruptible.default voidschedule(boolean interruptible)Schedules this command.default ParallelRaceGroupwithInterrupt(BooleanSupplier condition)Decorates this command with an interrupt condition.default ParallelRaceGroupwithTimeout(double seconds)Decorates this command with a timeout.
-
Method Details
-
initialize
The initial subroutine of a command. Called once when the command is initially scheduled. -
execute
The main body of a command. Called repeatedly while the command is scheduled. -
end
The action to take when the command ends. Called when either the command finishes normally, or when it interrupted/canceled.Do not schedule commands here that share requirements with this command. Use
andThen(Command...)instead.- Parameters:
interrupted- whether the command was interrupted/canceled
-
isFinished
Whether the command has finished. Once a command finishes, the scheduler will call its end() method and un-schedule it.- Returns:
- whether the command has finished.
-
getRequirements
Specifies the set of subsystems used by this command. Two commands cannot use the same subsystem at the same time. If the command is scheduled as interruptible and another command is scheduled that shares a requirement, the command will be interrupted. Else, the command will not be scheduled. If no subsystems are required, return an empty set.Note: it is recommended that user implementations contain the requirements as a field, and return that field here, rather than allocating a new set every time this is called.
- Returns:
- the set of subsystems that are required
-
withTimeout
Decorates this command with a timeout. If the specified timeout is exceeded before the command finishes normally, the command will be interrupted and un-scheduled. Note that the timeout only applies to the command returned by this method; the calling command is not itself changed.Note: This decorator works by composing this command within a CommandGroup. The command cannot be used independently after being decorated, or be re-decorated with a different decorator, unless it is manually cleared from the list of grouped commands with
CommandGroupBase.clearGroupedCommand(Command). The decorated command can, however, be further decorated without issue.- Parameters:
seconds- the timeout duration- Returns:
- the command with the timeout added
-
withInterrupt
Decorates this command with an interrupt condition. If the specified condition becomes true before the command finishes normally, the command will be interrupted and un-scheduled. Note that this only applies to the command returned by this method; the calling command is not itself changed.Note: This decorator works by composing this command within a CommandGroup. The command cannot be used independently after being decorated, or be re-decorated with a different decorator, unless it is manually cleared from the list of grouped commands with
CommandGroupBase.clearGroupedCommand(Command). The decorated command can, however, be further decorated without issue.- Parameters:
condition- the interrupt condition- Returns:
- the command with the interrupt condition added
-
beforeStarting
Decorates this command with a runnable to run before this command starts.Note: This decorator works by composing this command within a CommandGroup. The command cannot be used independently after being decorated, or be re-decorated with a different decorator, unless it is manually cleared from the list of grouped commands with
CommandGroupBase.clearGroupedCommand(Command). The decorated command can, however, be further decorated without issue.- Parameters:
toRun- the Runnable to runrequirements- the required subsystems- Returns:
- the decorated command
-
beforeStarting
Decorates this command with another command to run before this command starts.Note: This decorator works by composing this command within a CommandGroup. The command cannot be used independently after being decorated, or be re-decorated with a different decorator, unless it is manually cleared from the list of grouped commands with
CommandGroupBase.clearGroupedCommand(Command). The decorated command can, however, be further decorated without issue.- Parameters:
before- the command to run before this one- Returns:
- the decorated command
-
andThen
Decorates this command with a runnable to run after the command finishes.Note: This decorator works by composing this command within a CommandGroup. The command cannot be used independently after being decorated, or be re-decorated with a different decorator, unless it is manually cleared from the list of grouped commands with
CommandGroupBase.clearGroupedCommand(Command). The decorated command can, however, be further decorated without issue.- Parameters:
toRun- the Runnable to runrequirements- the required subsystems- Returns:
- the decorated command
-
andThen
Decorates this command with a set of commands to run after it in sequence. Often more convenient/less-verbose than constructing a newSequentialCommandGroupexplicitly.Note: This decorator works by composing this command within a CommandGroup. The command cannot be used independently after being decorated, or be re-decorated with a different decorator, unless it is manually cleared from the list of grouped commands with
CommandGroupBase.clearGroupedCommand(Command). The decorated command can, however, be further decorated without issue.- Parameters:
next- the commands to run next- Returns:
- the decorated command
-
deadlineWith
Decorates this command with a set of commands to run parallel to it, ending when the calling command ends and interrupting all the others. Often more convenient/less-verbose than constructing a newParallelDeadlineGroupexplicitly.Note: This decorator works by composing this command within a CommandGroup. The command cannot be used independently after being decorated, or be re-decorated with a different decorator, unless it is manually cleared from the list of grouped commands with
CommandGroupBase.clearGroupedCommand(Command). The decorated command can, however, be further decorated without issue.- Parameters:
parallel- the commands to run in parallel- Returns:
- the decorated command
-
alongWith
Decorates this command with a set of commands to run parallel to it, ending when the last command ends. Often more convenient/less-verbose than constructing a newParallelCommandGroupexplicitly.Note: This decorator works by composing this command within a CommandGroup. The command cannot be used independently after being decorated, or be re-decorated with a different decorator, unless it is manually cleared from the list of grouped commands with
CommandGroupBase.clearGroupedCommand(Command). The decorated command can, however, be further decorated without issue.- Parameters:
parallel- the commands to run in parallel- Returns:
- the decorated command
-
raceWith
Decorates this command with a set of commands to run parallel to it, ending when the first command ends. Often more convenient/less-verbose than constructing a newParallelRaceGroupexplicitly.Note: This decorator works by composing this command within a CommandGroup. The command cannot be used independently after being decorated, or be re-decorated with a different decorator, unless it is manually cleared from the list of grouped commands with
CommandGroupBase.clearGroupedCommand(Command). The decorated command can, however, be further decorated without issue.- Parameters:
parallel- the commands to run in parallel- Returns:
- the decorated command
-
perpetually
Decorates this command to run perpetually, ignoring its ordinary end conditions. The decorated command can still be interrupted or canceled.Note: This decorator works by composing this command within a CommandGroup. The command cannot be used independently after being decorated, or be re-decorated with a different decorator, unless it is manually cleared from the list of grouped commands with
CommandGroupBase.clearGroupedCommand(Command). The decorated command can, however, be further decorated without issue.- Returns:
- the decorated command
-
asProxy
Decorates this command to run "by proxy" by wrapping it in aProxyScheduleCommand. This is useful for "forking off" from command groups when the user does not wish to extend the command's requirements to the entire command group.- Returns:
- the decorated command
-
schedule
Schedules this command.- Parameters:
interruptible- whether this command can be interrupted by another command that shares one of its requirements
-
schedule
Schedules this command, defaulting to interruptible. -
cancel
Cancels this command. Will call the command's interrupted() method. Commands will be canceled even if they are not marked as interruptible. -
isScheduled
Whether or not the command is currently scheduled. Note that this does not detect whether the command is being run by a CommandGroup, only whether it is directly being run by the scheduler.- Returns:
- Whether the command is scheduled.
-
hasRequirement
Whether the command requires a given subsystem.- Parameters:
requirement- the subsystem to inquire about- Returns:
- whether the subsystem is required
-
runsWhenDisabled
Whether the given command should run when the robot is disabled. Override to return true if the command should run when disabled.- Returns:
- whether the command should run when the robot is disabled
-
getName
Gets the name of this Command.- Returns:
- Name
-