WPILibC++  2019.1.1-beta-4-1-g6e8f8be
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 <wpi/Twine.h>
13 
14 #include "frc/PIDController.h"
15 #include "frc/PIDOutput.h"
16 #include "frc/PIDSource.h"
17 #include "frc/commands/Command.h"
18 
19 namespace frc {
20 
21 class PIDCommand : public Command, public PIDOutput, public PIDSource {
22  public:
23  PIDCommand(const wpi::Twine& name, double p, double i, double d);
24  PIDCommand(const wpi::Twine& name, double p, double i, double d,
25  double period);
26  PIDCommand(const wpi::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  PIDCommand(const wpi::Twine& name, double p, double i, double d,
32  Subsystem& subsystem);
33  PIDCommand(const wpi::Twine& name, double p, double i, double d,
34  double period, Subsystem& subsystem);
35  PIDCommand(const wpi::Twine& name, double p, double i, double d, double f,
36  double period, Subsystem& subsystem);
37  PIDCommand(double p, double i, double d, Subsystem& subsystem);
38  PIDCommand(double p, double i, double d, double period, Subsystem& subsystem);
39  PIDCommand(double p, double i, double d, double f, double period,
40  Subsystem& subsystem);
41  virtual ~PIDCommand() = default;
42 
43  PIDCommand(PIDCommand&&) = default;
44  PIDCommand& operator=(PIDCommand&&) = default;
45 
46  void SetSetpointRelative(double deltaSetpoint);
47 
48  // PIDOutput interface
49  void PIDWrite(double output) override;
50 
51  // PIDSource interface
52  double PIDGet() override;
53 
54  protected:
55  std::shared_ptr<PIDController> GetPIDController() const;
56  void _Initialize() override;
57  void _Interrupted() override;
58  void _End() override;
59  void SetSetpoint(double setpoint);
60  double GetSetpoint() const;
61  double GetPosition();
62 
63  virtual double ReturnPIDInput() = 0;
64  virtual void UsePIDOutput(double output) = 0;
65 
66  private:
67  // The internal PIDController
68  std::shared_ptr<PIDController> m_controller;
69 
70  public:
71  void InitSendable(SendableBuilder& builder) override;
72 };
73 
74 } // namespace frc
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:20
Definition: Subsystem.h:23
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: SendableBuilder.h:23
The Command class is at the very core of the entire command framework.
Definition: Command.h:48
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79