From 44359ff6b2381525d74a43405ddf8cc23590e453 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 11 Apr 2024 19:14:02 +1000 Subject: [PATCH] AP_Common: add get_alt - 100 times better than get_alt_cm --- libraries/AP_Common/Location.cpp | 9 +++++++++ libraries/AP_Common/Location.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/libraries/AP_Common/Location.cpp b/libraries/AP_Common/Location.cpp index e1a1ec578c51d..50f134fb5b363 100644 --- a/libraries/AP_Common/Location.cpp +++ b/libraries/AP_Common/Location.cpp @@ -209,6 +209,15 @@ bool Location::get_alt_cm(AltFrame desired_frame, int32_t &ret_alt_cm) const } return false; // LCOV_EXCL_LINE - not reachable } +bool Location::get_alt_m(AltFrame desired_frame, float &ret_alt) const +{ + int32_t ret_alt_cm; + if (!get_alt_cm(desired_frame, ret_alt_cm)) { + return false; + } + ret_alt = ret_alt_cm * 0.01; + return true; +} #if AP_AHRS_ENABLED bool Location::get_vector_xy_from_origin_NE(Vector2f &vec_ne) const diff --git a/libraries/AP_Common/Location.h b/libraries/AP_Common/Location.h index eab834e2d427f..344187bf64a63 100644 --- a/libraries/AP_Common/Location.h +++ b/libraries/AP_Common/Location.h @@ -42,6 +42,8 @@ class Location // - above-home and home is not set // - above-origin and origin is not set bool get_alt_cm(AltFrame desired_frame, int32_t &ret_alt_cm) const WARN_IF_UNUSED; + // same as get_alt_cm but in metres: + bool get_alt_m(AltFrame desired_frame, float &ret_alt) const WARN_IF_UNUSED; // get altitude frame AltFrame get_alt_frame() const;