@@ -583,29 +583,34 @@ static bool estimationCalculateCorrection_Z(estimationContext_t * ctx)
583583 }
584584
585585 if (ctx -> newFlags & EST_BARO_VALID && wBaro ) {
586- timeUs_t currentTimeUs = micros ();
586+ bool isAirCushionEffectDetected = false;
587+ static float baroGroundAlt = 0.0f ;
587588
588- if (!ARMING_FLAG (ARMED )) {
589- posEstimator .state .baroGroundAlt = posEstimator .est .pos .z ;
590- posEstimator .state .isBaroGroundValid = true;
591- posEstimator .state .baroGroundTimeout = currentTimeUs + 250000 ; // 0.25 sec
592- }
593- else {
594- if (posEstimator .est .vel .z > 15 ) {
595- posEstimator .state .isBaroGroundValid = currentTimeUs > posEstimator .state .baroGroundTimeout ? false: true;
589+ if (STATE (MULTIROTOR )) {
590+ static bool isBaroGroundValid = false;
591+
592+ if (!ARMING_FLAG (ARMED )) {
593+ baroGroundAlt = posEstimator .baro .alt ;
594+ isBaroGroundValid = true;
596595 }
597- else {
598- posEstimator .state .baroGroundTimeout = currentTimeUs + 250000 ; // 0.25 sec
596+ else if (isBaroGroundValid ) {
597+ // We might be experiencing air cushion effect during takeoff - use sonar or baro ground altitude to detect it
598+ if (isMulticopterThrottleAboveMidHover ()) {
599+ // Disable ground effect detection at lift off when est alt and baro alt converge. Always disable if baro alt > 1m.
600+ isBaroGroundValid = fabsf (posEstimator .est .pos .z - posEstimator .baro .alt ) > 20.0f && posEstimator .baro .alt < 100.0f ;
601+ }
602+
603+ isAirCushionEffectDetected = (isEstimatedAglTrusted () && posEstimator .surface .alt < 20.0f ) || posEstimator .baro .alt < baroGroundAlt + 20.0f ;
599604 }
600605 }
601606
602- // We might be experiencing air cushion effect during takeoff - use sonar or baro ground altitude to detect it
603- bool isAirCushionEffectDetected = ARMING_FLAG (ARMED ) &&
604- (((ctx -> newFlags & EST_SURFACE_VALID ) && posEstimator .surface .alt < 20.0f && posEstimator .state .isBaroGroundValid ) ||
605- ((ctx -> newFlags & EST_BARO_VALID ) && posEstimator .state .isBaroGroundValid && posEstimator .baro .alt < posEstimator .state .baroGroundAlt ));
606-
607607 // Altitude
608- const float baroAltResidual = wBaro * ((isAirCushionEffectDetected ? posEstimator .state .baroGroundAlt : posEstimator .baro .alt ) - posEstimator .est .pos .z );
608+ float baroAltResidual = wBaro * ((isAirCushionEffectDetected ? baroGroundAlt : posEstimator .baro .alt ) - posEstimator .est .pos .z );
609+
610+ // Disable alt pos correction at point of lift off if ground effect active
611+ if (isAirCushionEffectDetected && isMulticopterThrottleAboveMidHover ()) {
612+ baroAltResidual = 0.0f ;
613+ }
609614 const float baroVelZResidual = isAirCushionEffectDetected ? 0.0f : wBaro * (posEstimator .baro .baroAltRate - posEstimator .est .vel .z );
610615 const float w_z_baro_p = positionEstimationConfig ()-> w_z_baro_p ;
611616
0 commit comments