WPILibC++  unspecified
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 <llvm/StringRef.h>
13 #include <llvm/Twine.h>
14 
15 #include "ErrorBase.h"
16 #include "SmartDashboard/Sendable.h"
17 #include "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:
27  explicit Subsystem(const llvm::Twine& name);
28 
29  void SetDefaultCommand(Command* command);
32  void SetCurrentCommand(Command* command);
33  Command* GetCurrentCommand() const;
35  virtual void Periodic();
36  virtual void InitDefaultCommand();
37 
38  void AddChild(const llvm::Twine& name, std::shared_ptr<Sendable> child);
39  void AddChild(const llvm::Twine& name, Sendable* child);
40  void AddChild(const llvm::Twine& name, Sendable& child);
41  void AddChild(std::shared_ptr<Sendable> child);
42  void AddChild(Sendable* child);
43  void AddChild(Sendable& child);
44 
45  private:
46  void ConfirmCommand();
47 
48  Command* m_currentCommand = nullptr;
49  bool m_currentCommandChanged = true;
50  Command* m_defaultCommand = nullptr;
51  bool m_initializedDefaultCommand = false;
52 
53  public:
54  void InitSendable(SendableBuilder& builder) override;
55 };
56 
57 } // namespace frc
llvm::StringRef GetDefaultCommandName()
Returns the default command name, or empty string is there is none.
Definition: Subsystem.cpp:90
Definition: RobotController.cpp:14
virtual void Periodic()
When the run method of the scheduler is called this method will be called.
Definition: Subsystem.cpp:133
llvm::StringRef GetCurrentCommandName() const
Returns the current command name, or empty string if no current command.
Definition: Subsystem.cpp:121
void AddChild(const llvm::Twine &name, std::shared_ptr< Sendable > child)
Associate a Sendable with this Subsystem.
Definition: Subsystem.cpp:154
virtual void InitDefaultCommand()
Initialize the default command for this subsystem.
Definition: Subsystem.cpp:38
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
Definition: Subsystem.h:23
Command * GetDefaultCommand()
Returns the default command (or null if there is none).
Definition: Subsystem.cpp:77
void SetDefaultCommand(Command *command)
Sets the default command.
Definition: Subsystem.cpp:49
Subsystem(const llvm::Twine &name)
Creates a subsystem with the given name.
Definition: Subsystem.cpp:23
Command * GetCurrentCommand() const
Returns the command which currently claims this subsystem.
Definition: Subsystem.cpp:114
Base class for most objects.
Definition: ErrorBase.h:74
Definition: SendableBase.h:19
Definition: SendableBuilder.h:23
Definition: Sendable.h:18
The Command class is at the very core of the entire command framework.
Definition: Command.h:48
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
void SetCurrentCommand(Command *command)
Sets the current command.
Definition: Subsystem.cpp:104
Definition: Scheduler.h:27
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: Subsystem.cpp:206