Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <cstdint> |
| 4 | |
| 5 | namespace ec |
| 6 | { |
| 7 | |
| 8 | typedef struct |
| 9 | { |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 10 | double min; |
| 11 | double max; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 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 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 19 | bool initialized; // has pid been initialized |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 20 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 21 | double ts; // sample time in seconds |
| 22 | double integral; // intergal of error |
| 23 | double last_output; // value of last output |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 24 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 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 |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 29 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 30 | limits_t i_lim; // clamp of integral |
| 31 | limits_t out_lim; // clamp of output |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 32 | double slew_neg; |
| 33 | double slew_pos; |
James Feist | 572c43d | 2019-01-31 15:52:22 -0800 | [diff] [blame] | 34 | double positiveHysteresis; |
| 35 | double negativeHysteresis; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 36 | } pid_info_t; |
| 37 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 38 | double pid(pid_info_t* pidinfoptr, double input, double setpoint); |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 39 | |
| 40 | /* Condensed version for use by the configuration. */ |
| 41 | struct pidinfo |
| 42 | { |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 43 | 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 Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 48 | ec::limits_t i_lim; // clamp of integral |
| 49 | ec::limits_t out_lim; // clamp of output |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 50 | double slew_neg; |
| 51 | double slew_pos; |
James Feist | 572c43d | 2019-01-31 15:52:22 -0800 | [diff] [blame] | 52 | double positiveHysteresis; |
| 53 | double negativeHysteresis; |
Patrick Venture | d801218 | 2018-03-08 08:21:38 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 56 | } // namespace ec |