From 0d3e2aaa8e76f0195b452c64e516b6431b7700a8 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sun, 13 Sep 2026 23:28:44 +1000 Subject: [PATCH] Plane: fail DO_REPOSITION if GUIDED cannot be entered When DO_REPOSITION asked for a change into GUIDED and the mode change was refused (for example GUIDED being blocked by FLTMODE_GCSBLOCK) the result of set_mode() was ignored. The requested location was still loaded with set_guided_WP() and the command was ACCEPTED, so a vehicle in AUTO stayed in AUTO but flew towards the reposition target. Return MAV_RESULT_FAILED instead, leaving the current mode's navigation alone. --- ArduPlane/GCS_MAVLink_Plane.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ArduPlane/GCS_MAVLink_Plane.cpp b/ArduPlane/GCS_MAVLink_Plane.cpp index 7f4641b8417..2f7ce5db12e 100644 --- a/ArduPlane/GCS_MAVLink_Plane.cpp +++ b/ArduPlane/GCS_MAVLink_Plane.cpp @@ -587,7 +587,11 @@ MAV_RESULT GCS_MAVLINK_Plane::handle_command_int_do_reposition(const mavlink_com // location is valid load and set if (((int32_t)packet.param2 & MAV_DO_REPOSITION_FLAGS_CHANGE_MODE) || (plane.control_mode == &plane.mode_guided)) { - plane.set_mode(plane.mode_guided, ModeReason::GCS_COMMAND); + if (!plane.set_mode(plane.mode_guided, ModeReason::GCS_COMMAND)) { + // e.g. GUIDED blocked by FLTMODE_GCSBLOCK; don't touch the + // current mode's navigation target + return MAV_RESULT_FAILED; + } #if AP_PLANE_OFFBOARD_GUIDED_SLEW_ENABLED plane.guided_state.target_heading_type = GUIDED_HEADING_NONE; #endif