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 24 double ts; // sample time in seconds 25 double integral; // integral of error 26 double lastOutput; // value of last output 27 double lastError; // value of last error 28 29 double proportionalCoeff; // coeff for P 30 double integralCoeff; // coeff for I 31 double derivativeCoeff; // coeff for D 32 double feedFwdOffset; // offset coeff for feed-forward term 33 double feedFwdGain; // gain for feed-forward term 34 35 limits_t integralLimit; // clamp of integral 36 limits_t outLim; // clamp of output 37 double slewNeg; 38 double slewPos; 39 double positiveHysteresis; 40 double negativeHysteresis; 41 } pid_info_t; 42 43 double pid(pid_info_t* pidinfoptr, double input, double setpoint, 44 const std::string* nameptr = nullptr); 45 46 /* Condensed version for use by the configuration. */ 47 struct pidinfo 48 { 49 double ts; // sample time in seconds 50 double proportionalCoeff; // coeff for P 51 double integralCoeff; // coeff for I 52 double derivativeCoeff; // coeff for D 53 double feedFwdOffset; // offset coeff for feed-forward term 54 double feedFwdGain; // gain for feed-forward term 55 ec::limits_t integralLimit; // clamp of integral 56 ec::limits_t outLim; // clamp of output 57 double slewNeg; 58 double slewPos; 59 double positiveHysteresis; 60 double negativeHysteresis; 61 }; 62 63 } // namespace ec 64 } // namespace pid_control 65