Skip to content

Commit f0217d9

Browse files
authored
Merge pull request iNavFlight#10925 from breadoven/abo_posest_air_cushion_fix
Nav position estimator baro air cushion compensation fix
2 parents 9f0fb42 + f5138df commit f0217d9

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

src/main/navigation/navigation_multicopter.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,14 +834,12 @@ bool isMulticopterLandingDetected(void)
834834
}
835835
#endif
836836

837-
bool throttleIsBelowMidHover = rcCommand[THROTTLE] < (0.5 * (currentBatteryProfile->nav.mc.hover_throttle + getThrottleIdleValue()));
838-
839837
/* Basic condition to start looking for landing
840838
* Detection active during Failsafe only if throttle below mid hover throttle
841839
* and WP mission not active (except landing states).
842840
* Also active in non autonomous flight modes but only when thottle low */
843841
bool startCondition = (navGetCurrentStateFlags() & (NAV_CTL_LAND | NAV_CTL_EMERG))
844-
|| (FLIGHT_MODE(FAILSAFE_MODE) && !FLIGHT_MODE(NAV_WP_MODE) && throttleIsBelowMidHover)
842+
|| (FLIGHT_MODE(FAILSAFE_MODE) && !FLIGHT_MODE(NAV_WP_MODE) && !isMulticopterThrottleAboveMidHover())
845843
|| (!navigationIsFlyingAutonomousMode() && throttleStickIsLow());
846844

847845
static timeMs_t landingDetectorStartedAt;
@@ -923,6 +921,11 @@ bool isMulticopterLandingDetected(void)
923921
}
924922
}
925923

924+
bool isMulticopterThrottleAboveMidHover(void)
925+
{
926+
return rcCommand[THROTTLE] > 0.5 * (currentBatteryProfile->nav.mc.hover_throttle + getThrottleIdleValue());
927+
}
928+
926929
/*-----------------------------------------------------------
927930
* Multicopter emergency landing
928931
*-----------------------------------------------------------*/

src/main/navigation/navigation_pos_estimator.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/main/navigation/navigation_pos_estimator_private.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,6 @@ typedef enum {
153153
ALTITUDE_SOURCE_BARO_ONLY,
154154
} navDefaultAltitudeSensor_e;
155155

156-
typedef struct {
157-
timeUs_t baroGroundTimeout;
158-
float baroGroundAlt;
159-
bool isBaroGroundValid;
160-
} navPositionEstimatorSTATE_t;
161-
162-
163156
typedef struct {
164157
uint32_t flags;
165158

@@ -175,9 +168,6 @@ typedef struct {
175168

176169
// Estimate
177170
navPositionEstimatorESTIMATE_t est;
178-
179-
// Extra state variables
180-
navPositionEstimatorSTATE_t state;
181171
} navigationPosEstimator_t;
182172

183173
typedef struct {

src/main/navigation/navigation_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ bool isMulticopterLandingDetected(void);
582582
void calculateMulticopterInitialHoldPosition(fpVector3_t * pos);
583583
float getSqrtControllerVelocity(float targetAltitude, timeDelta_t deltaMicros);
584584

585+
bool isMulticopterThrottleAboveMidHover(void);
586+
585587
/* Fixed-wing specific functions */
586588
void setupFixedWingAltitudeController(void);
587589

0 commit comments

Comments
 (0)