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