WPILibC++  2021.3.1
Subsystem.h
1 // Copyright (c) FIRST and other WPILib contributors.
2 // Open Source Software; you can modify and/or share it under the terms of
3 // the WPILib BSD license file in the root directory of this project.
4 
5 #pragma once
6 
7 #include <type_traits>
8 #include <utility>
9 
10 #include "frc2/command/CommandScheduler.h"
11 
12 namespace frc2 {
13 class Command;
36 class Subsystem {
37  public:
38  ~Subsystem();
46  virtual void Periodic();
47 
54  virtual void SimulationPeriodic();
55 
65  template <class T, typename = std::enable_if_t<std::is_base_of_v<
66  Command, std::remove_reference_t<T>>>>
67  void SetDefaultCommand(T&& defaultCommand) {
69  this, std::forward<T>(defaultCommand));
70  }
71 
79 
87 
92  void Register();
93 };
94 } // 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:49
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:36
frc2::Subsystem::SetDefaultCommand
void SetDefaultCommand(T &&defaultCommand)
Sets the default Command of the subsystem.
Definition: Subsystem.h:67
frc2::Subsystem::SimulationPeriodic
virtual void SimulationPeriodic()
This method is called periodically by the CommandScheduler.
frc2::CommandScheduler::SetDefaultCommand
void SetDefaultCommand(Subsystem *subsystem, T &&defaultCommand)
Sets the default command for a subsystem.
Definition: CommandScheduler.h:183