multirotor_pos_control: setpint reset rewritten

This commit is contained in:
Anton Babushkin
2013-09-10 22:58:44 +02:00
parent c3b6cea77a
commit 90873474a9
2 changed files with 85 additions and 58 deletions
+16 -10
View File
@@ -167,20 +167,26 @@ __EXPORT float pid_calculate(PID_t *pid, float sp, float val, float val_dot, flo
d = 0.0f;
}
// Calculate the error integral and check for saturation
i = pid->integral + (error * dt);
if (pid->ki > 0.0f) {
// Calculate the error integral and check for saturation
i = pid->integral + (error * dt);
if ((pid->limit > SIGMA && (fabsf((error * pid->kp) + (i * pid->ki) + (d * pid->kd)) > pid->limit)) ||
fabsf(i) > pid->intmax) {
i = pid->integral; // If saturated then do not update integral value
pid->saturated = 1;
if ((pid->limit > SIGMA && (fabsf((error * pid->kp) + (i * pid->ki) + (d * pid->kd)) > pid->limit)) ||
fabsf(i) > pid->intmax) {
i = pid->integral; // If saturated then do not update integral value
pid->saturated = 1;
} else {
if (!isfinite(i)) {
i = 0.0f;
} else {
if (!isfinite(i)) {
i = 0.0f;
}
pid->integral = i;
pid->saturated = 0;
}
pid->integral = i;
} else {
i = 0.0f;
pid->saturated = 0;
}