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