1 #pragma once 2 3 #include <cstdint> 4 #include <string> 5 6 namespace pid_control 7 { 8 namespace ec 9 { 10 11 typedef struct 12 { 13 double min = 0.0; 14 double max = 0.0; 15 } limits_t; 16 17 /* Note: If you update these structs you need to update the copy code in 18 * pid/util.cpp and the initialization code in pid/buildjson.hpp files. 19 */ 20 typedef struct 21 { 22 bool initialized = false; // has pid been initialized 23 bool checkHysterWithSetpt = false; // compare current input and setpoint to 24 // check hysteresis 25 26 double ts = 0.0; // sample time in seconds 27 double integral = 0.0; // integral of error 28 double lastOutput = 0.0; // value of last output 29 double lastError = 0.0; // value of last error 30 31 double proportionalCoeff = 0.0; // coeff for P 32 double integralCoeff = 0.0; // coeff for I 33 double derivativeCoeff = 0.0; // coeff for D 34 double feedFwdOffset = 0.0; // offset coeff for feed-forward term 35 double feedFwdGain = 0.0; // gain for feed-forward term 36 37 limits_t integralLimit; // clamp of integral 38 limits_t outLim; // clamp of output 39 double slewNeg = 0.0; 40 double slewPos = 0.0; 41 double positiveHysteresis = 0.0; 42 double negativeHysteresis = 0.0; 43 } pid_info_t; 44 45 double pid(pid_info_t* pidinfoptr, double input, double setpoint, 46 const std::string* nameptr = nullptr); 47 48 /* Condensed version for use by the configuration. */ 49 struct pidinfo 50 { 51 bool checkHysterWithSetpt = 0.0; // compare current input and setpoint to 52 // check hysteresis 53 54 double ts = 0.0; // sample time in seconds 55 double proportionalCoeff = 0.0; // coeff for P 56 double integralCoeff = 0.0; // coeff for I 57 double derivativeCoeff = 0.0; // coeff for D 58 double feedFwdOffset = 0.0; // offset coeff for feed-forward term 59 double feedFwdGain = 0.0; // gain for feed-forward term 60 ec::limits_t integralLimit; // clamp of integral 61 ec::limits_t outLim; // clamp of output 62 double slewNeg = 0.0; 63 double slewPos = 0.0; 64 double positiveHysteresis = 0.0; 65 double negativeHysteresis = 0.0; 66 }; 67 68 } // namespace ec 69 } // namespace pid_control 70