[GYRO] Refactor gyro driver for dual-gyro support
[inav.git] / lib / main / MAVLink / common / mavlink_msg_optical_flow.h
blob56b9a3c676a2f21f5c6361b045d4d212309db78d
1 #pragma once
2 // MESSAGE OPTICAL_FLOW PACKING
4 #define MAVLINK_MSG_ID_OPTICAL_FLOW 100
6 MAVPACKED(
7 typedef struct __mavlink_optical_flow_t {
8 uint64_t time_usec; /*< Timestamp (UNIX)*/
9 float flow_comp_m_x; /*< Flow in meters in x-sensor direction, angular-speed compensated*/
10 float flow_comp_m_y; /*< Flow in meters in y-sensor direction, angular-speed compensated*/
11 float ground_distance; /*< Ground distance in meters. Positive value: distance known. Negative value: Unknown distance*/
12 int16_t flow_x; /*< Flow in pixels * 10 in x-sensor direction (dezi-pixels)*/
13 int16_t flow_y; /*< Flow in pixels * 10 in y-sensor direction (dezi-pixels)*/
14 uint8_t sensor_id; /*< Sensor ID*/
15 uint8_t quality; /*< Optical flow quality / confidence. 0: bad, 255: maximum quality*/
16 }) mavlink_optical_flow_t;
18 #define MAVLINK_MSG_ID_OPTICAL_FLOW_LEN 26
19 #define MAVLINK_MSG_ID_OPTICAL_FLOW_MIN_LEN 26
20 #define MAVLINK_MSG_ID_100_LEN 26
21 #define MAVLINK_MSG_ID_100_MIN_LEN 26
23 #define MAVLINK_MSG_ID_OPTICAL_FLOW_CRC 175
24 #define MAVLINK_MSG_ID_100_CRC 175
28 #if MAVLINK_COMMAND_24BIT
29 #define MAVLINK_MESSAGE_INFO_OPTICAL_FLOW { \
30 100, \
31 "OPTICAL_FLOW", \
32 8, \
33 { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_optical_flow_t, time_usec) }, \
34 { "flow_comp_m_x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_optical_flow_t, flow_comp_m_x) }, \
35 { "flow_comp_m_y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_optical_flow_t, flow_comp_m_y) }, \
36 { "ground_distance", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_optical_flow_t, ground_distance) }, \
37 { "flow_x", NULL, MAVLINK_TYPE_INT16_T, 0, 20, offsetof(mavlink_optical_flow_t, flow_x) }, \
38 { "flow_y", NULL, MAVLINK_TYPE_INT16_T, 0, 22, offsetof(mavlink_optical_flow_t, flow_y) }, \
39 { "sensor_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 24, offsetof(mavlink_optical_flow_t, sensor_id) }, \
40 { "quality", NULL, MAVLINK_TYPE_UINT8_T, 0, 25, offsetof(mavlink_optical_flow_t, quality) }, \
41 } \
43 #else
44 #define MAVLINK_MESSAGE_INFO_OPTICAL_FLOW { \
45 "OPTICAL_FLOW", \
46 8, \
47 { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_optical_flow_t, time_usec) }, \
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 { "ground_distance", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_optical_flow_t, ground_distance) }, \
51 { "flow_x", NULL, MAVLINK_TYPE_INT16_T, 0, 20, offsetof(mavlink_optical_flow_t, flow_x) }, \
52 { "flow_y", NULL, MAVLINK_TYPE_INT16_T, 0, 22, offsetof(mavlink_optical_flow_t, flow_y) }, \
53 { "sensor_id", NULL, MAVLINK_TYPE_UINT8_T, 0, 24, offsetof(mavlink_optical_flow_t, sensor_id) }, \
54 { "quality", NULL, MAVLINK_TYPE_UINT8_T, 0, 25, offsetof(mavlink_optical_flow_t, quality) }, \
55 } \
57 #endif
59 /**
60 * @brief Pack a optical_flow message
61 * @param system_id ID of this system
62 * @param component_id ID of this component (e.g. 200 for IMU)
63 * @param msg The MAVLink message to compress the data into
65 * @param time_usec Timestamp (UNIX)
66 * @param sensor_id Sensor ID
67 * @param flow_x Flow in pixels * 10 in x-sensor direction (dezi-pixels)
68 * @param flow_y Flow in pixels * 10 in y-sensor direction (dezi-pixels)
69 * @param flow_comp_m_x Flow in meters in x-sensor direction, angular-speed compensated
70 * @param flow_comp_m_y Flow in meters in y-sensor direction, angular-speed compensated
71 * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality
72 * @param ground_distance Ground distance in meters. Positive value: distance known. Negative value: Unknown distance
73 * @return length of the message in bytes (excluding serial stream start sign)
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)
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);
89 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
90 #else
91 mavlink_optical_flow_t packet;
92 packet.time_usec = time_usec;
93 packet.flow_comp_m_x = flow_comp_m_x;
94 packet.flow_comp_m_y = flow_comp_m_y;
95 packet.ground_distance = ground_distance;
96 packet.flow_x = flow_x;
97 packet.flow_y = flow_y;
98 packet.sensor_id = sensor_id;
99 packet.quality = quality;
101 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
102 #endif
104 msg->msgid = MAVLINK_MSG_ID_OPTICAL_FLOW;
105 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);
109 * @brief Pack a optical_flow message on a channel
110 * @param system_id ID of this system
111 * @param component_id ID of this component (e.g. 200 for IMU)
112 * @param chan The MAVLink channel this message will be sent over
113 * @param msg The MAVLink message to compress the data into
114 * @param time_usec Timestamp (UNIX)
115 * @param sensor_id Sensor ID
116 * @param flow_x Flow in pixels * 10 in x-sensor direction (dezi-pixels)
117 * @param flow_y Flow in pixels * 10 in y-sensor direction (dezi-pixels)
118 * @param flow_comp_m_x Flow in meters in x-sensor direction, angular-speed compensated
119 * @param flow_comp_m_y Flow in meters in y-sensor direction, angular-speed compensated
120 * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality
121 * @param ground_distance Ground distance in meters. Positive value: distance known. Negative value: Unknown distance
122 * @return length of the message in bytes (excluding serial stream start sign)
124 static inline uint16_t mavlink_msg_optical_flow_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
125 mavlink_message_t* msg,
126 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)
128 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
129 char buf[MAVLINK_MSG_ID_OPTICAL_FLOW_LEN];
130 _mav_put_uint64_t(buf, 0, time_usec);
131 _mav_put_float(buf, 8, flow_comp_m_x);
132 _mav_put_float(buf, 12, flow_comp_m_y);
133 _mav_put_float(buf, 16, ground_distance);
134 _mav_put_int16_t(buf, 20, flow_x);
135 _mav_put_int16_t(buf, 22, flow_y);
136 _mav_put_uint8_t(buf, 24, sensor_id);
137 _mav_put_uint8_t(buf, 25, quality);
139 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
140 #else
141 mavlink_optical_flow_t packet;
142 packet.time_usec = time_usec;
143 packet.flow_comp_m_x = flow_comp_m_x;
144 packet.flow_comp_m_y = flow_comp_m_y;
145 packet.ground_distance = ground_distance;
146 packet.flow_x = flow_x;
147 packet.flow_y = flow_y;
148 packet.sensor_id = sensor_id;
149 packet.quality = quality;
151 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
152 #endif
154 msg->msgid = MAVLINK_MSG_ID_OPTICAL_FLOW;
155 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);
159 * @brief Encode a optical_flow struct
161 * @param system_id ID of this system
162 * @param component_id ID of this component (e.g. 200 for IMU)
163 * @param msg The MAVLink message to compress the data into
164 * @param optical_flow C-struct to read the message contents from
166 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)
168 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);
172 * @brief Encode a optical_flow struct on a channel
174 * @param system_id ID of this system
175 * @param component_id ID of this component (e.g. 200 for IMU)
176 * @param chan The MAVLink channel this message will be sent over
177 * @param msg The MAVLink message to compress the data into
178 * @param optical_flow C-struct to read the message contents from
180 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)
182 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);
186 * @brief Send a optical_flow message
187 * @param chan MAVLink channel to send the message
189 * @param time_usec Timestamp (UNIX)
190 * @param sensor_id Sensor ID
191 * @param flow_x Flow in pixels * 10 in x-sensor direction (dezi-pixels)
192 * @param flow_y Flow in pixels * 10 in y-sensor direction (dezi-pixels)
193 * @param flow_comp_m_x Flow in meters in x-sensor direction, angular-speed compensated
194 * @param flow_comp_m_y Flow in meters in y-sensor direction, angular-speed compensated
195 * @param quality Optical flow quality / confidence. 0: bad, 255: maximum quality
196 * @param ground_distance Ground distance in meters. Positive value: distance known. Negative value: Unknown distance
198 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
200 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)
202 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
203 char buf[MAVLINK_MSG_ID_OPTICAL_FLOW_LEN];
204 _mav_put_uint64_t(buf, 0, time_usec);
205 _mav_put_float(buf, 8, flow_comp_m_x);
206 _mav_put_float(buf, 12, flow_comp_m_y);
207 _mav_put_float(buf, 16, ground_distance);
208 _mav_put_int16_t(buf, 20, flow_x);
209 _mav_put_int16_t(buf, 22, flow_y);
210 _mav_put_uint8_t(buf, 24, sensor_id);
211 _mav_put_uint8_t(buf, 25, quality);
213 _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);
214 #else
215 mavlink_optical_flow_t packet;
216 packet.time_usec = time_usec;
217 packet.flow_comp_m_x = flow_comp_m_x;
218 packet.flow_comp_m_y = flow_comp_m_y;
219 packet.ground_distance = ground_distance;
220 packet.flow_x = flow_x;
221 packet.flow_y = flow_y;
222 packet.sensor_id = sensor_id;
223 packet.quality = quality;
225 _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);
226 #endif
230 * @brief Send a optical_flow message
231 * @param chan MAVLink channel to send the message
232 * @param struct The MAVLink struct to serialize
234 static inline void mavlink_msg_optical_flow_send_struct(mavlink_channel_t chan, const mavlink_optical_flow_t* optical_flow)
236 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
237 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);
238 #else
239 _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);
240 #endif
243 #if MAVLINK_MSG_ID_OPTICAL_FLOW_LEN <= MAVLINK_MAX_PAYLOAD_LEN
245 This varient of _send() can be used to save stack space by re-using
246 memory from the receive buffer. The caller provides a
247 mavlink_message_t which is the size of a full mavlink message. This
248 is usually the receive buffer for the channel, and allows a reply to an
249 incoming message with minimum stack space usage.
251 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)
253 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
254 char *buf = (char *)msgbuf;
255 _mav_put_uint64_t(buf, 0, time_usec);
256 _mav_put_float(buf, 8, flow_comp_m_x);
257 _mav_put_float(buf, 12, flow_comp_m_y);
258 _mav_put_float(buf, 16, ground_distance);
259 _mav_put_int16_t(buf, 20, flow_x);
260 _mav_put_int16_t(buf, 22, flow_y);
261 _mav_put_uint8_t(buf, 24, sensor_id);
262 _mav_put_uint8_t(buf, 25, quality);
264 _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);
265 #else
266 mavlink_optical_flow_t *packet = (mavlink_optical_flow_t *)msgbuf;
267 packet->time_usec = time_usec;
268 packet->flow_comp_m_x = flow_comp_m_x;
269 packet->flow_comp_m_y = flow_comp_m_y;
270 packet->ground_distance = ground_distance;
271 packet->flow_x = flow_x;
272 packet->flow_y = flow_y;
273 packet->sensor_id = sensor_id;
274 packet->quality = quality;
276 _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);
277 #endif
279 #endif
281 #endif
283 // MESSAGE OPTICAL_FLOW UNPACKING
287 * @brief Get field time_usec from optical_flow message
289 * @return Timestamp (UNIX)
291 static inline uint64_t mavlink_msg_optical_flow_get_time_usec(const mavlink_message_t* msg)
293 return _MAV_RETURN_uint64_t(msg, 0);
297 * @brief Get field sensor_id from optical_flow message
299 * @return Sensor ID
301 static inline uint8_t mavlink_msg_optical_flow_get_sensor_id(const mavlink_message_t* msg)
303 return _MAV_RETURN_uint8_t(msg, 24);
307 * @brief Get field flow_x from optical_flow message
309 * @return Flow in pixels * 10 in x-sensor direction (dezi-pixels)
311 static inline int16_t mavlink_msg_optical_flow_get_flow_x(const mavlink_message_t* msg)
313 return _MAV_RETURN_int16_t(msg, 20);
317 * @brief Get field flow_y from optical_flow message
319 * @return Flow in pixels * 10 in y-sensor direction (dezi-pixels)
321 static inline int16_t mavlink_msg_optical_flow_get_flow_y(const mavlink_message_t* msg)
323 return _MAV_RETURN_int16_t(msg, 22);
327 * @brief Get field flow_comp_m_x from optical_flow message
329 * @return Flow in meters in x-sensor direction, angular-speed compensated
331 static inline float mavlink_msg_optical_flow_get_flow_comp_m_x(const mavlink_message_t* msg)
333 return _MAV_RETURN_float(msg, 8);
337 * @brief Get field flow_comp_m_y from optical_flow message
339 * @return Flow in meters in y-sensor direction, angular-speed compensated
341 static inline float mavlink_msg_optical_flow_get_flow_comp_m_y(const mavlink_message_t* msg)
343 return _MAV_RETURN_float(msg, 12);
347 * @brief Get field quality from optical_flow message
349 * @return Optical flow quality / confidence. 0: bad, 255: maximum quality
351 static inline uint8_t mavlink_msg_optical_flow_get_quality(const mavlink_message_t* msg)
353 return _MAV_RETURN_uint8_t(msg, 25);
357 * @brief Get field ground_distance from optical_flow message
359 * @return Ground distance in meters. Positive value: distance known. Negative value: Unknown distance
361 static inline float mavlink_msg_optical_flow_get_ground_distance(const mavlink_message_t* msg)
363 return _MAV_RETURN_float(msg, 16);
367 * @brief Decode a optical_flow message into a struct
369 * @param msg The message to decode
370 * @param optical_flow C-struct to decode the message contents into
372 static inline void mavlink_msg_optical_flow_decode(const mavlink_message_t* msg, mavlink_optical_flow_t* optical_flow)
374 #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
375 optical_flow->time_usec = mavlink_msg_optical_flow_get_time_usec(msg);
376 optical_flow->flow_comp_m_x = mavlink_msg_optical_flow_get_flow_comp_m_x(msg);
377 optical_flow->flow_comp_m_y = mavlink_msg_optical_flow_get_flow_comp_m_y(msg);
378 optical_flow->ground_distance = mavlink_msg_optical_flow_get_ground_distance(msg);
379 optical_flow->flow_x = mavlink_msg_optical_flow_get_flow_x(msg);
380 optical_flow->flow_y = mavlink_msg_optical_flow_get_flow_y(msg);
381 optical_flow->sensor_id = mavlink_msg_optical_flow_get_sensor_id(msg);
382 optical_flow->quality = mavlink_msg_optical_flow_get_quality(msg);
383 #else
384 uint8_t len = msg->len < MAVLINK_MSG_ID_OPTICAL_FLOW_LEN? msg->len : MAVLINK_MSG_ID_OPTICAL_FLOW_LEN;
385 memset(optical_flow, 0, MAVLINK_MSG_ID_OPTICAL_FLOW_LEN);
386 memcpy(optical_flow, _MAV_PAYLOAD(msg), len);
387 #endif