mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-23 12:57:34 +08:00
pid lib fixes
This commit is contained in:
@@ -143,28 +143,18 @@ __EXPORT float pid_calculate(PID_t *pid, float sp, float val, float val_dot, flo
|
||||
/* calculate PD output */
|
||||
float output = (error * pid->kp) + (d * pid->kd);
|
||||
|
||||
if (pid->ki > SIGMA) {
|
||||
/* calculate error integral and check for saturation */
|
||||
float i = pid->integral + (error * dt);
|
||||
|
||||
/* fail-safe */
|
||||
if (!isfinite(i)) {
|
||||
i = 0.0f;
|
||||
}
|
||||
|
||||
if ((pid->output_limit > SIGMA && (fabsf(output + (i * pid->ki)) > pid->output_limit)) ||
|
||||
fabsf(i) > pid->integral_limit) {
|
||||
/* saturated, do not update integral value */
|
||||
i = pid->integral;
|
||||
|
||||
} else {
|
||||
/* check for saturation */
|
||||
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 += i * pid->ki;
|
||||
}
|
||||
|
||||
/* add I component to output */
|
||||
output += pid->integral * pid-> ki;
|
||||
|
||||
/* limit output */
|
||||
if (isfinite(output)) {
|
||||
if (pid->output_limit > SIGMA) {
|
||||
|
||||
Reference in New Issue
Block a user