diff options
| author | Patrick Venture <venture@google.com> | 2018-08-31 09:42:48 -0700 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2018-08-31 09:53:59 -0700 |
| commit | da4a5dd133b88ebfeb69e89d05b381f81ba70e50 (patch) | |
| tree | aa1b8dcd7ce1432491e20d8a110fe2f762b59908 /pid/ec | |
| parent | 40be36ac31a4756498a1f297324129fe1271b726 (diff) | |
| download | phosphor-pid-control-da4a5dd133b88ebfeb69e89d05b381f81ba70e50.tar.gz phosphor-pid-control-da4a5dd133b88ebfeb69e89d05b381f81ba70e50.zip | |
add .clang-format
Change-Id: I6627b5569c2e0f730be7331403218b823a2c622f
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'pid/ec')
| -rw-r--r-- | pid/ec/pid.cpp | 26 | ||||
| -rw-r--r-- | pid/ec/pid.hpp | 49 |
2 files changed, 37 insertions, 38 deletions
diff --git a/pid/ec/pid.cpp b/pid/ec/pid.cpp index a1c4e41..ef0df14 100644 --- a/pid/ec/pid.cpp +++ b/pid/ec/pid.cpp @@ -53,15 +53,15 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint) // calculate P, I, D, FF // Pid - error = setpoint - input; - p_term = pidinfoptr->p_c * error; + error = setpoint - input; + p_term = pidinfoptr->p_c * error; // pId if (0.0f != pidinfoptr->i_c) { - i_term = pidinfoptr->integral; - i_term += error * pidinfoptr->i_c * pidinfoptr->ts; - i_term = clamp(i_term, pidinfoptr->i_lim.min, pidinfoptr->i_lim.max); + i_term = pidinfoptr->integral; + i_term += error * pidinfoptr->i_c * pidinfoptr->ts; + i_term = clamp(i_term, pidinfoptr->i_lim.min, pidinfoptr->i_lim.max); } // FF @@ -79,8 +79,8 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint) if (pidinfoptr->slew_neg != 0.0f) { // Don't decrease too fast - float min_out = pidinfoptr->last_output + pidinfoptr->slew_neg * - pidinfoptr->ts; + float min_out = + pidinfoptr->last_output + pidinfoptr->slew_neg * pidinfoptr->ts; if (output < min_out) { output = min_out; @@ -89,8 +89,8 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint) if (pidinfoptr->slew_pos != 0.0f) { // Don't increase too fast - float max_out = pidinfoptr->last_output + pidinfoptr->slew_pos * - pidinfoptr->ts; + float max_out = + pidinfoptr->last_output + pidinfoptr->slew_pos * pidinfoptr->ts; if (output > max_out) { output = max_out; @@ -107,12 +107,12 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint) // Clamp again because having limited the output may result in a // larger integral term - i_term = clamp(i_term, pidinfoptr->i_lim.min, pidinfoptr->i_lim.max); + i_term = clamp(i_term, pidinfoptr->i_lim.min, pidinfoptr->i_lim.max); pidinfoptr->integral = i_term; - pidinfoptr->initialized = true; - pidinfoptr->last_output = output; + pidinfoptr->initialized = true; + pidinfoptr->last_output = output; return output; } -} +} // namespace ec diff --git a/pid/ec/pid.hpp b/pid/ec/pid.hpp index e138933..6b1030a 100644 --- a/pid/ec/pid.hpp +++ b/pid/ec/pid.hpp @@ -7,8 +7,8 @@ namespace ec typedef struct { - float min; - float max; + float min; + float max; } limits_t; /* Note: If you update these structs you need to update the copy code in @@ -16,21 +16,21 @@ typedef struct */ typedef struct { - bool initialized; // has pid been initialized + bool initialized; // has pid been initialized - float ts; // sample time in seconds - float integral; // intergal of error - float last_output; // value of last output + float ts; // sample time in seconds + float integral; // intergal of error + float last_output; // value of last output - float p_c; // coeff for P - float i_c; // coeff for I - float ff_off; // offset coeff for feed-forward term - float ff_gain; // gain for feed-forward term + float p_c; // coeff for P + float i_c; // coeff for I + float ff_off; // offset coeff for feed-forward term + float ff_gain; // gain for feed-forward term - limits_t i_lim; // clamp of integral - limits_t out_lim; // clamp of output - float slew_neg; - float slew_pos; + limits_t i_lim; // clamp of integral + limits_t out_lim; // clamp of output + float slew_neg; + float slew_pos; } pid_info_t; float pid(pid_info_t* pidinfoptr, float input, float setpoint); @@ -38,16 +38,15 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint); /* Condensed version for use by the configuration. */ struct pidinfo { - float ts; // sample time in seconds - float p_c; // coeff for P - float i_c; // coeff for I - float ff_off; // offset coeff for feed-forward term - float ff_gain; // gain for feed-forward term - ec::limits_t i_lim; // clamp of integral - ec::limits_t out_lim; // clamp of output - float slew_neg; - float slew_pos; + float ts; // sample time in seconds + float p_c; // coeff for P + float i_c; // coeff for I + float ff_off; // offset coeff for feed-forward term + float ff_gain; // gain for feed-forward term + ec::limits_t i_lim; // clamp of integral + ec::limits_t out_lim; // clamp of output + float slew_neg; + float slew_pos; }; - -} +} // namespace ec |

