From 8b157399ff5eddb4d635fbd5e6e6ca04c923e39a Mon Sep 17 00:00:00 2001 From: Ryan Friedman <25047695+Ryanf55@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:51:16 +0900 Subject: [PATCH] ArduPlane: use frame instead of bools for setting alt frame * And switch to mavlink_coordinate_frame_to_location_alt_frame Signed-off-by: Ryan Friedman <25047695+Ryanf55@users.noreply.github.com> --- ArduPlane/GCS_Mavlink.cpp | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/ArduPlane/GCS_Mavlink.cpp b/ArduPlane/GCS_Mavlink.cpp index 45a596bc6331a8..3f17c961f8a596 100644 --- a/ArduPlane/GCS_Mavlink.cpp +++ b/ArduPlane/GCS_Mavlink.cpp @@ -1382,33 +1382,19 @@ void GCS_MAVLINK_Plane::handle_set_position_target_global_int(const mavlink_mess if (pos_target.type_mask & alt_mask) { - cmd.content.location.alt = pos_target.alt * 100; - cmd.content.location.relative_alt = false; - cmd.content.location.terrain_alt = false; - switch (pos_target.coordinate_frame) - { - case MAV_FRAME_GLOBAL: - case MAV_FRAME_GLOBAL_INT: - break; //default to MSL altitude - case MAV_FRAME_GLOBAL_RELATIVE_ALT: - case MAV_FRAME_GLOBAL_RELATIVE_ALT_INT: - cmd.content.location.relative_alt = true; - break; - case MAV_FRAME_GLOBAL_TERRAIN_ALT: - case MAV_FRAME_GLOBAL_TERRAIN_ALT_INT: - cmd.content.location.relative_alt = true; - cmd.content.location.terrain_alt = true; - break; - default: - gcs().send_text(MAV_SEVERITY_WARNING, "Invalid coord frame in SET_POSTION_TARGET_GLOBAL_INT"); - msg_valid = false; - break; - } + const int32_t alt_cm = pos_target.alt * 100; + Location::AltFrame frame; + if (mavlink_coordinate_frame_to_location_alt_frame((MAV_FRAME)pos_target.coordinate_frame, frame)) { + gcs().send_text(MAV_SEVERITY_WARNING, "Invalid coord frame in SET_POSTION_TARGET_GLOBAL_INT"); + msg_valid = false; + } else { + cmd.content.location.set_alt_cm(alt_cm, frame); + } if (msg_valid) { handle_change_alt_request(cmd); } - } // end if alt_mask + } } MAV_RESULT GCS_MAVLINK_Plane::handle_command_do_set_mission_current(const mavlink_command_int_t &packet)