Code for autonomous rover for Sparkfun AVC. DataBus won 3rd in 2012 and the same code was used on Troubled Child, a 1986 Jeep Grand Wagoneer to win 1st in 2014.
Dependencies: mbed Watchdog SDFileSystem DigoleSerialDisp
MAVlink/include/common/mavlink_msg_vfr_hud.h@0:a6a169de725f, 2013-05-27 (annotated)
- Committer:
- shimniok
- Date:
- Mon May 27 13:26:03 2013 +0000
- Revision:
- 0:a6a169de725f
Working version with priorities set and update time display
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:a6a169de725f | 1 | // MESSAGE VFR_HUD PACKING |
shimniok | 0:a6a169de725f | 2 | |
shimniok | 0:a6a169de725f | 3 | #define MAVLINK_MSG_ID_VFR_HUD 74 |
shimniok | 0:a6a169de725f | 4 | |
shimniok | 0:a6a169de725f | 5 | typedef struct __mavlink_vfr_hud_t |
shimniok | 0:a6a169de725f | 6 | { |
shimniok | 0:a6a169de725f | 7 | float airspeed; ///< Current airspeed in m/s |
shimniok | 0:a6a169de725f | 8 | float groundspeed; ///< Current ground speed in m/s |
shimniok | 0:a6a169de725f | 9 | int16_t heading; ///< Current heading in degrees, in compass units (0..360, 0=north) |
shimniok | 0:a6a169de725f | 10 | uint16_t throttle; ///< Current throttle setting in integer percent, 0 to 100 |
shimniok | 0:a6a169de725f | 11 | float alt; ///< Current altitude (MSL), in meters |
shimniok | 0:a6a169de725f | 12 | float climb; ///< Current climb rate in meters/second |
shimniok | 0:a6a169de725f | 13 | |
shimniok | 0:a6a169de725f | 14 | } mavlink_vfr_hud_t; |
shimniok | 0:a6a169de725f | 15 | |
shimniok | 0:a6a169de725f | 16 | |
shimniok | 0:a6a169de725f | 17 | |
shimniok | 0:a6a169de725f | 18 | /** |
shimniok | 0:a6a169de725f | 19 | * @brief Pack a vfr_hud message |
shimniok | 0:a6a169de725f | 20 | * @param system_id ID of this system |
shimniok | 0:a6a169de725f | 21 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:a6a169de725f | 22 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:a6a169de725f | 23 | * |
shimniok | 0:a6a169de725f | 24 | * @param airspeed Current airspeed in m/s |
shimniok | 0:a6a169de725f | 25 | * @param groundspeed Current ground speed in m/s |
shimniok | 0:a6a169de725f | 26 | * @param heading Current heading in degrees, in compass units (0..360, 0=north) |
shimniok | 0:a6a169de725f | 27 | * @param throttle Current throttle setting in integer percent, 0 to 100 |
shimniok | 0:a6a169de725f | 28 | * @param alt Current altitude (MSL), in meters |
shimniok | 0:a6a169de725f | 29 | * @param climb Current climb rate in meters/second |
shimniok | 0:a6a169de725f | 30 | * @return length of the message in bytes (excluding serial stream start sign) |
shimniok | 0:a6a169de725f | 31 | */ |
shimniok | 0:a6a169de725f | 32 | static inline uint16_t mavlink_msg_vfr_hud_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, float airspeed, float groundspeed, int16_t heading, uint16_t throttle, float alt, float climb) |
shimniok | 0:a6a169de725f | 33 | { |
shimniok | 0:a6a169de725f | 34 | uint16_t i = 0; |
shimniok | 0:a6a169de725f | 35 | msg->msgid = MAVLINK_MSG_ID_VFR_HUD; |
shimniok | 0:a6a169de725f | 36 | |
shimniok | 0:a6a169de725f | 37 | i += put_float_by_index(airspeed, i, msg->payload); // Current airspeed in m/s |
shimniok | 0:a6a169de725f | 38 | i += put_float_by_index(groundspeed, i, msg->payload); // Current ground speed in m/s |
shimniok | 0:a6a169de725f | 39 | i += put_int16_t_by_index(heading, i, msg->payload); // Current heading in degrees, in compass units (0..360, 0=north) |
shimniok | 0:a6a169de725f | 40 | i += put_uint16_t_by_index(throttle, i, msg->payload); // Current throttle setting in integer percent, 0 to 100 |
shimniok | 0:a6a169de725f | 41 | i += put_float_by_index(alt, i, msg->payload); // Current altitude (MSL), in meters |
shimniok | 0:a6a169de725f | 42 | i += put_float_by_index(climb, i, msg->payload); // Current climb rate in meters/second |
shimniok | 0:a6a169de725f | 43 | |
shimniok | 0:a6a169de725f | 44 | return mavlink_finalize_message(msg, system_id, component_id, i); |
shimniok | 0:a6a169de725f | 45 | } |
shimniok | 0:a6a169de725f | 46 | |
shimniok | 0:a6a169de725f | 47 | /** |
shimniok | 0:a6a169de725f | 48 | * @brief Pack a vfr_hud message |
shimniok | 0:a6a169de725f | 49 | * @param system_id ID of this system |
shimniok | 0:a6a169de725f | 50 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:a6a169de725f | 51 | * @param chan The MAVLink channel this message was sent over |
shimniok | 0:a6a169de725f | 52 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:a6a169de725f | 53 | * @param airspeed Current airspeed in m/s |
shimniok | 0:a6a169de725f | 54 | * @param groundspeed Current ground speed in m/s |
shimniok | 0:a6a169de725f | 55 | * @param heading Current heading in degrees, in compass units (0..360, 0=north) |
shimniok | 0:a6a169de725f | 56 | * @param throttle Current throttle setting in integer percent, 0 to 100 |
shimniok | 0:a6a169de725f | 57 | * @param alt Current altitude (MSL), in meters |
shimniok | 0:a6a169de725f | 58 | * @param climb Current climb rate in meters/second |
shimniok | 0:a6a169de725f | 59 | * @return length of the message in bytes (excluding serial stream start sign) |
shimniok | 0:a6a169de725f | 60 | */ |
shimniok | 0:a6a169de725f | 61 | static inline uint16_t mavlink_msg_vfr_hud_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, float airspeed, float groundspeed, int16_t heading, uint16_t throttle, float alt, float climb) |
shimniok | 0:a6a169de725f | 62 | { |
shimniok | 0:a6a169de725f | 63 | uint16_t i = 0; |
shimniok | 0:a6a169de725f | 64 | msg->msgid = MAVLINK_MSG_ID_VFR_HUD; |
shimniok | 0:a6a169de725f | 65 | |
shimniok | 0:a6a169de725f | 66 | i += put_float_by_index(airspeed, i, msg->payload); // Current airspeed in m/s |
shimniok | 0:a6a169de725f | 67 | i += put_float_by_index(groundspeed, i, msg->payload); // Current ground speed in m/s |
shimniok | 0:a6a169de725f | 68 | i += put_int16_t_by_index(heading, i, msg->payload); // Current heading in degrees, in compass units (0..360, 0=north) |
shimniok | 0:a6a169de725f | 69 | i += put_uint16_t_by_index(throttle, i, msg->payload); // Current throttle setting in integer percent, 0 to 100 |
shimniok | 0:a6a169de725f | 70 | i += put_float_by_index(alt, i, msg->payload); // Current altitude (MSL), in meters |
shimniok | 0:a6a169de725f | 71 | i += put_float_by_index(climb, i, msg->payload); // Current climb rate in meters/second |
shimniok | 0:a6a169de725f | 72 | |
shimniok | 0:a6a169de725f | 73 | return mavlink_finalize_message_chan(msg, system_id, component_id, chan, i); |
shimniok | 0:a6a169de725f | 74 | } |
shimniok | 0:a6a169de725f | 75 | |
shimniok | 0:a6a169de725f | 76 | /** |
shimniok | 0:a6a169de725f | 77 | * @brief Encode a vfr_hud struct into a message |
shimniok | 0:a6a169de725f | 78 | * |
shimniok | 0:a6a169de725f | 79 | * @param system_id ID of this system |
shimniok | 0:a6a169de725f | 80 | * @param component_id ID of this component (e.g. 200 for IMU) |
shimniok | 0:a6a169de725f | 81 | * @param msg The MAVLink message to compress the data into |
shimniok | 0:a6a169de725f | 82 | * @param vfr_hud C-struct to read the message contents from |
shimniok | 0:a6a169de725f | 83 | */ |
shimniok | 0:a6a169de725f | 84 | static inline uint16_t mavlink_msg_vfr_hud_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_vfr_hud_t* vfr_hud) |
shimniok | 0:a6a169de725f | 85 | { |
shimniok | 0:a6a169de725f | 86 | return mavlink_msg_vfr_hud_pack(system_id, component_id, msg, vfr_hud->airspeed, vfr_hud->groundspeed, vfr_hud->heading, vfr_hud->throttle, vfr_hud->alt, vfr_hud->climb); |
shimniok | 0:a6a169de725f | 87 | } |
shimniok | 0:a6a169de725f | 88 | |
shimniok | 0:a6a169de725f | 89 | /** |
shimniok | 0:a6a169de725f | 90 | * @brief Send a vfr_hud message |
shimniok | 0:a6a169de725f | 91 | * @param chan MAVLink channel to send the message |
shimniok | 0:a6a169de725f | 92 | * |
shimniok | 0:a6a169de725f | 93 | * @param airspeed Current airspeed in m/s |
shimniok | 0:a6a169de725f | 94 | * @param groundspeed Current ground speed in m/s |
shimniok | 0:a6a169de725f | 95 | * @param heading Current heading in degrees, in compass units (0..360, 0=north) |
shimniok | 0:a6a169de725f | 96 | * @param throttle Current throttle setting in integer percent, 0 to 100 |
shimniok | 0:a6a169de725f | 97 | * @param alt Current altitude (MSL), in meters |
shimniok | 0:a6a169de725f | 98 | * @param climb Current climb rate in meters/second |
shimniok | 0:a6a169de725f | 99 | */ |
shimniok | 0:a6a169de725f | 100 | #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS |
shimniok | 0:a6a169de725f | 101 | |
shimniok | 0:a6a169de725f | 102 | static inline void mavlink_msg_vfr_hud_send(mavlink_channel_t chan, float airspeed, float groundspeed, int16_t heading, uint16_t throttle, float alt, float climb) |
shimniok | 0:a6a169de725f | 103 | { |
shimniok | 0:a6a169de725f | 104 | mavlink_message_t msg; |
shimniok | 0:a6a169de725f | 105 | mavlink_msg_vfr_hud_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg, airspeed, groundspeed, heading, throttle, alt, climb); |
shimniok | 0:a6a169de725f | 106 | mavlink_send_uart(chan, &msg); |
shimniok | 0:a6a169de725f | 107 | } |
shimniok | 0:a6a169de725f | 108 | |
shimniok | 0:a6a169de725f | 109 | #endif |
shimniok | 0:a6a169de725f | 110 | // MESSAGE VFR_HUD UNPACKING |
shimniok | 0:a6a169de725f | 111 | |
shimniok | 0:a6a169de725f | 112 | /** |
shimniok | 0:a6a169de725f | 113 | * @brief Get field airspeed from vfr_hud message |
shimniok | 0:a6a169de725f | 114 | * |
shimniok | 0:a6a169de725f | 115 | * @return Current airspeed in m/s |
shimniok | 0:a6a169de725f | 116 | */ |
shimniok | 0:a6a169de725f | 117 | static inline float mavlink_msg_vfr_hud_get_airspeed(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 118 | { |
shimniok | 0:a6a169de725f | 119 | generic_32bit r; |
shimniok | 0:a6a169de725f | 120 | r.b[3] = (msg->payload)[0]; |
shimniok | 0:a6a169de725f | 121 | r.b[2] = (msg->payload)[1]; |
shimniok | 0:a6a169de725f | 122 | r.b[1] = (msg->payload)[2]; |
shimniok | 0:a6a169de725f | 123 | r.b[0] = (msg->payload)[3]; |
shimniok | 0:a6a169de725f | 124 | return (float)r.f; |
shimniok | 0:a6a169de725f | 125 | } |
shimniok | 0:a6a169de725f | 126 | |
shimniok | 0:a6a169de725f | 127 | /** |
shimniok | 0:a6a169de725f | 128 | * @brief Get field groundspeed from vfr_hud message |
shimniok | 0:a6a169de725f | 129 | * |
shimniok | 0:a6a169de725f | 130 | * @return Current ground speed in m/s |
shimniok | 0:a6a169de725f | 131 | */ |
shimniok | 0:a6a169de725f | 132 | static inline float mavlink_msg_vfr_hud_get_groundspeed(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 133 | { |
shimniok | 0:a6a169de725f | 134 | generic_32bit r; |
shimniok | 0:a6a169de725f | 135 | r.b[3] = (msg->payload+sizeof(float))[0]; |
shimniok | 0:a6a169de725f | 136 | r.b[2] = (msg->payload+sizeof(float))[1]; |
shimniok | 0:a6a169de725f | 137 | r.b[1] = (msg->payload+sizeof(float))[2]; |
shimniok | 0:a6a169de725f | 138 | r.b[0] = (msg->payload+sizeof(float))[3]; |
shimniok | 0:a6a169de725f | 139 | return (float)r.f; |
shimniok | 0:a6a169de725f | 140 | } |
shimniok | 0:a6a169de725f | 141 | |
shimniok | 0:a6a169de725f | 142 | /** |
shimniok | 0:a6a169de725f | 143 | * @brief Get field heading from vfr_hud message |
shimniok | 0:a6a169de725f | 144 | * |
shimniok | 0:a6a169de725f | 145 | * @return Current heading in degrees, in compass units (0..360, 0=north) |
shimniok | 0:a6a169de725f | 146 | */ |
shimniok | 0:a6a169de725f | 147 | static inline int16_t mavlink_msg_vfr_hud_get_heading(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 148 | { |
shimniok | 0:a6a169de725f | 149 | generic_16bit r; |
shimniok | 0:a6a169de725f | 150 | r.b[1] = (msg->payload+sizeof(float)+sizeof(float))[0]; |
shimniok | 0:a6a169de725f | 151 | r.b[0] = (msg->payload+sizeof(float)+sizeof(float))[1]; |
shimniok | 0:a6a169de725f | 152 | return (int16_t)r.s; |
shimniok | 0:a6a169de725f | 153 | } |
shimniok | 0:a6a169de725f | 154 | |
shimniok | 0:a6a169de725f | 155 | /** |
shimniok | 0:a6a169de725f | 156 | * @brief Get field throttle from vfr_hud message |
shimniok | 0:a6a169de725f | 157 | * |
shimniok | 0:a6a169de725f | 158 | * @return Current throttle setting in integer percent, 0 to 100 |
shimniok | 0:a6a169de725f | 159 | */ |
shimniok | 0:a6a169de725f | 160 | static inline uint16_t mavlink_msg_vfr_hud_get_throttle(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 161 | { |
shimniok | 0:a6a169de725f | 162 | generic_16bit r; |
shimniok | 0:a6a169de725f | 163 | r.b[1] = (msg->payload+sizeof(float)+sizeof(float)+sizeof(int16_t))[0]; |
shimniok | 0:a6a169de725f | 164 | r.b[0] = (msg->payload+sizeof(float)+sizeof(float)+sizeof(int16_t))[1]; |
shimniok | 0:a6a169de725f | 165 | return (uint16_t)r.s; |
shimniok | 0:a6a169de725f | 166 | } |
shimniok | 0:a6a169de725f | 167 | |
shimniok | 0:a6a169de725f | 168 | /** |
shimniok | 0:a6a169de725f | 169 | * @brief Get field alt from vfr_hud message |
shimniok | 0:a6a169de725f | 170 | * |
shimniok | 0:a6a169de725f | 171 | * @return Current altitude (MSL), in meters |
shimniok | 0:a6a169de725f | 172 | */ |
shimniok | 0:a6a169de725f | 173 | static inline float mavlink_msg_vfr_hud_get_alt(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 174 | { |
shimniok | 0:a6a169de725f | 175 | generic_32bit r; |
shimniok | 0:a6a169de725f | 176 | r.b[3] = (msg->payload+sizeof(float)+sizeof(float)+sizeof(int16_t)+sizeof(uint16_t))[0]; |
shimniok | 0:a6a169de725f | 177 | r.b[2] = (msg->payload+sizeof(float)+sizeof(float)+sizeof(int16_t)+sizeof(uint16_t))[1]; |
shimniok | 0:a6a169de725f | 178 | r.b[1] = (msg->payload+sizeof(float)+sizeof(float)+sizeof(int16_t)+sizeof(uint16_t))[2]; |
shimniok | 0:a6a169de725f | 179 | r.b[0] = (msg->payload+sizeof(float)+sizeof(float)+sizeof(int16_t)+sizeof(uint16_t))[3]; |
shimniok | 0:a6a169de725f | 180 | return (float)r.f; |
shimniok | 0:a6a169de725f | 181 | } |
shimniok | 0:a6a169de725f | 182 | |
shimniok | 0:a6a169de725f | 183 | /** |
shimniok | 0:a6a169de725f | 184 | * @brief Get field climb from vfr_hud message |
shimniok | 0:a6a169de725f | 185 | * |
shimniok | 0:a6a169de725f | 186 | * @return Current climb rate in meters/second |
shimniok | 0:a6a169de725f | 187 | */ |
shimniok | 0:a6a169de725f | 188 | static inline float mavlink_msg_vfr_hud_get_climb(const mavlink_message_t* msg) |
shimniok | 0:a6a169de725f | 189 | { |
shimniok | 0:a6a169de725f | 190 | generic_32bit r; |
shimniok | 0:a6a169de725f | 191 | r.b[3] = (msg->payload+sizeof(float)+sizeof(float)+sizeof(int16_t)+sizeof(uint16_t)+sizeof(float))[0]; |
shimniok | 0:a6a169de725f | 192 | r.b[2] = (msg->payload+sizeof(float)+sizeof(float)+sizeof(int16_t)+sizeof(uint16_t)+sizeof(float))[1]; |
shimniok | 0:a6a169de725f | 193 | r.b[1] = (msg->payload+sizeof(float)+sizeof(float)+sizeof(int16_t)+sizeof(uint16_t)+sizeof(float))[2]; |
shimniok | 0:a6a169de725f | 194 | r.b[0] = (msg->payload+sizeof(float)+sizeof(float)+sizeof(int16_t)+sizeof(uint16_t)+sizeof(float))[3]; |
shimniok | 0:a6a169de725f | 195 | return (float)r.f; |
shimniok | 0:a6a169de725f | 196 | } |
shimniok | 0:a6a169de725f | 197 | |
shimniok | 0:a6a169de725f | 198 | /** |
shimniok | 0:a6a169de725f | 199 | * @brief Decode a vfr_hud message into a struct |
shimniok | 0:a6a169de725f | 200 | * |
shimniok | 0:a6a169de725f | 201 | * @param msg The message to decode |
shimniok | 0:a6a169de725f | 202 | * @param vfr_hud C-struct to decode the message contents into |
shimniok | 0:a6a169de725f | 203 | */ |
shimniok | 0:a6a169de725f | 204 | static inline void mavlink_msg_vfr_hud_decode(const mavlink_message_t* msg, mavlink_vfr_hud_t* vfr_hud) |
shimniok | 0:a6a169de725f | 205 | { |
shimniok | 0:a6a169de725f | 206 | vfr_hud->airspeed = mavlink_msg_vfr_hud_get_airspeed(msg); |
shimniok | 0:a6a169de725f | 207 | vfr_hud->groundspeed = mavlink_msg_vfr_hud_get_groundspeed(msg); |
shimniok | 0:a6a169de725f | 208 | vfr_hud->heading = mavlink_msg_vfr_hud_get_heading(msg); |
shimniok | 0:a6a169de725f | 209 | vfr_hud->throttle = mavlink_msg_vfr_hud_get_throttle(msg); |
shimniok | 0:a6a169de725f | 210 | vfr_hud->alt = mavlink_msg_vfr_hud_get_alt(msg); |
shimniok | 0:a6a169de725f | 211 | vfr_hud->climb = mavlink_msg_vfr_hud_get_climb(msg); |
shimniok | 0:a6a169de725f | 212 | } |