1 #pragma once
2 
3 #include "controller.hpp"
4 #include "ec/pid.hpp"
5 #include "fan.hpp"
6 
7 #include <memory>
8 #include <vector>
9 
10 class ZoneInterface;
11 
12 /*
13  * Base class for PID controllers.  Each PID that implements this needs to
14  * provide an inputProc, setptProc, and outputProc.
15  */
16 class PIDController : public Controller
17 {
18   public:
19     PIDController(const std::string& id, ZoneInterface* owner) :
20         Controller(), _owner(owner), _setpoint(0), _id(id)
21     {
22     }
23 
24     virtual ~PIDController()
25     {
26     }
27 
28     virtual double inputProc(void) override = 0;
29     virtual double setptProc(void) = 0;
30     virtual void outputProc(double value) override = 0;
31 
32     void process(void) override;
33 
34     std::string getID(void) override
35     {
36         return _id;
37     }
38     double getSetpoint(void)
39     {
40         return _setpoint;
41     }
42     void setSetpoint(double setpoint)
43     {
44         _setpoint = setpoint;
45     }
46 
47     ec::pid_info_t* getPIDInfo(void)
48     {
49         return &_pid_info;
50     }
51 
52     double getLastInput(void)
53     {
54         return lastInput;
55     }
56 
57   protected:
58     ZoneInterface* _owner;
59 
60   private:
61     // parameters
62     ec::pid_info_t _pid_info;
63     double _setpoint;
64     std::string _id;
65     double lastInput = std::numeric_limits<double>::quiet_NaN();
66 };
67