From 2dae917c86b8679b22381abd537d750a575761a4 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Wed, 20 Sep 2017 09:22:58 +0900 Subject: [PATCH] Sub: accept DO_SET_HOME within COMMAND_INT --- ArduSub/GCS_Mavlink.cpp | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/ArduSub/GCS_Mavlink.cpp b/ArduSub/GCS_Mavlink.cpp index 48b34ce351..bd945f258d 100644 --- a/ArduSub/GCS_Mavlink.cpp +++ b/ArduSub/GCS_Mavlink.cpp @@ -950,6 +950,50 @@ void GCS_MAVLINK_Sub::handleMessage(mavlink_message_t* msg) mavlink_command_int_t packet; mavlink_msg_command_int_decode(msg, &packet); switch (packet.command) { + + case MAV_CMD_DO_SET_HOME: { + // assume failure + result = MAV_RESULT_FAILED; + if (is_equal(packet.param1, 1.0f)) { + // if param1 is 1, use current location + if (sub.set_home_to_current_location(true)) { + result = MAV_RESULT_ACCEPTED; + } + break; + } + // ensure param1 is zero + if (!is_zero(packet.param1)) { + break; + } + // check frame type is supported + if (packet.frame != MAV_FRAME_GLOBAL && + packet.frame != MAV_FRAME_GLOBAL_INT && + packet.frame != MAV_FRAME_GLOBAL_RELATIVE_ALT && + packet.frame != MAV_FRAME_GLOBAL_RELATIVE_ALT_INT) { + break; + } + // sanity check location + if (!check_latlng(packet.x, packet.y)) { + break; + } + Location new_home_loc {}; + new_home_loc.lat = packet.x; + new_home_loc.lng = packet.y; + new_home_loc.alt = packet.z * 100; + // handle relative altitude + if (packet.frame == MAV_FRAME_GLOBAL_RELATIVE_ALT || packet.frame == MAV_FRAME_GLOBAL_RELATIVE_ALT_INT) { + if (sub.ap.home_state == HOME_UNSET) { + // cannot use relative altitude if home is not set + break; + } + new_home_loc.alt += sub.ahrs.get_home().alt; + } + if (sub.set_home(new_home_loc, true)) { + result = MAV_RESULT_ACCEPTED; + } + break; + } + case MAV_CMD_DO_SET_ROI: { // param1 : /* Region of interest mode (not used)*/ // param2 : /* MISSION index/ target ID (not used)*/