Optimized PI loop

This commit is contained in:
Jason Short 2011-09-29 22:37:56 -07:00
parent 758d0e1aec
commit 1f8576559a

View File

@ -10,23 +10,11 @@
long
APM_PI::get_pi(int32_t error, float dt)
{
float output = 0;
//float delta_time = (float)dt / 1000.0;
_integrator += ((float)error * _ki) * dt;
_integrator = min(_integrator, (float)_imax);
_integrator = max(_integrator, (float)-_imax);
// Compute proportional component
output += error * _kp;
// Compute integral component if time has elapsed
_integrator += (error * _ki) * dt;
if (_integrator < -_imax) {
_integrator = -_imax;
} else if (_integrator > _imax) {
_integrator = _imax;
}
output += _integrator;
return output;
return (float)error * _kp + _integrator;
}
void