From 378dff5568b3636e94236f9f08cf093d9d494694 Mon Sep 17 00:00:00 2001 From: Joshua Henderson Date: Thu, 28 Jul 2022 04:42:01 -0400 Subject: [PATCH] AP_GPS: added get_undulation support --- libraries/AP_GPS/AP_GPS.cpp | 40 ++++++++++++++++++++++++++++--- libraries/AP_GPS/AP_GPS.h | 12 ++++++++++ libraries/AP_GPS/AP_GPS_ERB.cpp | 2 ++ libraries/AP_GPS/AP_GPS_NOVA.cpp | 2 ++ libraries/AP_GPS/AP_GPS_SBF.cpp | 2 ++ libraries/AP_GPS/AP_GPS_SIRF.cpp | 2 ++ libraries/AP_GPS/AP_GPS_UBLOX.cpp | 5 ++++ libraries/AP_GPS/LogStructure.h | 4 +++- 8 files changed, 65 insertions(+), 4 deletions(-) diff --git a/libraries/AP_GPS/AP_GPS.cpp b/libraries/AP_GPS/AP_GPS.cpp index 95f7599b0d..f3fb2c41e1 100644 --- a/libraries/AP_GPS/AP_GPS.cpp +++ b/libraries/AP_GPS/AP_GPS.cpp @@ -1353,6 +1353,11 @@ void AP_GPS::send_mavlink_gps_raw(mavlink_channel_t chan) float hacc = 0.0f; float vacc = 0.0f; float sacc = 0.0f; + float undulation = 0.0; + int32_t height_elipsoid_mm = 0; + if (get_undulation(0, undulation)) { + height_elipsoid_mm = loc.alt*10 - undulation*1000; + } horizontal_accuracy(0, hacc); vertical_accuracy(0, vacc); speed_accuracy(0, sacc); @@ -1368,7 +1373,7 @@ void AP_GPS::send_mavlink_gps_raw(mavlink_channel_t chan) ground_speed(0)*100, // cm/s ground_course(0)*100, // 1/100 degrees, num_sats(0), - 0, // TODO: Elipsoid height in mm + height_elipsoid_mm, // Elipsoid height in mm hacc * 1000, // one-sigma standard deviation in mm vacc * 1000, // one-sigma standard deviation in mm sacc * 1000, // one-sigma standard deviation in mm/s @@ -1388,6 +1393,11 @@ void AP_GPS::send_mavlink_gps2_raw(mavlink_channel_t chan) float hacc = 0.0f; float vacc = 0.0f; float sacc = 0.0f; + float undulation = 0.0; + float height_elipsoid_mm = 0; + if (get_undulation(0, undulation)) { + height_elipsoid_mm = loc.alt*10 - undulation*1000; + } horizontal_accuracy(1, hacc); vertical_accuracy(1, vacc); speed_accuracy(1, sacc); @@ -1406,7 +1416,7 @@ void AP_GPS::send_mavlink_gps2_raw(mavlink_channel_t chan) state[1].rtk_num_sats, state[1].rtk_age_ms, gps_yaw_cdeg(1), - 0, // TODO: Elipsoid height in mm + height_elipsoid_mm, // Elipsoid height in mm hacc * 1000, // one-sigma standard deviation in mm vacc * 1000, // one-sigma standard deviation in mm sacc * 1000, // one-sigma standard deviation in mm/s @@ -1855,6 +1865,16 @@ void AP_GPS::calc_blended_state(void) timing[GPS_BLENDED_INSTANCE].last_fix_time_ms = 0; timing[GPS_BLENDED_INSTANCE].last_message_time_ms = 0; + if (state[0].have_undulation) { + state[GPS_BLENDED_INSTANCE].have_undulation = true; + state[GPS_BLENDED_INSTANCE].undulation = state[0].undulation; + } else if (state[1].have_undulation) { + state[GPS_BLENDED_INSTANCE].have_undulation = true; + state[GPS_BLENDED_INSTANCE].undulation = state[1].undulation; + } else { + state[GPS_BLENDED_INSTANCE].have_undulation = false; + } + // combine the states into a blended solution for (uint8_t i=0; iget_error_codes(error_codes); } +// get the difference between WGS84 and AMSL. A positive value means +// the AMSL height is higher than WGS84 ellipsoid height +bool AP_GPS::get_undulation(uint8_t instance, float &undulation) const +{ + if (!state[instance].have_undulation) { + return false; + } + undulation = state[instance].undulation; + return true; +} + // Logging support: // Write an GPS packet void AP_GPS::Write_GPS(uint8_t i) @@ -2133,9 +2164,11 @@ void AP_GPS::Write_GPS(uint8_t i) /* write auxiliary accuracy information as well */ float hacc = 0, vacc = 0, sacc = 0; + float undulation = 0; horizontal_accuracy(i, hacc); vertical_accuracy(i, vacc); speed_accuracy(i, sacc); + get_undulation(i, undulation); struct log_GPA pkt2{ LOG_PACKET_HEADER_INIT(LOG_GPA_MSG), time_us : time_us, @@ -2147,7 +2180,8 @@ void AP_GPS::Write_GPS(uint8_t i) yaw_accuracy : yaw_accuracy_deg, have_vv : (uint8_t)have_vertical_velocity(i), sample_ms : last_message_time_ms(i), - delta_ms : last_message_delta_time_ms(i) + delta_ms : last_message_delta_time_ms(i), + undulation : undulation, }; AP::logger().WriteBlock(&pkt2, sizeof(pkt2)); } diff --git a/libraries/AP_GPS/AP_GPS.h b/libraries/AP_GPS/AP_GPS.h index 5b2b5290a8..cc8a13e7e1 100644 --- a/libraries/AP_GPS/AP_GPS.h +++ b/libraries/AP_GPS/AP_GPS.h @@ -197,6 +197,8 @@ public: 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 + float undulation; //