James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "controller.hpp" |
| 4 | #include "ec/pid.hpp" |
| 5 | #include "fan.hpp" |
| 6 | |
Andrew Geissler | e30916c | 2020-05-20 21:27:05 -0500 | [diff] [blame] | 7 | #include <limits> |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 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 |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 15 | * provide an inputProc, setptProc, and outputProc. |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 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) |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 22 | {} |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 23 | |
| 24 | virtual ~PIDController() |
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 25 | {} |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 26 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 27 | virtual double inputProc(void) override = 0; |
| 28 | virtual double setptProc(void) = 0; |
| 29 | virtual void outputProc(double value) override = 0; |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 30 | |
Patrick Venture | ee30648 | 2018-10-30 13:35:37 -0700 | [diff] [blame] | 31 | void process(void) override; |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 32 | |
Patrick Venture | ee30648 | 2018-10-30 13:35:37 -0700 | [diff] [blame] | 33 | std::string getID(void) override |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 34 | { |
| 35 | return _id; |
| 36 | } |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 37 | double getSetpoint(void) |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 38 | { |
| 39 | return _setpoint; |
| 40 | } |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 41 | void setSetpoint(double setpoint) |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 42 | { |
| 43 | _setpoint = setpoint; |
| 44 | } |
| 45 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 46 | ec::pid_info_t* getPIDInfo(void) |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 47 | { |
| 48 | return &_pid_info; |
| 49 | } |
| 50 | |
James Feist | 572c43d | 2019-01-31 15:52:22 -0800 | [diff] [blame] | 51 | double getLastInput(void) |
| 52 | { |
| 53 | return lastInput; |
| 54 | } |
| 55 | |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 56 | protected: |
| 57 | ZoneInterface* _owner; |
| 58 | |
| 59 | private: |
| 60 | // parameters |
| 61 | ec::pid_info_t _pid_info; |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 62 | double _setpoint; |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 63 | std::string _id; |
James Feist | 572c43d | 2019-01-31 15:52:22 -0800 | [diff] [blame] | 64 | double lastInput = std::numeric_limits<double>::quiet_NaN(); |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 65 | }; |