Fix to calculation of ITerm anti-windup
This commit is contained in:
parent
70807d016b
commit
080f9b7923
|
@ -220,7 +220,7 @@ void pidController(const pidProfile_t *pidProfile, const rollAndPitchTrims_t *an
|
||||||
const float motorMixRange = getMotorMixRange();
|
const float motorMixRange = getMotorMixRange();
|
||||||
|
|
||||||
// Dynamic ki component to gradually scale back integration when above windup point
|
// Dynamic ki component to gradually scale back integration when above windup point
|
||||||
float dynKi = MIN((1.0f - motorMixRange) * ITermWindupPointInv, 1.0f);
|
const float dynKi = MIN((1.0f - motorMixRange) * ITermWindupPointInv, 1.0f);
|
||||||
|
|
||||||
// ----------PID controller----------
|
// ----------PID controller----------
|
||||||
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
|
for (int axis = FD_ROLL; axis <= FD_YAW; axis++) {
|
||||||
|
@ -251,11 +251,12 @@ void pidController(const pidProfile_t *pidProfile, const rollAndPitchTrims_t *an
|
||||||
// -----calculate I component
|
// -----calculate I component
|
||||||
float ITerm = previousGyroIf[axis];
|
float ITerm = previousGyroIf[axis];
|
||||||
if (motorMixRange < 1.0f) {
|
if (motorMixRange < 1.0f) {
|
||||||
// Only increase ITerm if motor output is not saturated and errorRate exceeds noise threshold
|
// Only increase ITerm if motor output is not saturated
|
||||||
// Iterm will only be accelerated below steady rate threshold
|
|
||||||
if (ABS(currentPidSetpoint) < itermAcceleratorRateLimit)
|
|
||||||
dynKi *= itermAccelerator;
|
|
||||||
float ITermDelta = Ki[axis] * errorRate * dT * dynKi;
|
float ITermDelta = Ki[axis] * errorRate * dT * dynKi;
|
||||||
|
if (ABS(currentPidSetpoint) < itermAcceleratorRateLimit) {
|
||||||
|
// ITerm will only be accelerated below steady rate threshold
|
||||||
|
ITermDelta *= itermAccelerator;
|
||||||
|
}
|
||||||
ITerm += ITermDelta;
|
ITerm += ITermDelta;
|
||||||
previousGyroIf[axis] = ITerm;
|
previousGyroIf[axis] = ITerm;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue