EKFGSF_yaw::update

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.

Linking the github issue which appears to be resolving this: EKFGSF_yaw.cpp error · Issue #32075 · ArduPilot/ardupilot · GitHub

@rmackay9 This is my first question, and I’ve mentioned you here.

Hi @triplez23,

Txs very much for your investigation and persistence. Claude code agrees that you’re right and just from looking at the code it does seem strange that the output, “accel_gain” would be used as an input to its own calculation.

I’ve created a new PR with just the required fix. The commit still has your name on it so the credit goes to you. Could you check that it seems OK to you?

BTW, there’s no shame in using AI of course, we all need to in order to keep up. The key though is to come through afterwards and make sure it’s output is sensible.

Anyway, txs again!