WPILibC++  2020.3.2-60-g3011ebe
Subsystem.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 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 <type_traits>
11 #include <utility>
12 
13 #include "frc2/command/CommandScheduler.h"
14 
15 namespace frc2 {
16 class Command;
39 class Subsystem {
40  public:
41  ~Subsystem();
49  virtual void Periodic();
50 
60  template <class T, typename = std::enable_if_t<std::is_base_of_v<
61  Command, std::remove_reference_t<T>>>>
62  void SetDefaultCommand(T&& defaultCommand) {
64  this, std::forward<T>(defaultCommand));
65  }
66 
73  Command* GetDefaultCommand() const;
74 
81  Command* GetCurrentCommand() const;
82 
87  void Register();
88 };
89 } // namespace frc2
frc2::Subsystem::Periodic
virtual void Periodic()
This method is called periodically by the CommandScheduler.
frc2::CommandScheduler::GetInstance
static CommandScheduler & GetInstance()
Returns the Scheduler instance.
frc2::Command
A state machine representing a complete action to be performed by the robot.
Definition: Command.h:52
frc2::Subsystem::Register
void Register()
Registers this subsystem with the CommandScheduler, allowing its Periodic() method to be called when ...
frc2::Subsystem::GetDefaultCommand
Command * GetDefaultCommand() const
Gets the default command for this subsystem.
frc2::Subsystem::GetCurrentCommand
Command * GetCurrentCommand() const
Returns the command currently running on this subsystem.
frc2::Subsystem
A robot subsystem.
Definition: Subsystem.h:39
frc2::Subsystem::SetDefaultCommand
void SetDefaultCommand(T &&defaultCommand)
Sets the default Command of the subsystem.
Definition: Subsystem.h:62
frc2::CommandScheduler::SetDefaultCommand
void SetDefaultCommand(Subsystem *subsystem, T &&defaultCommand)
Sets the default command for a subsystem.
Definition: CommandScheduler.h:186