xref: /openbmc/phosphor-pid-control/pid/pidcontroller.hpp (revision ee30648efa42d25979894082b5e300fdb192f3a2)
122c257abSJames Feist #pragma once
222c257abSJames Feist 
322c257abSJames Feist #include "controller.hpp"
422c257abSJames Feist #include "ec/pid.hpp"
522c257abSJames Feist #include "fan.hpp"
622c257abSJames Feist 
722c257abSJames Feist #include <memory>
822c257abSJames Feist #include <vector>
922c257abSJames Feist 
1022c257abSJames Feist class ZoneInterface;
1122c257abSJames Feist 
1222c257abSJames Feist /*
1322c257abSJames Feist  * Base class for PID controllers.  Each PID that implements this needs to
14563a356fSPatrick Venture  * provide an inputProc, setptProc, and outputProc.
1522c257abSJames Feist  */
1622c257abSJames Feist class PIDController : public Controller
1722c257abSJames Feist {
1822c257abSJames Feist   public:
1922c257abSJames Feist     PIDController(const std::string& id, ZoneInterface* owner) :
2022c257abSJames Feist         Controller(), _owner(owner), _setpoint(0), _id(id)
2122c257abSJames Feist     {
2222c257abSJames Feist     }
2322c257abSJames Feist 
2422c257abSJames Feist     virtual ~PIDController()
2522c257abSJames Feist     {
2622c257abSJames Feist     }
2722c257abSJames Feist 
28*ee30648eSPatrick Venture     virtual float inputProc(void) override = 0;
29563a356fSPatrick Venture     virtual float setptProc(void) = 0;
30*ee30648eSPatrick Venture     virtual void outputProc(float value) override = 0;
3122c257abSJames Feist 
32*ee30648eSPatrick Venture     void process(void) override;
3322c257abSJames Feist 
34*ee30648eSPatrick Venture     std::string getID(void) override
3522c257abSJames Feist     {
3622c257abSJames Feist         return _id;
3722c257abSJames Feist     }
38563a356fSPatrick Venture     float getSetpoint(void)
3922c257abSJames Feist     {
4022c257abSJames Feist         return _setpoint;
4122c257abSJames Feist     }
42563a356fSPatrick Venture     void setSetpoint(float setpoint)
4322c257abSJames Feist     {
4422c257abSJames Feist         _setpoint = setpoint;
4522c257abSJames Feist     }
4622c257abSJames Feist 
47563a356fSPatrick Venture     ec::pid_info_t* getPIDInfo(void)
4822c257abSJames Feist     {
4922c257abSJames Feist         return &_pid_info;
5022c257abSJames Feist     }
5122c257abSJames Feist 
5222c257abSJames Feist   protected:
5322c257abSJames Feist     ZoneInterface* _owner;
5422c257abSJames Feist 
5522c257abSJames Feist   private:
5622c257abSJames Feist     // parameters
5722c257abSJames Feist     ec::pid_info_t _pid_info;
5822c257abSJames Feist     float _setpoint;
5922c257abSJames Feist     std::string _id;
6022c257abSJames Feist };
61