10 #include <initializer_list>
14 #include <frc/ErrorBase.h>
15 #include <frc/WPIErrors.h>
16 #include <frc/smartdashboard/Sendable.h>
17 #include <frc/smartdashboard/SendableHelper.h>
18 #include <wpi/ArrayRef.h>
47 using Action = std::function<void(
const Command&)>;
104 void Schedule(
bool interruptible, std::initializer_list<Command*> commands);
120 void Schedule(std::initializer_list<Command*> commands);
176 template <
class T,
typename = std::enable_if_t<std::is_base_of_v<
177 Command, std::remove_reference_t<T>>>>
179 if (!defaultCommand.HasRequirement(subsystem)) {
180 wpi_setWPIErrorWithContext(
181 CommandIllegalUse,
"Default commands must require their subsystem!");
184 if (defaultCommand.IsFinished()) {
185 wpi_setWPIErrorWithContext(CommandIllegalUse,
186 "Default commands should not end!");
189 SetDefaultCommandImpl(subsystem,
190 std::make_unique<std::remove_reference_t<T>>(
191 std::forward<T>(defaultCommand)));
231 void Cancel(std::initializer_list<Command*> commands);
267 bool IsScheduled(std::initializer_list<const Command*> commands)
const;
334 void SetDefaultCommandImpl(
Subsystem* subsystem,
335 std::unique_ptr<Command> command);
338 std::unique_ptr<Impl> m_impl;
340 friend class CommandTestBase;
void Run()
Runs a single iteration of the scheduler.
void CancelAll()
Cancels all commands that are currently scheduled.
Definition: FunctionExtras.h:43
void UnregisterSubsystem(Subsystem *subsystem)
Un-registers subsystems with the scheduler.
void Cancel(Command *command)
Cancels a command.
Command * Requiring(const Subsystem *subsystem) const
Returns the command currently requiring a given subsystem.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
void OnCommandFinish(Action action)
Adds an action to perform on the finishing of any command by the scheduler.
double TimeSinceScheduled(const Command *command) const
Returns the time since a given command was scheduled.
void Enable()
Enables the command scheduler.
static CommandScheduler & GetInstance()
Returns the Scheduler instance.
void OnCommandExecute(Action action)
Adds an action to perform on the execution of any command by the scheduler.
bool IsScheduled(wpi::ArrayRef< const Command * > commands) const
Whether the given commands are running.
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:52
void ClearButtons()
Removes all button bindings from the scheduler.
The scheduler responsible for running Commands.
Definition: CommandScheduler.h:32
void OnCommandInitialize(Action action)
Adds an action to perform on the initialization of any command by the scheduler.
Base class for most objects.
Definition: ErrorBase.h:104
void Disable()
Disables the command scheduler.
void InitSendable(frc::SendableBuilder &builder) override
Initializes this Sendable object.
void AddButton(wpi::unique_function< void()> button)
Adds a button binding to the scheduler, which will be polled to schedule commands.
Interface for Sendable objects.
Definition: Sendable.h:17
void Schedule(bool interruptible, Command *command)
Schedules a command for execution.
A robot subsystem.
Definition: Subsystem.h:39
void SetDefaultCommand(Subsystem *subsystem, T &&defaultCommand)
Sets the default command for a subsystem.
Definition: CommandScheduler.h:178
void RegisterSubsystem(Subsystem *subsystem)
Registers subsystems with the scheduler.
Command * GetDefaultCommand(const Subsystem *subsystem) const
Gets the default command associated with this subsystem.
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
Definition: SendableBuilder.h:23
void OnCommandInterrupt(Action action)
Adds an action to perform on the interruption of any command by the scheduler.