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 <wpi/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:
34  static Scheduler* GetInstance();
35 
44  void AddCommand(Command* command);
45 
46  void AddButton(ButtonScheduler* button);
47 
56  void RegisterSubsystem(Subsystem* subsystem);
57 
72  void Run();
73 
79  void Remove(Command* command);
80 
81  void RemoveAll();
82 
86  void ResetAll();
87 
88  void SetEnabled(bool enabled);
89 
90  void InitSendable(SendableBuilder& builder) override;
91 
92  private:
93  Scheduler();
94  ~Scheduler() override = default;
95 
96  void ProcessCommandAddition(Command* command);
97 
98  Command::SubsystemSet m_subsystems;
99  wpi::mutex m_buttonsMutex;
100  typedef std::vector<ButtonScheduler*> ButtonVector;
101  ButtonVector m_buttons;
102  typedef std::vector<Command*> CommandVector;
103  wpi::mutex m_additionsMutex;
104  CommandVector m_additions;
105  typedef std::set<Command*> CommandSet;
106  CommandSet m_commands;
107  bool m_adding = false;
108  bool m_enabled = true;
109  std::vector<std::string> commands;
110  std::vector<double> ids;
111  std::vector<double> toCancel;
112  nt::NetworkTableEntry m_namesEntry;
113  nt::NetworkTableEntry m_idsEntry;
114  nt::NetworkTableEntry m_cancelEntry;
115  bool m_runningCommandsChanged = false;
116 };
117 
118 } // namespace frc
void AddCommand(Command *command)
Add a command to be scheduled later.
Definition: Scheduler.cpp:26
void Run()
Runs a single iteration of the loop.
Definition: Scheduler.cpp:47
Definition: Utility.cpp:119
void RegisterSubsystem(Subsystem *subsystem)
Registers a Subsystem to this Scheduler, so that the Scheduler might know if a default Command needs ...
Definition: Scheduler.cpp:39
Definition: Subsystem.h:23
Definition: ButtonScheduler.h:15
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: Scheduler.cpp:137
void ResetAll()
Completely resets the scheduler.
Definition: Scheduler.cpp:124
static Scheduler * GetInstance()
Returns the Scheduler, creating it if one does not exist.
Definition: Scheduler.cpp:21
Base class for most objects.
Definition: ErrorBase.h:74
void Remove(Command *command)
Removes the Command from the Scheduler.
Definition: Scheduler.cpp:101
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