From ff6a4d9e71964ba16fcccd1d742d26d7f293cfd1 Mon Sep 17 00:00:00 2001 From: Martina Rivizzigno Date: Mon, 17 Jun 2019 13:50:08 +0200 Subject: [PATCH] stream mavlink message OBSTACLE DISTANCE --- src/modules/mavlink/mavlink_messages.cpp | 78 +++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/modules/mavlink/mavlink_messages.cpp b/src/modules/mavlink/mavlink_messages.cpp index 2eba396d70..45e2e3dc64 100644 --- a/src/modules/mavlink/mavlink_messages.cpp +++ b/src/modules/mavlink/mavlink_messages.cpp @@ -74,6 +74,7 @@ #include #include #include +#include #include #include #include @@ -4834,6 +4835,80 @@ protected: } }; +class MavlinkStreamObstacleDistance : public MavlinkStream +{ +public: + const char *get_name() const + { + return MavlinkStreamObstacleDistance::get_name_static(); + } + + static const char *get_name_static() + { + return "OBSTACLE_DISTANCE"; + } + + static uint16_t get_id_static() + { + return MAVLINK_MSG_ID_OBSTACLE_DISTANCE; + } + + uint16_t get_id() + { + return get_id_static(); + } + + static MavlinkStream *new_instance(Mavlink *mavlink) + { + return new MavlinkStreamObstacleDistance(mavlink); + } + + unsigned get_size() + { + return _obstacle_distance_fused_sub->is_published() ? (MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN + + MAVLINK_NUM_NON_PAYLOAD_BYTES) : + 0; + } + +private: + MavlinkOrbSubscription *_obstacle_distance_fused_sub; + uint64_t _obstacle_distance_time; + + /* do not allow top copying this class */ + MavlinkStreamObstacleDistance(MavlinkStreamObstacleDistance &) = delete; + MavlinkStreamObstacleDistance &operator = (const MavlinkStreamObstacleDistance &) = delete; + +protected: + explicit MavlinkStreamObstacleDistance(Mavlink *mavlink) : MavlinkStream(mavlink), + _obstacle_distance_fused_sub(_mavlink->add_orb_subscription(ORB_ID(obstacle_distance_fused))), + _obstacle_distance_time(0) + {} + + bool send(const hrt_abstime t) + { + obstacle_distance_s obstacke_distance; + + if (_obstacle_distance_fused_sub->update(&_obstacle_distance_time, &obstacke_distance)) { + mavlink_obstacle_distance_t msg = {}; + + msg.time_usec = obstacke_distance.timestamp; + msg.sensor_type = obstacke_distance.sensor_type; + memcpy(msg.distances, obstacke_distance.distances, sizeof(msg.distances)); + msg.increment = 0; + msg.min_distance = obstacke_distance.min_distance; + msg.max_distance = obstacke_distance.max_distance; + msg.angle_offset = obstacke_distance.angle_offset; + msg.increment_f = obstacke_distance.increment; + + mavlink_msg_obstacle_distance_send_struct(_mavlink->get_channel(), &msg); + + return true; + } + + return false; + } +}; + static const StreamListItem streams_list[] = { StreamListItem(&MavlinkStreamHeartbeat::new_instance, &MavlinkStreamHeartbeat::get_name_static, &MavlinkStreamHeartbeat::get_id_static), StreamListItem(&MavlinkStreamStatustext::new_instance, &MavlinkStreamStatustext::get_name_static, &MavlinkStreamStatustext::get_id_static), @@ -4891,7 +4966,8 @@ static const StreamListItem streams_list[] = { StreamListItem(&MavlinkStreamHighLatency2::new_instance, &MavlinkStreamHighLatency2::get_name_static, &MavlinkStreamHighLatency2::get_id_static), StreamListItem(&MavlinkStreamGroundTruth::new_instance, &MavlinkStreamGroundTruth::get_name_static, &MavlinkStreamGroundTruth::get_id_static), StreamListItem(&MavlinkStreamPing::new_instance, &MavlinkStreamPing::get_name_static, &MavlinkStreamPing::get_id_static), - StreamListItem(&MavlinkStreamOrbitStatus::new_instance, &MavlinkStreamOrbitStatus::get_name_static, &MavlinkStreamOrbitStatus::get_id_static) + StreamListItem(&MavlinkStreamOrbitStatus::new_instance, &MavlinkStreamOrbitStatus::get_name_static, &MavlinkStreamOrbitStatus::get_id_static), + StreamListItem(&MavlinkStreamObstacleDistance::new_instance, &MavlinkStreamObstacleDistance::get_name_static, &MavlinkStreamObstacleDistance::get_id_static) }; const char *get_stream_name(const uint16_t msg_id)