diff options
| author | Patrick Venture <venture@google.com> | 2018-11-11 12:55:14 -0800 |
|---|---|---|
| committer | Patrick Venture <venture@google.com> | 2018-11-11 12:57:02 -0800 |
| commit | 5f59c0fdbda807ac54a58657fbd6cbde718e8678 (patch) | |
| tree | 8934e1a3e91c2281f4a306419a9c53a77f471ad9 /pid/ec | |
| parent | ba3c8c1c15ab10e3c9ad287c93d8a7598addc22f (diff) | |
| download | phosphor-pid-control-5f59c0fdbda807ac54a58657fbd6cbde718e8678.tar.gz phosphor-pid-control-5f59c0fdbda807ac54a58657fbd6cbde718e8678.zip | |
Move all floats to doubles
The code was developed initially around a pid loop implemented using
floats. Therefore, the code was converting back and forth between
double for sensor values as inputs and outputs from this PID loop.
Change-Id: I2d2919e1165103040729c9f16bb84fde3dd6b81b
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'pid/ec')
| -rw-r--r-- | pid/ec/pid.cpp | 18 | ||||
| -rw-r--r-- | pid/ec/pid.hpp | 38 | ||||
| -rw-r--r-- | pid/ec/stepwise.cpp | 6 | ||||
| -rw-r--r-- | pid/ec/stepwise.hpp | 12 |
4 files changed, 37 insertions, 37 deletions
diff --git a/pid/ec/pid.cpp b/pid/ec/pid.cpp index c2236c2..1ded7ac 100644 --- a/pid/ec/pid.cpp +++ b/pid/ec/pid.cpp @@ -23,7 +23,7 @@ namespace ec * clamp * */ -static float clamp(float x, float min, float max) +static double clamp(double x, double min, double max) { if (x < min) { @@ -40,15 +40,15 @@ static float clamp(float x, float min, float max) * pid code * Note: Codes assumes the ts field is non-zero */ -float pid(pid_info_t* pidinfoptr, float input, float setpoint) +double pid(pid_info_t* pidinfoptr, double input, double setpoint) { - float error; + double error; - float p_term; - float i_term = 0.0f; - float ff_term = 0.0f; + double p_term; + double i_term = 0.0f; + double ff_term = 0.0f; - float output; + double output; // calculate P, I, D, FF @@ -79,7 +79,7 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint) if (pidinfoptr->slew_neg != 0.0f) { // Don't decrease too fast - float min_out = + double min_out = pidinfoptr->last_output + pidinfoptr->slew_neg * pidinfoptr->ts; if (output < min_out) { @@ -89,7 +89,7 @@ float pid(pid_info_t* pidinfoptr, float input, float setpoint) if (pidinfoptr->slew_pos != 0.0f) { // Don't increase too fast - float max_out = + double max_out = pidinfoptr->last_output + pidinfoptr->slew_pos * pidinfoptr->ts; if (output > max_out) { diff --git a/pid/ec/pid.hpp b/pid/ec/pid.hpp index 6b1030a..779ced5 100644 --- a/pid/ec/pid.hpp +++ b/pid/ec/pid.hpp @@ -7,8 +7,8 @@ namespace ec typedef struct { - float min; - float max; + double min; + double max; } limits_t; /* Note: If you update these structs you need to update the copy code in @@ -18,35 +18,35 @@ typedef struct { bool initialized; // has pid been initialized - float ts; // sample time in seconds - float integral; // intergal of error - float last_output; // value of last output + double ts; // sample time in seconds + double integral; // intergal of error + double 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 + double p_c; // coeff for P + double i_c; // coeff for I + double ff_off; // offset coeff for feed-forward term + double 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; + double slew_neg; + double slew_pos; } pid_info_t; -float pid(pid_info_t* pidinfoptr, float input, float setpoint); +double pid(pid_info_t* pidinfoptr, double input, double 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 + double ts; // sample time in seconds + double p_c; // coeff for P + double i_c; // coeff for I + double ff_off; // offset coeff for feed-forward term + double 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; + double slew_neg; + double slew_pos; }; } // namespace ec diff --git a/pid/ec/stepwise.cpp b/pid/ec/stepwise.cpp index 4a71532..0a5c0b0 100644 --- a/pid/ec/stepwise.cpp +++ b/pid/ec/stepwise.cpp @@ -22,10 +22,10 @@ namespace ec { -float stepwise(const ec::StepwiseInfo& info, float input) +double stepwise(const ec::StepwiseInfo& info, double input) { - float value = info.output[0]; // if we are below the lowest - // point, we set the lowest value + double value = info.output[0]; // if we are below the lowest + // point, we set the lowest value for (size_t ii = 1; ii < ec::maxStepwisePoints; ii++) { diff --git a/pid/ec/stepwise.hpp b/pid/ec/stepwise.hpp index 4034b47..bc7c204 100644 --- a/pid/ec/stepwise.hpp +++ b/pid/ec/stepwise.hpp @@ -26,13 +26,13 @@ constexpr size_t maxStepwisePoints = 20; struct StepwiseInfo { - float ts; // sample time in seconds - float reading[maxStepwisePoints]; - float output[maxStepwisePoints]; - float positiveHysteresis; - float negativeHysteresis; + double ts; // sample time in seconds + double reading[maxStepwisePoints]; + double output[maxStepwisePoints]; + double positiveHysteresis; + double negativeHysteresis; }; -float stepwise(const ec::StepwiseInfo& info, float value); +double stepwise(const ec::StepwiseInfo& info, double value); } // namespace ec
\ No newline at end of file |

