From 127961e692bef909b078c9e47ac67b351842b6e1 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 24 Jan 2024 10:09:23 +1100 Subject: [PATCH] Plane: break out a method for set-attitude-target --- ArduPlane/GCS_Mavlink.cpp | 36 +++++++++++++++++++----------------- ArduPlane/GCS_Mavlink.h | 1 + 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/ArduPlane/GCS_Mavlink.cpp b/ArduPlane/GCS_Mavlink.cpp index ea7b291c59..c8ee1e7a20 100644 --- a/ArduPlane/GCS_Mavlink.cpp +++ b/ArduPlane/GCS_Mavlink.cpp @@ -1235,6 +1235,24 @@ void GCS_MAVLINK_Plane::handle_message(const mavlink_message_t &msg) break; case MAVLINK_MSG_ID_SET_ATTITUDE_TARGET: + handle_set_attitude_target(msg); + break; + + case MAVLINK_MSG_ID_SET_POSITION_TARGET_LOCAL_NED: + handle_set_position_target_local_ned(msg); + break; + + case MAVLINK_MSG_ID_SET_POSITION_TARGET_GLOBAL_INT: + handle_set_position_target_global_int(msg); + break; + + default: + GCS_MAVLINK::handle_message(msg); + break; + } // end switch +} // end handle mavlink + +void GCS_MAVLINK_Plane::handle_set_attitude_target(const mavlink_message_t &msg) { // Only allow companion computer (or other external controller) to // control attitude in GUIDED mode. We DON'T want external control @@ -1242,7 +1260,7 @@ void GCS_MAVLINK_Plane::handle_message(const mavlink_message_t &msg) // computer control is more safe (even more so when using // FENCE_ACTION = 4 for geofence failures). if (plane.control_mode != &plane.mode_guided) { // don't screw up failsafes - break; + return; } mavlink_set_attitude_target_t att_target; @@ -1300,24 +1318,8 @@ void GCS_MAVLINK_Plane::handle_message(const mavlink_message_t &msg) // Update timer for external throttle plane.guided_state.last_forced_throttle_ms = now; } - - break; } - case MAVLINK_MSG_ID_SET_POSITION_TARGET_LOCAL_NED: - handle_set_position_target_local_ned(msg); - break; - - case MAVLINK_MSG_ID_SET_POSITION_TARGET_GLOBAL_INT: - handle_set_position_target_global_int(msg); - break; - - default: - GCS_MAVLINK::handle_message(msg); - break; - } // end switch -} // end handle mavlink - void GCS_MAVLINK_Plane::handle_set_position_target_local_ned(const mavlink_message_t &msg) { // decode packet diff --git a/ArduPlane/GCS_Mavlink.h b/ArduPlane/GCS_Mavlink.h index e9df972aba..5920a35402 100644 --- a/ArduPlane/GCS_Mavlink.h +++ b/ArduPlane/GCS_Mavlink.h @@ -68,6 +68,7 @@ private: void handle_set_position_target_global_int(const mavlink_message_t &msg); void handle_set_position_target_local_ned(const mavlink_message_t &msg); + void handle_set_attitude_target(const mavlink_message_t &msg); #if HAL_QUADPLANE_ENABLED #if AP_MAVLINK_COMMAND_LONG_ENABLED