blob: 0b491e7cfe78306e342b034148d61c93cdca848c [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
Andrew Geisslere30916c2020-05-20 21:27:05 -05007#include <limits>
James Feist22c257a2018-08-31 14:07:12 -07008#include <memory>
9#include <vector>
10
11class ZoneInterface;
12
13/*
14 * Base class for PID controllers. Each PID that implements this needs to
Patrick Venture563a3562018-10-30 09:31:26 -070015 * provide an inputProc, setptProc, and outputProc.
James Feist22c257a2018-08-31 14:07:12 -070016 */
17class 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 Venture5f59c0f2018-11-11 12:55:14 -080029 virtual double inputProc(void) override = 0;
30 virtual double setptProc(void) = 0;
31 virtual void outputProc(double value) override = 0;
James Feist22c257a2018-08-31 14:07:12 -070032
Patrick Ventureee306482018-10-30 13:35:37 -070033 void process(void) override;
James Feist22c257a2018-08-31 14:07:12 -070034
Patrick Ventureee306482018-10-30 13:35:37 -070035 std::string getID(void) override
James Feist22c257a2018-08-31 14:07:12 -070036 {
37 return _id;
38 }
Patrick Venture5f59c0f2018-11-11 12:55:14 -080039 double getSetpoint(void)
James Feist22c257a2018-08-31 14:07:12 -070040 {
41 return _setpoint;
42 }
Patrick Venture5f59c0f2018-11-11 12:55:14 -080043 void setSetpoint(double setpoint)
James Feist22c257a2018-08-31 14:07:12 -070044 {
45 _setpoint = setpoint;
46 }
47
Patrick Venture563a3562018-10-30 09:31:26 -070048 ec::pid_info_t* getPIDInfo(void)
James Feist22c257a2018-08-31 14:07:12 -070049 {
50 return &_pid_info;
51 }
52
James Feist572c43d2019-01-31 15:52:22 -080053 double getLastInput(void)
54 {
55 return lastInput;
56 }
57
James Feist22c257a2018-08-31 14:07:12 -070058 protected:
59 ZoneInterface* _owner;
60
61 private:
62 // parameters
63 ec::pid_info_t _pid_info;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080064 double _setpoint;
James Feist22c257a2018-08-31 14:07:12 -070065 std::string _id;
James Feist572c43d2019-01-31 15:52:22 -080066 double lastInput = std::numeric_limits<double>::quiet_NaN();
James Feist22c257a2018-08-31 14:07:12 -070067};