blob: cb923776c9cee94c728634af1cb6b3e1b34c3bb3 [file] [log] [blame]
James Feist22c257a2018-08-31 14:07:12 -07001#pragma once
2
3#include "controller.hpp"
4#include "ec/pid.hpp"
5#include "fan.hpp"
6
Andrew Geisslere30916c2020-05-20 21:27:05 -05007#include <limits>
James Feist22c257a2018-08-31 14:07:12 -07008#include <memory>
9#include <vector>
10
Patrick Venturea0764872020-08-08 07:48:43 -070011namespace pid_control
12{
13
James Feist22c257a2018-08-31 14:07:12 -070014class ZoneInterface;
15
16/*
17 * Base class for PID controllers. Each PID that implements this needs to
Patrick Venture563a3562018-10-30 09:31:26 -070018 * provide an inputProc, setptProc, and outputProc.
James Feist22c257a2018-08-31 14:07:12 -070019 */
20class PIDController : public Controller
21{
22 public:
23 PIDController(const std::string& id, ZoneInterface* owner) :
24 Controller(), _owner(owner), _setpoint(0), _id(id)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070025 {}
James Feist22c257a2018-08-31 14:07:12 -070026
27 virtual ~PIDController()
Patrick Venturea83a3ec2020-08-04 09:52:05 -070028 {}
James Feist22c257a2018-08-31 14:07:12 -070029
Patrick Venture5f59c0f2018-11-11 12:55:14 -080030 virtual double inputProc(void) override = 0;
31 virtual double setptProc(void) = 0;
32 virtual void outputProc(double value) override = 0;
James Feist22c257a2018-08-31 14:07:12 -070033
Patrick Ventureee306482018-10-30 13:35:37 -070034 void process(void) override;
James Feist22c257a2018-08-31 14:07:12 -070035
Patrick Ventureee306482018-10-30 13:35:37 -070036 std::string getID(void) override
James Feist22c257a2018-08-31 14:07:12 -070037 {
38 return _id;
39 }
Patrick Venture5f59c0f2018-11-11 12:55:14 -080040 double getSetpoint(void)
James Feist22c257a2018-08-31 14:07:12 -070041 {
42 return _setpoint;
43 }
Patrick Venture5f59c0f2018-11-11 12:55:14 -080044 void setSetpoint(double setpoint)
James Feist22c257a2018-08-31 14:07:12 -070045 {
46 _setpoint = setpoint;
47 }
48
Patrick Venture563a3562018-10-30 09:31:26 -070049 ec::pid_info_t* getPIDInfo(void)
James Feist22c257a2018-08-31 14:07:12 -070050 {
51 return &_pid_info;
52 }
53
James Feist572c43d2019-01-31 15:52:22 -080054 double getLastInput(void)
55 {
56 return lastInput;
57 }
58
James Feist22c257a2018-08-31 14:07:12 -070059 protected:
60 ZoneInterface* _owner;
61
62 private:
63 // parameters
64 ec::pid_info_t _pid_info;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080065 double _setpoint;
James Feist22c257a2018-08-31 14:07:12 -070066 std::string _id;
James Feist572c43d2019-01-31 15:52:22 -080067 double lastInput = std::numeric_limits<double>::quiet_NaN();
James Feist22c257a2018-08-31 14:07:12 -070068};
Patrick Venturea0764872020-08-08 07:48:43 -070069
70} // namespace pid_control