WPILibC++  unspecified
Scheduler.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2017 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 <list>
11 #include <map>
12 #include <memory>
13 #include <mutex>
14 #include <set>
15 #include <string>
16 #include <vector>
17 
18 #include "Commands/Command.h"
19 #include "ErrorBase.h"
20 #include "SmartDashboard/NamedSendable.h"
21 #include "SmartDashboard/SmartDashboard.h"
22 #include "networktables/NetworkTable.h"
23 #include "networktables/NetworkTableEntry.h"
24 
25 namespace frc {
26 
27 class ButtonScheduler;
28 class Subsystem;
29 
30 class Scheduler : public ErrorBase, public NamedSendable {
31  public:
32  static Scheduler* GetInstance();
33 
34  void AddCommand(Command* command);
35  void AddButton(ButtonScheduler* button);
36  void RegisterSubsystem(Subsystem* subsystem);
37  void Run();
38  void Remove(Command* command);
39  void RemoveAll();
40  void ResetAll();
41  void SetEnabled(bool enabled);
42 
43  void UpdateTable();
44  std::string GetSmartDashboardType() const;
45  void InitTable(std::shared_ptr<nt::NetworkTable> subTable);
46  std::string GetName() const;
47  std::string GetType() const;
48 
49  private:
50  Scheduler();
51  virtual ~Scheduler() = default;
52 
53  void ProcessCommandAddition(Command* command);
54 
55  Command::SubsystemSet m_subsystems;
56  std::mutex m_buttonsLock;
57  typedef std::vector<ButtonScheduler*> ButtonVector;
58  ButtonVector m_buttons;
59  typedef std::vector<Command*> CommandVector;
60  std::mutex m_additionsLock;
61  CommandVector m_additions;
62  typedef std::set<Command*> CommandSet;
63  CommandSet m_commands;
64  bool m_adding = false;
65  bool m_enabled = true;
66  std::vector<std::string> commands;
67  std::vector<double> ids;
68  std::vector<double> toCancel;
69  nt::NetworkTableEntry m_namesEntry;
70  nt::NetworkTableEntry m_idsEntry;
71  nt::NetworkTableEntry m_cancelEntry;
72  bool m_runningCommandsChanged = false;
73 };
74 
75 } // namespace frc
void AddCommand(Command *command)
Add a command to be scheduled later.
Definition: Scheduler.cpp:42
void Run()
Runs a single iteration of the loop.
Definition: Scheduler.cpp:112
Definition: Timer.cpp:18
std::string GetName() const
Definition: Scheduler.cpp:272
void RegisterSubsystem(Subsystem *subsystem)
Registers a Subsystem to this Scheduler, so that the Scheduler might know if a default Command needs ...
Definition: Scheduler.cpp:176
Definition: Subsystem.h:21
Definition: ButtonScheduler.h:15
void InitTable(std::shared_ptr< nt::NetworkTable > subTable)
Initializes a table for this sendable object.
Definition: Scheduler.cpp:278
void ResetAll()
Completely resets the scheduler.
Definition: Scheduler.cpp:215
static Scheduler * GetInstance()
Returns the Scheduler, creating it if one does not exist.
Definition: Scheduler.cpp:27
Base class for most objects.
Definition: ErrorBase.h:74
void Remove(Command *command)
Removes the Command from the Scheduler.
Definition: Scheduler.cpp:189
void UpdateTable()
Update the network tables associated with the Scheduler object on the SmartDashboard.
Definition: Scheduler.cpp:230
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
std::string GetSmartDashboardType() const
Definition: Scheduler.cpp:276
The Command class is at the very core of the entire command framework.
Definition: Command.h:52
The interface for sendable objects that gives the sendable a default name in the Smart Dashboard...
Definition: NamedSendable.h:21
Definition: Scheduler.h:30