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 11a076487aSPatrick Venture namespace pid_control 12a076487aSPatrick Venture { 13a076487aSPatrick Venture 1422c257abSJames Feist class ZoneInterface; 1522c257abSJames Feist 1622c257abSJames Feist /* 1722c257abSJames Feist * Base class for PID controllers. Each PID that implements this needs to 18563a356fSPatrick Venture * provide an inputProc, setptProc, and outputProc. 1922c257abSJames Feist */ 2022c257abSJames Feist class PIDController : public Controller 2122c257abSJames Feist { 2222c257abSJames Feist public: 2322c257abSJames Feist PIDController(const std::string& id, ZoneInterface* owner) : 24ccc8bb62SNirav Shah Controller(), _owner(owner), _id(id) 25*22579ca4SHarvey Wu { 26*22579ca4SHarvey Wu _pid_info.initialized = false; 27*22579ca4SHarvey Wu _pid_info.ts = static_cast<double>(0.0); 28*22579ca4SHarvey Wu _pid_info.integral = static_cast<double>(0.0); 29*22579ca4SHarvey Wu _pid_info.lastOutput = static_cast<double>(0.0); 30*22579ca4SHarvey Wu _pid_info.proportionalCoeff = static_cast<double>(0.0); 31*22579ca4SHarvey Wu _pid_info.integralCoeff = static_cast<double>(0.0); 32*22579ca4SHarvey Wu _pid_info.feedFwdOffset = static_cast<double>(0.0); 33*22579ca4SHarvey Wu _pid_info.feedFwdGain = static_cast<double>(0.0); 34*22579ca4SHarvey Wu _pid_info.integralLimit.min = static_cast<double>(0.0); 35*22579ca4SHarvey Wu _pid_info.integralLimit.max = static_cast<double>(0.0); 36*22579ca4SHarvey Wu _pid_info.outLim.min = static_cast<double>(0.0); 37*22579ca4SHarvey Wu _pid_info.outLim.max = static_cast<double>(0.0); 38*22579ca4SHarvey Wu _pid_info.slewNeg = static_cast<double>(0.0); 39*22579ca4SHarvey Wu _pid_info.slewPos = static_cast<double>(0.0); 40*22579ca4SHarvey Wu _pid_info.negativeHysteresis = static_cast<double>(0.0); 41*22579ca4SHarvey Wu _pid_info.positiveHysteresis = static_cast<double>(0.0); 42*22579ca4SHarvey Wu } 4322c257abSJames Feist 4422c257abSJames Feist virtual ~PIDController() 45a83a3eccSPatrick Venture {} 4622c257abSJames Feist 475f59c0fdSPatrick Venture virtual double inputProc(void) override = 0; 485f59c0fdSPatrick Venture virtual double setptProc(void) = 0; 495f59c0fdSPatrick Venture virtual void outputProc(double value) override = 0; 5022c257abSJames Feist 51ee30648eSPatrick Venture void process(void) override; 5222c257abSJames Feist 53ee30648eSPatrick Venture std::string getID(void) override 5422c257abSJames Feist { 5522c257abSJames Feist return _id; 5622c257abSJames Feist } 575f59c0fdSPatrick Venture double getSetpoint(void) 5822c257abSJames Feist { 5922c257abSJames Feist return _setpoint; 6022c257abSJames Feist } 615f59c0fdSPatrick Venture void setSetpoint(double setpoint) 6222c257abSJames Feist { 6322c257abSJames Feist _setpoint = setpoint; 6422c257abSJames Feist } 6522c257abSJames Feist 66563a356fSPatrick Venture ec::pid_info_t* getPIDInfo(void) 6722c257abSJames Feist { 6822c257abSJames Feist return &_pid_info; 6922c257abSJames Feist } 7022c257abSJames Feist 71572c43daSJames Feist double getLastInput(void) 72572c43daSJames Feist { 73572c43daSJames Feist return lastInput; 74572c43daSJames Feist } 75572c43daSJames Feist 7622c257abSJames Feist protected: 7722c257abSJames Feist ZoneInterface* _owner; 78ccc8bb62SNirav Shah std::string _id; 7922c257abSJames Feist 8022c257abSJames Feist private: 8122c257abSJames Feist // parameters 8222c257abSJames Feist ec::pid_info_t _pid_info; 83ccc8bb62SNirav Shah double _setpoint = 0; 84572c43daSJames Feist double lastInput = std::numeric_limits<double>::quiet_NaN(); 8522c257abSJames Feist }; 86a076487aSPatrick Venture 87a076487aSPatrick Venture } // namespace pid_control 88