MAVLink
MAVLink or Micro Air Vehicle Link is a protocol for communicating with small unmanned vehicle. It is designed as a header-only message marshaling library. MAVLink was first released early 2009 by Lorenz Meier under LGPL license.
Applications
It is used mostly for communication between a Ground Control Station and Unmanned vehicles, and in the inter-communication of the subsystem of the vehicle. It can be used to transmit the orientation of the vehicle, its GPS location and speed.Packet Structure
In version 1.0 the packet structure is the following:Field name | Index | Purpose |
Start-of-frame | 0 | Denotes the start of frame transmission |
Payload-length | 1 | length of payload |
Packet sequence | 2 | Each component counts up their send sequence. Allows for detection of packet loss. |
System ID | 3 | Identification of the SENDING system. Allows to differentiate different systems on the same network. |
Component ID | 4 | Identification of the SENDING component. Allows to differentiate different components of the same system, e.g. the IMU and the autopilot. |
Message ID | 5 | Identification of the message - the id defines what the payload “means” and how it should be correctly decoded. |
Payload | 6 to | The data into the message, depends on the message id. |
CRC | to | Check-sum of the entire packet, excluding the packet start sign |
After Version 2, the packet structure was expanded into the following:
Field name | Index | Purpose |
Start-of-frame | 0 | Denotes the start of frame transmission |
Payload-length | 1 | length of payload |
incompatibility flags | 2 | Flags that must be understood for MAVLink compatibility |
compatibility flags | 3 | Flags that can be ignored if not understood |
Packet sequence | 4 | Each component counts up their send sequence. Allows for detection of packet loss. |
System ID | 5 | Identification of the SENDING system. Allows to differentiate different systems on the same network. |
Component ID | 6 | Identification of the SENDING component. Allows to differentiate different components of the same system, e.g. the IMU and the autopilot. |
Message ID | 7 to 9 | Identification of the message - the id defines what the payload “means” and how it should be correctly decoded. |
Payload | 10 to | The data into the message, depends on the message id. |
CRC | to | Check-sum of the entire packet, excluding the packet start sign |
Signature | to | Signature to verify that messages originate from a trusted source. |
CRC field
To ensure message integrity a cyclic redundancy check is calculated to every message into the last two bytes. Another function of the CRC field is to ensure the sender and receiver both agree in the message that is being transferred. It is computed using an ITU X.25/SAE AS-4 hash of the bytes in the packet, excluding the Start-of-Frame indicator.Additionally a seed value is appended to the end of the data when computing the CRC. The seed is generated with every new message set of the protocol, and it is hashed in a similar way as the packets from each message specifications. Systems using the MAVLink protocol can use a precomputed array to this purpose.
The CRC algorithm of MAVLink has been implemented in many languages, like Python and Java.
Messages
The payload from the packets described above are MAVLink messages. Every message is identifiable by the ID field on the packet, and the payload contains the data from the message. An XML document in the MAVlink source has the definition of the data stored in this payload.Below is the message with ID 24 extracted from the XML document.
Note: The XML document describes the logical ordering of the fields for the protocol. The actual wire format has the fields reordered to reduce Data structure alignment issues. This can be a source of confusion when reading the code generated from the message definitions.