mavlink_msg_obstacle_distance.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. #pragma once
  2. // MESSAGE OBSTACLE_DISTANCE PACKING
  3. #define MAVLINK_MSG_ID_OBSTACLE_DISTANCE 330
  4. MAVPACKED(
  5. typedef struct __mavlink_obstacle_distance_t {
  6. uint64_t time_usec; /*< [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude of the number.*/
  7. uint16_t distances[72]; /*< [cm] Distance of obstacles around the vehicle with index 0 corresponding to north + angle_offset, unless otherwise specified in the frame. A value of 0 is valid and means that the obstacle is practically touching the sensor. A value of max_distance +1 means no obstacle is present. A value of UINT16_MAX for unknown/not used. In a array element, one unit corresponds to 1cm.*/
  8. uint16_t min_distance; /*< [cm] Minimum distance the sensor can measure.*/
  9. uint16_t max_distance; /*< [cm] Maximum distance the sensor can measure.*/
  10. uint8_t sensor_type; /*< Class id of the distance sensor type.*/
  11. uint8_t increment; /*< [deg] Angular width in degrees of each array element. Increment direction is clockwise. This field is ignored if increment_f is non-zero.*/
  12. float increment_f; /*< [deg] Angular width in degrees of each array element as a float. If non-zero then this value is used instead of the uint8_t increment field. Positive is clockwise direction, negative is counter-clockwise.*/
  13. float angle_offset; /*< [deg] Relative angle offset of the 0-index element in the distances array. Value of 0 corresponds to forward. Positive is clockwise direction, negative is counter-clockwise.*/
  14. uint8_t frame; /*< Coordinate frame of reference for the yaw rotation and offset of the sensor data. Defaults to MAV_FRAME_GLOBAL, which is north aligned. For body-mounted sensors use MAV_FRAME_BODY_FRD, which is vehicle front aligned.*/
  15. }) mavlink_obstacle_distance_t;
  16. #define MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN 167
  17. #define MAVLINK_MSG_ID_OBSTACLE_DISTANCE_MIN_LEN 158
  18. #define MAVLINK_MSG_ID_330_LEN 167
  19. #define MAVLINK_MSG_ID_330_MIN_LEN 158
  20. #define MAVLINK_MSG_ID_OBSTACLE_DISTANCE_CRC 23
  21. #define MAVLINK_MSG_ID_330_CRC 23
  22. #define MAVLINK_MSG_OBSTACLE_DISTANCE_FIELD_DISTANCES_LEN 72
  23. #if MAVLINK_COMMAND_24BIT
  24. #define MAVLINK_MESSAGE_INFO_OBSTACLE_DISTANCE { \
  25. 330, \
  26. "OBSTACLE_DISTANCE", \
  27. 9, \
  28. { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_obstacle_distance_t, time_usec) }, \
  29. { "sensor_type", NULL, MAVLINK_TYPE_UINT8_T, 0, 156, offsetof(mavlink_obstacle_distance_t, sensor_type) }, \
  30. { "distances", NULL, MAVLINK_TYPE_UINT16_T, 72, 8, offsetof(mavlink_obstacle_distance_t, distances) }, \
  31. { "increment", NULL, MAVLINK_TYPE_UINT8_T, 0, 157, offsetof(mavlink_obstacle_distance_t, increment) }, \
  32. { "min_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 152, offsetof(mavlink_obstacle_distance_t, min_distance) }, \
  33. { "max_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 154, offsetof(mavlink_obstacle_distance_t, max_distance) }, \
  34. { "increment_f", NULL, MAVLINK_TYPE_FLOAT, 0, 158, offsetof(mavlink_obstacle_distance_t, increment_f) }, \
  35. { "angle_offset", NULL, MAVLINK_TYPE_FLOAT, 0, 162, offsetof(mavlink_obstacle_distance_t, angle_offset) }, \
  36. { "frame", NULL, MAVLINK_TYPE_UINT8_T, 0, 166, offsetof(mavlink_obstacle_distance_t, frame) }, \
  37. } \
  38. }
  39. #else
  40. #define MAVLINK_MESSAGE_INFO_OBSTACLE_DISTANCE { \
  41. "OBSTACLE_DISTANCE", \
  42. 9, \
  43. { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_obstacle_distance_t, time_usec) }, \
  44. { "sensor_type", NULL, MAVLINK_TYPE_UINT8_T, 0, 156, offsetof(mavlink_obstacle_distance_t, sensor_type) }, \
  45. { "distances", NULL, MAVLINK_TYPE_UINT16_T, 72, 8, offsetof(mavlink_obstacle_distance_t, distances) }, \
  46. { "increment", NULL, MAVLINK_TYPE_UINT8_T, 0, 157, offsetof(mavlink_obstacle_distance_t, increment) }, \
  47. { "min_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 152, offsetof(mavlink_obstacle_distance_t, min_distance) }, \
  48. { "max_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 154, offsetof(mavlink_obstacle_distance_t, max_distance) }, \
  49. { "increment_f", NULL, MAVLINK_TYPE_FLOAT, 0, 158, offsetof(mavlink_obstacle_distance_t, increment_f) }, \
  50. { "angle_offset", NULL, MAVLINK_TYPE_FLOAT, 0, 162, offsetof(mavlink_obstacle_distance_t, angle_offset) }, \
  51. { "frame", NULL, MAVLINK_TYPE_UINT8_T, 0, 166, offsetof(mavlink_obstacle_distance_t, frame) }, \
  52. } \
  53. }
  54. #endif
  55. /**
  56. * @brief Pack a obstacle_distance message
  57. * @param system_id ID of this system
  58. * @param component_id ID of this component (e.g. 200 for IMU)
  59. * @param msg The MAVLink message to compress the data into
  60. *
  61. * @param time_usec [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude of the number.
  62. * @param sensor_type Class id of the distance sensor type.
  63. * @param distances [cm] Distance of obstacles around the vehicle with index 0 corresponding to north + angle_offset, unless otherwise specified in the frame. A value of 0 is valid and means that the obstacle is practically touching the sensor. A value of max_distance +1 means no obstacle is present. A value of UINT16_MAX for unknown/not used. In a array element, one unit corresponds to 1cm.
  64. * @param increment [deg] Angular width in degrees of each array element. Increment direction is clockwise. This field is ignored if increment_f is non-zero.
  65. * @param min_distance [cm] Minimum distance the sensor can measure.
  66. * @param max_distance [cm] Maximum distance the sensor can measure.
  67. * @param increment_f [deg] Angular width in degrees of each array element as a float. If non-zero then this value is used instead of the uint8_t increment field. Positive is clockwise direction, negative is counter-clockwise.
  68. * @param angle_offset [deg] Relative angle offset of the 0-index element in the distances array. Value of 0 corresponds to forward. Positive is clockwise direction, negative is counter-clockwise.
  69. * @param frame Coordinate frame of reference for the yaw rotation and offset of the sensor data. Defaults to MAV_FRAME_GLOBAL, which is north aligned. For body-mounted sensors use MAV_FRAME_BODY_FRD, which is vehicle front aligned.
  70. * @return length of the message in bytes (excluding serial stream start sign)
  71. */
  72. static inline uint16_t mavlink_msg_obstacle_distance_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  73. uint64_t time_usec, uint8_t sensor_type, const uint16_t *distances, uint8_t increment, uint16_t min_distance, uint16_t max_distance, float increment_f, float angle_offset, uint8_t frame)
  74. {
  75. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  76. char buf[MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN];
  77. _mav_put_uint64_t(buf, 0, time_usec);
  78. _mav_put_uint16_t(buf, 152, min_distance);
  79. _mav_put_uint16_t(buf, 154, max_distance);
  80. _mav_put_uint8_t(buf, 156, sensor_type);
  81. _mav_put_uint8_t(buf, 157, increment);
  82. _mav_put_float(buf, 158, increment_f);
  83. _mav_put_float(buf, 162, angle_offset);
  84. _mav_put_uint8_t(buf, 166, frame);
  85. _mav_put_uint16_t_array(buf, 8, distances, 72);
  86. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN);
  87. #else
  88. mavlink_obstacle_distance_t packet;
  89. packet.time_usec = time_usec;
  90. packet.min_distance = min_distance;
  91. packet.max_distance = max_distance;
  92. packet.sensor_type = sensor_type;
  93. packet.increment = increment;
  94. packet.increment_f = increment_f;
  95. packet.angle_offset = angle_offset;
  96. packet.frame = frame;
  97. mav_array_memcpy(packet.distances, distances, sizeof(uint16_t)*72);
  98. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN);
  99. #endif
  100. msg->msgid = MAVLINK_MSG_ID_OBSTACLE_DISTANCE;
  101. return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_CRC);
  102. }
  103. /**
  104. * @brief Pack a obstacle_distance message
  105. * @param system_id ID of this system
  106. * @param component_id ID of this component (e.g. 200 for IMU)
  107. * @param status MAVLink status structure
  108. * @param msg The MAVLink message to compress the data into
  109. *
  110. * @param time_usec [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude of the number.
  111. * @param sensor_type Class id of the distance sensor type.
  112. * @param distances [cm] Distance of obstacles around the vehicle with index 0 corresponding to north + angle_offset, unless otherwise specified in the frame. A value of 0 is valid and means that the obstacle is practically touching the sensor. A value of max_distance +1 means no obstacle is present. A value of UINT16_MAX for unknown/not used. In a array element, one unit corresponds to 1cm.
  113. * @param increment [deg] Angular width in degrees of each array element. Increment direction is clockwise. This field is ignored if increment_f is non-zero.
  114. * @param min_distance [cm] Minimum distance the sensor can measure.
  115. * @param max_distance [cm] Maximum distance the sensor can measure.
  116. * @param increment_f [deg] Angular width in degrees of each array element as a float. If non-zero then this value is used instead of the uint8_t increment field. Positive is clockwise direction, negative is counter-clockwise.
  117. * @param angle_offset [deg] Relative angle offset of the 0-index element in the distances array. Value of 0 corresponds to forward. Positive is clockwise direction, negative is counter-clockwise.
  118. * @param frame Coordinate frame of reference for the yaw rotation and offset of the sensor data. Defaults to MAV_FRAME_GLOBAL, which is north aligned. For body-mounted sensors use MAV_FRAME_BODY_FRD, which is vehicle front aligned.
  119. * @return length of the message in bytes (excluding serial stream start sign)
  120. */
  121. static inline uint16_t mavlink_msg_obstacle_distance_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
  122. uint64_t time_usec, uint8_t sensor_type, const uint16_t *distances, uint8_t increment, uint16_t min_distance, uint16_t max_distance, float increment_f, float angle_offset, uint8_t frame)
  123. {
  124. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  125. char buf[MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN];
  126. _mav_put_uint64_t(buf, 0, time_usec);
  127. _mav_put_uint16_t(buf, 152, min_distance);
  128. _mav_put_uint16_t(buf, 154, max_distance);
  129. _mav_put_uint8_t(buf, 156, sensor_type);
  130. _mav_put_uint8_t(buf, 157, increment);
  131. _mav_put_float(buf, 158, increment_f);
  132. _mav_put_float(buf, 162, angle_offset);
  133. _mav_put_uint8_t(buf, 166, frame);
  134. _mav_put_uint16_t_array(buf, 8, distances, 72);
  135. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN);
  136. #else
  137. mavlink_obstacle_distance_t packet;
  138. packet.time_usec = time_usec;
  139. packet.min_distance = min_distance;
  140. packet.max_distance = max_distance;
  141. packet.sensor_type = sensor_type;
  142. packet.increment = increment;
  143. packet.increment_f = increment_f;
  144. packet.angle_offset = angle_offset;
  145. packet.frame = frame;
  146. mav_array_memcpy(packet.distances, distances, sizeof(uint16_t)*72);
  147. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN);
  148. #endif
  149. msg->msgid = MAVLINK_MSG_ID_OBSTACLE_DISTANCE;
  150. #if MAVLINK_CRC_EXTRA
  151. return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_CRC);
  152. #else
  153. return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN);
  154. #endif
  155. }
  156. /**
  157. * @brief Pack a obstacle_distance message on a channel
  158. * @param system_id ID of this system
  159. * @param component_id ID of this component (e.g. 200 for IMU)
  160. * @param chan The MAVLink channel this message will be sent over
  161. * @param msg The MAVLink message to compress the data into
  162. * @param time_usec [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude of the number.
  163. * @param sensor_type Class id of the distance sensor type.
  164. * @param distances [cm] Distance of obstacles around the vehicle with index 0 corresponding to north + angle_offset, unless otherwise specified in the frame. A value of 0 is valid and means that the obstacle is practically touching the sensor. A value of max_distance +1 means no obstacle is present. A value of UINT16_MAX for unknown/not used. In a array element, one unit corresponds to 1cm.
  165. * @param increment [deg] Angular width in degrees of each array element. Increment direction is clockwise. This field is ignored if increment_f is non-zero.
  166. * @param min_distance [cm] Minimum distance the sensor can measure.
  167. * @param max_distance [cm] Maximum distance the sensor can measure.
  168. * @param increment_f [deg] Angular width in degrees of each array element as a float. If non-zero then this value is used instead of the uint8_t increment field. Positive is clockwise direction, negative is counter-clockwise.
  169. * @param angle_offset [deg] Relative angle offset of the 0-index element in the distances array. Value of 0 corresponds to forward. Positive is clockwise direction, negative is counter-clockwise.
  170. * @param frame Coordinate frame of reference for the yaw rotation and offset of the sensor data. Defaults to MAV_FRAME_GLOBAL, which is north aligned. For body-mounted sensors use MAV_FRAME_BODY_FRD, which is vehicle front aligned.
  171. * @return length of the message in bytes (excluding serial stream start sign)
  172. */
  173. static inline uint16_t mavlink_msg_obstacle_distance_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  174. mavlink_message_t* msg,
  175. uint64_t time_usec,uint8_t sensor_type,const uint16_t *distances,uint8_t increment,uint16_t min_distance,uint16_t max_distance,float increment_f,float angle_offset,uint8_t frame)
  176. {
  177. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  178. char buf[MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN];
  179. _mav_put_uint64_t(buf, 0, time_usec);
  180. _mav_put_uint16_t(buf, 152, min_distance);
  181. _mav_put_uint16_t(buf, 154, max_distance);
  182. _mav_put_uint8_t(buf, 156, sensor_type);
  183. _mav_put_uint8_t(buf, 157, increment);
  184. _mav_put_float(buf, 158, increment_f);
  185. _mav_put_float(buf, 162, angle_offset);
  186. _mav_put_uint8_t(buf, 166, frame);
  187. _mav_put_uint16_t_array(buf, 8, distances, 72);
  188. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN);
  189. #else
  190. mavlink_obstacle_distance_t packet;
  191. packet.time_usec = time_usec;
  192. packet.min_distance = min_distance;
  193. packet.max_distance = max_distance;
  194. packet.sensor_type = sensor_type;
  195. packet.increment = increment;
  196. packet.increment_f = increment_f;
  197. packet.angle_offset = angle_offset;
  198. packet.frame = frame;
  199. mav_array_memcpy(packet.distances, distances, sizeof(uint16_t)*72);
  200. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN);
  201. #endif
  202. msg->msgid = MAVLINK_MSG_ID_OBSTACLE_DISTANCE;
  203. return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_CRC);
  204. }
  205. /**
  206. * @brief Encode a obstacle_distance struct
  207. *
  208. * @param system_id ID of this system
  209. * @param component_id ID of this component (e.g. 200 for IMU)
  210. * @param msg The MAVLink message to compress the data into
  211. * @param obstacle_distance C-struct to read the message contents from
  212. */
  213. static inline uint16_t mavlink_msg_obstacle_distance_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_obstacle_distance_t* obstacle_distance)
  214. {
  215. return mavlink_msg_obstacle_distance_pack(system_id, component_id, msg, obstacle_distance->time_usec, obstacle_distance->sensor_type, obstacle_distance->distances, obstacle_distance->increment, obstacle_distance->min_distance, obstacle_distance->max_distance, obstacle_distance->increment_f, obstacle_distance->angle_offset, obstacle_distance->frame);
  216. }
  217. /**
  218. * @brief Encode a obstacle_distance struct on a channel
  219. *
  220. * @param system_id ID of this system
  221. * @param component_id ID of this component (e.g. 200 for IMU)
  222. * @param chan The MAVLink channel this message will be sent over
  223. * @param msg The MAVLink message to compress the data into
  224. * @param obstacle_distance C-struct to read the message contents from
  225. */
  226. static inline uint16_t mavlink_msg_obstacle_distance_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_obstacle_distance_t* obstacle_distance)
  227. {
  228. return mavlink_msg_obstacle_distance_pack_chan(system_id, component_id, chan, msg, obstacle_distance->time_usec, obstacle_distance->sensor_type, obstacle_distance->distances, obstacle_distance->increment, obstacle_distance->min_distance, obstacle_distance->max_distance, obstacle_distance->increment_f, obstacle_distance->angle_offset, obstacle_distance->frame);
  229. }
  230. /**
  231. * @brief Encode a obstacle_distance struct with provided status structure
  232. *
  233. * @param system_id ID of this system
  234. * @param component_id ID of this component (e.g. 200 for IMU)
  235. * @param status MAVLink status structure
  236. * @param msg The MAVLink message to compress the data into
  237. * @param obstacle_distance C-struct to read the message contents from
  238. */
  239. static inline uint16_t mavlink_msg_obstacle_distance_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_obstacle_distance_t* obstacle_distance)
  240. {
  241. return mavlink_msg_obstacle_distance_pack_status(system_id, component_id, _status, msg, obstacle_distance->time_usec, obstacle_distance->sensor_type, obstacle_distance->distances, obstacle_distance->increment, obstacle_distance->min_distance, obstacle_distance->max_distance, obstacle_distance->increment_f, obstacle_distance->angle_offset, obstacle_distance->frame);
  242. }
  243. /**
  244. * @brief Send a obstacle_distance message
  245. * @param chan MAVLink channel to send the message
  246. *
  247. * @param time_usec [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude of the number.
  248. * @param sensor_type Class id of the distance sensor type.
  249. * @param distances [cm] Distance of obstacles around the vehicle with index 0 corresponding to north + angle_offset, unless otherwise specified in the frame. A value of 0 is valid and means that the obstacle is practically touching the sensor. A value of max_distance +1 means no obstacle is present. A value of UINT16_MAX for unknown/not used. In a array element, one unit corresponds to 1cm.
  250. * @param increment [deg] Angular width in degrees of each array element. Increment direction is clockwise. This field is ignored if increment_f is non-zero.
  251. * @param min_distance [cm] Minimum distance the sensor can measure.
  252. * @param max_distance [cm] Maximum distance the sensor can measure.
  253. * @param increment_f [deg] Angular width in degrees of each array element as a float. If non-zero then this value is used instead of the uint8_t increment field. Positive is clockwise direction, negative is counter-clockwise.
  254. * @param angle_offset [deg] Relative angle offset of the 0-index element in the distances array. Value of 0 corresponds to forward. Positive is clockwise direction, negative is counter-clockwise.
  255. * @param frame Coordinate frame of reference for the yaw rotation and offset of the sensor data. Defaults to MAV_FRAME_GLOBAL, which is north aligned. For body-mounted sensors use MAV_FRAME_BODY_FRD, which is vehicle front aligned.
  256. */
  257. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  258. static inline void mavlink_msg_obstacle_distance_send(mavlink_channel_t chan, uint64_t time_usec, uint8_t sensor_type, const uint16_t *distances, uint8_t increment, uint16_t min_distance, uint16_t max_distance, float increment_f, float angle_offset, uint8_t frame)
  259. {
  260. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  261. char buf[MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN];
  262. _mav_put_uint64_t(buf, 0, time_usec);
  263. _mav_put_uint16_t(buf, 152, min_distance);
  264. _mav_put_uint16_t(buf, 154, max_distance);
  265. _mav_put_uint8_t(buf, 156, sensor_type);
  266. _mav_put_uint8_t(buf, 157, increment);
  267. _mav_put_float(buf, 158, increment_f);
  268. _mav_put_float(buf, 162, angle_offset);
  269. _mav_put_uint8_t(buf, 166, frame);
  270. _mav_put_uint16_t_array(buf, 8, distances, 72);
  271. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OBSTACLE_DISTANCE, buf, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_CRC);
  272. #else
  273. mavlink_obstacle_distance_t packet;
  274. packet.time_usec = time_usec;
  275. packet.min_distance = min_distance;
  276. packet.max_distance = max_distance;
  277. packet.sensor_type = sensor_type;
  278. packet.increment = increment;
  279. packet.increment_f = increment_f;
  280. packet.angle_offset = angle_offset;
  281. packet.frame = frame;
  282. mav_array_memcpy(packet.distances, distances, sizeof(uint16_t)*72);
  283. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OBSTACLE_DISTANCE, (const char *)&packet, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_CRC);
  284. #endif
  285. }
  286. /**
  287. * @brief Send a obstacle_distance message
  288. * @param chan MAVLink channel to send the message
  289. * @param struct The MAVLink struct to serialize
  290. */
  291. static inline void mavlink_msg_obstacle_distance_send_struct(mavlink_channel_t chan, const mavlink_obstacle_distance_t* obstacle_distance)
  292. {
  293. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  294. mavlink_msg_obstacle_distance_send(chan, obstacle_distance->time_usec, obstacle_distance->sensor_type, obstacle_distance->distances, obstacle_distance->increment, obstacle_distance->min_distance, obstacle_distance->max_distance, obstacle_distance->increment_f, obstacle_distance->angle_offset, obstacle_distance->frame);
  295. #else
  296. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OBSTACLE_DISTANCE, (const char *)obstacle_distance, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_CRC);
  297. #endif
  298. }
  299. #if MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  300. /*
  301. This variant of _send() can be used to save stack space by re-using
  302. memory from the receive buffer. The caller provides a
  303. mavlink_message_t which is the size of a full mavlink message. This
  304. is usually the receive buffer for the channel, and allows a reply to an
  305. incoming message with minimum stack space usage.
  306. */
  307. static inline void mavlink_msg_obstacle_distance_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint64_t time_usec, uint8_t sensor_type, const uint16_t *distances, uint8_t increment, uint16_t min_distance, uint16_t max_distance, float increment_f, float angle_offset, uint8_t frame)
  308. {
  309. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  310. char *buf = (char *)msgbuf;
  311. _mav_put_uint64_t(buf, 0, time_usec);
  312. _mav_put_uint16_t(buf, 152, min_distance);
  313. _mav_put_uint16_t(buf, 154, max_distance);
  314. _mav_put_uint8_t(buf, 156, sensor_type);
  315. _mav_put_uint8_t(buf, 157, increment);
  316. _mav_put_float(buf, 158, increment_f);
  317. _mav_put_float(buf, 162, angle_offset);
  318. _mav_put_uint8_t(buf, 166, frame);
  319. _mav_put_uint16_t_array(buf, 8, distances, 72);
  320. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OBSTACLE_DISTANCE, buf, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_CRC);
  321. #else
  322. mavlink_obstacle_distance_t *packet = (mavlink_obstacle_distance_t *)msgbuf;
  323. packet->time_usec = time_usec;
  324. packet->min_distance = min_distance;
  325. packet->max_distance = max_distance;
  326. packet->sensor_type = sensor_type;
  327. packet->increment = increment;
  328. packet->increment_f = increment_f;
  329. packet->angle_offset = angle_offset;
  330. packet->frame = frame;
  331. mav_array_memcpy(packet->distances, distances, sizeof(uint16_t)*72);
  332. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OBSTACLE_DISTANCE, (const char *)packet, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_MIN_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_CRC);
  333. #endif
  334. }
  335. #endif
  336. #endif
  337. // MESSAGE OBSTACLE_DISTANCE UNPACKING
  338. /**
  339. * @brief Get field time_usec from obstacle_distance message
  340. *
  341. * @return [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude of the number.
  342. */
  343. static inline uint64_t mavlink_msg_obstacle_distance_get_time_usec(const mavlink_message_t* msg)
  344. {
  345. return _MAV_RETURN_uint64_t(msg, 0);
  346. }
  347. /**
  348. * @brief Get field sensor_type from obstacle_distance message
  349. *
  350. * @return Class id of the distance sensor type.
  351. */
  352. static inline uint8_t mavlink_msg_obstacle_distance_get_sensor_type(const mavlink_message_t* msg)
  353. {
  354. return _MAV_RETURN_uint8_t(msg, 156);
  355. }
  356. /**
  357. * @brief Get field distances from obstacle_distance message
  358. *
  359. * @return [cm] Distance of obstacles around the vehicle with index 0 corresponding to north + angle_offset, unless otherwise specified in the frame. A value of 0 is valid and means that the obstacle is practically touching the sensor. A value of max_distance +1 means no obstacle is present. A value of UINT16_MAX for unknown/not used. In a array element, one unit corresponds to 1cm.
  360. */
  361. static inline uint16_t mavlink_msg_obstacle_distance_get_distances(const mavlink_message_t* msg, uint16_t *distances)
  362. {
  363. return _MAV_RETURN_uint16_t_array(msg, distances, 72, 8);
  364. }
  365. /**
  366. * @brief Get field increment from obstacle_distance message
  367. *
  368. * @return [deg] Angular width in degrees of each array element. Increment direction is clockwise. This field is ignored if increment_f is non-zero.
  369. */
  370. static inline uint8_t mavlink_msg_obstacle_distance_get_increment(const mavlink_message_t* msg)
  371. {
  372. return _MAV_RETURN_uint8_t(msg, 157);
  373. }
  374. /**
  375. * @brief Get field min_distance from obstacle_distance message
  376. *
  377. * @return [cm] Minimum distance the sensor can measure.
  378. */
  379. static inline uint16_t mavlink_msg_obstacle_distance_get_min_distance(const mavlink_message_t* msg)
  380. {
  381. return _MAV_RETURN_uint16_t(msg, 152);
  382. }
  383. /**
  384. * @brief Get field max_distance from obstacle_distance message
  385. *
  386. * @return [cm] Maximum distance the sensor can measure.
  387. */
  388. static inline uint16_t mavlink_msg_obstacle_distance_get_max_distance(const mavlink_message_t* msg)
  389. {
  390. return _MAV_RETURN_uint16_t(msg, 154);
  391. }
  392. /**
  393. * @brief Get field increment_f from obstacle_distance message
  394. *
  395. * @return [deg] Angular width in degrees of each array element as a float. If non-zero then this value is used instead of the uint8_t increment field. Positive is clockwise direction, negative is counter-clockwise.
  396. */
  397. static inline float mavlink_msg_obstacle_distance_get_increment_f(const mavlink_message_t* msg)
  398. {
  399. return _MAV_RETURN_float(msg, 158);
  400. }
  401. /**
  402. * @brief Get field angle_offset from obstacle_distance message
  403. *
  404. * @return [deg] Relative angle offset of the 0-index element in the distances array. Value of 0 corresponds to forward. Positive is clockwise direction, negative is counter-clockwise.
  405. */
  406. static inline float mavlink_msg_obstacle_distance_get_angle_offset(const mavlink_message_t* msg)
  407. {
  408. return _MAV_RETURN_float(msg, 162);
  409. }
  410. /**
  411. * @brief Get field frame from obstacle_distance message
  412. *
  413. * @return Coordinate frame of reference for the yaw rotation and offset of the sensor data. Defaults to MAV_FRAME_GLOBAL, which is north aligned. For body-mounted sensors use MAV_FRAME_BODY_FRD, which is vehicle front aligned.
  414. */
  415. static inline uint8_t mavlink_msg_obstacle_distance_get_frame(const mavlink_message_t* msg)
  416. {
  417. return _MAV_RETURN_uint8_t(msg, 166);
  418. }
  419. /**
  420. * @brief Decode a obstacle_distance message into a struct
  421. *
  422. * @param msg The message to decode
  423. * @param obstacle_distance C-struct to decode the message contents into
  424. */
  425. static inline void mavlink_msg_obstacle_distance_decode(const mavlink_message_t* msg, mavlink_obstacle_distance_t* obstacle_distance)
  426. {
  427. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  428. obstacle_distance->time_usec = mavlink_msg_obstacle_distance_get_time_usec(msg);
  429. mavlink_msg_obstacle_distance_get_distances(msg, obstacle_distance->distances);
  430. obstacle_distance->min_distance = mavlink_msg_obstacle_distance_get_min_distance(msg);
  431. obstacle_distance->max_distance = mavlink_msg_obstacle_distance_get_max_distance(msg);
  432. obstacle_distance->sensor_type = mavlink_msg_obstacle_distance_get_sensor_type(msg);
  433. obstacle_distance->increment = mavlink_msg_obstacle_distance_get_increment(msg);
  434. obstacle_distance->increment_f = mavlink_msg_obstacle_distance_get_increment_f(msg);
  435. obstacle_distance->angle_offset = mavlink_msg_obstacle_distance_get_angle_offset(msg);
  436. obstacle_distance->frame = mavlink_msg_obstacle_distance_get_frame(msg);
  437. #else
  438. uint8_t len = msg->len < MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN? msg->len : MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN;
  439. memset(obstacle_distance, 0, MAVLINK_MSG_ID_OBSTACLE_DISTANCE_LEN);
  440. memcpy(obstacle_distance, _MAV_PAYLOAD(msg), len);
  441. #endif
  442. }