From f4fc910feab841d39b19e09829efb1cbee043b16 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Mon, 8 Dec 2014 14:07:49 +0900 Subject: [PATCH] Plane: send OPTICAL_FLOW msg to GCS --- ArduPlane/GCS_Mavlink.pde | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ArduPlane/GCS_Mavlink.pde b/ArduPlane/GCS_Mavlink.pde index 15c85f9ddc..8283cd14d7 100644 --- a/ArduPlane/GCS_Mavlink.pde +++ b/ArduPlane/GCS_Mavlink.pde @@ -478,6 +478,32 @@ static void NOINLINE send_current_waypoint(mavlink_channel_t chan) mavlink_msg_mission_current_send(chan, mission.get_current_nav_index()); } +#if OPTFLOW == ENABLED +static void NOINLINE send_opticalflow(mavlink_channel_t chan) +{ + // exit immediately if no optical flow sensor or not healthy + if (!optflow.healthy()) { + return; + } + + // get rates from sensor + const Vector2f &flowRate = optflow.flowRate(); + const Vector2f &bodyRate = optflow.bodyRate(); + + // populate and send message + mavlink_msg_optical_flow_send( + chan, + millis(), + 0, // sensor id is zero + flowRate.x, + flowRate.y, + bodyRate.x, + bodyRate.y, + optflow.quality(), + 0); // ground distance (in meters) set to zero +} +#endif // OPTFLOW == ENABLED + static void NOINLINE send_statustext(mavlink_channel_t chan) { mavlink_statustext_t *s = &gcs[chan-MAVLINK_COMM_0].pending_status; @@ -687,6 +713,13 @@ bool GCS_MAVLINK::try_send_message(enum ap_message id) #endif // MOUNT == ENABLED break; + case MSG_OPTICAL_FLOW: +#if OPTFLOW == ENABLED + CHECK_PAYLOAD_SIZE(OPTICAL_FLOW); + send_opticalflow(chan); +#endif + break; + case MSG_RETRY_DEFERRED: break; // just here to prevent a warning @@ -920,6 +953,7 @@ GCS_MAVLINK::data_stream_send(void) #endif send_message(MSG_BATTERY2); send_message(MSG_MOUNT_STATUS); + send_message(MSG_OPTICAL_FLOW); } }