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