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 | |||||
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 11 | namespace pid_control |
12 | { | ||||
13 | |||||
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 14 | class ZoneInterface; |
15 | |||||
16 | /* | ||||
17 | * Base class for PID controllers. Each PID that implements this needs to | ||||
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 18 | * provide an inputProc, setptProc, and outputProc. |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 19 | */ |
20 | class PIDController : public Controller | ||||
21 | { | ||||
22 | public: | ||||
23 | PIDController(const std::string& id, ZoneInterface* owner) : | ||||
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 24 | Controller(), _owner(owner), _id(id) |
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 | |
27 | virtual ~PIDController() | ||||
Patrick Venture | a83a3ec | 2020-08-04 09:52:05 -0700 | [diff] [blame] | 28 | {} |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 29 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 30 | virtual double inputProc(void) override = 0; |
31 | virtual double setptProc(void) = 0; | ||||
32 | virtual void outputProc(double value) override = 0; | ||||
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 33 | |
Patrick Venture | ee30648 | 2018-10-30 13:35:37 -0700 | [diff] [blame] | 34 | void process(void) override; |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 35 | |
Patrick Venture | ee30648 | 2018-10-30 13:35:37 -0700 | [diff] [blame] | 36 | std::string getID(void) override |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 37 | { |
38 | return _id; | ||||
39 | } | ||||
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 40 | double getSetpoint(void) |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 41 | { |
42 | return _setpoint; | ||||
43 | } | ||||
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 44 | void setSetpoint(double setpoint) |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 45 | { |
46 | _setpoint = setpoint; | ||||
47 | } | ||||
48 | |||||
Patrick Venture | 563a356 | 2018-10-30 09:31:26 -0700 | [diff] [blame] | 49 | ec::pid_info_t* getPIDInfo(void) |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 50 | { |
51 | return &_pid_info; | ||||
52 | } | ||||
53 | |||||
James Feist | 572c43d | 2019-01-31 15:52:22 -0800 | [diff] [blame] | 54 | double getLastInput(void) |
55 | { | ||||
56 | return lastInput; | ||||
57 | } | ||||
58 | |||||
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 59 | protected: |
60 | ZoneInterface* _owner; | ||||
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 61 | std::string _id; |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 62 | |
63 | private: | ||||
64 | // parameters | ||||
65 | ec::pid_info_t _pid_info; | ||||
Nirav Shah | ccc8bb6 | 2022-02-17 21:06:51 -0800 | [diff] [blame] | 66 | double _setpoint = 0; |
James Feist | 572c43d | 2019-01-31 15:52:22 -0800 | [diff] [blame] | 67 | double lastInput = std::numeric_limits<double>::quiet_NaN(); |
James Feist | 22c257a | 2018-08-31 14:07:12 -0700 | [diff] [blame] | 68 | }; |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 69 | |
70 | } // namespace pid_control |