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; 14 double max; 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; // has pid been initialized 23 bool checkHysterWithSetpt; // compare current input and setpoint to check 24 // hysteresis 25 26 double ts; // sample time in seconds 27 double integral; // integral of error 28 double lastOutput; // value of last output 29 double lastError; // value of last error 30 31 double proportionalCoeff; // coeff for P 32 double integralCoeff; // coeff for I 33 double derivativeCoeff; // coeff for D 34 double feedFwdOffset; // offset coeff for feed-forward term 35 double feedFwdGain; // gain for feed-forward term 36 37 limits_t integralLimit; // clamp of integral 38 limits_t outLim; // clamp of output 39 double slewNeg; 40 double slewPos; 41 double positiveHysteresis; 42 double negativeHysteresis; 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; // compare current input and setpoint to check 52 // hysteresis 53 54 double ts; // sample time in seconds 55 double proportionalCoeff; // coeff for P 56 double integralCoeff; // coeff for I 57 double derivativeCoeff; // coeff for D 58 double feedFwdOffset; // offset coeff for feed-forward term 59 double feedFwdGain; // gain for feed-forward term 60 ec::limits_t integralLimit; // clamp of integral 61 ec::limits_t outLim; // clamp of output 62 double slewNeg; 63 double slewPos; 64 double positiveHysteresis; 65 double negativeHysteresis; 66 }; 67 68 } // namespace ec 69 } // namespace pid_control 70