blob: 432e0434b0b50b8ff86feec2d0a3955e00a06c71 [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 Venture5f59c0f2018-11-11 12:55:14 -080010 double min;
11 double 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 Venture4b0df322019-02-11 09:04:57 -080021 double ts; // sample time in seconds
22 double integral; // intergal of error
23 double lastOutput; // value of last output
Patrick Ventured8012182018-03-08 08:21:38 -080024
Patrick Venture4b0df322019-02-11 09:04:57 -080025 double proportionalCoeff; // coeff for P
26 double integralCoeff; // coeff for I
27 double feedFwdOffset; // offset coeff for feed-forward term
28 double feedFwdGain; // gain for feed-forward term
Patrick Ventured8012182018-03-08 08:21:38 -080029
Patrick Venture4b0df322019-02-11 09:04:57 -080030 limits_t integralLimit; // clamp of integral
31 limits_t outLim; // clamp of output
32 double slewNeg;
33 double slewPos;
James Feist572c43d2019-01-31 15:52:22 -080034 double positiveHysteresis;
35 double negativeHysteresis;
Patrick Ventured8012182018-03-08 08:21:38 -080036} pid_info_t;
37
Patrick Venture5f59c0f2018-11-11 12:55:14 -080038double pid(pid_info_t* pidinfoptr, double input, double setpoint);
Patrick Ventured8012182018-03-08 08:21:38 -080039
40/* Condensed version for use by the configuration. */
41struct pidinfo
42{
Patrick Venture5f59c0f2018-11-11 12:55:14 -080043 double ts; // sample time in seconds
44 double p_c; // coeff for P
45 double i_c; // coeff for I
46 double ff_off; // offset coeff for feed-forward term
47 double ff_gain; // gain for feed-forward term
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070048 ec::limits_t i_lim; // clamp of integral
49 ec::limits_t out_lim; // clamp of output
Patrick Venture5f59c0f2018-11-11 12:55:14 -080050 double slew_neg;
51 double slew_pos;
James Feist572c43d2019-01-31 15:52:22 -080052 double positiveHysteresis;
53 double negativeHysteresis;
Patrick Ventured8012182018-03-08 08:21:38 -080054};
55
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070056} // namespace ec