blob: 6b1030aaa3a976fd2311acff7bf45e8ff0ca5209 [file] [log] [blame]
Patrick Ventured8012182018-03-08 08:21:38 -08001#pragma once
2
3#include <cstdint>
4
5namespace ec
6{
7
8typedef struct
9{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070010 float min;
11 float max;
Patrick Ventured8012182018-03-08 08:21:38 -080012} limits_t;
13
14/* Note: If you update these structs you need to update the copy code in
15 * pid/util.cpp.
16 */
17typedef struct
18{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070019 bool initialized; // has pid been initialized
Patrick Ventured8012182018-03-08 08:21:38 -080020
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070021 float ts; // sample time in seconds
22 float integral; // intergal of error
23 float last_output; // value of last output
Patrick Ventured8012182018-03-08 08:21:38 -080024
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025 float p_c; // coeff for P
26 float i_c; // coeff for I
27 float ff_off; // offset coeff for feed-forward term
28 float ff_gain; // gain for feed-forward term
Patrick Ventured8012182018-03-08 08:21:38 -080029
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070030 limits_t i_lim; // clamp of integral
31 limits_t out_lim; // clamp of output
32 float slew_neg;
33 float slew_pos;
Patrick Ventured8012182018-03-08 08:21:38 -080034} pid_info_t;
35
36float pid(pid_info_t* pidinfoptr, float input, float setpoint);
37
38/* Condensed version for use by the configuration. */
39struct pidinfo
40{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070041 float ts; // sample time in seconds
42 float p_c; // coeff for P
43 float i_c; // coeff for I
44 float ff_off; // offset coeff for feed-forward term
45 float 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 float slew_neg;
49 float slew_pos;
Patrick Ventured8012182018-03-08 08:21:38 -080050};
51
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070052} // namespace ec