xref: /openbmc/phosphor-pid-control/pid/pidcontroller.hpp (revision a83a3ecc8c5be5f1b38253568ec8952f6fc9682f)
122c257abSJames Feist #pragma once
222c257abSJames Feist 
322c257abSJames Feist #include "controller.hpp"
422c257abSJames Feist #include "ec/pid.hpp"
522c257abSJames Feist #include "fan.hpp"
622c257abSJames Feist 
7e30916c9SAndrew Geissler #include <limits>
822c257abSJames Feist #include <memory>
922c257abSJames Feist #include <vector>
1022c257abSJames Feist 
1122c257abSJames Feist class ZoneInterface;
1222c257abSJames Feist 
1322c257abSJames Feist /*
1422c257abSJames Feist  * Base class for PID controllers.  Each PID that implements this needs to
15563a356fSPatrick Venture  * provide an inputProc, setptProc, and outputProc.
1622c257abSJames Feist  */
1722c257abSJames Feist class PIDController : public Controller
1822c257abSJames Feist {
1922c257abSJames Feist   public:
2022c257abSJames Feist     PIDController(const std::string& id, ZoneInterface* owner) :
2122c257abSJames Feist         Controller(), _owner(owner), _setpoint(0), _id(id)
22*a83a3eccSPatrick Venture     {}
2322c257abSJames Feist 
2422c257abSJames Feist     virtual ~PIDController()
25*a83a3eccSPatrick Venture     {}
2622c257abSJames Feist 
275f59c0fdSPatrick Venture     virtual double inputProc(void) override = 0;
285f59c0fdSPatrick Venture     virtual double setptProc(void) = 0;
295f59c0fdSPatrick Venture     virtual void outputProc(double value) override = 0;
3022c257abSJames Feist 
31ee30648eSPatrick Venture     void process(void) override;
3222c257abSJames Feist 
33ee30648eSPatrick Venture     std::string getID(void) override
3422c257abSJames Feist     {
3522c257abSJames Feist         return _id;
3622c257abSJames Feist     }
375f59c0fdSPatrick Venture     double getSetpoint(void)
3822c257abSJames Feist     {
3922c257abSJames Feist         return _setpoint;
4022c257abSJames Feist     }
415f59c0fdSPatrick Venture     void setSetpoint(double setpoint)
4222c257abSJames Feist     {
4322c257abSJames Feist         _setpoint = setpoint;
4422c257abSJames Feist     }
4522c257abSJames Feist 
46563a356fSPatrick Venture     ec::pid_info_t* getPIDInfo(void)
4722c257abSJames Feist     {
4822c257abSJames Feist         return &_pid_info;
4922c257abSJames Feist     }
5022c257abSJames Feist 
51572c43daSJames Feist     double getLastInput(void)
52572c43daSJames Feist     {
53572c43daSJames Feist         return lastInput;
54572c43daSJames Feist     }
55572c43daSJames Feist 
5622c257abSJames Feist   protected:
5722c257abSJames Feist     ZoneInterface* _owner;
5822c257abSJames Feist 
5922c257abSJames Feist   private:
6022c257abSJames Feist     // parameters
6122c257abSJames Feist     ec::pid_info_t _pid_info;
625f59c0fdSPatrick Venture     double _setpoint;
6322c257abSJames Feist     std::string _id;
64572c43daSJames Feist     double lastInput = std::numeric_limits<double>::quiet_NaN();
6522c257abSJames Feist };
66