diff options
author | Anton Babushkin <anton.babushkin@me.com> | 2013-09-01 14:12:48 +0200 |
---|---|---|
committer | Anton Babushkin <anton.babushkin@me.com> | 2013-09-01 14:12:48 +0200 |
commit | f0a750714ae07976b295c0a857d85cbd57a09a72 (patch) | |
tree | 953c8b7a0cba03ec6c722bd41cdeac970abdec6e /src | |
parent | 2d83c6f825db02f04624467f3d0b492ee371c72a (diff) | |
download | px4-firmware-f0a750714ae07976b295c0a857d85cbd57a09a72.tar.gz px4-firmware-f0a750714ae07976b295c0a857d85cbd57a09a72.tar.bz2 px4-firmware-f0a750714ae07976b295c0a857d85cbd57a09a72.zip |
pid.c: fixed bad merge of seatbelt_multirotor, should fix EASY/AUTO modes
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/systemlib/pid/pid.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/modules/systemlib/pid/pid.c b/src/modules/systemlib/pid/pid.c index 4996a8f66..562f3ac04 100644 --- a/src/modules/systemlib/pid/pid.c +++ b/src/modules/systemlib/pid/pid.c @@ -168,8 +168,8 @@ __EXPORT float pid_calculate(PID_t *pid, float sp, float val, float val_dot, flo // Calculate the error integral and check for saturation i = pid->integral + (error * dt); - if (fabsf((error * pid->kp) + (i * pid->ki) + (d * pid->kd)) > pid->limit || - fabsf(i) > pid->intmax) { + if ((pid->limit != 0.0f && (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; @@ -186,11 +186,13 @@ __EXPORT float pid_calculate(PID_t *pid, float sp, float val, float val_dot, flo float output = (error * pid->kp) + (i * pid->ki) + (d * pid->kd); if (isfinite(output)) { - if (output > pid->limit) { - output = pid->limit; + if (pid->limit != 0.0f) { + if (output > pid->limit) { + output = pid->limit; - } else if (output < -pid->limit) { - output = -pid->limit; + } else if (output < -pid->limit) { + output = -pid->limit; + } } pid->last_output = output; |