source: flair-src/branches/mavlink/tools/Controller/Mavlink/src/include/common/mavlink_msg_optical_flow.h@ 75

Last change on this file since 75 was 75, checked in by Thomas Fuhrmann, 8 years ago

Change the version of mavlink generated messages and rename it to include

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