From 3900a4f14a637668c36c7b1294fe46cb55aa7869 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Wed, 16 Jun 2021 10:35:18 +0900 Subject: [PATCH] GCS_MAVLink: send water depth and temp --- libraries/GCS_MAVLink/GCS.h | 1 + libraries/GCS_MAVLink/GCS_Common.cpp | 46 ++++++++++++++++++++++++++++ libraries/GCS_MAVLink/ap_message.h | 1 + 3 files changed, 48 insertions(+) diff --git a/libraries/GCS_MAVLink/GCS.h b/libraries/GCS_MAVLink/GCS.h index 31ab05efb8..b137ef1a73 100644 --- a/libraries/GCS_MAVLink/GCS.h +++ b/libraries/GCS_MAVLink/GCS.h @@ -268,6 +268,7 @@ public: void send_rpm() const; void send_generator_status() const; virtual void send_winch_status() const {}; + void send_water_depth() 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 53eebff74d..3b55d19e72 100644 --- a/libraries/GCS_MAVLink/GCS_Common.cpp +++ b/libraries/GCS_MAVLink/GCS_Common.cpp @@ -851,6 +851,7 @@ ap_message GCS_MAVLINK::mavlink_id_to_ap_message_id(const uint32_t mavlink_id) c { MAVLINK_MSG_ID_EFI_STATUS, MSG_EFI_STATUS}, { MAVLINK_MSG_ID_GENERATOR_STATUS, MSG_GENERATOR_STATUS}, { MAVLINK_MSG_ID_WINCH_STATUS, MSG_WINCH_STATUS}, + { MAVLINK_MSG_ID_WATER_DEPTH, MSG_WATER_DEPTH}, }; for (uint8_t i=0; ihas_data_orient(ROTATION_PITCH_270)) { + // no rangefinder or not facing downwards + return; + } + + const bool sensor_healthy = (rangefinder->status_orient(ROTATION_PITCH_270) == RangeFinder::Status::Good); + + // get position + const AP_AHRS &ahrs = AP::ahrs(); + Location loc; + IGNORE_RETURN(ahrs.get_position(loc)); + + // get temperature + float temp_C = 0.0f; + IGNORE_RETURN(rangefinder->get_temp(ROTATION_PITCH_270, temp_C)); + + mavlink_msg_water_depth_send( + chan, + AP_HAL::millis(), // time since system boot TODO: take time of measurement + 0, // sensor id always zero + sensor_healthy, // sensor healthy + loc.lat, // latitude of vehicle + loc.lng, // longitude of vehicle + loc.alt * 0.01f, // altitude of vehicle (MSL) + ahrs.get_roll(), // roll in radians + ahrs.get_pitch(), // pitch in radians + ahrs.get_yaw(), // yaw in radians + rangefinder->distance_cm_orient(ROTATION_PITCH_270) * 0.01f, // distance in meters + temp_C); // temperature in degC +#endif +} + bool GCS_MAVLINK::try_send_message(const enum ap_message id) { bool ret = true; @@ -5066,6 +5107,11 @@ bool GCS_MAVLINK::try_send_message(const enum ap_message id) send_winch_status(); break; + case MSG_WATER_DEPTH: + CHECK_PAYLOAD_SIZE(WATER_DEPTH); + send_water_depth(); + 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 5865789852..5db094d7c8 100644 --- a/libraries/GCS_MAVLink/ap_message.h +++ b/libraries/GCS_MAVLink/ap_message.h @@ -77,5 +77,6 @@ enum ap_message : uint8_t { MSG_EFI_STATUS, MSG_GENERATOR_STATUS, MSG_WINCH_STATUS, + MSG_WATER_DEPTH, MSG_LAST // MSG_LAST must be the last entry in this enum };