From be808343fa7557b2113235feac3b1a7ce294cbfb Mon Sep 17 00:00:00 2001 From: Mykhailo Tomashivskyi Date: Thu, 26 Sep 2024 09:23:25 +0300 Subject: [PATCH] AP_GPS: Ignore Z-axis difference while dual GPS difference check --- libraries/AP_GPS/AP_GPS.cpp | 9 +++++++-- libraries/AP_GPS/AP_GPS.h | 1 + libraries/AP_GPS/AP_GPS_MAV.cpp | 1 + libraries/AP_GPS/GPS_Backend.cpp | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libraries/AP_GPS/AP_GPS.cpp b/libraries/AP_GPS/AP_GPS.cpp index 070276dd45c9f..bfb4a86b8b6d2 100644 --- a/libraries/AP_GPS/AP_GPS.cpp +++ b/libraries/AP_GPS/AP_GPS.cpp @@ -1484,13 +1484,18 @@ bool AP_GPS::all_consistent(float &distance) const { // return true immediately if only one valid receiver if (num_instances <= 1 || - drivers[0] == nullptr || params[0].type == GPS_TYPE_NONE) { + drivers[0] == nullptr || params[0].type == GPS_TYPE_NONE || GPS_MAX_INSTANCES <= 1) { distance = 0; return true; } // calculate distance - distance = state[0].location.get_distance_NED(state[1].location).length(); + if (state[0].have_altitude && state[1].have_altitude) { + distance = state[0].location.get_distance_NED(state[1].location).length(); + } else { + distance = state[0].location.get_distance_NE(state[1].location).length(); + } + // success if distance is within 50m return (distance < 50); } diff --git a/libraries/AP_GPS/AP_GPS.h b/libraries/AP_GPS/AP_GPS.h index a3c814ffc241f..25ebf903041d2 100644 --- a/libraries/AP_GPS/AP_GPS.h +++ b/libraries/AP_GPS/AP_GPS.h @@ -216,6 +216,7 @@ class AP_GPS bool have_vertical_accuracy; ///< does GPS give vertical position accuracy? Set to true only once available. bool have_gps_yaw; ///< does GPS give yaw? Set to true only once available. bool have_gps_yaw_accuracy; ///< does the GPS give a heading accuracy estimate? Set to true only once available + bool have_altitude; ///< does GPS give altitude? Set to false only if GPS instance does not provide altitude. float undulation; //