WPILibC++  2020.3.2
Subsystem.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2019 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 <wpi/StringRef.h>
14 #include <wpi/Twine.h>
15 
16 #include "frc/ErrorBase.h"
17 #include "frc/smartdashboard/Sendable.h"
18 #include "frc/smartdashboard/SendableHelper.h"
19 
20 namespace frc {
21 
22 class Command;
23 
24 class Subsystem : public ErrorBase,
25  public Sendable,
26  public SendableHelper<Subsystem> {
27  friend class Scheduler;
28 
29  public:
35  explicit Subsystem(const wpi::Twine& name);
36 
37  Subsystem(Subsystem&&) = default;
38  Subsystem& operator=(Subsystem&&) = default;
39 
49  void SetDefaultCommand(Command* command);
50 
57 
64 
70  void SetCurrentCommand(Command* command);
71 
77  Command* GetCurrentCommand() const;
78 
85 
89  virtual void Periodic();
90 
101  virtual void InitDefaultCommand();
102 
108  std::string GetName() const;
109 
115  void SetName(const wpi::Twine& name);
116 
122  std::string GetSubsystem() const;
123 
129  void SetSubsystem(const wpi::Twine& subsystem);
130 
138  void AddChild(const wpi::Twine& name, std::shared_ptr<Sendable> child);
139 
147  void AddChild(const wpi::Twine& name, Sendable* child);
148 
156  void AddChild(const wpi::Twine& name, Sendable& child);
157 
163  void AddChild(std::shared_ptr<Sendable> child);
164 
170  void AddChild(Sendable* child);
171 
177  void AddChild(Sendable& child);
178 
179  private:
188  void ConfirmCommand();
189 
190  Command* m_currentCommand = nullptr;
191  bool m_currentCommandChanged = true;
192  Command* m_defaultCommand = nullptr;
193  bool m_initializedDefaultCommand = false;
194 
195  public:
196  void InitSendable(SendableBuilder& builder) override;
197 };
198 
199 } // namespace frc
frc::Subsystem::Periodic
virtual void Periodic()
When the run method of the scheduler is called this method will be called.
frc::Scheduler
Definition: Scheduler.h:22
frc::Subsystem::SetName
void SetName(const wpi::Twine &name)
Sets the name of this Subsystem.
frc::Subsystem::GetName
std::string GetName() const
Gets the name of this Subsystem.
frc::Subsystem::GetDefaultCommand
Command * GetDefaultCommand()
Returns the default command (or null if there is none).
frc::Command
The Command class is at the very core of the entire command framework.
Definition: Command.h:49
frc::Subsystem::GetSubsystem
std::string GetSubsystem() const
Gets the subsystem name of this Subsystem.
frc::Subsystem
Definition: Subsystem.h:24
frc::Subsystem::AddChild
void AddChild(const wpi::Twine &name, std::shared_ptr< Sendable > child)
Associate a Sendable with this Subsystem.
frc::Subsystem::SetSubsystem
void SetSubsystem(const wpi::Twine &subsystem)
Sets the subsystem name of this Subsystem.
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
wpi::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
frc::Subsystem::SetDefaultCommand
void SetDefaultCommand(Command *command)
Sets the default command.
frc::Subsystem::SetCurrentCommand
void SetCurrentCommand(Command *command)
Sets the current command.
frc::Subsystem::Subsystem
Subsystem(const wpi::Twine &name)
Creates a subsystem with the given name.
frc::Sendable
Interface for Sendable objects.
Definition: Sendable.h:17
frc::Subsystem::InitDefaultCommand
virtual void InitDefaultCommand()
Initialize the default command for this subsystem.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
frc::Subsystem::GetCurrentCommand
Command * GetCurrentCommand() const
Returns the command which currently claims this subsystem.
frc::Subsystem::InitSendable
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
wpi::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85
frc::SendableHelper
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
frc::SendableBuilder
Definition: SendableBuilder.h:23
frc::Subsystem::GetDefaultCommandName
wpi::StringRef GetDefaultCommandName()
Returns the default command name, or empty string is there is none.
frc::Subsystem::GetCurrentCommandName
wpi::StringRef GetCurrentCommandName() const
Returns the current command name, or empty string if no current command.