Robot Core Documentation
Loading...
Searching...
No Matches
edu.wpi.first.wpilibj2.command.CommandScheduler Class Reference
Inheritance diagram for edu.wpi.first.wpilibj2.command.CommandScheduler:
edu.wpi.first.util.sendable.Sendable

Public Member Functions

void setPeriod (double period)
 
EventLoop getDefaultButtonLoop ()
 
EventLoop getActiveButtonLoop ()
 
void setActiveButtonLoop (EventLoop loop)
 
void schedule (Command... commands)
 
void run ()
 
void registerSubsystem (Subsystem... subsystems)
 
void unregisterSubsystem (Subsystem... subsystems)
 
void unregisterAllSubsystems ()
 
void setDefaultCommand (Subsystem subsystem, Command defaultCommand)
 
void removeDefaultCommand (Subsystem subsystem)
 
Command getDefaultCommand (Subsystem subsystem)
 
void cancel (Command... commands)
 
void cancelAll ()
 
boolean isScheduled (Command... commands)
 
Command requiring (Subsystem subsystem)
 
void disable ()
 
void enable ()
 
void onCommandInitialize (Consumer< Command > action)
 
void onCommandExecute (Consumer< Command > action)
 
void onCommandInterrupt (Consumer< Command > action)
 
void onCommandInterrupt (BiConsumer< Command, Optional< Command > > action)
 
void onCommandFinish (Consumer< Command > action)
 
void registerComposedCommands (Command... commands)
 
void clearComposedCommands ()
 
void removeComposedCommand (Command command)
 
void requireNotComposed (Command... commands)
 
void requireNotComposed (Collection< Command > commands)
 
void requireNotComposedOrScheduled (Command command)
 
void requireNotComposedOrScheduled (Collection< Command > commands)
 
boolean isComposed (Command command)
 
void initSendable (SendableBuilder builder)
 
- Public Member Functions inherited from edu.wpi.first.util.sendable.Sendable

Static Public Member Functions

static synchronized CommandScheduler getInstance ()
 

Detailed Description

The scheduler responsible for running Commands. A Command-based robot should call CommandScheduler#run() on the singleton instance in its periodic block in order to run commands synchronously from the main loop. Subsystems should be registered with the scheduler using CommandScheduler#registerSubsystem(Subsystem...) in order for their Subsystem#periodic() methods to be called and for their default commands to be scheduled.

This class is provided by the NewCommands VendorDep

Member Function Documentation

◆ cancel()

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

Cancels commands. The scheduler will only call Command#end(boolean) method of the canceled command with true, indicating they were canceled (as opposed to finishing normally).

Commands will be canceled regardless of interruption behavior.

Parameters
commandsthe commands to cancel

◆ cancelAll()

void edu.wpi.first.wpilibj2.command.CommandScheduler.cancelAll ( )

Cancels all commands that are currently scheduled.

◆ clearComposedCommands()

void edu.wpi.first.wpilibj2.command.CommandScheduler.clearComposedCommands ( )

Clears the list of composed commands, allowing all commands to be freely used again.

WARNING: Using this haphazardly can result in unexpected/undesirable behavior. Do not use this unless you fully understand what you are doing.

◆ disable()

void edu.wpi.first.wpilibj2.command.CommandScheduler.disable ( )

Disables the command scheduler.

◆ enable()

void edu.wpi.first.wpilibj2.command.CommandScheduler.enable ( )

Enables the command scheduler.

◆ getActiveButtonLoop()

EventLoop edu.wpi.first.wpilibj2.command.CommandScheduler.getActiveButtonLoop ( )

Get the active button poll.

Returns
a reference to the current EventLoop object polling buttons.

◆ getDefaultButtonLoop()

EventLoop edu.wpi.first.wpilibj2.command.CommandScheduler.getDefaultButtonLoop ( )

Get the default button poll.

Returns
a reference to the default EventLoop object polling buttons.

◆ getDefaultCommand()

Command edu.wpi.first.wpilibj2.command.CommandScheduler.getDefaultCommand ( Subsystem subsystem)

Gets the default command associated with this subsystem. Null if this subsystem has no default command associated with it.

Parameters
subsystemthe subsystem to inquire about
Returns
the default command associated with the subsystem

◆ getInstance()

static synchronized CommandScheduler edu.wpi.first.wpilibj2.command.CommandScheduler.getInstance ( )
static

Returns the Scheduler instance.

Returns
the instance

◆ initSendable()

void edu.wpi.first.wpilibj2.command.CommandScheduler.initSendable ( SendableBuilder builder)

Initializes this Sendable object.

Parameters
buildersendable builder

Implements edu.wpi.first.util.sendable.Sendable.

◆ isComposed()

boolean edu.wpi.first.wpilibj2.command.CommandScheduler.isComposed ( Command command)

Check if the given command has been composed.

Parameters
commandThe command to check
Returns
true if composed

◆ isScheduled()

boolean edu.wpi.first.wpilibj2.command.CommandScheduler.isScheduled ( Command... commands)

Whether the given commands are running. Note that this only works on commands that are directly scheduled by the scheduler; it will not work on commands inside compositions, as the scheduler does not see them.

Parameters
commandsthe command to query
Returns
whether the command is currently scheduled

◆ onCommandExecute()

void edu.wpi.first.wpilibj2.command.CommandScheduler.onCommandExecute ( Consumer< Command > action)

Adds an action to perform on the execution of any command by the scheduler.

Parameters
actionthe action to perform

◆ onCommandFinish()

void edu.wpi.first.wpilibj2.command.CommandScheduler.onCommandFinish ( Consumer< Command > action)

Adds an action to perform on the finishing of any command by the scheduler.

Parameters
actionthe action to perform

◆ onCommandInitialize()

void edu.wpi.first.wpilibj2.command.CommandScheduler.onCommandInitialize ( Consumer< Command > action)

Adds an action to perform on the initialization of any command by the scheduler.

Parameters
actionthe action to perform

◆ onCommandInterrupt() [1/2]

void edu.wpi.first.wpilibj2.command.CommandScheduler.onCommandInterrupt ( BiConsumer< Command, Optional< Command > > action)

Adds an action to perform on the interruption of any command by the scheduler. The action receives the interrupted command and an Optional containing the interrupting command, or Optional.empty() if it was not canceled by a command (e.g., by CommandScheduler#cancel).

Parameters
actionthe action to perform

◆ onCommandInterrupt() [2/2]

void edu.wpi.first.wpilibj2.command.CommandScheduler.onCommandInterrupt ( Consumer< Command > action)

Adds an action to perform on the interruption of any command by the scheduler.

Parameters
actionthe action to perform

◆ registerComposedCommands()

void edu.wpi.first.wpilibj2.command.CommandScheduler.registerComposedCommands ( Command... commands)

Register commands as composed. An exception will be thrown if these commands are scheduled directly or added to a composition.

Parameters
commandsthe commands to register
Exceptions
IllegalArgumentExceptionif the given commands have already been composed, or the array of commands has duplicates.

◆ registerSubsystem()

void edu.wpi.first.wpilibj2.command.CommandScheduler.registerSubsystem ( Subsystem... subsystems)

Registers subsystems with the scheduler. This must be called for the subsystem's periodic block to run when the scheduler is run, and for the subsystem's default command to be scheduled. It is recommended to call this from the constructor of your subsystem implementations.

Parameters
subsystemsthe subsystem to register

◆ removeComposedCommand()

void edu.wpi.first.wpilibj2.command.CommandScheduler.removeComposedCommand ( Command command)

Removes a single command from the list of composed commands, allowing it to be freely used again.

WARNING: Using this haphazardly can result in unexpected/undesirable behavior. Do not use this unless you fully understand what you are doing.

Parameters
commandthe command to remove from the list of grouped commands

◆ removeDefaultCommand()

void edu.wpi.first.wpilibj2.command.CommandScheduler.removeDefaultCommand ( Subsystem subsystem)

Removes the default command for a subsystem. The current default command will run until another command is scheduled that requires the subsystem, at which point the current default command will not be re-scheduled.

Parameters
subsystemthe subsystem whose default command will be removed

◆ requireNotComposed() [1/2]

void edu.wpi.first.wpilibj2.command.CommandScheduler.requireNotComposed ( Collection< Command > commands)

Requires that the specified commands have not already been added to a composition.

Parameters
commandsThe commands to check
Exceptions
IllegalArgumentExceptionif the given commands have already been composed.

◆ requireNotComposed() [2/2]

void edu.wpi.first.wpilibj2.command.CommandScheduler.requireNotComposed ( Command... commands)

Requires that the specified command hasn't already been added to a composition.

Parameters
commandsThe commands to check
Exceptions
IllegalArgumentExceptionif the given commands have already been composed.

◆ requireNotComposedOrScheduled() [1/2]

void edu.wpi.first.wpilibj2.command.CommandScheduler.requireNotComposedOrScheduled ( Collection< Command > commands)

Requires that the specified commands have not already been added to a composition, and are not currently scheduled.

Parameters
commandsThe commands to check
Exceptions
IllegalArgumentExceptionif the given commands have already been composed or scheduled.

◆ requireNotComposedOrScheduled() [2/2]

void edu.wpi.first.wpilibj2.command.CommandScheduler.requireNotComposedOrScheduled ( Command command)

Requires that the specified command hasn't already been added to a composition, and is not currently scheduled.

Parameters
commandThe command to check
Exceptions
IllegalArgumentExceptionif the given command has already been composed or scheduled.

◆ requiring()

Command edu.wpi.first.wpilibj2.command.CommandScheduler.requiring ( Subsystem subsystem)

Returns the command currently requiring a given subsystem. Null if no command is currently requiring the subsystem

Parameters
subsystemthe subsystem to be inquired about
Returns
the command currently requiring the subsystem, or null if no command is currently scheduled

◆ run()

void edu.wpi.first.wpilibj2.command.CommandScheduler.run ( )

Runs a single iteration of the scheduler. The execution occurs in the following order:

Subsystem periodic methods are called.

Button bindings are polled, and new commands are scheduled from them.

Currently-scheduled commands are executed.

End conditions are checked on currently-scheduled commands, and commands that are finished have their end methods called and are removed.

Any subsystems not being used as requirements have their default methods started.

◆ schedule()

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

Schedules multiple commands for execution. Does nothing for commands already scheduled.

Parameters
commandsthe commands to schedule. No-op on null.

◆ setActiveButtonLoop()

void edu.wpi.first.wpilibj2.command.CommandScheduler.setActiveButtonLoop ( EventLoop loop)

Replace the button poll with another one.

Parameters
loopthe new button polling loop object.

◆ setDefaultCommand()

void edu.wpi.first.wpilibj2.command.CommandScheduler.setDefaultCommand ( Subsystem subsystem,
Command defaultCommand )

Sets the default command for a subsystem. Registers that subsystem if it is not already registered. Default commands will run whenever there is no other command currently scheduled that requires the subsystem. Default commands should be written to never end (i.e. their Command#isFinished() method should return false), as they would simply be re-scheduled if they do. Default commands must also require their subsystem.

Parameters
subsystemthe subsystem whose default command will be set
defaultCommandthe default command to associate with the subsystem

◆ setPeriod()

void edu.wpi.first.wpilibj2.command.CommandScheduler.setPeriod ( double period)

Changes the period of the loop overrun watchdog. This should be kept in sync with the TimedRobot period.

Parameters
periodPeriod in seconds.

◆ unregisterAllSubsystems()

void edu.wpi.first.wpilibj2.command.CommandScheduler.unregisterAllSubsystems ( )

Un-registers all registered Subsystems with the scheduler. All currently registered subsystems will no longer have their periodic block called, and will not have their default command scheduled.

◆ unregisterSubsystem()

void edu.wpi.first.wpilibj2.command.CommandScheduler.unregisterSubsystem ( Subsystem... subsystems)

Un-registers subsystems with the scheduler. The subsystem will no longer have its periodic block called, and will not have its default command scheduled.

Parameters
subsystemsthe subsystem to un-register

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