WPILibC++  unspecified
PIDCommand.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2017 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 "Commands/Command.h"
14 #include "PIDController.h"
15 #include "PIDOutput.h"
16 #include "PIDSource.h"
17 
18 namespace frc {
19 
20 class PIDCommand : public Command, public PIDOutput, public PIDSource {
21  public:
22  PIDCommand(const std::string& name, double p, double i, double d);
23  PIDCommand(const std::string& name, double p, double i, double d,
24  double period);
25  PIDCommand(const std::string& name, double p, double i, double d, double f,
26  double period);
27  PIDCommand(double p, double i, double d);
28  PIDCommand(double p, double i, double d, double period);
29  PIDCommand(double p, double i, double d, double f, double period);
30  virtual ~PIDCommand() = default;
31 
32  void SetSetpointRelative(double deltaSetpoint);
33 
34  // PIDOutput interface
35  void PIDWrite(double output) override;
36 
37  // PIDSource interface
38  double PIDGet() override;
39 
40  protected:
41  std::shared_ptr<PIDController> GetPIDController() const;
42  void _Initialize() override;
43  void _Interrupted() override;
44  void _End() override;
45  void SetSetpoint(double setpoint);
46  double GetSetpoint() const;
47  double GetPosition();
48 
49  virtual double ReturnPIDInput() = 0;
50  virtual void UsePIDOutput(double output) = 0;
51 
52  private:
54  std::shared_ptr<PIDController> m_controller;
55 
56  public:
57  void InitTable(std::shared_ptr<nt::NetworkTable> subtable) override;
58  std::string GetSmartDashboardType() const override;
59 };
60 
61 } // namespace frc
Definition: Timer.cpp:18
void InitTable(std::shared_ptr< nt::NetworkTable > subtable) override
Initializes a table for this sendable object.
Definition: PIDCommand.cpp:70
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:19
Definition: PIDCommand.h:20
PIDOutput interface is a generic output for the PID class.
Definition: PIDOutput.h:20
std::string GetSmartDashboardType() const override
Definition: PIDCommand.cpp:68
The Command class is at the very core of the entire command framework.
Definition: Command.h:52