Robot Core Documentation
|
Classes | |
enum | InterruptionBehavior |
Protected Member Functions | |
Command () | |
Protected Attributes | |
Set< Subsystem > | m_requirements = new HashSet<>() |
A state machine representing a complete action to be performed by the robot. Commands are run by the CommandScheduler
, and can be composed into CommandGroups to allow users to build complicated multistep 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.
This class is provided by the NewCommands VendorDep
|
protected |
Default constructor.
final void edu.wpi.first.wpilibj2.command.Command.addRequirements | ( | Subsystem... | requirements | ) |
Adds the specified subsystems to the requirements of the command. The scheduler will prevent two commands that require the same subsystem from being scheduled simultaneously.
Note that the scheduler determines the requirements of a command when it is scheduled, so this method should normally be called from the command's constructor.
requirements | the requirements to add |
ParallelCommandGroup edu.wpi.first.wpilibj2.command.Command.alongWith | ( | Command... | parallel | ) |
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 new ParallelCommandGroup
explicitly.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
parallel | the commands to run in parallel |
SequentialCommandGroup edu.wpi.first.wpilibj2.command.Command.andThen | ( | Command... | next | ) |
Decorates this command with a set of commands to run after it in sequence. Often more convenient/less-verbose than constructing a new SequentialCommandGroup
explicitly.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
next | the commands to run next |
SequentialCommandGroup edu.wpi.first.wpilibj2.command.Command.andThen | ( | Runnable | toRun, |
Subsystem... | requirements ) |
Decorates this command with a runnable to run after the command finishes.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
toRun | the Runnable to run |
requirements | the required subsystems |
ProxyCommand edu.wpi.first.wpilibj2.command.Command.asProxy | ( | ) |
Decorates this command to run "by proxy" by wrapping it in a ProxyCommand
. This is useful for "forking off" from command compositions when the user does not wish to extend the command's requirements to the entire command composition.
SequentialCommandGroup edu.wpi.first.wpilibj2.command.Command.beforeStarting | ( | Command | before | ) |
Decorates this command with another command to run before this command starts.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
before | the command to run before this one |
SequentialCommandGroup edu.wpi.first.wpilibj2.command.Command.beforeStarting | ( | Runnable | toRun, |
Subsystem... | requirements ) |
Decorates this command with a runnable to run before this command starts.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
toRun | the Runnable to run |
requirements | the required subsystems |
void edu.wpi.first.wpilibj2.command.Command.cancel | ( | ) |
Cancels this command. Will call end(true)
. Commands will be canceled regardless of interruption behavior
.
ParallelDeadlineGroup edu.wpi.first.wpilibj2.command.Command.deadlineWith | ( | 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. Often more convenient/less-verbose than constructing a new ParallelDeadlineGroup
explicitly.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
parallel | the commands to run in parallel |
void edu.wpi.first.wpilibj2.command.Command.end | ( | boolean | interrupted | ) |
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.
interrupted | whether the command was interrupted/canceled |
Reimplemented in com.pathplanner.lib.commands.FollowPathCommand, com.pathplanner.lib.commands.FollowPathWithEvents, com.pathplanner.lib.commands.PathfindingCommand, com.pathplanner.lib.commands.PathPlannerAuto, edu.wpi.first.wpilibj2.command.ConditionalCommand, edu.wpi.first.wpilibj2.command.DeferredCommand, edu.wpi.first.wpilibj2.command.FunctionalCommand, edu.wpi.first.wpilibj2.command.ParallelCommandGroup, edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup, edu.wpi.first.wpilibj2.command.ParallelRaceGroup, edu.wpi.first.wpilibj2.command.PerpetualCommand, edu.wpi.first.wpilibj2.command.ProxyCommand, edu.wpi.first.wpilibj2.command.RepeatCommand, edu.wpi.first.wpilibj2.command.SelectCommand< K >, edu.wpi.first.wpilibj2.command.SequentialCommandGroup, edu.wpi.first.wpilibj2.command.WaitCommand, and edu.wpi.first.wpilibj2.command.WrapperCommand.
void edu.wpi.first.wpilibj2.command.Command.execute | ( | ) |
The main body of a command. Called repeatedly while the command is scheduled.
Reimplemented in com.pathplanner.lib.commands.FollowPathCommand, com.pathplanner.lib.commands.FollowPathWithEvents, com.pathplanner.lib.commands.PathfindingCommand, com.pathplanner.lib.commands.PathPlannerAuto, edu.wpi.first.wpilibj2.command.ConditionalCommand, edu.wpi.first.wpilibj2.command.DeferredCommand, edu.wpi.first.wpilibj2.command.FunctionalCommand, edu.wpi.first.wpilibj2.command.ParallelCommandGroup, edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup, edu.wpi.first.wpilibj2.command.ParallelRaceGroup, edu.wpi.first.wpilibj2.command.PerpetualCommand, edu.wpi.first.wpilibj2.command.ProxyCommand, edu.wpi.first.wpilibj2.command.RepeatCommand, edu.wpi.first.wpilibj2.command.SelectCommand< K >, edu.wpi.first.wpilibj2.command.SequentialCommandGroup, and edu.wpi.first.wpilibj2.command.WrapperCommand.
WrapperCommand edu.wpi.first.wpilibj2.command.Command.finallyDo | ( | BooleanConsumer | end | ) |
Decorates this command with a lambda to call on interrupt or end, following the command's inherent end(boolean)
method.
end | a lambda accepting a boolean parameter specifying whether the command was interrupted. |
WrapperCommand edu.wpi.first.wpilibj2.command.Command.finallyDo | ( | Runnable | end | ) |
Decorates this command with a lambda to call on interrupt or end, following the command's inherent end(boolean)
method. The provided lambda will run identically in both interrupt and end cases.
end | a lambda to run when the command ends, whether or not it was interrupted. |
InterruptionBehavior edu.wpi.first.wpilibj2.command.Command.getInterruptionBehavior | ( | ) |
How the command behaves when another command with a shared requirement is scheduled.
InterruptionBehavior
, defaulting to kCancelSelf
. Reimplemented in edu.wpi.first.wpilibj2.command.ConditionalCommand, edu.wpi.first.wpilibj2.command.ParallelCommandGroup, edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup, edu.wpi.first.wpilibj2.command.ParallelRaceGroup, edu.wpi.first.wpilibj2.command.RepeatCommand, edu.wpi.first.wpilibj2.command.SelectCommand< K >, edu.wpi.first.wpilibj2.command.SequentialCommandGroup, and edu.wpi.first.wpilibj2.command.WrapperCommand.
String edu.wpi.first.wpilibj2.command.Command.getName | ( | ) |
Gets the name of this Command.
By default, the simple class name is used. This can be changed with setName(String)
.
Set< Subsystem > edu.wpi.first.wpilibj2.command.Command.getRequirements | ( | ) |
Specifies the set of subsystems used by this command. Two commands cannot use the same subsystem at the same time. If another command is scheduled that shares a requirement, getInterruptionBehavior()
will be checked and followed. 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.
Reimplemented in edu.wpi.first.wpilibj2.command.WrapperCommand.
String edu.wpi.first.wpilibj2.command.Command.getSubsystem | ( | ) |
WrapperCommand edu.wpi.first.wpilibj2.command.Command.handleInterrupt | ( | Runnable | handler | ) |
Decorates this command with a lambda to call on interrupt, following the command's inherent end(boolean)
method.
handler | a lambda to run when the command is interrupted |
boolean edu.wpi.first.wpilibj2.command.Command.hasRequirement | ( | Subsystem | requirement | ) |
Whether the command requires a given subsystem.
requirement | the subsystem to inquire about |
WrapperCommand edu.wpi.first.wpilibj2.command.Command.ignoringDisable | ( | boolean | doesRunWhenDisabled | ) |
Decorates this command to run or stop when disabled.
doesRunWhenDisabled | true to run when disabled. |
void edu.wpi.first.wpilibj2.command.Command.initialize | ( | ) |
The initial subroutine of a command. Called once when the command is initially scheduled.
Reimplemented in com.pathplanner.lib.commands.FollowPathCommand, com.pathplanner.lib.commands.FollowPathWithEvents, com.pathplanner.lib.commands.PathfindingCommand, com.pathplanner.lib.commands.PathPlannerAuto, edu.wpi.first.wpilibj2.command.ConditionalCommand, edu.wpi.first.wpilibj2.command.DeferredCommand, edu.wpi.first.wpilibj2.command.FunctionalCommand, edu.wpi.first.wpilibj2.command.ParallelCommandGroup, edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup, edu.wpi.first.wpilibj2.command.ParallelRaceGroup, edu.wpi.first.wpilibj2.command.PerpetualCommand, edu.wpi.first.wpilibj2.command.ProxyCommand, edu.wpi.first.wpilibj2.command.RepeatCommand, edu.wpi.first.wpilibj2.command.ScheduleCommand, edu.wpi.first.wpilibj2.command.SelectCommand< K >, edu.wpi.first.wpilibj2.command.SequentialCommandGroup, edu.wpi.first.wpilibj2.command.WaitCommand, and edu.wpi.first.wpilibj2.command.WrapperCommand.
void edu.wpi.first.wpilibj2.command.Command.initSendable | ( | SendableBuilder | builder | ) |
Initializes this Sendable
object.
builder | sendable builder |
Implements edu.wpi.first.util.sendable.Sendable.
Reimplemented in edu.wpi.first.wpilibj2.command.ConditionalCommand, edu.wpi.first.wpilibj2.command.DeferredCommand, edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup, edu.wpi.first.wpilibj2.command.ProxyCommand, edu.wpi.first.wpilibj2.command.RepeatCommand, edu.wpi.first.wpilibj2.command.SelectCommand< K >, edu.wpi.first.wpilibj2.command.SequentialCommandGroup, and edu.wpi.first.wpilibj2.command.WaitCommand.
boolean edu.wpi.first.wpilibj2.command.Command.isFinished | ( | ) |
Whether the command has finished. Once a command finishes, the scheduler will call its end() method and un-schedule it.
Reimplemented in com.pathplanner.lib.commands.FollowPathCommand, com.pathplanner.lib.commands.FollowPathWithEvents, com.pathplanner.lib.commands.PathfindingCommand, com.pathplanner.lib.commands.PathPlannerAuto, edu.wpi.first.wpilibj2.command.ConditionalCommand, edu.wpi.first.wpilibj2.command.DeferredCommand, edu.wpi.first.wpilibj2.command.FunctionalCommand, edu.wpi.first.wpilibj2.command.ParallelCommandGroup, edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup, edu.wpi.first.wpilibj2.command.ParallelRaceGroup, edu.wpi.first.wpilibj2.command.ProxyCommand, edu.wpi.first.wpilibj2.command.RepeatCommand, edu.wpi.first.wpilibj2.command.ScheduleCommand, edu.wpi.first.wpilibj2.command.SelectCommand< K >, edu.wpi.first.wpilibj2.command.SequentialCommandGroup, edu.wpi.first.wpilibj2.command.WaitCommand, edu.wpi.first.wpilibj2.command.WaitUntilCommand, and edu.wpi.first.wpilibj2.command.WrapperCommand.
boolean edu.wpi.first.wpilibj2.command.Command.isScheduled | ( | ) |
Whether the command is currently scheduled. Note that this does not detect whether the command is in a composition, only whether it is directly being run by the scheduler.
ConditionalCommand edu.wpi.first.wpilibj2.command.Command.onlyIf | ( | BooleanSupplier | condition | ) |
Decorates this command to only run if this condition is met. If the command is already running and the condition changes to false, the command will not stop running. The requirements of this command will be kept for the new conditional command.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
condition | the condition that will allow the command to run |
ParallelRaceGroup edu.wpi.first.wpilibj2.command.Command.onlyWhile | ( | BooleanSupplier | condition | ) |
Decorates this command with a run condition. If the specified condition becomes false before the command finishes normally, the command will be interrupted and un-scheduled.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
condition | the run condition |
ParallelRaceGroup edu.wpi.first.wpilibj2.command.Command.raceWith | ( | Command... | parallel | ) |
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 new ParallelRaceGroup
explicitly.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
parallel | the commands to run in parallel |
RepeatCommand edu.wpi.first.wpilibj2.command.Command.repeatedly | ( | ) |
Decorates this command to run repeatedly, restarting it when it ends, until this command is interrupted. The decorated command can still be canceled.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
boolean edu.wpi.first.wpilibj2.command.Command.runsWhenDisabled | ( | ) |
Whether the given command should run when the robot is disabled. Override to return true if the command should run when disabled.
Reimplemented in edu.wpi.first.wpilibj2.command.ConditionalCommand, edu.wpi.first.wpilibj2.command.ParallelCommandGroup, edu.wpi.first.wpilibj2.command.ParallelDeadlineGroup, edu.wpi.first.wpilibj2.command.ParallelRaceGroup, edu.wpi.first.wpilibj2.command.PerpetualCommand, edu.wpi.first.wpilibj2.command.PrintCommand, edu.wpi.first.wpilibj2.command.ProxyCommand, edu.wpi.first.wpilibj2.command.RepeatCommand, edu.wpi.first.wpilibj2.command.ScheduleCommand, edu.wpi.first.wpilibj2.command.SelectCommand< K >, edu.wpi.first.wpilibj2.command.SequentialCommandGroup, edu.wpi.first.wpilibj2.command.WaitCommand, edu.wpi.first.wpilibj2.command.WaitUntilCommand, and edu.wpi.first.wpilibj2.command.WrapperCommand.
void edu.wpi.first.wpilibj2.command.Command.schedule | ( | ) |
Schedules this command.
void edu.wpi.first.wpilibj2.command.Command.setName | ( | String | name | ) |
void edu.wpi.first.wpilibj2.command.Command.setSubsystem | ( | String | subsystem | ) |
Sets the subsystem name of this Command.
subsystem | subsystem name |
ConditionalCommand edu.wpi.first.wpilibj2.command.Command.unless | ( | BooleanSupplier | condition | ) |
Decorates this command to only run if this condition is not met. If the command is already running and the condition changes to true, the command will not stop running. The requirements of this command will be kept for the new conditional command.
Note: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
condition | the condition that will prevent the command from running |
ParallelRaceGroup edu.wpi.first.wpilibj2.command.Command.until | ( | BooleanSupplier | condition | ) |
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: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
condition | the interrupt condition |
WrapperCommand edu.wpi.first.wpilibj2.command.Command.withInterruptBehavior | ( | InterruptionBehavior | interruptBehavior | ) |
Decorates this command to have a different interruption behavior
.
interruptBehavior | the desired interrupt behavior |
WrapperCommand edu.wpi.first.wpilibj2.command.Command.withName | ( | String | name | ) |
ParallelRaceGroup edu.wpi.first.wpilibj2.command.Command.withTimeout | ( | double | seconds | ) |
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: This decorator works by adding this command to a composition. The command the decorator was called on cannot be scheduled independently or be added to a different composition (namely, decorators), unless it is manually cleared from the list of composed commands with CommandScheduler#removeComposedCommand(Command)
. The command composition returned from this method can be further decorated without issue.
seconds | the timeout duration |
|
protected |
Requirements set.