if (EKFGSF_ahrs_ng > 1.0f) {
if (is_positive(true_airspeed)) {
// When flying in fixed wing mode we need to allow for more positive g due to coordinated turns
// Gain varies from unity at 1g to zero at 2g
accel_gain = EKFGSF_tiltGain \* sq(2.0f - EKFGSF_ahrs_ng);
} else if (accel_gain <= 1.5f) { // \[BUG\] This condition uses 'accel_gain' incorrectly; should be 'EKFGSF_ahrs_ng'
// Gain varies from unity at 1g to zero at 1.5g
accel_gain = EKFGSF_tiltGain \* sq(3.0f - 2.0f \* EKFGSF_ahrs_ng);
} else {
// Gain is zero above max g
accel_gain = 0.0f;
}
} else if (accel_gain > 0.5f) { // \[BUG\] This condition uses 'accel_gain' incorrectly; should be 'EKFGSF_ahrs_ng'
// Gain varies from zero at 0.5g to unity at 1g
accel_gain = EKFGSF_tiltGain \* sq(2.0f \* EKFGSF_ahrs_ng - 1.0f);
} else {
// Gain is zero below min g
accel_gain = 0.0f;
}
The two conditional checks marked with [BUG] incorrectly use accel_gain as the judgment variable—this is a logical error. The intended variable here should be EKFGSF_ahrs_ng (the normalized acceleration value relative to 1g), as the logic is meant to judge the range of gravitational acceleration multiples, not the fusion gain itself.