blob: fd41c094a1a36d57a203e8eb304cc9aa94ed5666 [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)
Patrick Venturea83a3ec2020-08-04 09:52:05 -070022 {}
James Feist22c257a2018-08-31 14:07:12 -070023
24 virtual ~PIDController()
Patrick Venturea83a3ec2020-08-04 09:52:05 -070025 {}
James Feist22c257a2018-08-31 14:07:12 -070026
Patrick Venture5f59c0f2018-11-11 12:55:14 -080027 virtual double inputProc(void) override = 0;
28 virtual double setptProc(void) = 0;
29 virtual void outputProc(double value) override = 0;
James Feist22c257a2018-08-31 14:07:12 -070030
Patrick Ventureee306482018-10-30 13:35:37 -070031 void process(void) override;
James Feist22c257a2018-08-31 14:07:12 -070032
Patrick Ventureee306482018-10-30 13:35:37 -070033 std::string getID(void) override
James Feist22c257a2018-08-31 14:07:12 -070034 {
35 return _id;
36 }
Patrick Venture5f59c0f2018-11-11 12:55:14 -080037 double getSetpoint(void)
James Feist22c257a2018-08-31 14:07:12 -070038 {
39 return _setpoint;
40 }
Patrick Venture5f59c0f2018-11-11 12:55:14 -080041 void setSetpoint(double setpoint)
James Feist22c257a2018-08-31 14:07:12 -070042 {
43 _setpoint = setpoint;
44 }
45
Patrick Venture563a3562018-10-30 09:31:26 -070046 ec::pid_info_t* getPIDInfo(void)
James Feist22c257a2018-08-31 14:07:12 -070047 {
48 return &_pid_info;
49 }
50
James Feist572c43d2019-01-31 15:52:22 -080051 double getLastInput(void)
52 {
53 return lastInput;
54 }
55
James Feist22c257a2018-08-31 14:07:12 -070056 protected:
57 ZoneInterface* _owner;
58
59 private:
60 // parameters
61 ec::pid_info_t _pid_info;
Patrick Venture5f59c0f2018-11-11 12:55:14 -080062 double _setpoint;
James Feist22c257a2018-08-31 14:07:12 -070063 std::string _id;
James Feist572c43d2019-01-31 15:52:22 -080064 double lastInput = std::numeric_limits<double>::quiet_NaN();
James Feist22c257a2018-08-31 14:07:12 -070065};