2
0

mavlink_msg_optical_flow.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. #pragma once
  2. // MESSAGE OPTICAL_FLOW PACKING
  3. #define MAVLINK_MSG_ID_OPTICAL_FLOW 100
  4. MAVPACKED(
  5. typedef struct __mavlink_optical_flow_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. float flow_comp_m_x; /*< [m/s] Flow in x-sensor direction, angular-speed compensated*/
  8. float flow_comp_m_y; /*< [m/s] Flow in y-sensor direction, angular-speed compensated*/
  9. float ground_distance; /*< [m] Ground distance. Positive value: distance known. Negative value: Unknown distance*/
  10. int16_t flow_x; /*< [dpix] Flow in x-sensor direction*/
  11. int16_t flow_y; /*< [dpix] Flow in y-sensor direction*/
  12. uint8_t sensor_id; /*< Sensor ID*/
  13. uint8_t quality; /*< Optical flow quality / confidence. 0: bad, 255: maximum quality*/
  14. float flow_rate_x; /*< [rad/s] Flow rate about X axis*/
  15. float flow_rate_y; /*< [rad/s] Flow rate about Y axis*/
  16. }) mavlink_optical_flow_t;
  17. #define MAVLINK_MSG_ID_OPTICAL_FLOW_LEN 34
  18. #define MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN 26
  19. #define MAVLINK_MSG_ID_100_LEN 34
  20. #define MAVLINK_MSG_ID_100_MIN_LEN 26
  21. #define MAVLINK_MSG_ID_OPTICAL_FLOW_CRC 175
  22. #define MAVLINK_MSG_ID_100_CRC 175
  23. #if MAVLINK_COMMAND_24BIT
  24. #define MAVLINK_MESSAGE_INFO_OPTICAL_FLOW { \
  25. 100, \
  26. "OPTICAL_FLOW", \
  27. 10, \
  28. { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_optical_flow_t, time_usec) }, \
  29. { "sensor_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 24, offsetof(mavlink_optical_flow_t, sensor_id) }, \
  30. { "flow_x", NULL, MAVLINK_TYPE_INT16_T, 0, 20, offsetof(mavlink_optical_flow_t, flow_x) }, \
  31. { "flow_y", NULL, MAVLINK_TYPE_INT16_T, 0, 22, offsetof(mavlink_optical_flow_t, flow_y) }, \
  32. { "flow_comp_m_x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_optical_flow_t, flow_comp_m_x) }, \
  33. { "flow_comp_m_y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_optical_flow_t, flow_comp_m_y) }, \
  34. { "quality", NULL, MAVLINK_TYPE_UINT8_T, 0, 25, offsetof(mavlink_optical_flow_t, quality) }, \
  35. { "ground_distance", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_optical_flow_t, ground_distance) }, \
  36. { "flow_rate_x", NULL, MAVLINK_TYPE_FLOAT, 0, 26, offsetof(mavlink_optical_flow_t, flow_rate_x) }, \
  37. { "flow_rate_y", NULL, MAVLINK_TYPE_FLOAT, 0, 30, offsetof(mavlink_optical_flow_t, flow_rate_y) }, \
  38. } \
  39. }
  40. #else
  41. #define MAVLINK_MESSAGE_INFO_OPTICAL_FLOW { \
  42. "OPTICAL_FLOW", \
  43. 10, \
  44. { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_optical_flow_t, time_usec) }, \
  45. { "sensor_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 24, offsetof(mavlink_optical_flow_t, sensor_id) }, \
  46. { "flow_x", NULL, MAVLINK_TYPE_INT16_T, 0, 20, offsetof(mavlink_optical_flow_t, flow_x) }, \
  47. { "flow_y", NULL, MAVLINK_TYPE_INT16_T, 0, 22, offsetof(mavlink_optical_flow_t, flow_y) }, \
  48. { "flow_comp_m_x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_optical_flow_t, flow_comp_m_x) }, \
  49. { "flow_comp_m_y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_optical_flow_t, flow_comp_m_y) }, \
  50. { "quality", NULL, MAVLINK_TYPE_UINT8_T, 0, 25, offsetof(mavlink_optical_flow_t, quality) }, \
  51. { "ground_distance", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_optical_flow_t, ground_distance) }, \
  52. { "flow_rate_x", NULL, MAVLINK_TYPE_FLOAT, 0, 26, offsetof(mavlink_optical_flow_t, flow_rate_x) }, \
  53. { "flow_rate_y", NULL, MAVLINK_TYPE_FLOAT, 0, 30, offsetof(mavlink_optical_flow_t, flow_rate_y) }, \
  54. } \
  55. }
  56. #endif
  57. /**
  58. * @brief Pack a optical_flow message
  59. * @param system_id ID of this system
  60. * @param component_id ID of this component (e.g. 200 for IMU)
  61. * @param msg The MAVLink message to compress the data into
  62. *
  63. * @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.
  64. * @param sensor_id Sensor ID
  65. * @param flow_x [dpix] Flow in x-sensor direction
  66. * @param flow_y [dpix] Flow in y-sensor direction
  67. * @param flow_comp_m_x [m/s] Flow in x-sensor direction, angular-speed compensated
  68. * @param flow_comp_m_y [m/s] Flow in y-sensor direction, angular-speed compensated
  69. * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality
  70. * @param ground_distance [m] Ground distance. Positive value: distance known. Negative value: Unknown distance
  71. * @param flow_rate_x [rad/s] Flow rate about X axis
  72. * @param flow_rate_y [rad/s] Flow rate about Y axis
  73. * @return length of the message in bytes (excluding serial stream start sign)
  74. */
  75. static inline uint16_t mavlink_msg_optical_flow_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
  76. uint64_t time_usec, uint8_t sensor_id, int16_t flow_x, int16_t flow_y, float flow_comp_m_x, float flow_comp_m_y, uint8_t quality, float ground_distance, float flow_rate_x, float flow_rate_y)
  77. {
  78. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  79. char buf[MAVLINK_MSG_ID_OPTICAL_FLOW_LEN];
  80. _mav_put_uint64_t(buf, 0, time_usec);
  81. _mav_put_float(buf, 8, flow_comp_m_x);
  82. _mav_put_float(buf, 12, flow_comp_m_y);
  83. _mav_put_float(buf, 16, ground_distance);
  84. _mav_put_int16_t(buf, 20, flow_x);
  85. _mav_put_int16_t(buf, 22, flow_y);
  86. _mav_put_uint8_t(buf, 24, sensor_id);
  87. _mav_put_uint8_t(buf, 25, quality);
  88. _mav_put_float(buf, 26, flow_rate_x);
  89. _mav_put_float(buf, 30, flow_rate_y);
  90. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
  91. #else
  92. mavlink_optical_flow_t packet;
  93. packet.time_usec = time_usec;
  94. packet.flow_comp_m_x = flow_comp_m_x;
  95. packet.flow_comp_m_y = flow_comp_m_y;
  96. packet.ground_distance = ground_distance;
  97. packet.flow_x = flow_x;
  98. packet.flow_y = flow_y;
  99. packet.sensor_id = sensor_id;
  100. packet.quality = quality;
  101. packet.flow_rate_x = flow_rate_x;
  102. packet.flow_rate_y = flow_rate_y;
  103. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
  104. #endif
  105. msg->msgid = MAVLINK_MSG_ID_OPTICAL_FLOW;
  106. return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
  107. }
  108. /**
  109. * @brief Pack a optical_flow message
  110. * @param system_id ID of this system
  111. * @param component_id ID of this component (e.g. 200 for IMU)
  112. * @param status MAVLink status structure
  113. * @param msg The MAVLink message to compress the data into
  114. *
  115. * @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.
  116. * @param sensor_id Sensor ID
  117. * @param flow_x [dpix] Flow in x-sensor direction
  118. * @param flow_y [dpix] Flow in y-sensor direction
  119. * @param flow_comp_m_x [m/s] Flow in x-sensor direction, angular-speed compensated
  120. * @param flow_comp_m_y [m/s] Flow in y-sensor direction, angular-speed compensated
  121. * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality
  122. * @param ground_distance [m] Ground distance. Positive value: distance known. Negative value: Unknown distance
  123. * @param flow_rate_x [rad/s] Flow rate about X axis
  124. * @param flow_rate_y [rad/s] Flow rate about Y axis
  125. * @return length of the message in bytes (excluding serial stream start sign)
  126. */
  127. static inline uint16_t mavlink_msg_optical_flow_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
  128. uint64_t time_usec, uint8_t sensor_id, int16_t flow_x, int16_t flow_y, float flow_comp_m_x, float flow_comp_m_y, uint8_t quality, float ground_distance, float flow_rate_x, float flow_rate_y)
  129. {
  130. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  131. char buf[MAVLINK_MSG_ID_OPTICAL_FLOW_LEN];
  132. _mav_put_uint64_t(buf, 0, time_usec);
  133. _mav_put_float(buf, 8, flow_comp_m_x);
  134. _mav_put_float(buf, 12, flow_comp_m_y);
  135. _mav_put_float(buf, 16, ground_distance);
  136. _mav_put_int16_t(buf, 20, flow_x);
  137. _mav_put_int16_t(buf, 22, flow_y);
  138. _mav_put_uint8_t(buf, 24, sensor_id);
  139. _mav_put_uint8_t(buf, 25, quality);
  140. _mav_put_float(buf, 26, flow_rate_x);
  141. _mav_put_float(buf, 30, flow_rate_y);
  142. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
  143. #else
  144. mavlink_optical_flow_t packet;
  145. packet.time_usec = time_usec;
  146. packet.flow_comp_m_x = flow_comp_m_x;
  147. packet.flow_comp_m_y = flow_comp_m_y;
  148. packet.ground_distance = ground_distance;
  149. packet.flow_x = flow_x;
  150. packet.flow_y = flow_y;
  151. packet.sensor_id = sensor_id;
  152. packet.quality = quality;
  153. packet.flow_rate_x = flow_rate_x;
  154. packet.flow_rate_y = flow_rate_y;
  155. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
  156. #endif
  157. msg->msgid = MAVLINK_MSG_ID_OPTICAL_FLOW;
  158. #if MAVLINK_CRC_EXTRA
  159. return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
  160. #else
  161. return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
  162. #endif
  163. }
  164. /**
  165. * @brief Pack a optical_flow message on a channel
  166. * @param system_id ID of this system
  167. * @param component_id ID of this component (e.g. 200 for IMU)
  168. * @param chan The MAVLink channel this message will be sent over
  169. * @param msg The MAVLink message to compress the data into
  170. * @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.
  171. * @param sensor_id Sensor ID
  172. * @param flow_x [dpix] Flow in x-sensor direction
  173. * @param flow_y [dpix] Flow in y-sensor direction
  174. * @param flow_comp_m_x [m/s] Flow in x-sensor direction, angular-speed compensated
  175. * @param flow_comp_m_y [m/s] Flow in y-sensor direction, angular-speed compensated
  176. * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality
  177. * @param ground_distance [m] Ground distance. Positive value: distance known. Negative value: Unknown distance
  178. * @param flow_rate_x [rad/s] Flow rate about X axis
  179. * @param flow_rate_y [rad/s] Flow rate about Y axis
  180. * @return length of the message in bytes (excluding serial stream start sign)
  181. */
  182. static inline uint16_t mavlink_msg_optical_flow_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
  183. mavlink_message_t* msg,
  184. uint64_t time_usec,uint8_t sensor_id,int16_t flow_x,int16_t flow_y,float flow_comp_m_x,float flow_comp_m_y,uint8_t quality,float ground_distance,float flow_rate_x,float flow_rate_y)
  185. {
  186. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  187. char buf[MAVLINK_MSG_ID_OPTICAL_FLOW_LEN];
  188. _mav_put_uint64_t(buf, 0, time_usec);
  189. _mav_put_float(buf, 8, flow_comp_m_x);
  190. _mav_put_float(buf, 12, flow_comp_m_y);
  191. _mav_put_float(buf, 16, ground_distance);
  192. _mav_put_int16_t(buf, 20, flow_x);
  193. _mav_put_int16_t(buf, 22, flow_y);
  194. _mav_put_uint8_t(buf, 24, sensor_id);
  195. _mav_put_uint8_t(buf, 25, quality);
  196. _mav_put_float(buf, 26, flow_rate_x);
  197. _mav_put_float(buf, 30, flow_rate_y);
  198. memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
  199. #else
  200. mavlink_optical_flow_t packet;
  201. packet.time_usec = time_usec;
  202. packet.flow_comp_m_x = flow_comp_m_x;
  203. packet.flow_comp_m_y = flow_comp_m_y;
  204. packet.ground_distance = ground_distance;
  205. packet.flow_x = flow_x;
  206. packet.flow_y = flow_y;
  207. packet.sensor_id = sensor_id;
  208. packet.quality = quality;
  209. packet.flow_rate_x = flow_rate_x;
  210. packet.flow_rate_y = flow_rate_y;
  211. memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
  212. #endif
  213. msg->msgid = MAVLINK_MSG_ID_OPTICAL_FLOW;
  214. return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
  215. }
  216. /**
  217. * @brief Encode a optical_flow struct
  218. *
  219. * @param system_id ID of this system
  220. * @param component_id ID of this component (e.g. 200 for IMU)
  221. * @param msg The MAVLink message to compress the data into
  222. * @param optical_flow C-struct to read the message contents from
  223. */
  224. static inline uint16_t mavlink_msg_optical_flow_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_optical_flow_t* optical_flow)
  225. {
  226. return mavlink_msg_optical_flow_pack(system_id, component_id, msg, optical_flow->time_usec, optical_flow->sensor_id, optical_flow->flow_x, optical_flow->flow_y, optical_flow->flow_comp_m_x, optical_flow->flow_comp_m_y, optical_flow->quality, optical_flow->ground_distance, optical_flow->flow_rate_x, optical_flow->flow_rate_y);
  227. }
  228. /**
  229. * @brief Encode a optical_flow struct on a channel
  230. *
  231. * @param system_id ID of this system
  232. * @param component_id ID of this component (e.g. 200 for IMU)
  233. * @param chan The MAVLink channel this message will be sent over
  234. * @param msg The MAVLink message to compress the data into
  235. * @param optical_flow C-struct to read the message contents from
  236. */
  237. static inline uint16_t mavlink_msg_optical_flow_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_optical_flow_t* optical_flow)
  238. {
  239. return mavlink_msg_optical_flow_pack_chan(system_id, component_id, chan, msg, optical_flow->time_usec, optical_flow->sensor_id, optical_flow->flow_x, optical_flow->flow_y, optical_flow->flow_comp_m_x, optical_flow->flow_comp_m_y, optical_flow->quality, optical_flow->ground_distance, optical_flow->flow_rate_x, optical_flow->flow_rate_y);
  240. }
  241. /**
  242. * @brief Encode a optical_flow struct with provided status structure
  243. *
  244. * @param system_id ID of this system
  245. * @param component_id ID of this component (e.g. 200 for IMU)
  246. * @param status MAVLink status structure
  247. * @param msg The MAVLink message to compress the data into
  248. * @param optical_flow C-struct to read the message contents from
  249. */
  250. static inline uint16_t mavlink_msg_optical_flow_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_optical_flow_t* optical_flow)
  251. {
  252. return mavlink_msg_optical_flow_pack_status(system_id, component_id, _status, msg, optical_flow->time_usec, optical_flow->sensor_id, optical_flow->flow_x, optical_flow->flow_y, optical_flow->flow_comp_m_x, optical_flow->flow_comp_m_y, optical_flow->quality, optical_flow->ground_distance, optical_flow->flow_rate_x, optical_flow->flow_rate_y);
  253. }
  254. /**
  255. * @brief Send a optical_flow message
  256. * @param chan MAVLink channel to send the message
  257. *
  258. * @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.
  259. * @param sensor_id Sensor ID
  260. * @param flow_x [dpix] Flow in x-sensor direction
  261. * @param flow_y [dpix] Flow in y-sensor direction
  262. * @param flow_comp_m_x [m/s] Flow in x-sensor direction, angular-speed compensated
  263. * @param flow_comp_m_y [m/s] Flow in y-sensor direction, angular-speed compensated
  264. * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality
  265. * @param ground_distance [m] Ground distance. Positive value: distance known. Negative value: Unknown distance
  266. * @param flow_rate_x [rad/s] Flow rate about X axis
  267. * @param flow_rate_y [rad/s] Flow rate about Y axis
  268. */
  269. #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
  270. static inline void mavlink_msg_optical_flow_send(mavlink_channel_t chan, uint64_t time_usec, uint8_t sensor_id, int16_t flow_x, int16_t flow_y, float flow_comp_m_x, float flow_comp_m_y, uint8_t quality, float ground_distance, float flow_rate_x, float flow_rate_y)
  271. {
  272. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  273. char buf[MAVLINK_MSG_ID_OPTICAL_FLOW_LEN];
  274. _mav_put_uint64_t(buf, 0, time_usec);
  275. _mav_put_float(buf, 8, flow_comp_m_x);
  276. _mav_put_float(buf, 12, flow_comp_m_y);
  277. _mav_put_float(buf, 16, ground_distance);
  278. _mav_put_int16_t(buf, 20, flow_x);
  279. _mav_put_int16_t(buf, 22, flow_y);
  280. _mav_put_uint8_t(buf, 24, sensor_id);
  281. _mav_put_uint8_t(buf, 25, quality);
  282. _mav_put_float(buf, 26, flow_rate_x);
  283. _mav_put_float(buf, 30, flow_rate_y);
  284. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, buf, MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
  285. #else
  286. mavlink_optical_flow_t packet;
  287. packet.time_usec = time_usec;
  288. packet.flow_comp_m_x = flow_comp_m_x;
  289. packet.flow_comp_m_y = flow_comp_m_y;
  290. packet.ground_distance = ground_distance;
  291. packet.flow_x = flow_x;
  292. packet.flow_y = flow_y;
  293. packet.sensor_id = sensor_id;
  294. packet.quality = quality;
  295. packet.flow_rate_x = flow_rate_x;
  296. packet.flow_rate_y = flow_rate_y;
  297. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, (const char *)&packet, MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
  298. #endif
  299. }
  300. /**
  301. * @brief Send a optical_flow message
  302. * @param chan MAVLink channel to send the message
  303. * @param struct The MAVLink struct to serialize
  304. */
  305. static inline void mavlink_msg_optical_flow_send_struct(mavlink_channel_t chan, const mavlink_optical_flow_t* optical_flow)
  306. {
  307. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  308. mavlink_msg_optical_flow_send(chan, optical_flow->time_usec, optical_flow->sensor_id, optical_flow->flow_x, optical_flow->flow_y, optical_flow->flow_comp_m_x, optical_flow->flow_comp_m_y, optical_flow->quality, optical_flow->ground_distance, optical_flow->flow_rate_x, optical_flow->flow_rate_y);
  309. #else
  310. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, (const char *)optical_flow, MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
  311. #endif
  312. }
  313. #if MAVLINK_MSG_ID_OPTICAL_FLOW_LEN <= MAVLINK_MAX_PAYLOAD_LEN
  314. /*
  315. This variant of _send() can be used to save stack space by re-using
  316. memory from the receive buffer. The caller provides a
  317. mavlink_message_t which is the size of a full mavlink message. This
  318. is usually the receive buffer for the channel, and allows a reply to an
  319. incoming message with minimum stack space usage.
  320. */
  321. static inline void mavlink_msg_optical_flow_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint64_t time_usec, uint8_t sensor_id, int16_t flow_x, int16_t flow_y, float flow_comp_m_x, float flow_comp_m_y, uint8_t quality, float ground_distance, float flow_rate_x, float flow_rate_y)
  322. {
  323. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  324. char *buf = (char *)msgbuf;
  325. _mav_put_uint64_t(buf, 0, time_usec);
  326. _mav_put_float(buf, 8, flow_comp_m_x);
  327. _mav_put_float(buf, 12, flow_comp_m_y);
  328. _mav_put_float(buf, 16, ground_distance);
  329. _mav_put_int16_t(buf, 20, flow_x);
  330. _mav_put_int16_t(buf, 22, flow_y);
  331. _mav_put_uint8_t(buf, 24, sensor_id);
  332. _mav_put_uint8_t(buf, 25, quality);
  333. _mav_put_float(buf, 26, flow_rate_x);
  334. _mav_put_float(buf, 30, flow_rate_y);
  335. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, buf, MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
  336. #else
  337. mavlink_optical_flow_t *packet = (mavlink_optical_flow_t *)msgbuf;
  338. packet->time_usec = time_usec;
  339. packet->flow_comp_m_x = flow_comp_m_x;
  340. packet->flow_comp_m_y = flow_comp_m_y;
  341. packet->ground_distance = ground_distance;
  342. packet->flow_x = flow_x;
  343. packet->flow_y = flow_y;
  344. packet->sensor_id = sensor_id;
  345. packet->quality = quality;
  346. packet->flow_rate_x = flow_rate_x;
  347. packet->flow_rate_y = flow_rate_y;
  348. _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_OPTICAL_FLOW, (const char *)packet, MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN, MAVLINK_MSG_ID_OPTICAL_FLOW_CRC);
  349. #endif
  350. }
  351. #endif
  352. #endif
  353. // MESSAGE OPTICAL_FLOW UNPACKING
  354. /**
  355. * @brief Get field time_usec from optical_flow message
  356. *
  357. * @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.
  358. */
  359. static inline uint64_t mavlink_msg_optical_flow_get_time_usec(const mavlink_message_t* msg)
  360. {
  361. return _MAV_RETURN_uint64_t(msg, 0);
  362. }
  363. /**
  364. * @brief Get field sensor_id from optical_flow message
  365. *
  366. * @return Sensor ID
  367. */
  368. static inline uint8_t mavlink_msg_optical_flow_get_sensor_id(const mavlink_message_t* msg)
  369. {
  370. return _MAV_RETURN_uint8_t(msg, 24);
  371. }
  372. /**
  373. * @brief Get field flow_x from optical_flow message
  374. *
  375. * @return [dpix] Flow in x-sensor direction
  376. */
  377. static inline int16_t mavlink_msg_optical_flow_get_flow_x(const mavlink_message_t* msg)
  378. {
  379. return _MAV_RETURN_int16_t(msg, 20);
  380. }
  381. /**
  382. * @brief Get field flow_y from optical_flow message
  383. *
  384. * @return [dpix] Flow in y-sensor direction
  385. */
  386. static inline int16_t mavlink_msg_optical_flow_get_flow_y(const mavlink_message_t* msg)
  387. {
  388. return _MAV_RETURN_int16_t(msg, 22);
  389. }
  390. /**
  391. * @brief Get field flow_comp_m_x from optical_flow message
  392. *
  393. * @return [m/s] Flow in x-sensor direction, angular-speed compensated
  394. */
  395. static inline float mavlink_msg_optical_flow_get_flow_comp_m_x(const mavlink_message_t* msg)
  396. {
  397. return _MAV_RETURN_float(msg, 8);
  398. }
  399. /**
  400. * @brief Get field flow_comp_m_y from optical_flow message
  401. *
  402. * @return [m/s] Flow in y-sensor direction, angular-speed compensated
  403. */
  404. static inline float mavlink_msg_optical_flow_get_flow_comp_m_y(const mavlink_message_t* msg)
  405. {
  406. return _MAV_RETURN_float(msg, 12);
  407. }
  408. /**
  409. * @brief Get field quality from optical_flow message
  410. *
  411. * @return Optical flow quality / confidence. 0: bad, 255: maximum quality
  412. */
  413. static inline uint8_t mavlink_msg_optical_flow_get_quality(const mavlink_message_t* msg)
  414. {
  415. return _MAV_RETURN_uint8_t(msg, 25);
  416. }
  417. /**
  418. * @brief Get field ground_distance from optical_flow message
  419. *
  420. * @return [m] Ground distance. Positive value: distance known. Negative value: Unknown distance
  421. */
  422. static inline float mavlink_msg_optical_flow_get_ground_distance(const mavlink_message_t* msg)
  423. {
  424. return _MAV_RETURN_float(msg, 16);
  425. }
  426. /**
  427. * @brief Get field flow_rate_x from optical_flow message
  428. *
  429. * @return [rad/s] Flow rate about X axis
  430. */
  431. static inline float mavlink_msg_optical_flow_get_flow_rate_x(const mavlink_message_t* msg)
  432. {
  433. return _MAV_RETURN_float(msg, 26);
  434. }
  435. /**
  436. * @brief Get field flow_rate_y from optical_flow message
  437. *
  438. * @return [rad/s] Flow rate about Y axis
  439. */
  440. static inline float mavlink_msg_optical_flow_get_flow_rate_y(const mavlink_message_t* msg)
  441. {
  442. return _MAV_RETURN_float(msg, 30);
  443. }
  444. /**
  445. * @brief Decode a optical_flow message into a struct
  446. *
  447. * @param msg The message to decode
  448. * @param optical_flow C-struct to decode the message contents into
  449. */
  450. static inline void mavlink_msg_optical_flow_decode(const mavlink_message_t* msg, mavlink_optical_flow_t* optical_flow)
  451. {
  452. #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
  453. optical_flow->time_usec = mavlink_msg_optical_flow_get_time_usec(msg);
  454. optical_flow->flow_comp_m_x = mavlink_msg_optical_flow_get_flow_comp_m_x(msg);
  455. optical_flow->flow_comp_m_y = mavlink_msg_optical_flow_get_flow_comp_m_y(msg);
  456. optical_flow->ground_distance = mavlink_msg_optical_flow_get_ground_distance(msg);
  457. optical_flow->flow_x = mavlink_msg_optical_flow_get_flow_x(msg);
  458. optical_flow->flow_y = mavlink_msg_optical_flow_get_flow_y(msg);
  459. optical_flow->sensor_id = mavlink_msg_optical_flow_get_sensor_id(msg);
  460. optical_flow->quality = mavlink_msg_optical_flow_get_quality(msg);
  461. optical_flow->flow_rate_x = mavlink_msg_optical_flow_get_flow_rate_x(msg);
  462. optical_flow->flow_rate_y = mavlink_msg_optical_flow_get_flow_rate_y(msg);
  463. #else
  464. uint8_t len = msg->len < MAVLINK_MSG_ID_OPTICAL_FLOW_LEN? msg->len : MAVLINK_MSG_ID_OPTICAL_FLOW_LEN;
  465. memset(optical_flow, 0, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
  466. memcpy(optical_flow, _MAV_PAYLOAD(msg), len);
  467. #endif
  468. }