From 6fd7c1dcdad77c5cdc302c774b1ef53301329154 Mon Sep 17 00:00:00 2001 From: Jason Short Date: Wed, 26 Oct 2011 09:46:16 -0700 Subject: [PATCH] AP_PI AP_Var change using the If statement rather than Max to avoid potential AP_Var issues. I don't know if this is a real prob or not. Just being careful. --- libraries/APM_PI/APM_PI.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/APM_PI/APM_PI.cpp b/libraries/APM_PI/APM_PI.cpp index 6fd710a32a..5b18fc4ed7 100644 --- a/libraries/APM_PI/APM_PI.cpp +++ b/libraries/APM_PI/APM_PI.cpp @@ -11,8 +11,12 @@ long APM_PI::get_pi(int32_t error, float dt) { _integrator += ((float)error * _ki) * dt; - _integrator = min(_integrator, (float)_imax); - _integrator = max(_integrator, (float)-_imax); + + if (_integrator < -_imax) { + _integrator = -_imax; + } else if (_integrator > _imax) { + _integrator = _imax; + } return (float)error * _kp + _integrator; }