Robot Core Documentation
Loading...
Searching...
No Matches
edu.wpi.first.wpilibj2.command.Command Class Referenceabstract
Inheritance diagram for edu.wpi.first.wpilibj2.command.Command:
edu.wpi.first.util.sendable.Sendable com.pathplanner.lib.commands.FollowPathCommand com.pathplanner.lib.commands.FollowPathWithEvents com.pathplanner.lib.commands.PathPlannerAuto com.pathplanner.lib.commands.PathfindingCommand edu.wpi.first.wpilibj2.command.CommandBase 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 edu.wpi.first.wpilibj2.command.WrapperCommand

Classes

enum  InterruptionBehavior
 

Public Member Functions

void initialize ()
 
void execute ()
 
void end (boolean interrupted)
 
boolean isFinished ()
 
Set< SubsystemgetRequirements ()
 
final void addRequirements (Subsystem... requirements)
 
String getName ()
 
void setName (String name)
 
String getSubsystem ()
 
void setSubsystem (String subsystem)
 
ParallelRaceGroup withTimeout (double seconds)
 
ParallelRaceGroup until (BooleanSupplier condition)
 
ParallelRaceGroup onlyWhile (BooleanSupplier condition)
 
SequentialCommandGroup beforeStarting (Runnable toRun, Subsystem... requirements)
 
SequentialCommandGroup beforeStarting (Command before)
 
SequentialCommandGroup andThen (Runnable toRun, Subsystem... requirements)
 
SequentialCommandGroup andThen (Command... next)
 
ParallelDeadlineGroup deadlineWith (Command... parallel)
 
ParallelCommandGroup alongWith (Command... parallel)
 
ParallelRaceGroup raceWith (Command... parallel)
 
RepeatCommand repeatedly ()
 
ProxyCommand asProxy ()
 
ConditionalCommand unless (BooleanSupplier condition)
 
ConditionalCommand onlyIf (BooleanSupplier condition)
 
WrapperCommand ignoringDisable (boolean doesRunWhenDisabled)
 
WrapperCommand withInterruptBehavior (InterruptionBehavior interruptBehavior)
 
WrapperCommand finallyDo (BooleanConsumer end)
 
WrapperCommand finallyDo (Runnable end)
 
WrapperCommand handleInterrupt (Runnable handler)
 
void schedule ()
 
void cancel ()
 
boolean isScheduled ()
 
boolean hasRequirement (Subsystem requirement)
 
InterruptionBehavior getInterruptionBehavior ()
 
boolean runsWhenDisabled ()
 
WrapperCommand withName (String name)
 
void initSendable (SendableBuilder builder)
 
- Public Member Functions inherited from edu.wpi.first.util.sendable.Sendable

Protected Member Functions

 Command ()
 

Protected Attributes

Set< Subsystemm_requirements = new HashSet<>()
 

Detailed Description

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

Constructor & Destructor Documentation

◆ Command()

edu.wpi.first.wpilibj2.command.Command.Command ( )
protected

Default constructor.

Member Function Documentation

◆ addRequirements()

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.

Parameters
requirementsthe requirements to add

◆ alongWith()

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.

Parameters
parallelthe commands to run in parallel
Returns
the decorated command

◆ andThen() [1/2]

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.

Parameters
nextthe commands to run next
Returns
the decorated command

◆ andThen() [2/2]

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.

Parameters
toRunthe Runnable to run
requirementsthe required subsystems
Returns
the decorated command

◆ asProxy()

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.

Returns
the decorated command

◆ beforeStarting() [1/2]

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.

Parameters
beforethe command to run before this one
Returns
the decorated command

◆ beforeStarting() [2/2]

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.

Parameters
toRunthe Runnable to run
requirementsthe required subsystems
Returns
the decorated command

◆ cancel()

void edu.wpi.first.wpilibj2.command.Command.cancel ( )

Cancels this command. Will call end(true). Commands will be canceled regardless of interruption behavior.

See also
CommandScheduler.cancel(Command...)

◆ deadlineWith()

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.

Parameters
parallelthe commands to run in parallel
Returns
the decorated command

◆ end()

◆ execute()

◆ finallyDo() [1/2]

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.

Parameters
enda lambda accepting a boolean parameter specifying whether the command was interrupted.
Returns
the decorated command

◆ finallyDo() [2/2]

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.

Parameters
enda lambda to run when the command ends, whether or not it was interrupted.
Returns
the decorated command

◆ getInterruptionBehavior()

◆ getName()

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).

Returns
The display name of the Command

◆ getRequirements()

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.

Returns
the set of subsystems that are required
See also
InterruptionBehavior

Reimplemented in edu.wpi.first.wpilibj2.command.WrapperCommand.

◆ getSubsystem()

String edu.wpi.first.wpilibj2.command.Command.getSubsystem ( )

Gets the subsystem name of this Command.

Returns
Subsystem name

◆ handleInterrupt()

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.

Parameters
handlera lambda to run when the command is interrupted
Returns
the decorated command

◆ hasRequirement()

boolean edu.wpi.first.wpilibj2.command.Command.hasRequirement ( Subsystem requirement)

Whether the command requires a given subsystem.

Parameters
requirementthe subsystem to inquire about
Returns
whether the subsystem is required

◆ ignoringDisable()

WrapperCommand edu.wpi.first.wpilibj2.command.Command.ignoringDisable ( boolean doesRunWhenDisabled)

Decorates this command to run or stop when disabled.

Parameters
doesRunWhenDisabledtrue to run when disabled.
Returns
the decorated command

◆ initialize()

◆ initSendable()

◆ isFinished()

◆ isScheduled()

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.

Returns
Whether the command is scheduled.

◆ onlyIf()

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.

Parameters
conditionthe condition that will allow the command to run
Returns
the decorated command
See also
unless(BooleanSupplier)

◆ onlyWhile()

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.

Parameters
conditionthe run condition
Returns
the command with the run condition added
See also
until(BooleanSupplier)

◆ raceWith()

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.

Parameters
parallelthe commands to run in parallel
Returns
the decorated command

◆ repeatedly()

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.

Returns
the decorated command

◆ runsWhenDisabled()

◆ schedule()

void edu.wpi.first.wpilibj2.command.Command.schedule ( )

Schedules this command.

◆ setName()

void edu.wpi.first.wpilibj2.command.Command.setName ( String name)

Sets the name of this Command.

Parameters
nameThe display name of the Command.

◆ setSubsystem()

void edu.wpi.first.wpilibj2.command.Command.setSubsystem ( String subsystem)

Sets the subsystem name of this Command.

Parameters
subsystemsubsystem name

◆ unless()

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.

Parameters
conditionthe condition that will prevent the command from running
Returns
the decorated command
See also
onlyIf(BooleanSupplier)

◆ until()

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.

Parameters
conditionthe interrupt condition
Returns
the command with the interrupt condition added
See also
onlyWhile(BooleanSupplier)

◆ withInterruptBehavior()

WrapperCommand edu.wpi.first.wpilibj2.command.Command.withInterruptBehavior ( InterruptionBehavior interruptBehavior)

Decorates this command to have a different interruption behavior.

Parameters
interruptBehaviorthe desired interrupt behavior
Returns
the decorated command

◆ withName()

WrapperCommand edu.wpi.first.wpilibj2.command.Command.withName ( String name)

Decorates this Command with a name.

Parameters
namename
Returns
the decorated Command

◆ withTimeout()

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.

Parameters
secondsthe timeout duration
Returns
the command with the timeout added

Member Data Documentation

◆ m_requirements

Set<Subsystem> edu.wpi.first.wpilibj2.command.Command.m_requirements = new HashSet<>()
protected

Requirements set.


The documentation for this class was generated from the following file: