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