WPILibC++  unspecified
Subsystem.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 <memory>
11 #include <string>
12 
13 #include "ErrorBase.h"
14 #include "SmartDashboard/NamedSendable.h"
15 #include "networktables/NetworkTableEntry.h"
16 
17 namespace frc {
18 
19 class Command;
20 
21 class Subsystem : public ErrorBase, public NamedSendable {
22  friend class Scheduler;
23 
24  public:
25  explicit Subsystem(const std::string& name);
26  virtual ~Subsystem() = default;
27 
28  void SetDefaultCommand(Command* command);
30  void SetCurrentCommand(Command* command);
31  Command* GetCurrentCommand() const;
32  virtual void Periodic();
33  virtual void InitDefaultCommand();
34 
35  private:
36  void ConfirmCommand();
37 
38  Command* m_currentCommand = nullptr;
39  bool m_currentCommandChanged = true;
40  Command* m_defaultCommand = nullptr;
41  std::string m_name;
42  bool m_initializedDefaultCommand = false;
43 
44  public:
45  std::string GetName() const override;
46  void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
47  std::string GetSmartDashboardType() const override;
48 
49  protected:
50  nt::NetworkTableEntry m_hasDefaultEntry;
51  nt::NetworkTableEntry m_defaultEntry;
52  nt::NetworkTableEntry m_hasCommandEntry;
53  nt::NetworkTableEntry m_commandEntry;
54 };
55 
56 } // namespace frc
Definition: Timer.cpp:18
virtual void Periodic()
When the run method of the scheduler is called this method will be called.
Definition: Subsystem.cpp:110
virtual void InitDefaultCommand()
Initialize the default command for this subsystem.
Definition: Subsystem.cpp:35
Definition: Subsystem.h:21
Command * GetDefaultCommand()
Returns the default command (or null if there is none).
Definition: Subsystem.cpp:82
void SetDefaultCommand(Command *command)
Sets the default command.
Definition: Subsystem.cpp:46
Command * GetCurrentCommand() const
Returns the command which currently claims this subsystem.
Definition: Subsystem.cpp:105
std::string GetName() const override
Definition: Subsystem.cpp:134
std::string GetSmartDashboardType() const override
Definition: Subsystem.cpp:136
void InitTable(std::shared_ptr< nt::NetworkTable > subtable) override
Initializes a table for this sendable object.
Definition: Subsystem.cpp:138
Base class for most objects.
Definition: ErrorBase.h:74
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
The Command class is at the very core of the entire command framework.
Definition: Command.h:52
Subsystem(const std::string &name)
Creates a subsystem with the given name.
Definition: Subsystem.cpp:21
The interface for sendable objects that gives the sendable a default name in the Smart Dashboard...
Definition: NamedSendable.h:21
void SetCurrentCommand(Command *command)
Sets the current command.
Definition: Subsystem.cpp:95
Definition: Scheduler.h:30