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

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Committer:
shimniok
Date:
Wed Jun 20 14:57:48 2012 +0000
Revision:
0:826c6171fc1b
Updated documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:826c6171fc1b 1 // MESSAGE RADIO_CALIBRATION PACKING
shimniok 0:826c6171fc1b 2
shimniok 0:826c6171fc1b 3 #define MAVLINK_MSG_ID_RADIO_CALIBRATION 221
shimniok 0:826c6171fc1b 4
shimniok 0:826c6171fc1b 5 typedef struct __mavlink_radio_calibration_t
shimniok 0:826c6171fc1b 6 {
shimniok 0:826c6171fc1b 7 uint16_t aileron[3]; ///< Aileron setpoints: left, center, right
shimniok 0:826c6171fc1b 8 uint16_t elevator[3]; ///< Elevator setpoints: nose down, center, nose up
shimniok 0:826c6171fc1b 9 uint16_t rudder[3]; ///< Rudder setpoints: nose left, center, nose right
shimniok 0:826c6171fc1b 10 uint16_t gyro[2]; ///< Tail gyro mode/gain setpoints: heading hold, rate mode
shimniok 0:826c6171fc1b 11 uint16_t pitch[5]; ///< Pitch curve setpoints (every 25%)
shimniok 0:826c6171fc1b 12 uint16_t throttle[5]; ///< Throttle curve setpoints (every 25%)
shimniok 0:826c6171fc1b 13
shimniok 0:826c6171fc1b 14 } mavlink_radio_calibration_t;
shimniok 0:826c6171fc1b 15
shimniok 0:826c6171fc1b 16 #define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_AILERON_LEN 3
shimniok 0:826c6171fc1b 17 #define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_ELEVATOR_LEN 3
shimniok 0:826c6171fc1b 18 #define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_RUDDER_LEN 3
shimniok 0:826c6171fc1b 19 #define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_GYRO_LEN 2
shimniok 0:826c6171fc1b 20 #define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_PITCH_LEN 5
shimniok 0:826c6171fc1b 21 #define MAVLINK_MSG_RADIO_CALIBRATION_FIELD_THROTTLE_LEN 5
shimniok 0:826c6171fc1b 22
shimniok 0:826c6171fc1b 23
shimniok 0:826c6171fc1b 24 /**
shimniok 0:826c6171fc1b 25 * @brief Pack a radio_calibration message
shimniok 0:826c6171fc1b 26 * @param system_id ID of this system
shimniok 0:826c6171fc1b 27 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:826c6171fc1b 28 * @param msg The MAVLink message to compress the data into
shimniok 0:826c6171fc1b 29 *
shimniok 0:826c6171fc1b 30 * @param aileron Aileron setpoints: left, center, right
shimniok 0:826c6171fc1b 31 * @param elevator Elevator setpoints: nose down, center, nose up
shimniok 0:826c6171fc1b 32 * @param rudder Rudder setpoints: nose left, center, nose right
shimniok 0:826c6171fc1b 33 * @param gyro Tail gyro mode/gain setpoints: heading hold, rate mode
shimniok 0:826c6171fc1b 34 * @param pitch Pitch curve setpoints (every 25%)
shimniok 0:826c6171fc1b 35 * @param throttle Throttle curve setpoints (every 25%)
shimniok 0:826c6171fc1b 36 * @return length of the message in bytes (excluding serial stream start sign)
shimniok 0:826c6171fc1b 37 */
shimniok 0:826c6171fc1b 38 static inline uint16_t mavlink_msg_radio_calibration_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const uint16_t* aileron, const uint16_t* elevator, const uint16_t* rudder, const uint16_t* gyro, const uint16_t* pitch, const uint16_t* throttle)
shimniok 0:826c6171fc1b 39 {
shimniok 0:826c6171fc1b 40 uint16_t i = 0;
shimniok 0:826c6171fc1b 41 msg->msgid = MAVLINK_MSG_ID_RADIO_CALIBRATION;
shimniok 0:826c6171fc1b 42
shimniok 0:826c6171fc1b 43 i += put_array_by_index((const int8_t*)aileron, sizeof(uint16_t)*3, i, msg->payload); // Aileron setpoints: left, center, right
shimniok 0:826c6171fc1b 44 i += put_array_by_index((const int8_t*)elevator, sizeof(uint16_t)*3, i, msg->payload); // Elevator setpoints: nose down, center, nose up
shimniok 0:826c6171fc1b 45 i += put_array_by_index((const int8_t*)rudder, sizeof(uint16_t)*3, i, msg->payload); // Rudder setpoints: nose left, center, nose right
shimniok 0:826c6171fc1b 46 i += put_array_by_index((const int8_t*)gyro, sizeof(uint16_t)*2, i, msg->payload); // Tail gyro mode/gain setpoints: heading hold, rate mode
shimniok 0:826c6171fc1b 47 i += put_array_by_index((const int8_t*)pitch, sizeof(uint16_t)*5, i, msg->payload); // Pitch curve setpoints (every 25%)
shimniok 0:826c6171fc1b 48 i += put_array_by_index((const int8_t*)throttle, sizeof(uint16_t)*5, i, msg->payload); // Throttle curve setpoints (every 25%)
shimniok 0:826c6171fc1b 49
shimniok 0:826c6171fc1b 50 return mavlink_finalize_message(msg, system_id, component_id, i);
shimniok 0:826c6171fc1b 51 }
shimniok 0:826c6171fc1b 52
shimniok 0:826c6171fc1b 53 /**
shimniok 0:826c6171fc1b 54 * @brief Pack a radio_calibration message
shimniok 0:826c6171fc1b 55 * @param system_id ID of this system
shimniok 0:826c6171fc1b 56 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:826c6171fc1b 57 * @param chan The MAVLink channel this message was sent over
shimniok 0:826c6171fc1b 58 * @param msg The MAVLink message to compress the data into
shimniok 0:826c6171fc1b 59 * @param aileron Aileron setpoints: left, center, right
shimniok 0:826c6171fc1b 60 * @param elevator Elevator setpoints: nose down, center, nose up
shimniok 0:826c6171fc1b 61 * @param rudder Rudder setpoints: nose left, center, nose right
shimniok 0:826c6171fc1b 62 * @param gyro Tail gyro mode/gain setpoints: heading hold, rate mode
shimniok 0:826c6171fc1b 63 * @param pitch Pitch curve setpoints (every 25%)
shimniok 0:826c6171fc1b 64 * @param throttle Throttle curve setpoints (every 25%)
shimniok 0:826c6171fc1b 65 * @return length of the message in bytes (excluding serial stream start sign)
shimniok 0:826c6171fc1b 66 */
shimniok 0:826c6171fc1b 67 static inline uint16_t mavlink_msg_radio_calibration_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const uint16_t* aileron, const uint16_t* elevator, const uint16_t* rudder, const uint16_t* gyro, const uint16_t* pitch, const uint16_t* throttle)
shimniok 0:826c6171fc1b 68 {
shimniok 0:826c6171fc1b 69 uint16_t i = 0;
shimniok 0:826c6171fc1b 70 msg->msgid = MAVLINK_MSG_ID_RADIO_CALIBRATION;
shimniok 0:826c6171fc1b 71
shimniok 0:826c6171fc1b 72 i += put_array_by_index((const int8_t*)aileron, sizeof(uint16_t)*3, i, msg->payload); // Aileron setpoints: left, center, right
shimniok 0:826c6171fc1b 73 i += put_array_by_index((const int8_t*)elevator, sizeof(uint16_t)*3, i, msg->payload); // Elevator setpoints: nose down, center, nose up
shimniok 0:826c6171fc1b 74 i += put_array_by_index((const int8_t*)rudder, sizeof(uint16_t)*3, i, msg->payload); // Rudder setpoints: nose left, center, nose right
shimniok 0:826c6171fc1b 75 i += put_array_by_index((const int8_t*)gyro, sizeof(uint16_t)*2, i, msg->payload); // Tail gyro mode/gain setpoints: heading hold, rate mode
shimniok 0:826c6171fc1b 76 i += put_array_by_index((const int8_t*)pitch, sizeof(uint16_t)*5, i, msg->payload); // Pitch curve setpoints (every 25%)
shimniok 0:826c6171fc1b 77 i += put_array_by_index((const int8_t*)throttle, sizeof(uint16_t)*5, i, msg->payload); // Throttle curve setpoints (every 25%)
shimniok 0:826c6171fc1b 78
shimniok 0:826c6171fc1b 79 return mavlink_finalize_message_chan(msg, system_id, component_id, chan, i);
shimniok 0:826c6171fc1b 80 }
shimniok 0:826c6171fc1b 81
shimniok 0:826c6171fc1b 82 /**
shimniok 0:826c6171fc1b 83 * @brief Encode a radio_calibration struct into a message
shimniok 0:826c6171fc1b 84 *
shimniok 0:826c6171fc1b 85 * @param system_id ID of this system
shimniok 0:826c6171fc1b 86 * @param component_id ID of this component (e.g. 200 for IMU)
shimniok 0:826c6171fc1b 87 * @param msg The MAVLink message to compress the data into
shimniok 0:826c6171fc1b 88 * @param radio_calibration C-struct to read the message contents from
shimniok 0:826c6171fc1b 89 */
shimniok 0:826c6171fc1b 90 static inline uint16_t mavlink_msg_radio_calibration_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_radio_calibration_t* radio_calibration)
shimniok 0:826c6171fc1b 91 {
shimniok 0:826c6171fc1b 92 return mavlink_msg_radio_calibration_pack(system_id, component_id, msg, radio_calibration->aileron, radio_calibration->elevator, radio_calibration->rudder, radio_calibration->gyro, radio_calibration->pitch, radio_calibration->throttle);
shimniok 0:826c6171fc1b 93 }
shimniok 0:826c6171fc1b 94
shimniok 0:826c6171fc1b 95 /**
shimniok 0:826c6171fc1b 96 * @brief Send a radio_calibration message
shimniok 0:826c6171fc1b 97 * @param chan MAVLink channel to send the message
shimniok 0:826c6171fc1b 98 *
shimniok 0:826c6171fc1b 99 * @param aileron Aileron setpoints: left, center, right
shimniok 0:826c6171fc1b 100 * @param elevator Elevator setpoints: nose down, center, nose up
shimniok 0:826c6171fc1b 101 * @param rudder Rudder setpoints: nose left, center, nose right
shimniok 0:826c6171fc1b 102 * @param gyro Tail gyro mode/gain setpoints: heading hold, rate mode
shimniok 0:826c6171fc1b 103 * @param pitch Pitch curve setpoints (every 25%)
shimniok 0:826c6171fc1b 104 * @param throttle Throttle curve setpoints (every 25%)
shimniok 0:826c6171fc1b 105 */
shimniok 0:826c6171fc1b 106 #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS
shimniok 0:826c6171fc1b 107
shimniok 0:826c6171fc1b 108 static inline void mavlink_msg_radio_calibration_send(mavlink_channel_t chan, const uint16_t* aileron, const uint16_t* elevator, const uint16_t* rudder, const uint16_t* gyro, const uint16_t* pitch, const uint16_t* throttle)
shimniok 0:826c6171fc1b 109 {
shimniok 0:826c6171fc1b 110 mavlink_message_t msg;
shimniok 0:826c6171fc1b 111 mavlink_msg_radio_calibration_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg, aileron, elevator, rudder, gyro, pitch, throttle);
shimniok 0:826c6171fc1b 112 mavlink_send_uart(chan, &msg);
shimniok 0:826c6171fc1b 113 }
shimniok 0:826c6171fc1b 114
shimniok 0:826c6171fc1b 115 #endif
shimniok 0:826c6171fc1b 116 // MESSAGE RADIO_CALIBRATION UNPACKING
shimniok 0:826c6171fc1b 117
shimniok 0:826c6171fc1b 118 /**
shimniok 0:826c6171fc1b 119 * @brief Get field aileron from radio_calibration message
shimniok 0:826c6171fc1b 120 *
shimniok 0:826c6171fc1b 121 * @return Aileron setpoints: left, center, right
shimniok 0:826c6171fc1b 122 */
shimniok 0:826c6171fc1b 123 static inline uint16_t mavlink_msg_radio_calibration_get_aileron(const mavlink_message_t* msg, uint16_t* r_data)
shimniok 0:826c6171fc1b 124 {
shimniok 0:826c6171fc1b 125
shimniok 0:826c6171fc1b 126 memcpy(r_data, msg->payload, sizeof(uint16_t)*3);
shimniok 0:826c6171fc1b 127 return sizeof(uint16_t)*3;
shimniok 0:826c6171fc1b 128 }
shimniok 0:826c6171fc1b 129
shimniok 0:826c6171fc1b 130 /**
shimniok 0:826c6171fc1b 131 * @brief Get field elevator from radio_calibration message
shimniok 0:826c6171fc1b 132 *
shimniok 0:826c6171fc1b 133 * @return Elevator setpoints: nose down, center, nose up
shimniok 0:826c6171fc1b 134 */
shimniok 0:826c6171fc1b 135 static inline uint16_t mavlink_msg_radio_calibration_get_elevator(const mavlink_message_t* msg, uint16_t* r_data)
shimniok 0:826c6171fc1b 136 {
shimniok 0:826c6171fc1b 137
shimniok 0:826c6171fc1b 138 memcpy(r_data, msg->payload+sizeof(uint16_t)*3, sizeof(uint16_t)*3);
shimniok 0:826c6171fc1b 139 return sizeof(uint16_t)*3;
shimniok 0:826c6171fc1b 140 }
shimniok 0:826c6171fc1b 141
shimniok 0:826c6171fc1b 142 /**
shimniok 0:826c6171fc1b 143 * @brief Get field rudder from radio_calibration message
shimniok 0:826c6171fc1b 144 *
shimniok 0:826c6171fc1b 145 * @return Rudder setpoints: nose left, center, nose right
shimniok 0:826c6171fc1b 146 */
shimniok 0:826c6171fc1b 147 static inline uint16_t mavlink_msg_radio_calibration_get_rudder(const mavlink_message_t* msg, uint16_t* r_data)
shimniok 0:826c6171fc1b 148 {
shimniok 0:826c6171fc1b 149
shimniok 0:826c6171fc1b 150 memcpy(r_data, msg->payload+sizeof(uint16_t)*3+sizeof(uint16_t)*3, sizeof(uint16_t)*3);
shimniok 0:826c6171fc1b 151 return sizeof(uint16_t)*3;
shimniok 0:826c6171fc1b 152 }
shimniok 0:826c6171fc1b 153
shimniok 0:826c6171fc1b 154 /**
shimniok 0:826c6171fc1b 155 * @brief Get field gyro from radio_calibration message
shimniok 0:826c6171fc1b 156 *
shimniok 0:826c6171fc1b 157 * @return Tail gyro mode/gain setpoints: heading hold, rate mode
shimniok 0:826c6171fc1b 158 */
shimniok 0:826c6171fc1b 159 static inline uint16_t mavlink_msg_radio_calibration_get_gyro(const mavlink_message_t* msg, uint16_t* r_data)
shimniok 0:826c6171fc1b 160 {
shimniok 0:826c6171fc1b 161
shimniok 0:826c6171fc1b 162 memcpy(r_data, msg->payload+sizeof(uint16_t)*3+sizeof(uint16_t)*3+sizeof(uint16_t)*3, sizeof(uint16_t)*2);
shimniok 0:826c6171fc1b 163 return sizeof(uint16_t)*2;
shimniok 0:826c6171fc1b 164 }
shimniok 0:826c6171fc1b 165
shimniok 0:826c6171fc1b 166 /**
shimniok 0:826c6171fc1b 167 * @brief Get field pitch from radio_calibration message
shimniok 0:826c6171fc1b 168 *
shimniok 0:826c6171fc1b 169 * @return Pitch curve setpoints (every 25%)
shimniok 0:826c6171fc1b 170 */
shimniok 0:826c6171fc1b 171 static inline uint16_t mavlink_msg_radio_calibration_get_pitch(const mavlink_message_t* msg, uint16_t* r_data)
shimniok 0:826c6171fc1b 172 {
shimniok 0:826c6171fc1b 173
shimniok 0:826c6171fc1b 174 memcpy(r_data, msg->payload+sizeof(uint16_t)*3+sizeof(uint16_t)*3+sizeof(uint16_t)*3+sizeof(uint16_t)*2, sizeof(uint16_t)*5);
shimniok 0:826c6171fc1b 175 return sizeof(uint16_t)*5;
shimniok 0:826c6171fc1b 176 }
shimniok 0:826c6171fc1b 177
shimniok 0:826c6171fc1b 178 /**
shimniok 0:826c6171fc1b 179 * @brief Get field throttle from radio_calibration message
shimniok 0:826c6171fc1b 180 *
shimniok 0:826c6171fc1b 181 * @return Throttle curve setpoints (every 25%)
shimniok 0:826c6171fc1b 182 */
shimniok 0:826c6171fc1b 183 static inline uint16_t mavlink_msg_radio_calibration_get_throttle(const mavlink_message_t* msg, uint16_t* r_data)
shimniok 0:826c6171fc1b 184 {
shimniok 0:826c6171fc1b 185
shimniok 0:826c6171fc1b 186 memcpy(r_data, msg->payload+sizeof(uint16_t)*3+sizeof(uint16_t)*3+sizeof(uint16_t)*3+sizeof(uint16_t)*2+sizeof(uint16_t)*5, sizeof(uint16_t)*5);
shimniok 0:826c6171fc1b 187 return sizeof(uint16_t)*5;
shimniok 0:826c6171fc1b 188 }
shimniok 0:826c6171fc1b 189
shimniok 0:826c6171fc1b 190 /**
shimniok 0:826c6171fc1b 191 * @brief Decode a radio_calibration message into a struct
shimniok 0:826c6171fc1b 192 *
shimniok 0:826c6171fc1b 193 * @param msg The message to decode
shimniok 0:826c6171fc1b 194 * @param radio_calibration C-struct to decode the message contents into
shimniok 0:826c6171fc1b 195 */
shimniok 0:826c6171fc1b 196 static inline void mavlink_msg_radio_calibration_decode(const mavlink_message_t* msg, mavlink_radio_calibration_t* radio_calibration)
shimniok 0:826c6171fc1b 197 {
shimniok 0:826c6171fc1b 198 mavlink_msg_radio_calibration_get_aileron(msg, radio_calibration->aileron);
shimniok 0:826c6171fc1b 199 mavlink_msg_radio_calibration_get_elevator(msg, radio_calibration->elevator);
shimniok 0:826c6171fc1b 200 mavlink_msg_radio_calibration_get_rudder(msg, radio_calibration->rudder);
shimniok 0:826c6171fc1b 201 mavlink_msg_radio_calibration_get_gyro(msg, radio_calibration->gyro);
shimniok 0:826c6171fc1b 202 mavlink_msg_radio_calibration_get_pitch(msg, radio_calibration->pitch);
shimniok 0:826c6171fc1b 203 mavlink_msg_radio_calibration_get_throttle(msg, radio_calibration->throttle);
shimniok 0:826c6171fc1b 204 }