|
WPILibC++
2020.3.2
|
The scheduler responsible for running Commands. More...
#include <CommandScheduler.h>
Public Types | |
| using | Action = std::function< void(const Command &)> |
Public Member Functions | |
| CommandScheduler (const CommandScheduler &)=delete | |
| CommandScheduler & | operator= (const CommandScheduler &)=delete |
| void | AddButton (wpi::unique_function< void()> button) |
| Adds a button binding to the scheduler, which will be polled to schedule commands. More... | |
| void | ClearButtons () |
| Removes all button bindings from the scheduler. | |
| void | Schedule (bool interruptible, Command *command) |
| Schedules a command for execution. More... | |
| void | Schedule (Command *command) |
| Schedules a command for execution, with interruptible defaulted to true. More... | |
| void | Schedule (bool interruptible, wpi::ArrayRef< Command * > commands) |
| Schedules multiple commands for execution. More... | |
| void | Schedule (bool interruptible, std::initializer_list< Command * > commands) |
| Schedules multiple commands for execution. More... | |
| void | Schedule (wpi::ArrayRef< Command * > commands) |
| Schedules multiple commands for execution, with interruptible defaulted to true. More... | |
| void | Schedule (std::initializer_list< Command * > commands) |
| Schedules multiple commands for execution, with interruptible defaulted to true. 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 (wpi::ArrayRef< Subsystem * > subsystems) |
| void | UnregisterSubsystem (std::initializer_list< Subsystem * > subsystems) |
| void | UnregisterSubsystem (wpi::ArrayRef< Subsystem * > subsystems) |
| template<class T , typename = std::enable_if_t<std::is_base_of_v< Command, std::remove_reference_t<T>>>> | |
| void | SetDefaultCommand (Subsystem *subsystem, T &&defaultCommand) |
| Sets 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 a command. More... | |
| void | Cancel (wpi::ArrayRef< Command * > commands) |
| Cancels commands. More... | |
| void | Cancel (std::initializer_list< Command * > commands) |
| Cancels commands. More... | |
| void | CancelAll () |
| Cancels all commands that are currently scheduled. | |
| double | TimeSinceScheduled (const Command *command) const |
| Returns the time since a given command was scheduled. More... | |
| bool | IsScheduled (wpi::ArrayRef< const Command * > 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... | |
| Command * | Requiring (const Subsystem *subsystem) const |
| Returns the command currently requiring a given subsystem. More... | |
| void | Disable () |
| Disables the command scheduler. | |
| void | Enable () |
| Enables the command scheduler. | |
| 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 | InitSendable (frc::SendableBuilder &builder) override |
| Initializes this Sendable object. More... | |
Public Member Functions inherited from frc::ErrorBase | |
| ErrorBase (const ErrorBase &)=default | |
| ErrorBase & | operator= (const ErrorBase &)=default |
| ErrorBase (ErrorBase &&)=default | |
| ErrorBase & | operator= (ErrorBase &&)=default |
| virtual Error & | GetError () |
| Retrieve the current error. More... | |
| virtual const Error & | GetError () const |
| Retrieve the current error. More... | |
| virtual void | ClearError () const |
| Clear the current error information associated with this sensor. | |
| virtual void | SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
| Set error information associated with a C library call that set an error to the "errno" global variable. More... | |
| virtual void | SetImaqError (int success, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
| Set the current error information associated from the nivision Imaq API. More... | |
| virtual void | SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
| Set the current error information associated with this sensor. More... | |
| virtual void | SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
| Set the current error information associated with this sensor. More... | |
| virtual void | SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const |
| Set the current error information associated with this sensor. More... | |
| virtual void | CloneError (const ErrorBase &rhs) const |
| virtual bool | StatusIsFatal () const |
| Check if the current error code represents a fatal error. More... | |
| void | ClearGlobalErrors () |
| Clear global errors. | |
Public Member Functions inherited from frc::SendableHelper< CommandScheduler > | |
| SendableHelper (const SendableHelper &rhs)=default | |
| SendableHelper (SendableHelper &&rhs) | |
| SendableHelper & | operator= (const SendableHelper &rhs)=default |
| SendableHelper & | operator= (SendableHelper &&rhs) |
| std::string | GetName () const |
| Gets the name of this Sendable object. More... | |
| void | SetName (const wpi::Twine &name) |
| Sets the name of this Sendable object. More... | |
| void | SetName (const wpi::Twine &subsystem, const wpi::Twine &name) |
| Sets both the subsystem name and device name of this Sendable object. More... | |
| std::string | GetSubsystem () const |
| Gets the subsystem name of this Sendable object. More... | |
| void | SetSubsystem (const wpi::Twine &subsystem) |
| Sets the subsystem name of this Sendable object. More... | |
Static Public Member Functions | |
| static CommandScheduler & | GetInstance () |
| Returns the Scheduler instance. More... | |
Static Public Member Functions inherited from frc::ErrorBase | |
| static void | SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) |
| static void | SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) |
| static Error | GetGlobalError () |
| Retrieve the last global error. | |
| static std::vector< Error > | GetGlobalErrors () |
| Retrieve all global errors. | |
Friends | |
| class | CommandTestBase |
Additional Inherited Members | |
Protected Member Functions inherited from frc::SendableHelper< CommandScheduler > | |
| void | SetName (const wpi::Twine &moduleType, int channel) |
| Sets the name of the sensor with a channel number. More... | |
| void | SetName (const wpi::Twine &moduleType, int moduleNumber, int channel) |
| Sets the name of the sensor with a module and channel number. More... | |
| void | AddChild (std::shared_ptr< Sendable > child) |
| Add a child component. More... | |
| void | AddChild (void *child) |
| Add a child component. More... | |
Protected Attributes inherited from frc::ErrorBase | |
| Error | m_error |
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.
| void frc2::CommandScheduler::AddButton | ( | wpi::unique_function< void()> | button | ) |
Adds a button binding to the scheduler, which will be polled to schedule commands.
| button | The button to add |
| void frc2::CommandScheduler::Cancel | ( | Command * | command | ) |
Cancels a command.
The scheduler will only call the interrupted method of a canceled command, not the end method (though the interrupted method may itself call the end method). 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 the interrupted method of a canceled command, not the end method (though the interrupted method may itself call the end method). Commands will be canceled even if they are not scheduled as interruptible.
| commands | the commands to cancel |
| void frc2::CommandScheduler::Cancel | ( | wpi::ArrayRef< Command * > | commands | ) |
Cancels commands.
The scheduler will only call the interrupted method of a canceled command, not the end method (though the interrupted method may itself call the end method). Commands will be canceled even if they are not scheduled as interruptible.
| commands | the commands to cancel |
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.
| commands | 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 | ( | wpi::ArrayRef< 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 |
| 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 |
| 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 |
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 | ( | bool | interruptible, |
| 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.
| interruptible | whether this command can be interrupted |
| command | the command to schedule |
| void frc2::CommandScheduler::Schedule | ( | bool | interruptible, |
| std::initializer_list< Command * > | commands | ||
| ) |
Schedules multiple commands 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.
| interruptible | whether the commands should be interruptible |
| commands | the commands to schedule |
| void frc2::CommandScheduler::Schedule | ( | bool | interruptible, |
| wpi::ArrayRef< Command * > | commands | ||
| ) |
Schedules multiple commands 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.
| interruptible | whether the commands should be interruptible |
| commands | the commands to schedule |
| void frc2::CommandScheduler::Schedule | ( | Command * | command | ) |
Schedules a command for execution, with interruptible defaulted to true.
Does nothing if the command is already scheduled.
| command | the command to schedule |
| void frc2::CommandScheduler::Schedule | ( | std::initializer_list< Command * > | commands | ) |
Schedules multiple commands for execution, with interruptible defaulted to true.
Does nothing if the command is already scheduled.
| commands | the commands to schedule |
| void frc2::CommandScheduler::Schedule | ( | wpi::ArrayRef< Command * > | commands | ) |
Schedules multiple commands for execution, with interruptible defaulted to true.
Does nothing if the command is already scheduled.
| commands | the commands to schedule |
|
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 |
| double frc2::CommandScheduler::TimeSinceScheduled | ( | const Command * | command | ) | const |
Returns the time since a given command was scheduled.
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 |
| 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 |