Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 3 | #include "ec/pid.hpp" |
| 4 | #include "fan.hpp" |
| 5 | |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 6 | #include <memory> |
| 7 | #include <vector> |
| 8 | |
Patrick Venture | a58197c | 2018-06-11 15:29:45 -0700 | [diff] [blame] | 9 | class ZoneInterface; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 10 | |
| 11 | /* |
| 12 | * Base class for PID controllers. Each PID that implements this needs to |
| 13 | * provide an input_proc, setpt_proc, and output_proc. |
| 14 | */ |
| 15 | class PIDController |
| 16 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 17 | public: |
| 18 | PIDController(const std::string& id, ZoneInterface* owner) : |
| 19 | _owner(owner), _setpoint(0), _id(id) |
| 20 | { |
| 21 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 22 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 23 | virtual ~PIDController() |
| 24 | { |
| 25 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 26 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 27 | virtual float input_proc(void) = 0; |
| 28 | virtual float setpt_proc(void) = 0; |
| 29 | virtual void output_proc(float value) = 0; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 30 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 31 | void pid_process(void); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 32 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 33 | std::string get_id(void) |
| 34 | { |
| 35 | return _id; |
| 36 | } |
| 37 | float get_setpoint(void) |
| 38 | { |
| 39 | return _setpoint; |
| 40 | } |
| 41 | void set_setpoint(float setpoint) |
| 42 | { |
| 43 | _setpoint = setpoint; |
| 44 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 45 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 46 | ec::pid_info_t* get_pid_info(void) |
| 47 | { |
| 48 | return &_pid_info; |
| 49 | } |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 50 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 51 | protected: |
| 52 | ZoneInterface* _owner; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 53 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 54 | private: |
| 55 | // parameters |
| 56 | ec::pid_info_t _pid_info; |
| 57 | float _setpoint; |
| 58 | std::string _id; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 59 | }; |