blob: 3d38c2a8f6fab348fb34efe26a646cd16cd7d420 [file] [log] [blame]
James Feist22c257a2018-08-31 14:07:12 -07001#pragma once
2
3#include "controller.hpp"
4#include "ec/pid.hpp"
5#include "fan.hpp"
6
7#include <memory>
8#include <vector>
9
10class ZoneInterface;
11
12/*
13 * Base class for PID controllers. Each PID that implements this needs to
Patrick Venture563a3562018-10-30 09:31:26 -070014 * provide an inputProc, setptProc, and outputProc.
James Feist22c257a2018-08-31 14:07:12 -070015 */
16class PIDController : public Controller
17{
18 public:
19 PIDController(const std::string& id, ZoneInterface* owner) :
20 Controller(), _owner(owner), _setpoint(0), _id(id)
21 {
22 }
23
24 virtual ~PIDController()
25 {
26 }
27
Patrick Venture5f59c0f2018-11-11 12:55:14 -080028 virtual double inputProc(void) override = 0;
29 virtual double setptProc(void) = 0;
30 virtual void outputProc(double value) override = 0;
James Feist22c257a2018-08-31 14:07:12 -070031
Patrick Ventureee306482018-10-30 13:35:37 -070032 void process(void) override;
James Feist22c257a2018-08-31 14:07:12 -070033
Patrick Ventureee306482018-10-30 13:35:37 -070034 std::string getID(void) override
James Feist22c257a2018-08-31 14:07:12 -070035 {
36 return _id;
37 }
Patrick Venture5f59c0f2018-11-11 12:55:14 -080038 double getSetpoint(void)
James Feist22c257a2018-08-31 14:07:12 -070039 {
40 return _setpoint;
41 }
Patrick Venture5f59c0f2018-11-11 12:55:14 -080042 void setSetpoint(double setpoint)
James Feist22c257a2018-08-31 14:07:12 -070043 {
44 _setpoint = setpoint;
45 }
46
Patrick Venture563a3562018-10-30 09:31:26 -070047 ec::pid_info_t* getPIDInfo(void)
James Feist22c257a2018-08-31 14:07:12 -070048 {
49 return &_pid_info;
50 }
51
James Feist572c43d2019-01-31 15:52:22 -080052 double getLastInput(void)
53 {
54 return lastInput;
55 }
56
James Feist22c257a2018-08-31 14:07:12 -070057 protected:
58 ZoneInterface* _owner;
59
60 private:
61 // parameters
62 ec::pid_info_t _pid_info;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080063 double _setpoint;
James Feist22c257a2018-08-31 14:07:12 -070064 std::string _id;
James Feist572c43d2019-01-31 15:52:22 -080065 double lastInput = std::numeric_limits<double>::quiet_NaN();
James Feist22c257a2018-08-31 14:07:12 -070066};