Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mavlink_msg_scaled_imu.h Source File

mavlink_msg_scaled_imu.h

00001 // MESSAGE SCALED_IMU PACKING
00002 
00003 #define MAVLINK_MSG_ID_SCALED_IMU 26
00004 
00005 typedef struct __mavlink_scaled_imu_t 
00006 {
00007     uint64_t usec; ///< Timestamp (microseconds since UNIX epoch or microseconds since system boot)
00008     int16_t xacc; ///< X acceleration (mg)
00009     int16_t yacc; ///< Y acceleration (mg)
00010     int16_t zacc; ///< Z acceleration (mg)
00011     int16_t xgyro; ///< Angular speed around X axis (millirad /sec)
00012     int16_t ygyro; ///< Angular speed around Y axis (millirad /sec)
00013     int16_t zgyro; ///< Angular speed around Z axis (millirad /sec)
00014     int16_t xmag; ///< X Magnetic field (milli tesla)
00015     int16_t ymag; ///< Y Magnetic field (milli tesla)
00016     int16_t zmag; ///< Z Magnetic field (milli tesla)
00017 
00018 } mavlink_scaled_imu_t;
00019 
00020 
00021 
00022 /**
00023  * @brief Pack a scaled_imu message
00024  * @param system_id ID of this system
00025  * @param component_id ID of this component (e.g. 200 for IMU)
00026  * @param msg The MAVLink message to compress the data into
00027  *
00028  * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot)
00029  * @param xacc X acceleration (mg)
00030  * @param yacc Y acceleration (mg)
00031  * @param zacc Z acceleration (mg)
00032  * @param xgyro Angular speed around X axis (millirad /sec)
00033  * @param ygyro Angular speed around Y axis (millirad /sec)
00034  * @param zgyro Angular speed around Z axis (millirad /sec)
00035  * @param xmag X Magnetic field (milli tesla)
00036  * @param ymag Y Magnetic field (milli tesla)
00037  * @param zmag Z Magnetic field (milli tesla)
00038  * @return length of the message in bytes (excluding serial stream start sign)
00039  */
00040 static inline uint16_t mavlink_msg_scaled_imu_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint64_t usec, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag)
00041 {
00042     uint16_t i = 0;
00043     msg->msgid = MAVLINK_MSG_ID_SCALED_IMU;
00044 
00045     i += put_uint64_t_by_index(usec, i, msg->payload); // Timestamp (microseconds since UNIX epoch or microseconds since system boot)
00046     i += put_int16_t_by_index(xacc, i, msg->payload); // X acceleration (mg)
00047     i += put_int16_t_by_index(yacc, i, msg->payload); // Y acceleration (mg)
00048     i += put_int16_t_by_index(zacc, i, msg->payload); // Z acceleration (mg)
00049     i += put_int16_t_by_index(xgyro, i, msg->payload); // Angular speed around X axis (millirad /sec)
00050     i += put_int16_t_by_index(ygyro, i, msg->payload); // Angular speed around Y axis (millirad /sec)
00051     i += put_int16_t_by_index(zgyro, i, msg->payload); // Angular speed around Z axis (millirad /sec)
00052     i += put_int16_t_by_index(xmag, i, msg->payload); // X Magnetic field (milli tesla)
00053     i += put_int16_t_by_index(ymag, i, msg->payload); // Y Magnetic field (milli tesla)
00054     i += put_int16_t_by_index(zmag, i, msg->payload); // Z Magnetic field (milli tesla)
00055 
00056     return mavlink_finalize_message(msg, system_id, component_id, i);
00057 }
00058 
00059 /**
00060  * @brief Pack a scaled_imu message
00061  * @param system_id ID of this system
00062  * @param component_id ID of this component (e.g. 200 for IMU)
00063  * @param chan The MAVLink channel this message was sent over
00064  * @param msg The MAVLink message to compress the data into
00065  * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot)
00066  * @param xacc X acceleration (mg)
00067  * @param yacc Y acceleration (mg)
00068  * @param zacc Z acceleration (mg)
00069  * @param xgyro Angular speed around X axis (millirad /sec)
00070  * @param ygyro Angular speed around Y axis (millirad /sec)
00071  * @param zgyro Angular speed around Z axis (millirad /sec)
00072  * @param xmag X Magnetic field (milli tesla)
00073  * @param ymag Y Magnetic field (milli tesla)
00074  * @param zmag Z Magnetic field (milli tesla)
00075  * @return length of the message in bytes (excluding serial stream start sign)
00076  */
00077 static inline uint16_t mavlink_msg_scaled_imu_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, uint64_t usec, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag)
00078 {
00079     uint16_t i = 0;
00080     msg->msgid = MAVLINK_MSG_ID_SCALED_IMU;
00081 
00082     i += put_uint64_t_by_index(usec, i, msg->payload); // Timestamp (microseconds since UNIX epoch or microseconds since system boot)
00083     i += put_int16_t_by_index(xacc, i, msg->payload); // X acceleration (mg)
00084     i += put_int16_t_by_index(yacc, i, msg->payload); // Y acceleration (mg)
00085     i += put_int16_t_by_index(zacc, i, msg->payload); // Z acceleration (mg)
00086     i += put_int16_t_by_index(xgyro, i, msg->payload); // Angular speed around X axis (millirad /sec)
00087     i += put_int16_t_by_index(ygyro, i, msg->payload); // Angular speed around Y axis (millirad /sec)
00088     i += put_int16_t_by_index(zgyro, i, msg->payload); // Angular speed around Z axis (millirad /sec)
00089     i += put_int16_t_by_index(xmag, i, msg->payload); // X Magnetic field (milli tesla)
00090     i += put_int16_t_by_index(ymag, i, msg->payload); // Y Magnetic field (milli tesla)
00091     i += put_int16_t_by_index(zmag, i, msg->payload); // Z Magnetic field (milli tesla)
00092 
00093     return mavlink_finalize_message_chan(msg, system_id, component_id, chan, i);
00094 }
00095 
00096 /**
00097  * @brief Encode a scaled_imu struct into a message
00098  *
00099  * @param system_id ID of this system
00100  * @param component_id ID of this component (e.g. 200 for IMU)
00101  * @param msg The MAVLink message to compress the data into
00102  * @param scaled_imu C-struct to read the message contents from
00103  */
00104 static inline uint16_t mavlink_msg_scaled_imu_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_scaled_imu_t* scaled_imu)
00105 {
00106     return mavlink_msg_scaled_imu_pack(system_id, component_id, msg, scaled_imu->usec, scaled_imu->xacc, scaled_imu->yacc, scaled_imu->zacc, scaled_imu->xgyro, scaled_imu->ygyro, scaled_imu->zgyro, scaled_imu->xmag, scaled_imu->ymag, scaled_imu->zmag);
00107 }
00108 
00109 /**
00110  * @brief Send a scaled_imu message
00111  * @param chan MAVLink channel to send the message
00112  *
00113  * @param usec Timestamp (microseconds since UNIX epoch or microseconds since system boot)
00114  * @param xacc X acceleration (mg)
00115  * @param yacc Y acceleration (mg)
00116  * @param zacc Z acceleration (mg)
00117  * @param xgyro Angular speed around X axis (millirad /sec)
00118  * @param ygyro Angular speed around Y axis (millirad /sec)
00119  * @param zgyro Angular speed around Z axis (millirad /sec)
00120  * @param xmag X Magnetic field (milli tesla)
00121  * @param ymag Y Magnetic field (milli tesla)
00122  * @param zmag Z Magnetic field (milli tesla)
00123  */
00124 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
00125 
00126 static inline void mavlink_msg_scaled_imu_send(mavlink_channel_t chan, uint64_t usec, int16_t xacc, int16_t yacc, int16_t zacc, int16_t xgyro, int16_t ygyro, int16_t zgyro, int16_t xmag, int16_t ymag, int16_t zmag)
00127 {
00128     mavlink_message_t msg;
00129     mavlink_msg_scaled_imu_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg, usec, xacc, yacc, zacc, xgyro, ygyro, zgyro, xmag, ymag, zmag);
00130     mavlink_send_uart(chan, &msg);
00131 }
00132 
00133 #endif
00134 // MESSAGE SCALED_IMU UNPACKING
00135 
00136 /**
00137  * @brief Get field usec from scaled_imu message
00138  *
00139  * @return Timestamp (microseconds since UNIX epoch or microseconds since system boot)
00140  */
00141 static inline uint64_t mavlink_msg_scaled_imu_get_usec(const mavlink_message_t* msg)
00142 {
00143     generic_64bit r;
00144     r.b[7] = (msg->payload)[0];
00145     r.b[6] = (msg->payload)[1];
00146     r.b[5] = (msg->payload)[2];
00147     r.b[4] = (msg->payload)[3];
00148     r.b[3] = (msg->payload)[4];
00149     r.b[2] = (msg->payload)[5];
00150     r.b[1] = (msg->payload)[6];
00151     r.b[0] = (msg->payload)[7];
00152     return (uint64_t)r.ll;
00153 }
00154 
00155 /**
00156  * @brief Get field xacc from scaled_imu message
00157  *
00158  * @return X acceleration (mg)
00159  */
00160 static inline int16_t mavlink_msg_scaled_imu_get_xacc(const mavlink_message_t* msg)
00161 {
00162     generic_16bit r;
00163     r.b[1] = (msg->payload+sizeof(uint64_t))[0];
00164     r.b[0] = (msg->payload+sizeof(uint64_t))[1];
00165     return (int16_t)r.s;
00166 }
00167 
00168 /**
00169  * @brief Get field yacc from scaled_imu message
00170  *
00171  * @return Y acceleration (mg)
00172  */
00173 static inline int16_t mavlink_msg_scaled_imu_get_yacc(const mavlink_message_t* msg)
00174 {
00175     generic_16bit r;
00176     r.b[1] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t))[0];
00177     r.b[0] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t))[1];
00178     return (int16_t)r.s;
00179 }
00180 
00181 /**
00182  * @brief Get field zacc from scaled_imu message
00183  *
00184  * @return Z acceleration (mg)
00185  */
00186 static inline int16_t mavlink_msg_scaled_imu_get_zacc(const mavlink_message_t* msg)
00187 {
00188     generic_16bit r;
00189     r.b[1] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t))[0];
00190     r.b[0] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t))[1];
00191     return (int16_t)r.s;
00192 }
00193 
00194 /**
00195  * @brief Get field xgyro from scaled_imu message
00196  *
00197  * @return Angular speed around X axis (millirad /sec)
00198  */
00199 static inline int16_t mavlink_msg_scaled_imu_get_xgyro(const mavlink_message_t* msg)
00200 {
00201     generic_16bit r;
00202     r.b[1] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[0];
00203     r.b[0] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[1];
00204     return (int16_t)r.s;
00205 }
00206 
00207 /**
00208  * @brief Get field ygyro from scaled_imu message
00209  *
00210  * @return Angular speed around Y axis (millirad /sec)
00211  */
00212 static inline int16_t mavlink_msg_scaled_imu_get_ygyro(const mavlink_message_t* msg)
00213 {
00214     generic_16bit r;
00215     r.b[1] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[0];
00216     r.b[0] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[1];
00217     return (int16_t)r.s;
00218 }
00219 
00220 /**
00221  * @brief Get field zgyro from scaled_imu message
00222  *
00223  * @return Angular speed around Z axis (millirad /sec)
00224  */
00225 static inline int16_t mavlink_msg_scaled_imu_get_zgyro(const mavlink_message_t* msg)
00226 {
00227     generic_16bit r;
00228     r.b[1] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[0];
00229     r.b[0] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[1];
00230     return (int16_t)r.s;
00231 }
00232 
00233 /**
00234  * @brief Get field xmag from scaled_imu message
00235  *
00236  * @return X Magnetic field (milli tesla)
00237  */
00238 static inline int16_t mavlink_msg_scaled_imu_get_xmag(const mavlink_message_t* msg)
00239 {
00240     generic_16bit r;
00241     r.b[1] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[0];
00242     r.b[0] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[1];
00243     return (int16_t)r.s;
00244 }
00245 
00246 /**
00247  * @brief Get field ymag from scaled_imu message
00248  *
00249  * @return Y Magnetic field (milli tesla)
00250  */
00251 static inline int16_t mavlink_msg_scaled_imu_get_ymag(const mavlink_message_t* msg)
00252 {
00253     generic_16bit r;
00254     r.b[1] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[0];
00255     r.b[0] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[1];
00256     return (int16_t)r.s;
00257 }
00258 
00259 /**
00260  * @brief Get field zmag from scaled_imu message
00261  *
00262  * @return Z Magnetic field (milli tesla)
00263  */
00264 static inline int16_t mavlink_msg_scaled_imu_get_zmag(const mavlink_message_t* msg)
00265 {
00266     generic_16bit r;
00267     r.b[1] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[0];
00268     r.b[0] = (msg->payload+sizeof(uint64_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t)+sizeof(int16_t))[1];
00269     return (int16_t)r.s;
00270 }
00271 
00272 /**
00273  * @brief Decode a scaled_imu message into a struct
00274  *
00275  * @param msg The message to decode
00276  * @param scaled_imu C-struct to decode the message contents into
00277  */
00278 static inline void mavlink_msg_scaled_imu_decode(const mavlink_message_t* msg, mavlink_scaled_imu_t* scaled_imu)
00279 {
00280     scaled_imu->usec = mavlink_msg_scaled_imu_get_usec(msg);
00281     scaled_imu->xacc = mavlink_msg_scaled_imu_get_xacc(msg);
00282     scaled_imu->yacc = mavlink_msg_scaled_imu_get_yacc(msg);
00283     scaled_imu->zacc = mavlink_msg_scaled_imu_get_zacc(msg);
00284     scaled_imu->xgyro = mavlink_msg_scaled_imu_get_xgyro(msg);
00285     scaled_imu->ygyro = mavlink_msg_scaled_imu_get_ygyro(msg);
00286     scaled_imu->zgyro = mavlink_msg_scaled_imu_get_zgyro(msg);
00287     scaled_imu->xmag = mavlink_msg_scaled_imu_get_xmag(msg);
00288     scaled_imu->ymag = mavlink_msg_scaled_imu_get_ymag(msg);
00289     scaled_imu->zmag = mavlink_msg_scaled_imu_get_zmag(msg);
00290 }