mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-04 03:21:36 +08:00
pid library fix
This commit is contained in:
@@ -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)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user