Arduino Mavlink
Loading...
Searching...
No Matches
mavlink_msg_distance_sensor.h
Go to the documentation of this file.
1#pragma once
2// MESSAGE DISTANCE_SENSOR PACKING
3
4#define MAVLINK_MSG_ID_DISTANCE_SENSOR 132
5
6MAVPACKED(
7typedef struct __mavlink_distance_sensor_t {
8 uint32_t time_boot_ms; /*< [ms] Timestamp (time since system boot).*/
9 uint16_t min_distance; /*< [cm] Minimum distance the sensor can measure*/
10 uint16_t max_distance; /*< [cm] Maximum distance the sensor can measure*/
11 uint16_t current_distance; /*< [cm] Current distance reading*/
12 uint8_t type; /*< Type of distance sensor.*/
13 uint8_t id; /*< Onboard ID of the sensor*/
14 uint8_t orientation; /*< Direction the sensor faces. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270*/
15 uint8_t covariance; /*< [cm^2] Measurement variance. Max standard deviation is 6cm. UINT8_MAX if unknown.*/
16 float horizontal_fov; /*< [rad] Horizontal Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.*/
17 float vertical_fov; /*< [rad] Vertical Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.*/
18 float quaternion[4]; /*< Quaternion of the sensor orientation in vehicle body frame (w, x, y, z order, zero-rotation is 1, 0, 0, 0). Zero-rotation is along the vehicle body x-axis. This field is required if the orientation is set to MAV_SENSOR_ROTATION_CUSTOM. Set it to 0 if invalid."*/
19 uint8_t signal_quality; /*< [%] Signal quality of the sensor. Specific to each sensor type, representing the relation of the signal strength with the target reflectivity, distance, size or aspect, but normalised as a percentage. 0 = unknown/unset signal quality, 1 = invalid signal, 100 = perfect signal.*/
20}) mavlink_distance_sensor_t;
21
22#define MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN 39
23#define MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN 14
24#define MAVLINK_MSG_ID_132_LEN 39
25#define MAVLINK_MSG_ID_132_MIN_LEN 14
26
27#define MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC 85
28#define MAVLINK_MSG_ID_132_CRC 85
29
30#define MAVLINK_MSG_DISTANCE_SENSOR_FIELD_QUATERNION_LEN 4
31
32#if MAVLINK_COMMAND_24BIT
33#define MAVLINK_MESSAGE_INFO_DISTANCE_SENSOR {
34 132,
35 "DISTANCE_SENSOR",
36 12,
37 { { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_distance_sensor_t, time_boot_ms) },
38 { "min_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_distance_sensor_t, min_distance) },
39 { "max_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_distance_sensor_t, max_distance) },
40 { "current_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_distance_sensor_t, current_distance) },
41 { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 10, offsetof(mavlink_distance_sensor_t, type) },
42 { "id", NULL, MAVLINK_TYPE_UINT8_T, 0, 11, offsetof(mavlink_distance_sensor_t, id) },
43 { "orientation", NULL, MAVLINK_TYPE_UINT8_T, 0, 12, offsetof(mavlink_distance_sensor_t, orientation) },
44 { "covariance", NULL, MAVLINK_TYPE_UINT8_T, 0, 13, offsetof(mavlink_distance_sensor_t, covariance) },
45 { "horizontal_fov", NULL, MAVLINK_TYPE_FLOAT, 0, 14, offsetof(mavlink_distance_sensor_t, horizontal_fov) },
46 { "vertical_fov", NULL, MAVLINK_TYPE_FLOAT, 0, 18, offsetof(mavlink_distance_sensor_t, vertical_fov) },
47 { "quaternion", NULL, MAVLINK_TYPE_FLOAT, 4, 22, offsetof(mavlink_distance_sensor_t, quaternion) },
48 { "signal_quality", NULL, MAVLINK_TYPE_UINT8_T, 0, 38, offsetof(mavlink_distance_sensor_t, signal_quality) },
49 } \
50}
51#else
52#define MAVLINK_MESSAGE_INFO_DISTANCE_SENSOR {
53 "DISTANCE_SENSOR",
54 12,
55 { { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_distance_sensor_t, time_boot_ms) },
56 { "min_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_distance_sensor_t, min_distance) },
57 { "max_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_distance_sensor_t, max_distance) },
58 { "current_distance", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_distance_sensor_t, current_distance) },
59 { "type", NULL, MAVLINK_TYPE_UINT8_T, 0, 10, offsetof(mavlink_distance_sensor_t, type) },
60 { "id", NULL, MAVLINK_TYPE_UINT8_T, 0, 11, offsetof(mavlink_distance_sensor_t, id) },
61 { "orientation", NULL, MAVLINK_TYPE_UINT8_T, 0, 12, offsetof(mavlink_distance_sensor_t, orientation) },
62 { "covariance", NULL, MAVLINK_TYPE_UINT8_T, 0, 13, offsetof(mavlink_distance_sensor_t, covariance) },
63 { "horizontal_fov", NULL, MAVLINK_TYPE_FLOAT, 0, 14, offsetof(mavlink_distance_sensor_t, horizontal_fov) },
64 { "vertical_fov", NULL, MAVLINK_TYPE_FLOAT, 0, 18, offsetof(mavlink_distance_sensor_t, vertical_fov) },
65 { "quaternion", NULL, MAVLINK_TYPE_FLOAT, 4, 22, offsetof(mavlink_distance_sensor_t, quaternion) },
66 { "signal_quality", NULL, MAVLINK_TYPE_UINT8_T, 0, 38, offsetof(mavlink_distance_sensor_t, signal_quality) },
67 } \
68}
69#endif
70
71/**
72 * @brief Pack a distance_sensor message
73 * @param system_id ID of this system
74 * @param component_id ID of this component (e.g. 200 for IMU)
75 * @param msg The MAVLink message to compress the data into
76 *
77 * @param time_boot_ms [ms] Timestamp (time since system boot).
78 * @param min_distance [cm] Minimum distance the sensor can measure
79 * @param max_distance [cm] Maximum distance the sensor can measure
80 * @param current_distance [cm] Current distance reading
81 * @param type Type of distance sensor.
82 * @param id Onboard ID of the sensor
83 * @param orientation Direction the sensor faces. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270
84 * @param covariance [cm^2] Measurement variance. Max standard deviation is 6cm. UINT8_MAX if unknown.
85 * @param horizontal_fov [rad] Horizontal Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.
86 * @param vertical_fov [rad] Vertical Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.
87 * @param quaternion Quaternion of the sensor orientation in vehicle body frame (w, x, y, z order, zero-rotation is 1, 0, 0, 0). Zero-rotation is along the vehicle body x-axis. This field is required if the orientation is set to MAV_SENSOR_ROTATION_CUSTOM. Set it to 0 if invalid."
88 * @param signal_quality [%] Signal quality of the sensor. Specific to each sensor type, representing the relation of the signal strength with the target reflectivity, distance, size or aspect, but normalised as a percentage. 0 = unknown/unset signal quality, 1 = invalid signal, 100 = perfect signal.
89 * @return length of the message in bytes (excluding serial stream start sign)
90 */
91static inline uint16_t mavlink_msg_distance_sensor_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
92 uint32_t time_boot_ms, uint16_t min_distance, uint16_t max_distance, uint16_t current_distance, uint8_t type, uint8_t id, uint8_t orientation, uint8_t covariance, float horizontal_fov, float vertical_fov, const float *quaternion, uint8_t signal_quality)
93{
94#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
96 _mav_put_uint32_t(buf, 0, time_boot_ms);
97 _mav_put_uint16_t(buf, 4, min_distance);
98 _mav_put_uint16_t(buf, 6, max_distance);
99 _mav_put_uint16_t(buf, 8, current_distance);
100 _mav_put_uint8_t(buf, 10, type);
101 _mav_put_uint8_t(buf, 11, id);
102 _mav_put_uint8_t(buf, 12, orientation);
103 _mav_put_uint8_t(buf, 13, covariance);
104 _mav_put_float(buf, 14, horizontal_fov);
105 _mav_put_float(buf, 18, vertical_fov);
106 _mav_put_uint8_t(buf, 38, signal_quality);
107 _mav_put_float_array(buf, 22, quaternion, 4);
108 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
109#else
110 mavlink_distance_sensor_t packet;
111 packet.time_boot_ms = time_boot_ms;
112 packet.min_distance = min_distance;
113 packet.max_distance = max_distance;
114 packet.current_distance = current_distance;
115 packet.type = type;
116 packet.id = id;
117 packet.orientation = orientation;
118 packet.covariance = covariance;
119 packet.horizontal_fov = horizontal_fov;
120 packet.vertical_fov = vertical_fov;
121 packet.signal_quality = signal_quality;
122 mav_array_memcpy(packet.quaternion, quaternion, sizeof(float)*4);
123 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
124#endif
125
127 return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC);
128}
129
130/**
131 * @brief Pack a distance_sensor message
132 * @param system_id ID of this system
133 * @param component_id ID of this component (e.g. 200 for IMU)
134 * @param status MAVLink status structure
135 * @param msg The MAVLink message to compress the data into
136 *
137 * @param time_boot_ms [ms] Timestamp (time since system boot).
138 * @param min_distance [cm] Minimum distance the sensor can measure
139 * @param max_distance [cm] Maximum distance the sensor can measure
140 * @param current_distance [cm] Current distance reading
141 * @param type Type of distance sensor.
142 * @param id Onboard ID of the sensor
143 * @param orientation Direction the sensor faces. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270
144 * @param covariance [cm^2] Measurement variance. Max standard deviation is 6cm. UINT8_MAX if unknown.
145 * @param horizontal_fov [rad] Horizontal Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.
146 * @param vertical_fov [rad] Vertical Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.
147 * @param quaternion Quaternion of the sensor orientation in vehicle body frame (w, x, y, z order, zero-rotation is 1, 0, 0, 0). Zero-rotation is along the vehicle body x-axis. This field is required if the orientation is set to MAV_SENSOR_ROTATION_CUSTOM. Set it to 0 if invalid."
148 * @param signal_quality [%] Signal quality of the sensor. Specific to each sensor type, representing the relation of the signal strength with the target reflectivity, distance, size or aspect, but normalised as a percentage. 0 = unknown/unset signal quality, 1 = invalid signal, 100 = perfect signal.
149 * @return length of the message in bytes (excluding serial stream start sign)
150 */
151static inline uint16_t mavlink_msg_distance_sensor_pack_status(uint8_t system_id, uint8_t component_id, mavlink_status_t *_status, mavlink_message_t* msg,
152 uint32_t time_boot_ms, uint16_t min_distance, uint16_t max_distance, uint16_t current_distance, uint8_t type, uint8_t id, uint8_t orientation, uint8_t covariance, float horizontal_fov, float vertical_fov, const float *quaternion, uint8_t signal_quality)
153{
154#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
156 _mav_put_uint32_t(buf, 0, time_boot_ms);
157 _mav_put_uint16_t(buf, 4, min_distance);
158 _mav_put_uint16_t(buf, 6, max_distance);
159 _mav_put_uint16_t(buf, 8, current_distance);
160 _mav_put_uint8_t(buf, 10, type);
161 _mav_put_uint8_t(buf, 11, id);
162 _mav_put_uint8_t(buf, 12, orientation);
163 _mav_put_uint8_t(buf, 13, covariance);
164 _mav_put_float(buf, 14, horizontal_fov);
165 _mav_put_float(buf, 18, vertical_fov);
166 _mav_put_uint8_t(buf, 38, signal_quality);
167 _mav_put_float_array(buf, 22, quaternion, 4);
168 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
169#else
170 mavlink_distance_sensor_t packet;
171 packet.time_boot_ms = time_boot_ms;
172 packet.min_distance = min_distance;
173 packet.max_distance = max_distance;
174 packet.current_distance = current_distance;
175 packet.type = type;
176 packet.id = id;
177 packet.orientation = orientation;
178 packet.covariance = covariance;
179 packet.horizontal_fov = horizontal_fov;
180 packet.vertical_fov = vertical_fov;
181 packet.signal_quality = signal_quality;
182 mav_array_memcpy(packet.quaternion, quaternion, sizeof(float)*4);
183 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
184#endif
185
187#if MAVLINK_CRC_EXTRA
188 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC);
189#else
190 return mavlink_finalize_message_buffer(msg, system_id, component_id, _status, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
191#endif
192}
193
194/**
195 * @brief Pack a distance_sensor message on a channel
196 * @param system_id ID of this system
197 * @param component_id ID of this component (e.g. 200 for IMU)
198 * @param chan The MAVLink channel this message will be sent over
199 * @param msg The MAVLink message to compress the data into
200 * @param time_boot_ms [ms] Timestamp (time since system boot).
201 * @param min_distance [cm] Minimum distance the sensor can measure
202 * @param max_distance [cm] Maximum distance the sensor can measure
203 * @param current_distance [cm] Current distance reading
204 * @param type Type of distance sensor.
205 * @param id Onboard ID of the sensor
206 * @param orientation Direction the sensor faces. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270
207 * @param covariance [cm^2] Measurement variance. Max standard deviation is 6cm. UINT8_MAX if unknown.
208 * @param horizontal_fov [rad] Horizontal Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.
209 * @param vertical_fov [rad] Vertical Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.
210 * @param quaternion Quaternion of the sensor orientation in vehicle body frame (w, x, y, z order, zero-rotation is 1, 0, 0, 0). Zero-rotation is along the vehicle body x-axis. This field is required if the orientation is set to MAV_SENSOR_ROTATION_CUSTOM. Set it to 0 if invalid."
211 * @param signal_quality [%] Signal quality of the sensor. Specific to each sensor type, representing the relation of the signal strength with the target reflectivity, distance, size or aspect, but normalised as a percentage. 0 = unknown/unset signal quality, 1 = invalid signal, 100 = perfect signal.
212 * @return length of the message in bytes (excluding serial stream start sign)
213 */
214static inline uint16_t mavlink_msg_distance_sensor_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
215 mavlink_message_t* msg,
216 uint32_t time_boot_ms,uint16_t min_distance,uint16_t max_distance,uint16_t current_distance,uint8_t type,uint8_t id,uint8_t orientation,uint8_t covariance,float horizontal_fov,float vertical_fov,const float *quaternion,uint8_t signal_quality)
217{
218#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
220 _mav_put_uint32_t(buf, 0, time_boot_ms);
221 _mav_put_uint16_t(buf, 4, min_distance);
222 _mav_put_uint16_t(buf, 6, max_distance);
223 _mav_put_uint16_t(buf, 8, current_distance);
224 _mav_put_uint8_t(buf, 10, type);
225 _mav_put_uint8_t(buf, 11, id);
226 _mav_put_uint8_t(buf, 12, orientation);
227 _mav_put_uint8_t(buf, 13, covariance);
228 _mav_put_float(buf, 14, horizontal_fov);
229 _mav_put_float(buf, 18, vertical_fov);
230 _mav_put_uint8_t(buf, 38, signal_quality);
231 _mav_put_float_array(buf, 22, quaternion, 4);
232 memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
233#else
234 mavlink_distance_sensor_t packet;
235 packet.time_boot_ms = time_boot_ms;
236 packet.min_distance = min_distance;
237 packet.max_distance = max_distance;
238 packet.current_distance = current_distance;
239 packet.type = type;
240 packet.id = id;
241 packet.orientation = orientation;
242 packet.covariance = covariance;
243 packet.horizontal_fov = horizontal_fov;
244 packet.vertical_fov = vertical_fov;
245 packet.signal_quality = signal_quality;
246 mav_array_memcpy(packet.quaternion, quaternion, sizeof(float)*4);
247 memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
248#endif
249
251 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC);
252}
253
254/**
255 * @brief Encode a distance_sensor struct
256 *
257 * @param system_id ID of this system
258 * @param component_id ID of this component (e.g. 200 for IMU)
259 * @param msg The MAVLink message to compress the data into
260 * @param distance_sensor C-struct to read the message contents from
261 */
262static inline uint16_t mavlink_msg_distance_sensor_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_distance_sensor_t* distance_sensor)
263{
264 return mavlink_msg_distance_sensor_pack(system_id, component_id, msg, distance_sensor->time_boot_ms, distance_sensor->min_distance, distance_sensor->max_distance, distance_sensor->current_distance, distance_sensor->type, distance_sensor->id, distance_sensor->orientation, distance_sensor->covariance, distance_sensor->horizontal_fov, distance_sensor->vertical_fov, distance_sensor->quaternion, distance_sensor->signal_quality);
265}
266
267/**
268 * @brief Encode a distance_sensor struct on a channel
269 *
270 * @param system_id ID of this system
271 * @param component_id ID of this component (e.g. 200 for IMU)
272 * @param chan The MAVLink channel this message will be sent over
273 * @param msg The MAVLink message to compress the data into
274 * @param distance_sensor C-struct to read the message contents from
275 */
276static inline uint16_t mavlink_msg_distance_sensor_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_distance_sensor_t* distance_sensor)
277{
278 return mavlink_msg_distance_sensor_pack_chan(system_id, component_id, chan, msg, distance_sensor->time_boot_ms, distance_sensor->min_distance, distance_sensor->max_distance, distance_sensor->current_distance, distance_sensor->type, distance_sensor->id, distance_sensor->orientation, distance_sensor->covariance, distance_sensor->horizontal_fov, distance_sensor->vertical_fov, distance_sensor->quaternion, distance_sensor->signal_quality);
279}
280
281/**
282 * @brief Encode a distance_sensor struct with provided status structure
283 *
284 * @param system_id ID of this system
285 * @param component_id ID of this component (e.g. 200 for IMU)
286 * @param status MAVLink status structure
287 * @param msg The MAVLink message to compress the data into
288 * @param distance_sensor C-struct to read the message contents from
289 */
290static inline uint16_t mavlink_msg_distance_sensor_encode_status(uint8_t system_id, uint8_t component_id, mavlink_status_t* _status, mavlink_message_t* msg, const mavlink_distance_sensor_t* distance_sensor)
291{
292 return mavlink_msg_distance_sensor_pack_status(system_id, component_id, _status, msg, distance_sensor->time_boot_ms, distance_sensor->min_distance, distance_sensor->max_distance, distance_sensor->current_distance, distance_sensor->type, distance_sensor->id, distance_sensor->orientation, distance_sensor->covariance, distance_sensor->horizontal_fov, distance_sensor->vertical_fov, distance_sensor->quaternion, distance_sensor->signal_quality);
293}
294
295/**
296 * @brief Send a distance_sensor message
297 * @param chan MAVLink channel to send the message
298 *
299 * @param time_boot_ms [ms] Timestamp (time since system boot).
300 * @param min_distance [cm] Minimum distance the sensor can measure
301 * @param max_distance [cm] Maximum distance the sensor can measure
302 * @param current_distance [cm] Current distance reading
303 * @param type Type of distance sensor.
304 * @param id Onboard ID of the sensor
305 * @param orientation Direction the sensor faces. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270
306 * @param covariance [cm^2] Measurement variance. Max standard deviation is 6cm. UINT8_MAX if unknown.
307 * @param horizontal_fov [rad] Horizontal Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.
308 * @param vertical_fov [rad] Vertical Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.
309 * @param quaternion Quaternion of the sensor orientation in vehicle body frame (w, x, y, z order, zero-rotation is 1, 0, 0, 0). Zero-rotation is along the vehicle body x-axis. This field is required if the orientation is set to MAV_SENSOR_ROTATION_CUSTOM. Set it to 0 if invalid."
310 * @param signal_quality [%] Signal quality of the sensor. Specific to each sensor type, representing the relation of the signal strength with the target reflectivity, distance, size or aspect, but normalised as a percentage. 0 = unknown/unset signal quality, 1 = invalid signal, 100 = perfect signal.
311 */
312#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
313
314static inline void mavlink_msg_distance_sensor_send(mavlink_channel_t chan, uint32_t time_boot_ms, uint16_t min_distance, uint16_t max_distance, uint16_t current_distance, uint8_t type, uint8_t id, uint8_t orientation, uint8_t covariance, float horizontal_fov, float vertical_fov, const float *quaternion, uint8_t signal_quality)
315{
316#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
317 char buf[MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN];
318 _mav_put_uint32_t(buf, 0, time_boot_ms);
319 _mav_put_uint16_t(buf, 4, min_distance);
320 _mav_put_uint16_t(buf, 6, max_distance);
321 _mav_put_uint16_t(buf, 8, current_distance);
322 _mav_put_uint8_t(buf, 10, type);
323 _mav_put_uint8_t(buf, 11, id);
324 _mav_put_uint8_t(buf, 12, orientation);
325 _mav_put_uint8_t(buf, 13, covariance);
326 _mav_put_float(buf, 14, horizontal_fov);
327 _mav_put_float(buf, 18, vertical_fov);
328 _mav_put_uint8_t(buf, 38, signal_quality);
329 _mav_put_float_array(buf, 22, quaternion, 4);
330 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DISTANCE_SENSOR, buf, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC);
331#else
332 mavlink_distance_sensor_t packet;
333 packet.time_boot_ms = time_boot_ms;
334 packet.min_distance = min_distance;
335 packet.max_distance = max_distance;
336 packet.current_distance = current_distance;
337 packet.type = type;
338 packet.id = id;
339 packet.orientation = orientation;
340 packet.covariance = covariance;
341 packet.horizontal_fov = horizontal_fov;
342 packet.vertical_fov = vertical_fov;
343 packet.signal_quality = signal_quality;
344 mav_array_memcpy(packet.quaternion, quaternion, sizeof(float)*4);
345 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DISTANCE_SENSOR, (const char *)&packet, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC);
346#endif
347}
348
349/**
350 * @brief Send a distance_sensor message
351 * @param chan MAVLink channel to send the message
352 * @param struct The MAVLink struct to serialize
353 */
354static inline void mavlink_msg_distance_sensor_send_struct(mavlink_channel_t chan, const mavlink_distance_sensor_t* distance_sensor)
355{
356#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
357 mavlink_msg_distance_sensor_send(chan, distance_sensor->time_boot_ms, distance_sensor->min_distance, distance_sensor->max_distance, distance_sensor->current_distance, distance_sensor->type, distance_sensor->id, distance_sensor->orientation, distance_sensor->covariance, distance_sensor->horizontal_fov, distance_sensor->vertical_fov, distance_sensor->quaternion, distance_sensor->signal_quality);
358#else
359 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DISTANCE_SENSOR, (const char *)distance_sensor, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC);
360#endif
361}
362
363#if MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN <= MAVLINK_MAX_PAYLOAD_LEN
364/*
365 This variant of _send() can be used to save stack space by reusing
366 memory from the receive buffer. The caller provides a
367 mavlink_message_t which is the size of a full mavlink message. This
368 is usually the receive buffer for the channel, and allows a reply to an
369 incoming message with minimum stack space usage.
370 */
371static inline void mavlink_msg_distance_sensor_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint32_t time_boot_ms, uint16_t min_distance, uint16_t max_distance, uint16_t current_distance, uint8_t type, uint8_t id, uint8_t orientation, uint8_t covariance, float horizontal_fov, float vertical_fov, const float *quaternion, uint8_t signal_quality)
372{
373#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
374 char *buf = (char *)msgbuf;
375 _mav_put_uint32_t(buf, 0, time_boot_ms);
376 _mav_put_uint16_t(buf, 4, min_distance);
377 _mav_put_uint16_t(buf, 6, max_distance);
378 _mav_put_uint16_t(buf, 8, current_distance);
379 _mav_put_uint8_t(buf, 10, type);
380 _mav_put_uint8_t(buf, 11, id);
381 _mav_put_uint8_t(buf, 12, orientation);
382 _mav_put_uint8_t(buf, 13, covariance);
383 _mav_put_float(buf, 14, horizontal_fov);
384 _mav_put_float(buf, 18, vertical_fov);
385 _mav_put_uint8_t(buf, 38, signal_quality);
386 _mav_put_float_array(buf, 22, quaternion, 4);
387 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DISTANCE_SENSOR, buf, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC);
388#else
389 mavlink_distance_sensor_t *packet = (mavlink_distance_sensor_t *)msgbuf;
390 packet->time_boot_ms = time_boot_ms;
391 packet->min_distance = min_distance;
392 packet->max_distance = max_distance;
393 packet->current_distance = current_distance;
394 packet->type = type;
395 packet->id = id;
396 packet->orientation = orientation;
397 packet->covariance = covariance;
398 packet->horizontal_fov = horizontal_fov;
399 packet->vertical_fov = vertical_fov;
400 packet->signal_quality = signal_quality;
401 mav_array_memcpy(packet->quaternion, quaternion, sizeof(float)*4);
402 _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_DISTANCE_SENSOR, (const char *)packet, MAVLINK_MSG_ID_DISTANCE_SENSOR_MIN_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN, MAVLINK_MSG_ID_DISTANCE_SENSOR_CRC);
403#endif
404}
405#endif
406
407#endif
408
409// MESSAGE DISTANCE_SENSOR UNPACKING
410
411
412/**
413 * @brief Get field time_boot_ms from distance_sensor message
414 *
415 * @return [ms] Timestamp (time since system boot).
416 */
417static inline uint32_t mavlink_msg_distance_sensor_get_time_boot_ms(const mavlink_message_t* msg)
418{
419 return _MAV_RETURN_uint32_t(msg, 0);
420}
421
422/**
423 * @brief Get field min_distance from distance_sensor message
424 *
425 * @return [cm] Minimum distance the sensor can measure
426 */
427static inline uint16_t mavlink_msg_distance_sensor_get_min_distance(const mavlink_message_t* msg)
428{
429 return _MAV_RETURN_uint16_t(msg, 4);
430}
431
432/**
433 * @brief Get field max_distance from distance_sensor message
434 *
435 * @return [cm] Maximum distance the sensor can measure
436 */
437static inline uint16_t mavlink_msg_distance_sensor_get_max_distance(const mavlink_message_t* msg)
438{
439 return _MAV_RETURN_uint16_t(msg, 6);
440}
441
442/**
443 * @brief Get field current_distance from distance_sensor message
444 *
445 * @return [cm] Current distance reading
446 */
447static inline uint16_t mavlink_msg_distance_sensor_get_current_distance(const mavlink_message_t* msg)
448{
449 return _MAV_RETURN_uint16_t(msg, 8);
450}
451
452/**
453 * @brief Get field type from distance_sensor message
454 *
455 * @return Type of distance sensor.
456 */
457static inline uint8_t mavlink_msg_distance_sensor_get_type(const mavlink_message_t* msg)
458{
459 return _MAV_RETURN_uint8_t(msg, 10);
460}
461
462/**
463 * @brief Get field id from distance_sensor message
464 *
465 * @return Onboard ID of the sensor
466 */
467static inline uint8_t mavlink_msg_distance_sensor_get_id(const mavlink_message_t* msg)
468{
469 return _MAV_RETURN_uint8_t(msg, 11);
470}
471
472/**
473 * @brief Get field orientation from distance_sensor message
474 *
475 * @return Direction the sensor faces. downward-facing: ROTATION_PITCH_270, upward-facing: ROTATION_PITCH_90, backward-facing: ROTATION_PITCH_180, forward-facing: ROTATION_NONE, left-facing: ROTATION_YAW_90, right-facing: ROTATION_YAW_270
476 */
477static inline uint8_t mavlink_msg_distance_sensor_get_orientation(const mavlink_message_t* msg)
478{
479 return _MAV_RETURN_uint8_t(msg, 12);
480}
481
482/**
483 * @brief Get field covariance from distance_sensor message
484 *
485 * @return [cm^2] Measurement variance. Max standard deviation is 6cm. UINT8_MAX if unknown.
486 */
487static inline uint8_t mavlink_msg_distance_sensor_get_covariance(const mavlink_message_t* msg)
488{
489 return _MAV_RETURN_uint8_t(msg, 13);
490}
491
492/**
493 * @brief Get field horizontal_fov from distance_sensor message
494 *
495 * @return [rad] Horizontal Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.
496 */
497static inline float mavlink_msg_distance_sensor_get_horizontal_fov(const mavlink_message_t* msg)
498{
499 return _MAV_RETURN_float(msg, 14);
500}
501
502/**
503 * @brief Get field vertical_fov from distance_sensor message
504 *
505 * @return [rad] Vertical Field of View (angle) where the distance measurement is valid and the field of view is known. Otherwise this is set to 0.
506 */
507static inline float mavlink_msg_distance_sensor_get_vertical_fov(const mavlink_message_t* msg)
508{
509 return _MAV_RETURN_float(msg, 18);
510}
511
512/**
513 * @brief Get field quaternion from distance_sensor message
514 *
515 * @return Quaternion of the sensor orientation in vehicle body frame (w, x, y, z order, zero-rotation is 1, 0, 0, 0). Zero-rotation is along the vehicle body x-axis. This field is required if the orientation is set to MAV_SENSOR_ROTATION_CUSTOM. Set it to 0 if invalid."
516 */
517static inline uint16_t mavlink_msg_distance_sensor_get_quaternion(const mavlink_message_t* msg, float *quaternion)
518{
519 return _MAV_RETURN_float_array(msg, quaternion, 4, 22);
520}
521
522/**
523 * @brief Get field signal_quality from distance_sensor message
524 *
525 * @return [%] Signal quality of the sensor. Specific to each sensor type, representing the relation of the signal strength with the target reflectivity, distance, size or aspect, but normalised as a percentage. 0 = unknown/unset signal quality, 1 = invalid signal, 100 = perfect signal.
526 */
527static inline uint8_t mavlink_msg_distance_sensor_get_signal_quality(const mavlink_message_t* msg)
528{
529 return _MAV_RETURN_uint8_t(msg, 38);
530}
531
532/**
533 * @brief Decode a distance_sensor message into a struct
534 *
535 * @param msg The message to decode
536 * @param distance_sensor C-struct to decode the message contents into
537 */
538static inline void mavlink_msg_distance_sensor_decode(const mavlink_message_t* msg, mavlink_distance_sensor_t* distance_sensor)
539{
540#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
541 distance_sensor->time_boot_ms = mavlink_msg_distance_sensor_get_time_boot_ms(msg);
542 distance_sensor->min_distance = mavlink_msg_distance_sensor_get_min_distance(msg);
543 distance_sensor->max_distance = mavlink_msg_distance_sensor_get_max_distance(msg);
544 distance_sensor->current_distance = mavlink_msg_distance_sensor_get_current_distance(msg);
545 distance_sensor->type = mavlink_msg_distance_sensor_get_type(msg);
546 distance_sensor->id = mavlink_msg_distance_sensor_get_id(msg);
547 distance_sensor->orientation = mavlink_msg_distance_sensor_get_orientation(msg);
548 distance_sensor->covariance = mavlink_msg_distance_sensor_get_covariance(msg);
549 distance_sensor->horizontal_fov = mavlink_msg_distance_sensor_get_horizontal_fov(msg);
550 distance_sensor->vertical_fov = mavlink_msg_distance_sensor_get_vertical_fov(msg);
551 mavlink_msg_distance_sensor_get_quaternion(msg, distance_sensor->quaternion);
552 distance_sensor->signal_quality = mavlink_msg_distance_sensor_get_signal_quality(msg);
553#else
554 uint8_t len = msg->len < MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN? msg->len : MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN;
555 memset(distance_sensor, 0, MAVLINK_MSG_ID_DISTANCE_SENSOR_LEN);
556 memcpy(distance_sensor, _MAV_PAYLOAD(msg), len);
557#endif
558}