pid: rename structure components for style
Rename the struct components to camelCase.
Change-Id: I0e76c4bd5aed0ec2d78edd31ddef66f852ddc71e
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/pid/ec/pid.cpp b/pid/ec/pid.cpp
index 1ded7ac..6c70bbe 100644
--- a/pid/ec/pid.cpp
+++ b/pid/ec/pid.cpp
@@ -54,21 +54,22 @@
// Pid
error = setpoint - input;
- p_term = pidinfoptr->p_c * error;
+ p_term = pidinfoptr->proportionalCoeff * error;
// pId
- if (0.0f != pidinfoptr->i_c)
+ if (0.0f != pidinfoptr->integralCoeff)
{
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 += error * pidinfoptr->integralCoeff * pidinfoptr->ts;
+ i_term = clamp(i_term, pidinfoptr->integralLimit.min,
+ pidinfoptr->integralLimit.max);
}
// FF
- ff_term = (setpoint + pidinfoptr->ff_off) * pidinfoptr->ff_gain;
+ ff_term = (setpoint + pidinfoptr->feedFwdOffset) * pidinfoptr->feedFwdGain;
output = p_term + i_term + ff_term;
- output = clamp(output, pidinfoptr->out_lim.min, pidinfoptr->out_lim.max);
+ output = clamp(output, pidinfoptr->outLim.min, pidinfoptr->outLim.max);
// slew rate
// TODO(aarena) - Simplify logic as Andy suggested by creating dynamic
@@ -76,28 +77,28 @@
// to those instead of effectively clamping twice.
if (pidinfoptr->initialized)
{
- if (pidinfoptr->slew_neg != 0.0f)
+ if (pidinfoptr->slewNeg != 0.0f)
{
// Don't decrease too fast
double min_out =
- pidinfoptr->last_output + pidinfoptr->slew_neg * pidinfoptr->ts;
+ pidinfoptr->lastOutput + pidinfoptr->slewNeg * pidinfoptr->ts;
if (output < min_out)
{
output = min_out;
}
}
- if (pidinfoptr->slew_pos != 0.0f)
+ if (pidinfoptr->slewPos != 0.0f)
{
// Don't increase too fast
double max_out =
- pidinfoptr->last_output + pidinfoptr->slew_pos * pidinfoptr->ts;
+ pidinfoptr->lastOutput + pidinfoptr->slewPos * pidinfoptr->ts;
if (output > max_out)
{
output = max_out;
}
}
- if (pidinfoptr->slew_neg != 0.0f || pidinfoptr->slew_pos != 0.0f)
+ if (pidinfoptr->slewNeg != 0.0f || pidinfoptr->slewPos != 0.0f)
{
// Back calculate integral term for the cases where we limited the
// output
@@ -107,10 +108,11 @@
// 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->integralLimit.min,
+ pidinfoptr->integralLimit.max);
pidinfoptr->integral = i_term;
pidinfoptr->initialized = true;
- pidinfoptr->last_output = output;
+ pidinfoptr->lastOutput = output;
return output;
}
diff --git a/pid/ec/pid.hpp b/pid/ec/pid.hpp
index 3ab64cd..432e043 100644
--- a/pid/ec/pid.hpp
+++ b/pid/ec/pid.hpp
@@ -18,19 +18,19 @@
{
bool initialized; // has pid been initialized
- double ts; // sample time in seconds
- double integral; // intergal of error
- double last_output; // value of last output
+ double ts; // sample time in seconds
+ double integral; // intergal of error
+ double lastOutput; // value of last output
- 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
+ double proportionalCoeff; // coeff for P
+ double integralCoeff; // coeff for I
+ double feedFwdOffset; // offset coeff for feed-forward term
+ double feedFwdGain; // gain for feed-forward term
- limits_t i_lim; // clamp of integral
- limits_t out_lim; // clamp of output
- double slew_neg;
- double slew_pos;
+ limits_t integralLimit; // clamp of integral
+ limits_t outLim; // clamp of output
+ double slewNeg;
+ double slewPos;
double positiveHysteresis;
double negativeHysteresis;
} pid_info_t;
diff --git a/pid/util.cpp b/pid/util.cpp
index a5936b0..6993fbb 100644
--- a/pid/util.cpp
+++ b/pid/util.cpp
@@ -24,32 +24,33 @@
std::memset(info, 0x00, sizeof(ec::pid_info_t));
info->ts = initial.ts;
- info->p_c = initial.p_c;
- info->i_c = initial.i_c;
- info->ff_off = initial.ff_off;
- info->ff_gain = initial.ff_gain;
- info->i_lim.min = initial.i_lim.min;
- info->i_lim.max = initial.i_lim.max;
- info->out_lim.min = initial.out_lim.min;
- info->out_lim.max = initial.out_lim.max;
- info->slew_neg = initial.slew_neg;
- info->slew_pos = initial.slew_pos;
+ info->proportionalCoeff = initial.p_c;
+ info->integralCoeff = initial.i_c;
+ info->feedFwdOffset = initial.ff_off;
+ info->feedFwdGain = initial.ff_gain;
+ info->integralLimit.min = initial.i_lim.min;
+ info->integralLimit.max = initial.i_lim.max;
+ info->outLim.min = initial.out_lim.min;
+ info->outLim.max = initial.out_lim.max;
+ info->slewNeg = initial.slew_neg;
+ info->slewPos = initial.slew_pos;
info->negativeHysteresis = initial.negativeHysteresis;
info->positiveHysteresis = initial.positiveHysteresis;
}
void dumpPIDStruct(ec::pid_info_t* info)
{
- std::cerr << " ts: " << info->ts << " p_c: " << info->p_c
- << " i_c: " << info->i_c << " ff_off: " << info->ff_off
- << " ff_gain: " << info->ff_gain
- << " i_lim.min: " << info->i_lim.min
- << " i_lim.max: " << info->i_lim.max
- << " out_lim.min: " << info->out_lim.min
- << " out_lim.max: " << info->out_lim.max
- << " slew_neg: " << info->slew_neg
- << " slew_pos: " << info->slew_pos
- << " last_output: " << info->last_output
+ std::cerr << " ts: " << info->ts << " p_c: " << info->proportionalCoeff
+ << " i_c: " << info->integralCoeff
+ << " ff_off: " << info->feedFwdOffset
+ << " ff_gain: " << info->feedFwdGain
+ << " i_lim.min: " << info->integralLimit.min
+ << " i_lim.max: " << info->integralLimit.max
+ << " out_lim.min: " << info->outLim.min
+ << " out_lim.max: " << info->outLim.max
+ << " slew_neg: " << info->slewNeg
+ << " slew_pos: " << info->slewPos
+ << " last_output: " << info->lastOutput
<< " integral: " << info->integral << std::endl;
return;