WPILibC++  unspecified
PIDCommand.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/Twine.h>
13 
14 #include "Commands/Command.h"
15 #include "PIDController.h"
16 #include "PIDOutput.h"
17 #include "PIDSource.h"
18 
19 namespace frc {
20 
21 class PIDCommand : public Command, public PIDOutput, public PIDSource {
22  public:
23  PIDCommand(const llvm::Twine& name, double p, double i, double d);
24  PIDCommand(const llvm::Twine& name, double p, double i, double d,
25  double period);
26  PIDCommand(const llvm::Twine& name, double p, double i, double d, double f,
27  double period);
28  PIDCommand(double p, double i, double d);
29  PIDCommand(double p, double i, double d, double period);
30  PIDCommand(double p, double i, double d, double f, double period);
31  virtual ~PIDCommand() = default;
32 
33  void SetSetpointRelative(double deltaSetpoint);
34 
35  // PIDOutput interface
36  void PIDWrite(double output) override;
37 
38  // PIDSource interface
39  double PIDGet() override;
40 
41  protected:
42  std::shared_ptr<PIDController> GetPIDController() const;
43  void _Initialize() override;
44  void _Interrupted() override;
45  void _End() override;
46  void SetSetpoint(double setpoint);
47  double GetSetpoint() const;
48  double GetPosition();
49 
50  virtual double ReturnPIDInput() = 0;
51  virtual void UsePIDOutput(double output) = 0;
52 
53  private:
54  // The internal PIDController
55  std::shared_ptr<PIDController> m_controller;
56 
57  public:
58  void InitSendable(SendableBuilder& builder) override;
59 };
60 
61 } // namespace frc
Definition: RobotController.cpp:14
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:20
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
Definition: PIDCommand.h:21
PIDOutput interface is a generic output for the PID class.
Definition: PIDOutput.h:20
void InitSendable(SendableBuilder &builder) override
Initializes this Sendable object.
Definition: PIDCommand.cpp:70
Definition: SendableBuilder.h:23
The Command class is at the very core of the entire command framework.
Definition: Command.h:48