pid library fix

This commit is contained in:
Anton Babushkin
2013-12-15 12:34:56 +04:00
parent faa3826de6
commit f5c24c6e71
+15 -10
View File
@@ -143,17 +143,22 @@ __EXPORT float pid_calculate(PID_t *pid, float sp, float val, float val_dot, flo
/* calculate PD output */ /* calculate PD output */
float output = (error * pid->kp) + (d * pid->kd); float output = (error * pid->kp) + (d * pid->kd);
/* check for saturation */ if (pid->ki > SIGMA) {
if (isfinite(i)) { // Calculate the error integral and check for saturation
if ((pid->output_limit < SIGMA || (fabsf(output + (i * pid->ki)) <= pid->output_limit)) && i = pid->integral + (error * dt);
fabsf(i) <= pid->integral_limit) {
/* not saturated, use new integral value */
pid->integral = i;
}
}
/* add I component to output */ /* check for saturation */
output += pid->integral * pid-> ki; if (isfinite(i)) {
if ((pid->output_limit < SIGMA || (fabsf(output + (i * pid->ki)) <= pid->output_limit)) &&
fabsf(i) <= pid->integral_limit) {
/* not saturated, use new integral value */
pid->integral = i;
}
}
/* add I component to output */
output += pid->integral * pid->ki;
}
/* limit output */ /* limit output */
if (isfinite(output)) { if (isfinite(output)) {