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) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | virtual ~PIDController() |
| 26 | { |
| 27 | } |
| 28 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 29 | virtual double inputProc(void) override = 0; |
| 30 | virtual double setptProc(void) = 0; |
| 31 | virtual void outputProc(double value) override = 0; |
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 | void process(void) override; |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 34 | |
Patrick Venture | ee30648 | 2018-10-30 13:35:37 -0700 | [diff] [blame] | 35 | std::string getID(void) override |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 36 | { |
| 37 | return _id; |
| 38 | } |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 39 | double getSetpoint(void) |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 40 | { |
| 41 | return _setpoint; |
| 42 | } |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 43 | void setSetpoint(double setpoint) |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 44 | { |
| 45 | _setpoint = setpoint; |
| 46 | } |
| 47 | |
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 48 | ec::pid_info_t* getPIDInfo(void) |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 49 | { |
| 50 | return &_pid_info; |
| 51 | } |
| 52 | |
James Feist | 572c43d | 2019-01-31 15:52:22 -0800 | [diff] [blame] | 53 | double getLastInput(void) |
| 54 | { |
| 55 | return lastInput; |
| 56 | } |
| 57 | |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 58 | protected: |
| 59 | ZoneInterface* _owner; |
| 60 | |
| 61 | private: |
| 62 | // parameters |
| 63 | ec::pid_info_t _pid_info; |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 64 | double _setpoint; |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 65 | std::string _id; |
James Feist | 572c43d | 2019-01-31 15:52:22 -0800 | [diff] [blame] | 66 | double lastInput = std::numeric_limits<double>::quiet_NaN(); |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 67 | }; |