From f83b4cdb408c7e4cfb107dd46e9f0248eb725d45 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Wed, 1 Jun 2022 20:03:09 +0900 Subject: [PATCH] GCS_MAVLink: support sending AUTOPILOT_STATE_FOR_GIMBAL_DEVICE --- libraries/GCS_MAVLink/GCS.h | 1 + libraries/GCS_MAVLink/GCS_Common.cpp | 52 ++++++++++++++++++++++++++++ libraries/GCS_MAVLink/ap_message.h | 1 + 3 files changed, 54 insertions(+) diff --git a/libraries/GCS_MAVLink/GCS.h b/libraries/GCS_MAVLink/GCS.h index a16015a481..0f631d9c68 100644 --- a/libraries/GCS_MAVLink/GCS.h +++ b/libraries/GCS_MAVLink/GCS.h @@ -318,6 +318,7 @@ public: void send_high_latency2() const; #endif // HAL_HIGH_LATENCY2_ENABLED void send_uavionix_adsb_out_status() const; + void send_autopilot_state_for_gimbal_device() const; // lock a channel, preventing use by MAVLink void lock(bool _lock) { diff --git a/libraries/GCS_MAVLink/GCS_Common.cpp b/libraries/GCS_MAVLink/GCS_Common.cpp index 06e1bf87a7..cf31758bd2 100644 --- a/libraries/GCS_MAVLink/GCS_Common.cpp +++ b/libraries/GCS_MAVLink/GCS_Common.cpp @@ -916,6 +916,7 @@ ap_message GCS_MAVLINK::mavlink_id_to_ap_message_id(const uint32_t mavlink_id) c { MAVLINK_MSG_ID_HIGH_LATENCY2, MSG_HIGH_LATENCY2}, { MAVLINK_MSG_ID_AIS_VESSEL, MSG_AIS_VESSEL}, { MAVLINK_MSG_ID_UAVIONIX_ADSB_OUT_STATUS, MSG_UAVIONIX_ADSB_OUT_STATUS}, + { MAVLINK_MSG_ID_AUTOPILOT_STATE_FOR_GIMBAL_DEVICE, MSG_AUTOPILOT_STATE_FOR_GIMBAL_DEVICE}, }; for (uint8_t i=0; iget_rate_bf_targets(rate_bf_targets); + } + + // get estimator flags + uint16_t est_status_flags = 0; + nav_filter_status nav_filt_status; + if (ahrs.get_filter_status(nav_filt_status)) { + est_status_flags = (uint16_t)(nav_filt_status.value & 0xFFFF); + } + + mavlink_msg_autopilot_state_for_gimbal_device_send( + chan, + mavlink_system.sysid, // target system (this autopilot's gimbal) + 0, // target component (anything) + AP_HAL::micros(), // time boot us + repr_offseq_q, // attitude as quaternion + 0, // attitude estimated delay in micros + vel.x, // x speed in NED (m/s) + vel.y, // y speed in NED (m/s) + vel.z, // z speed in NED (m/s) + 0, // velocity estimated delay in micros + rate_bf_targets.z,// feed forward angular velocity z + est_status_flags, // estimator status + 0); // landed_state (see MAV_LANDED_STATE) +} + void GCS_MAVLINK::send_received_message_deprecation_warning(const char * message) { // we're not expecting very many of these ever, so a tiny bit of @@ -5498,6 +5545,11 @@ bool GCS_MAVLINK::try_send_message(const enum ap_message id) send_uavionix_adsb_out_status(); break; + case MSG_AUTOPILOT_STATE_FOR_GIMBAL_DEVICE: + CHECK_PAYLOAD_SIZE(AUTOPILOT_STATE_FOR_GIMBAL_DEVICE); + send_autopilot_state_for_gimbal_device(); + break; + default: // try_send_message must always at some stage return true for // a message, or we will attempt to infinitely retry the diff --git a/libraries/GCS_MAVLink/ap_message.h b/libraries/GCS_MAVLink/ap_message.h index ea6a6474f3..b954a7b4c2 100644 --- a/libraries/GCS_MAVLink/ap_message.h +++ b/libraries/GCS_MAVLink/ap_message.h @@ -81,5 +81,6 @@ enum ap_message : uint8_t { MSG_MCU_STATUS, MSG_UAVIONIX_ADSB_OUT_STATUS, MSG_ATTITUDE_TARGET, + MSG_AUTOPILOT_STATE_FOR_GIMBAL_DEVICE, MSG_LAST // MSG_LAST must be the last entry in this enum };