From ff4fb223dbb5278ce7e0ced28c9513e6c0252ef2 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Wed, 12 Aug 2026 16:19:44 +0900 Subject: [PATCH] AP_GroundEffect: remove use of AP_Terrain --- libraries/AP_GroundEffect/AP_GroundEffect.cpp | 25 +++++-------------- libraries/AP_GroundEffect/AP_GroundEffect.h | 13 ++++------ 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/libraries/AP_GroundEffect/AP_GroundEffect.cpp b/libraries/AP_GroundEffect/AP_GroundEffect.cpp index 0e26864866f..c35181f5bec 100644 --- a/libraries/AP_GroundEffect/AP_GroundEffect.cpp +++ b/libraries/AP_GroundEffect/AP_GroundEffect.cpp @@ -20,7 +20,6 @@ #include "AP_GroundEffect.h" #include #include -#include #include // hard cap on the takeoff_expected window, irrespective of GNDEFF_TMO @@ -39,7 +38,7 @@ const AP_Param::GroupInfo AP_GroundEffect::var_info[] = { // @Param: ALT // @DisplayName: Ground effect altitude threshold - // @Description: Ground effect compensation altitude threshold. Compensation is turned off once the vehicle climbs this many meters above the takeoff location. Positive values cause compensation to be applied both during takeoff and landing. Zero keeps compensation enabled but removes the landing altitude gate, matching the legacy behaviour where any gentle descent counts. Negative values disable the feature. Altitude of the vehicle is derived from a downward facing rangefinder (if present), the terrain database (when available) or worst case using the height-change-since-takeoff assuming flat ground with a 20m horizontal gate disabling the touchdown side if the vehicle's horizontal position is available. + // @Description: Ground effect compensation altitude threshold. Compensation is turned off once the vehicle climbs this many meters above the takeoff location. Positive values cause compensation to be applied both during takeoff and landing. Zero keeps compensation enabled but removes the landing altitude gate, matching the legacy behaviour where any gentle descent counts. Negative values disable the feature. Altitude of the vehicle is derived from a downward facing rangefinder (if present) or using the height-change-since-takeoff assuming flat ground with a 20m horizontal gate from the takeoff location if the horizontal position is available. // @Range: -1 10 // @Units: m // @User: Advanced @@ -85,7 +84,7 @@ void AP_GroundEffect::update(bool armed, bool land_complete, bool throttle_up) // Anchor the takeoff timer, altitude and XY position while still on // the ground without throttle up. Only the relative-to-takeoff - // fallback consumes these; HAGL / terrain paths ignore them. + // fallback consumes these; HAGL path ignores them. float pos_d_m = 0; UNUSED_RESULT(ahrs.get_relative_position_D_origin_float(pos_d_m)); Vector2f pos_ne_m; @@ -97,23 +96,11 @@ void AP_GroundEffect::update(bool armed, bool land_complete, bool throttle_up) _state.takeoff_pos_ne_m = pos_ne_m; } - // Pick the best available height. EKF HAGL covers rangefinder and - // EKF3's optflow AGL KF; terrain database covers GPS + onboard tiles; - // otherwise fall back to height-since-takeoff and assume flat ground. + // Pick the best available height + // EKF's HAGL uses rangefinder or optflow AGL KF + // fall back to height-since-takeoff and assume flat ground float height_m = 0; bool height_is_agl = ahrs.get_hagl(height_m); - -#if AP_TERRAIN_AVAILABLE - if (!height_is_agl) { - AP_Terrain *terrain = AP::terrain(); - // extrapolate=false: with no tiles loaded, height_above_terrain - // still "succeeds" by returning the raw AMSL altitude, which we - // do not want; require real data. - if (terrain != nullptr && terrain->height_above_terrain(height_m, false)) { - height_is_agl = true; - } - } -#endif if (!height_is_agl) { height_m = -pos_d_m - _state.takeoff_alt_m; } @@ -151,7 +138,7 @@ void AP_GroundEffect::update(bool armed, bool land_complete, bool throttle_up) // Touchdown altitude gate. // - GNDEFF_ALT <= 0: legacy behaviour, any gentle descent counts - // - HAGL or terrain height available: trust height_m directly + // - HAGL: trust height_m directly // - relative-to-takeoff fallback with horizontal position: only // trust the gate while still within AP_GROUNDEFFECT_TAKEOFF_DRIFT_MAX_M // of the launch point; further out we cannot assume the ground diff --git a/libraries/AP_GroundEffect/AP_GroundEffect.h b/libraries/AP_GroundEffect/AP_GroundEffect.h index c039f2335b4..9f2390802b8 100644 --- a/libraries/AP_GroundEffect/AP_GroundEffect.h +++ b/libraries/AP_GroundEffect/AP_GroundEffect.h @@ -44,26 +44,23 @@ // // 1. AP_AHRS::get_hagl() - rangefinder, or EKF3's // optflow AGL Kalman filter -// 2. AP_Terrain::height_above_terrain() -// - GPS position plus onboard -// terrain tiles for current loc -// 3. relative-to-takeoff (-pos_d minus the altitude latched at +// 2. relative-to-takeoff (-pos_d minus the altitude latched at // takeoff) with horizontal position available -// 4. relative-to-takeoff with no horizontal position (baro-only): +// 3. relative-to-takeoff with no horizontal position (baro-only): // assumes the ground beneath the vehicle is at // the takeoff elevation // -// Paths 3 and 4 are not strictly AGL: they trust that the ground has +// Paths 2 and 3 are not strictly AGL: they trust that the ground has // not changed elevation since takeoff. For the takeoff_expected window // (which closes within ~5 s of takeoff) that is almost always fine. // For touchdown_expected (which the vehicle may evaluate minutes later, -// hundreds of metres from launch) it is not, so path 3 additionally +// hundreds of metres from launch) it is not, so path 2 additionally // requires the vehicle to be within // AP_GROUNDEFFECT_TAKEOFF_DRIFT_MAX_M of the takeoff XY position before // the touchdown altitude gate is allowed to fire. Drift further than // that and touchdown_expected stays false regardless of motion, since // we have no basis to believe the ground below is at takeoff elevation. -// Path 4 (no horizontal position at all) cannot apply the drift gate +// Path 3 (no horizontal position at all) cannot apply the drift gate // and has to assume flat terrain. // // GNDEFF_ALT carries three regimes: