WPILibC++  2020.3.2-60-g3011ebe
PIDSubsystem.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 <frc/controller/PIDController.h>
11 
12 #include "frc2/command/SubsystemBase.h"
13 
14 namespace frc2 {
21 class PIDSubsystem : public SubsystemBase {
22  public:
29  explicit PIDSubsystem(PIDController controller, double initialPosition = 0);
30 
31  void Periodic() override;
32 
38  void SetSetpoint(double setpoint);
39 
43  virtual void Enable();
44 
48  virtual void Disable();
49 
55  bool IsEnabled();
56 
63 
64  protected:
65  PIDController m_controller;
66  bool m_enabled{false};
67 
73  virtual double GetMeasurement() = 0;
74 
81  virtual void UseOutput(double output, double setpoint) = 0;
82 
83  private:
84  double m_setpoint{0};
85 };
86 } // namespace frc2
frc2::PIDSubsystem::PIDSubsystem
PIDSubsystem(PIDController controller, double initialPosition=0)
Creates a new PIDSubsystem.
frc2::PIDSubsystem
A subsystem that uses a PIDController to control an output.
Definition: PIDSubsystem.h:21
frc2::PIDSubsystem::Disable
virtual void Disable()
Disables the PID control.
frc2::PIDSubsystem::IsEnabled
bool IsEnabled()
Returns whether the controller is enabled.
frc2::PIDSubsystem::SetSetpoint
void SetSetpoint(double setpoint)
Sets the setpoint for the subsystem.
frc2::PIDSubsystem::GetMeasurement
virtual double GetMeasurement()=0
Returns the measurement of the process variable used by the PIDController.
frc2::PIDSubsystem::GetController
PIDController & GetController()
Returns the PIDController.
frc2::PIDSubsystem::UseOutput
virtual void UseOutput(double output, double setpoint)=0
Uses the output from the PIDController.
frc2::PIDController
Implements a PID control loop.
Definition: PIDController.h:23
frc2::PIDSubsystem::Periodic
void Periodic() override
This method is called periodically by the CommandScheduler.
frc2::PIDSubsystem::Enable
virtual void Enable()
Enables the PID control.
frc2::SubsystemBase
A base for subsystems that handles registration in the constructor, and provides a more intuitive met...
Definition: SubsystemBase.h:22