From 5fe91f16afc14a2f1de014619f8dacee5b5dec69 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 29 Jan 2022 20:48:28 +1100 Subject: [PATCH] AP_Terrain: avoid direct use of Location alt field --- libraries/AP_Terrain/TerrainGCS.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libraries/AP_Terrain/TerrainGCS.cpp b/libraries/AP_Terrain/TerrainGCS.cpp index 640e7875ba..141570a34f 100644 --- a/libraries/AP_Terrain/TerrainGCS.cpp +++ b/libraries/AP_Terrain/TerrainGCS.cpp @@ -247,11 +247,9 @@ void AP_Terrain::send_terrain_report(mavlink_channel_t chan, const Location &loc if (spacing == 0 && !(extrapolate && have_current_loc_height)) { current_height = 0; } else { - if (current_loc.relative_alt) { - current_height = current_loc.alt*0.01f; - } else { - current_height = (current_loc.alt - ahrs.get_home().alt)*0.01f; - } + int32_t height_above_home_cm = 0; + UNUSED_RESULT(current_loc.get_alt_cm(Location::AltFrame::ABOVE_HOME, height_above_home_cm)); + current_height = height_above_home_cm * 0.01f; // cm -> m } current_height += home_terrain_height - terrain_height;