Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.
Dependencies: Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo
mavlink_msg_marker.h
00001 // MESSAGE MARKER PACKING 00002 00003 #define MAVLINK_MSG_ID_MARKER 130 00004 00005 typedef struct __mavlink_marker_t 00006 { 00007 uint16_t id; ///< ID 00008 float x; ///< x position 00009 float y; ///< y position 00010 float z; ///< z position 00011 float roll; ///< roll orientation 00012 float pitch; ///< pitch orientation 00013 float yaw; ///< yaw orientation 00014 00015 } mavlink_marker_t; 00016 00017 00018 00019 /** 00020 * @brief Pack a marker message 00021 * @param system_id ID of this system 00022 * @param component_id ID of this component (e.g. 200 for IMU) 00023 * @param msg The MAVLink message to compress the data into 00024 * 00025 * @param id ID 00026 * @param x x position 00027 * @param y y position 00028 * @param z z position 00029 * @param roll roll orientation 00030 * @param pitch pitch orientation 00031 * @param yaw yaw orientation 00032 * @return length of the message in bytes (excluding serial stream start sign) 00033 */ 00034 static inline uint16_t mavlink_msg_marker_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint16_t id, float x, float y, float z, float roll, float pitch, float yaw) 00035 { 00036 uint16_t i = 0; 00037 msg->msgid = MAVLINK_MSG_ID_MARKER; 00038 00039 i += put_uint16_t_by_index(id, i, msg->payload); // ID 00040 i += put_float_by_index(x, i, msg->payload); // x position 00041 i += put_float_by_index(y, i, msg->payload); // y position 00042 i += put_float_by_index(z, i, msg->payload); // z position 00043 i += put_float_by_index(roll, i, msg->payload); // roll orientation 00044 i += put_float_by_index(pitch, i, msg->payload); // pitch orientation 00045 i += put_float_by_index(yaw, i, msg->payload); // yaw orientation 00046 00047 return mavlink_finalize_message(msg, system_id, component_id, i); 00048 } 00049 00050 /** 00051 * @brief Pack a marker message 00052 * @param system_id ID of this system 00053 * @param component_id ID of this component (e.g. 200 for IMU) 00054 * @param chan The MAVLink channel this message was sent over 00055 * @param msg The MAVLink message to compress the data into 00056 * @param id ID 00057 * @param x x position 00058 * @param y y position 00059 * @param z z position 00060 * @param roll roll orientation 00061 * @param pitch pitch orientation 00062 * @param yaw yaw orientation 00063 * @return length of the message in bytes (excluding serial stream start sign) 00064 */ 00065 static inline uint16_t mavlink_msg_marker_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, uint16_t id, float x, float y, float z, float roll, float pitch, float yaw) 00066 { 00067 uint16_t i = 0; 00068 msg->msgid = MAVLINK_MSG_ID_MARKER; 00069 00070 i += put_uint16_t_by_index(id, i, msg->payload); // ID 00071 i += put_float_by_index(x, i, msg->payload); // x position 00072 i += put_float_by_index(y, i, msg->payload); // y position 00073 i += put_float_by_index(z, i, msg->payload); // z position 00074 i += put_float_by_index(roll, i, msg->payload); // roll orientation 00075 i += put_float_by_index(pitch, i, msg->payload); // pitch orientation 00076 i += put_float_by_index(yaw, i, msg->payload); // yaw orientation 00077 00078 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, i); 00079 } 00080 00081 /** 00082 * @brief Encode a marker struct into a message 00083 * 00084 * @param system_id ID of this system 00085 * @param component_id ID of this component (e.g. 200 for IMU) 00086 * @param msg The MAVLink message to compress the data into 00087 * @param marker C-struct to read the message contents from 00088 */ 00089 static inline uint16_t mavlink_msg_marker_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_marker_t* marker) 00090 { 00091 return mavlink_msg_marker_pack(system_id, component_id, msg, marker->id, marker->x, marker->y, marker->z, marker->roll, marker->pitch, marker->yaw); 00092 } 00093 00094 /** 00095 * @brief Send a marker message 00096 * @param chan MAVLink channel to send the message 00097 * 00098 * @param id ID 00099 * @param x x position 00100 * @param y y position 00101 * @param z z position 00102 * @param roll roll orientation 00103 * @param pitch pitch orientation 00104 * @param yaw yaw orientation 00105 */ 00106 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS 00107 00108 static inline void mavlink_msg_marker_send(mavlink_channel_t chan, uint16_t id, float x, float y, float z, float roll, float pitch, float yaw) 00109 { 00110 mavlink_message_t msg; 00111 mavlink_msg_marker_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg, id, x, y, z, roll, pitch, yaw); 00112 mavlink_send_uart(chan, &msg); 00113 } 00114 00115 #endif 00116 // MESSAGE MARKER UNPACKING 00117 00118 /** 00119 * @brief Get field id from marker message 00120 * 00121 * @return ID 00122 */ 00123 static inline uint16_t mavlink_msg_marker_get_id(const mavlink_message_t* msg) 00124 { 00125 generic_16bit r; 00126 r.b[1] = (msg->payload)[0]; 00127 r.b[0] = (msg->payload)[1]; 00128 return (uint16_t)r.s; 00129 } 00130 00131 /** 00132 * @brief Get field x from marker message 00133 * 00134 * @return x position 00135 */ 00136 static inline float mavlink_msg_marker_get_x(const mavlink_message_t* msg) 00137 { 00138 generic_32bit r; 00139 r.b[3] = (msg->payload+sizeof(uint16_t))[0]; 00140 r.b[2] = (msg->payload+sizeof(uint16_t))[1]; 00141 r.b[1] = (msg->payload+sizeof(uint16_t))[2]; 00142 r.b[0] = (msg->payload+sizeof(uint16_t))[3]; 00143 return (float)r.f; 00144 } 00145 00146 /** 00147 * @brief Get field y from marker message 00148 * 00149 * @return y position 00150 */ 00151 static inline float mavlink_msg_marker_get_y(const mavlink_message_t* msg) 00152 { 00153 generic_32bit r; 00154 r.b[3] = (msg->payload+sizeof(uint16_t)+sizeof(float))[0]; 00155 r.b[2] = (msg->payload+sizeof(uint16_t)+sizeof(float))[1]; 00156 r.b[1] = (msg->payload+sizeof(uint16_t)+sizeof(float))[2]; 00157 r.b[0] = (msg->payload+sizeof(uint16_t)+sizeof(float))[3]; 00158 return (float)r.f; 00159 } 00160 00161 /** 00162 * @brief Get field z from marker message 00163 * 00164 * @return z position 00165 */ 00166 static inline float mavlink_msg_marker_get_z(const mavlink_message_t* msg) 00167 { 00168 generic_32bit r; 00169 r.b[3] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float))[0]; 00170 r.b[2] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float))[1]; 00171 r.b[1] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float))[2]; 00172 r.b[0] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float))[3]; 00173 return (float)r.f; 00174 } 00175 00176 /** 00177 * @brief Get field roll from marker message 00178 * 00179 * @return roll orientation 00180 */ 00181 static inline float mavlink_msg_marker_get_roll(const mavlink_message_t* msg) 00182 { 00183 generic_32bit r; 00184 r.b[3] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float))[0]; 00185 r.b[2] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float))[1]; 00186 r.b[1] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float))[2]; 00187 r.b[0] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float))[3]; 00188 return (float)r.f; 00189 } 00190 00191 /** 00192 * @brief Get field pitch from marker message 00193 * 00194 * @return pitch orientation 00195 */ 00196 static inline float mavlink_msg_marker_get_pitch(const mavlink_message_t* msg) 00197 { 00198 generic_32bit r; 00199 r.b[3] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float))[0]; 00200 r.b[2] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float))[1]; 00201 r.b[1] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float))[2]; 00202 r.b[0] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float))[3]; 00203 return (float)r.f; 00204 } 00205 00206 /** 00207 * @brief Get field yaw from marker message 00208 * 00209 * @return yaw orientation 00210 */ 00211 static inline float mavlink_msg_marker_get_yaw(const mavlink_message_t* msg) 00212 { 00213 generic_32bit r; 00214 r.b[3] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float))[0]; 00215 r.b[2] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float))[1]; 00216 r.b[1] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float))[2]; 00217 r.b[0] = (msg->payload+sizeof(uint16_t)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float)+sizeof(float))[3]; 00218 return (float)r.f; 00219 } 00220 00221 /** 00222 * @brief Decode a marker message into a struct 00223 * 00224 * @param msg The message to decode 00225 * @param marker C-struct to decode the message contents into 00226 */ 00227 static inline void mavlink_msg_marker_decode(const mavlink_message_t* msg, mavlink_marker_t* marker) 00228 { 00229 marker->id = mavlink_msg_marker_get_id(msg); 00230 marker->x = mavlink_msg_marker_get_x(msg); 00231 marker->y = mavlink_msg_marker_get_y(msg); 00232 marker->z = mavlink_msg_marker_get_z(msg); 00233 marker->roll = mavlink_msg_marker_get_roll(msg); 00234 marker->pitch = mavlink_msg_marker_get_pitch(msg); 00235 marker->yaw = mavlink_msg_marker_get_yaw(msg); 00236 }
Generated on Tue Jul 12 2022 14:09:26 by 1.7.2