WPILibC++  unspecified
Scheduler.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <memory>
11 #include <set>
12 #include <string>
13 #include <vector>
14 
15 #include <networktables/NetworkTableEntry.h>
16 #include <support/mutex.h>
17 
18 #include "Commands/Command.h"
19 #include "ErrorBase.h"
20 #include "SmartDashboard/SendableBase.h"
21 
22 namespace frc {
23 
24 class ButtonScheduler;
25 class Subsystem;
26 
27 class Scheduler : public ErrorBase, public SendableBase {
28  public:
29  static Scheduler* GetInstance();
30 
31  void AddCommand(Command* command);
32  void AddButton(ButtonScheduler* button);
33  void RegisterSubsystem(Subsystem* subsystem);
34  void Run();
35  void Remove(Command* command);
36  void RemoveAll();
37  void ResetAll();
38  void SetEnabled(bool enabled);
39 
40  void InitSendable(SendableBuilder& builder) override;
41 
42  private:
43  Scheduler();
44  ~Scheduler() override = default;
45 
46  void ProcessCommandAddition(Command* command);
47 
48  Command::SubsystemSet m_subsystems;
49  wpi::mutex m_buttonsMutex;
50  typedef std::vector<ButtonScheduler*> ButtonVector;
51  ButtonVector m_buttons;
52  typedef std::vector<Command*> CommandVector;
53  wpi::mutex m_additionsMutex;
54  CommandVector m_additions;
55  typedef std::set<Command*> CommandSet;
56  CommandSet m_commands;
57  bool m_adding = false;
58  bool m_enabled = true;
59  std::vector<std::string> commands;
60  std::vector<double> ids;
61  std::vector<double> toCancel;
62  nt::NetworkTableEntry m_namesEntry;
63  nt::NetworkTableEntry m_idsEntry;
64  nt::NetworkTableEntry m_cancelEntry;
65  bool m_runningCommandsChanged = false;
66 };
67 
68 } // namespace frc
void AddCommand(Command *command)
Add a command to be scheduled later.
Definition: Scheduler.cpp:46
void Run()
Runs a single iteration of the loop.
Definition: Scheduler.cpp:116
Definition: RobotController.cpp:14
void RegisterSubsystem(Subsystem *subsystem)
Registers a Subsystem to this Scheduler, so that the Scheduler might know if a default Command needs ...
Definition: Scheduler.cpp:178
Definition: Subsystem.h:23
Definition: ButtonScheduler.h:15
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: Scheduler.cpp:228
void ResetAll()
Completely resets the scheduler.
Definition: Scheduler.cpp:217
static Scheduler * GetInstance()
Returns the Scheduler, creating it if one does not exist.
Definition: Scheduler.cpp:31
Base class for most objects.
Definition: ErrorBase.h:74
void Remove(Command *command)
Removes the Command from the Scheduler.
Definition: Scheduler.cpp:191
Definition: SendableBase.h:19
Definition: SendableBuilder.h:23
NetworkTables Entry.
Definition: NetworkTableEntry.h:35
The Command class is at the very core of the entire command framework.
Definition: Command.h:48
Definition: Scheduler.h:27