WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
Scheduler.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2011-2017. 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 <set>
14 #include <string>
15 #include <vector>
16 
17 #include "Commands/Command.h"
18 #include "ErrorBase.h"
19 #include "HAL/cpp/priority_mutex.h"
20 #include "SmartDashboard/NamedSendable.h"
21 #include "SmartDashboard/SmartDashboard.h"
22 #include "networktables/NetworkTable.h"
23 
24 namespace frc {
25 
26 class ButtonScheduler;
27 class Subsystem;
28 
29 class Scheduler : public ErrorBase, public NamedSendable {
30  public:
31  static Scheduler* GetInstance();
32 
33  void AddCommand(Command* command);
34  void AddButton(ButtonScheduler* button);
35  void RegisterSubsystem(Subsystem* subsystem);
36  void Run();
37  void Remove(Command* command);
38  void RemoveAll();
39  void ResetAll();
40  void SetEnabled(bool enabled);
41 
42  void UpdateTable();
43  std::string GetSmartDashboardType() const;
44  void InitTable(std::shared_ptr<ITable> subTable);
45  std::shared_ptr<ITable> GetTable() const;
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  hal::priority_mutex m_buttonsLock;
57  typedef std::vector<ButtonScheduler*> ButtonVector;
58  ButtonVector m_buttons;
59  typedef std::vector<Command*> CommandVector;
60  hal::priority_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  std::shared_ptr<ITable> m_table;
70  bool m_runningCommandsChanged = false;
71 };
72 
73 } // namespace frc
void AddCommand(Command *command)
Add a command to be scheduled later.
Definition: Scheduler.cpp:43
void Run()
Runs a single iteration of the loop.
Definition: Scheduler.cpp:113
std::string GetName() const
Definition: Scheduler.cpp:264
void RegisterSubsystem(Subsystem *subsystem)
Registers a Subsystem to this Scheduler, so that the Scheduler might know if a default Command needs ...
Definition: Scheduler.cpp:170
Definition: Subsystem.h:20
Definition: ButtonScheduler.h:15
void InitTable(std::shared_ptr< ITable > subTable)
Initializes a table for this sendable object.
Definition: Scheduler.cpp:270
std::shared_ptr< ITable > GetTable() const
Definition: Scheduler.cpp:278
void ResetAll()
Completely resets the scheduler.
Definition: Scheduler.cpp:209
static Scheduler * GetInstance()
Returns the Scheduler, creating it if one does not exist.
Definition: Scheduler.cpp:28
Base class for most objects.
Definition: ErrorBase.h:72
void Remove(Command *command)
Removes the Command from the Scheduler.
Definition: Scheduler.cpp:183
void UpdateTable()
Update the network tables associated with the Scheduler object on the SmartDashboard.
Definition: Scheduler.cpp:222
Definition: priority_mutex.h:57
std::string GetSmartDashboardType() const
Definition: Scheduler.cpp:268
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:29