WPILibC++ 2023.4.3-108-ge5452e3
|
The scheduler responsible for running Commands. More...
#include <frc2/command/CommandScheduler.h>
Public Types | |
using | Action = std::function< void(const Command &)> |
Public Member Functions | |
~CommandScheduler () override | |
CommandScheduler (const CommandScheduler &)=delete | |
CommandScheduler & | operator= (const CommandScheduler &)=delete |
void | SetPeriod (units::second_t period) |
Changes the period of the loop overrun watchdog. More... | |
frc::EventLoop * | GetActiveButtonLoop () const |
Get the active button poll. More... | |
void | SetActiveButtonLoop (frc::EventLoop *loop) |
Replace the button poll with another one. More... | |
frc::EventLoop * | GetDefaultButtonLoop () const |
Get the default button poll. More... | |
void | Schedule (const CommandPtr &command) |
Schedules a command for execution. More... | |
void | Schedule (Command *command) |
Schedules a command for execution. More... | |
void | Schedule (std::span< Command *const > commands) |
Schedules multiple commands for execution. More... | |
void | Schedule (std::initializer_list< Command * > commands) |
Schedules multiple commands for execution. More... | |
void | Run () |
Runs a single iteration of the scheduler. More... | |
void | RegisterSubsystem (Subsystem *subsystem) |
Registers subsystems with the scheduler. More... | |
void | UnregisterSubsystem (Subsystem *subsystem) |
Un-registers subsystems with the scheduler. More... | |
void | RegisterSubsystem (std::initializer_list< Subsystem * > subsystems) |
void | RegisterSubsystem (std::span< Subsystem *const > subsystems) |
void | UnregisterSubsystem (std::initializer_list< Subsystem * > subsystems) |
void | UnregisterSubsystem (std::span< Subsystem *const > subsystems) |
template<std::derived_from< Command > T> | |
void | SetDefaultCommand (Subsystem *subsystem, T &&defaultCommand) |
Sets the default command for a subsystem. More... | |
void | SetDefaultCommand (Subsystem *subsystem, CommandPtr &&defaultCommand) |
Sets the default command for a subsystem. More... | |
void | RemoveDefaultCommand (Subsystem *subsystem) |
Removes the default command for a subsystem. More... | |
Command * | GetDefaultCommand (const Subsystem *subsystem) const |
Gets the default command associated with this subsystem. More... | |
void | Cancel (Command *command) |
Cancels commands. More... | |
void | Cancel (const CommandPtr &command) |
Cancels commands. More... | |
void | Cancel (std::span< Command *const > commands) |
Cancels commands. More... | |
void | Cancel (std::initializer_list< Command * > commands) |
Cancels commands. More... | |
void | CancelAll () |
Cancels all commands that are currently scheduled. More... | |
bool | IsScheduled (std::span< const Command *const > commands) const |
Whether the given commands are running. More... | |
bool | IsScheduled (std::initializer_list< const Command * > commands) const |
Whether the given commands are running. More... | |
bool | IsScheduled (const Command *command) const |
Whether a given command is running. More... | |
bool | IsScheduled (const CommandPtr &command) const |
Whether a given command is running. More... | |
Command * | Requiring (const Subsystem *subsystem) const |
Returns the command currently requiring a given subsystem. More... | |
void | Disable () |
Disables the command scheduler. More... | |
void | Enable () |
Enables the command scheduler. More... | |
void | OnCommandInitialize (Action action) |
Adds an action to perform on the initialization of any command by the scheduler. More... | |
void | OnCommandExecute (Action action) |
Adds an action to perform on the execution of any command by the scheduler. More... | |
void | OnCommandInterrupt (Action action) |
Adds an action to perform on the interruption of any command by the scheduler. More... | |
void | OnCommandFinish (Action action) |
Adds an action to perform on the finishing of any command by the scheduler. More... | |
void | RequireUngrouped (const Command *command) |
Requires that the specified command hasn't been already added to a composition. More... | |
void | RequireUngrouped (std::span< const std::unique_ptr< Command > > commands) |
Requires that the specified commands not have been already added to a composition. More... | |
void | RequireUngrouped (std::initializer_list< const Command * > commands) |
Requires that the specified commands not have been already added to a composition. More... | |
void | InitSendable (nt::NTSendableBuilder &builder) override |
Initializes this Sendable object. More... | |
Public Member Functions inherited from nt::NTSendable | |
virtual void | InitSendable (NTSendableBuilder &builder)=0 |
Initializes this Sendable object. More... | |
void | InitSendable (wpi::SendableBuilder &builder) override |
Initializes this Sendable object. More... | |
Public Member Functions inherited from wpi::Sendable | |
virtual | ~Sendable ()=default |
virtual void | InitSendable (SendableBuilder &builder)=0 |
Initializes this Sendable object. More... | |
Public Member Functions inherited from wpi::SendableHelper< CommandScheduler > | |
SendableHelper (const SendableHelper &rhs)=default | |
SendableHelper (SendableHelper &&rhs) | |
SendableHelper & | operator= (const SendableHelper &rhs)=default |
SendableHelper & | operator= (SendableHelper &&rhs) |
Static Public Member Functions | |
static CommandScheduler & | GetInstance () |
Returns the Scheduler instance. More... | |
Friends | |
class | CommandTestBase |
template<typename T > | |
class | CommandTestBaseWithParam |
Additional Inherited Members | |
Protected Member Functions inherited from wpi::SendableHelper< CommandScheduler > | |
SendableHelper ()=default | |
~SendableHelper () | |
The scheduler responsible for running Commands.
A Command-based robot should call 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 RegisterSubsystem() in order for their Periodic() methods to be called and for their default commands to be scheduled.
This class is provided by the NewCommands VendorDep
using frc2::CommandScheduler::Action = std::function<void(const Command&)> |
|
override |
|
delete |
void frc2::CommandScheduler::Cancel | ( | Command * | command | ) |
Cancels commands.
The scheduler will only call Command::End() method of the canceled command with true, indicating they were canceled (as opposed to finishing normally).
Commands will be canceled even if they are not scheduled as interruptible.
command | the command to cancel |
void frc2::CommandScheduler::Cancel | ( | const CommandPtr & | command | ) |
Cancels commands.
The scheduler will only call Command::End() method of the canceled command with true, indicating they were canceled (as opposed to finishing normally).
Commands will be canceled even if they are not scheduled as interruptible.
command | the command to cancel |
void frc2::CommandScheduler::Cancel | ( | std::initializer_list< Command * > | commands | ) |
Cancels commands.
The scheduler will only call Command::End() method of the canceled command with true, indicating they were canceled (as opposed to finishing normally).
Commands will be canceled even if they are not scheduled as interruptible.
commands | the commands to cancel |
void frc2::CommandScheduler::Cancel | ( | std::span< Command *const > | commands | ) |
Cancels commands.
The scheduler will only call Command::End() method of the canceled command with true, indicating they were canceled (as opposed to finishing normally).
Commands will be canceled even if they are not scheduled as interruptible.
commands | the commands to cancel |
void frc2::CommandScheduler::CancelAll | ( | ) |
Cancels all commands that are currently scheduled.
void frc2::CommandScheduler::Disable | ( | ) |
Disables the command scheduler.
void frc2::CommandScheduler::Enable | ( | ) |
Enables the command scheduler.
frc::EventLoop * frc2::CommandScheduler::GetActiveButtonLoop | ( | ) | const |
Get the active button poll.
frc::EventLoop
object polling buttons. frc::EventLoop * frc2::CommandScheduler::GetDefaultButtonLoop | ( | ) | const |
Get the default button poll.
frc::EventLoop
object polling buttons. Gets the default command associated with this subsystem.
Null if this subsystem has no default command associated with it.
subsystem | the subsystem to inquire about |
|
static |
Returns the Scheduler instance.
|
overridevirtual |
bool frc2::CommandScheduler::IsScheduled | ( | const Command * | command | ) | const |
Whether a given command is running.
Note that this only works on commands that are directly scheduled by the scheduler; it will not work on commands inside of CommandGroups, as the scheduler does not see them.
command | the command to query |
bool frc2::CommandScheduler::IsScheduled | ( | const CommandPtr & | command | ) | const |
Whether a given command is running.
Note that this only works on commands that are directly scheduled by the scheduler; it will not work on commands inside of CommandGroups, as the scheduler does not see them.
command | the command to query |
bool frc2::CommandScheduler::IsScheduled | ( | std::initializer_list< const Command * > | commands | ) | const |
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 of CommandGroups, as the scheduler does not see them.
commands | the command to query |
bool frc2::CommandScheduler::IsScheduled | ( | std::span< const Command *const > | commands | ) | const |
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 of CommandGroups, as the scheduler does not see them.
commands | the command to query |
void frc2::CommandScheduler::OnCommandExecute | ( | Action | action | ) |
Adds an action to perform on the execution of any command by the scheduler.
action | the action to perform |
void frc2::CommandScheduler::OnCommandFinish | ( | Action | action | ) |
Adds an action to perform on the finishing of any command by the scheduler.
action | the action to perform |
void frc2::CommandScheduler::OnCommandInitialize | ( | Action | action | ) |
Adds an action to perform on the initialization of any command by the scheduler.
action | the action to perform |
void frc2::CommandScheduler::OnCommandInterrupt | ( | Action | action | ) |
Adds an action to perform on the interruption of any command by the scheduler.
action | the action to perform |
|
delete |
void frc2::CommandScheduler::RegisterSubsystem | ( | std::initializer_list< Subsystem * > | subsystems | ) |
void frc2::CommandScheduler::RegisterSubsystem | ( | std::span< Subsystem *const > | subsystems | ) |
void frc2::CommandScheduler::RegisterSubsystem | ( | Subsystem * | subsystem | ) |
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.
subsystem | the subsystem to register |
void frc2::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.
subsystem | the subsystem whose default command will be removed |
void frc2::CommandScheduler::RequireUngrouped | ( | const Command * | command | ) |
Requires that the specified command hasn't been already added to a composition.
command | The command to check |
if | the given commands have already been composed. |
void frc2::CommandScheduler::RequireUngrouped | ( | std::initializer_list< const Command * > | commands | ) |
Requires that the specified commands not have been already added to a composition.
commands | The commands to check |
IllegalArgumentException | if the given commands have already been composed. |
void frc2::CommandScheduler::RequireUngrouped | ( | std::span< const std::unique_ptr< Command > > | commands | ) |
Requires that the specified commands not have been already added to a composition.
commands | The commands to check |
if | the given commands have already been composed. |
Returns the command currently requiring a given subsystem.
Null if no command is currently requiring the subsystem
subsystem | the subsystem to be inquired about |
void frc2::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.
void frc2::CommandScheduler::Schedule | ( | Command * | command | ) |
Schedules a command for execution.
Does nothing if the command is already scheduled. If a command's requirements are not available, it will only be started if all the commands currently using those requirements have been scheduled as interruptible. If this is the case, they will be interrupted and the command will be scheduled.
command | the command to schedule |
void frc2::CommandScheduler::Schedule | ( | const CommandPtr & | command | ) |
Schedules a command for execution.
Does nothing if the command is already scheduled. If a command's requirements are not available, it will only be started if all the commands currently using those requirements are interruptible. If this is the case, they will be interrupted and the command will be scheduled.
command | the command to schedule |
void frc2::CommandScheduler::Schedule | ( | std::initializer_list< Command * > | commands | ) |
Schedules multiple commands for execution.
Does nothing for commands already scheduled.
commands | the commands to schedule |
void frc2::CommandScheduler::Schedule | ( | std::span< Command *const > | commands | ) |
Schedules multiple commands for execution.
Does nothing for commands already scheduled.
commands | the commands to schedule |
void frc2::CommandScheduler::SetActiveButtonLoop | ( | frc::EventLoop * | loop | ) |
Replace the button poll with another one.
loop | the new button polling loop object. |
void frc2::CommandScheduler::SetDefaultCommand | ( | Subsystem * | subsystem, |
CommandPtr && | 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 IsFinished() method should return false), as they would simply be re-scheduled if they do. Default commands must also require their subsystem.
subsystem | the subsystem whose default command will be set |
defaultCommand | the default command to associate with the subsystem |
|
inline |
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 IsFinished() method should return false), as they would simply be re-scheduled if they do. Default commands must also require their subsystem.
subsystem | the subsystem whose default command will be set |
defaultCommand | the default command to associate with the subsystem |
void frc2::CommandScheduler::SetPeriod | ( | units::second_t | period | ) |
Changes the period of the loop overrun watchdog.
This should be kept in sync with the TimedRobot period.
void frc2::CommandScheduler::UnregisterSubsystem | ( | std::initializer_list< Subsystem * > | subsystems | ) |
void frc2::CommandScheduler::UnregisterSubsystem | ( | std::span< Subsystem *const > | subsystems | ) |
void frc2::CommandScheduler::UnregisterSubsystem | ( | Subsystem * | subsystem | ) |
Un-registers subsystems with the scheduler.
The subsystem will no longer have its periodic block called, and will not have its default command scheduled.
subsystem | the subsystem to un-register |
|
friend |
|
friend |