WPILibC++  2019.1.1-beta-2-31-g26e8e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Subsystem.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 
12 #include <wpi/StringRef.h>
13 #include <wpi/Twine.h>
14 
15 #include "frc/ErrorBase.h"
16 #include "frc/smartdashboard/Sendable.h"
17 #include "frc/smartdashboard/SendableBase.h"
18 
19 namespace frc {
20 
21 class Command;
22 
23 class Subsystem : public ErrorBase, public SendableBase {
24  friend class Scheduler;
25 
26  public:
32  explicit Subsystem(const wpi::Twine& name);
33 
34  Subsystem(Subsystem&&) = default;
35  Subsystem& operator=(Subsystem&&) = default;
36 
46  void SetDefaultCommand(Command* command);
47 
54 
61 
67  void SetCurrentCommand(Command* command);
68 
74  Command* GetCurrentCommand() const;
75 
82 
86  virtual void Periodic();
87 
98  virtual void InitDefaultCommand();
99 
107  void AddChild(const wpi::Twine& name, std::shared_ptr<Sendable> child);
108 
116  void AddChild(const wpi::Twine& name, Sendable* child);
117 
125  void AddChild(const wpi::Twine& name, Sendable& child);
126 
132  void AddChild(std::shared_ptr<Sendable> child);
133 
139  void AddChild(Sendable* child);
140 
146  void AddChild(Sendable& child);
147 
148  private:
157  void ConfirmCommand();
158 
159  Command* m_currentCommand = nullptr;
160  bool m_currentCommandChanged = true;
161  Command* m_defaultCommand = nullptr;
162  bool m_initializedDefaultCommand = false;
163 
164  public:
165  void InitSendable(SendableBuilder& builder) override;
166 };
167 
168 } // namespace frc
void SetDefaultCommand(Command *command)
Sets the default command.
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
void SetCurrentCommand(Command *command)
Sets the current command.
Subsystem(const wpi::Twine &name)
Creates a subsystem with the given name.
virtual void InitDefaultCommand()
Initialize the default command for this subsystem.
wpi::StringRef GetCurrentCommandName() const
Returns the current command name, or empty string if no current command.
Definition: Subsystem.h:23
Command * GetCurrentCommand() const
Returns the command which currently claims this subsystem.
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
virtual void Periodic()
When the run method of the scheduler is called this method will be called.
wpi::StringRef GetDefaultCommandName()
Returns the default command name, or empty string is there is none.
Base class for most objects.
Definition: ErrorBase.h:74
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Definition: SendableBase.h:19
Command * GetDefaultCommand()
Returns the default command (or null if there is none).
Definition: SendableBuilder.h:23
Definition: Sendable.h:18
void AddChild(const wpi::Twine &name, std::shared_ptr< Sendable > child)
Associate a Sendable with this Subsystem.
The Command class is at the very core of the entire command framework.
Definition: Command.h:48
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
Definition: Scheduler.h:21