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 namespace pid_control 12 { 13 14 class ZoneInterface; 15 16 /* 17 * Base class for PID controllers. Each PID that implements this needs to 18 * provide an inputProc, setptProc, and outputProc. 19 */ 20 class PIDController : public Controller 21 { 22 public: 23 PIDController(const std::string& id, ZoneInterface* owner) : 24 Controller(), _owner(owner), _setpoint(0), _id(id) 25 {} 26 27 virtual ~PIDController() 28 {} 29 30 virtual double inputProc(void) override = 0; 31 virtual double setptProc(void) = 0; 32 virtual void outputProc(double value) override = 0; 33 34 void process(void) override; 35 36 std::string getID(void) override 37 { 38 return _id; 39 } 40 double getSetpoint(void) 41 { 42 return _setpoint; 43 } 44 void setSetpoint(double setpoint) 45 { 46 _setpoint = setpoint; 47 } 48 49 ec::pid_info_t* getPIDInfo(void) 50 { 51 return &_pid_info; 52 } 53 54 double getLastInput(void) 55 { 56 return lastInput; 57 } 58 59 protected: 60 ZoneInterface* _owner; 61 62 private: 63 // parameters 64 ec::pid_info_t _pid_info; 65 double _setpoint; 66 std::string _id; 67 double lastInput = std::numeric_limits<double>::quiet_NaN(); 68 }; 69 70 } // namespace pid_control 71