MAVLink

Basic documentation: https://mavlink.io/en/open in new window.

MAVLink is a communication protocol between autonomous aircraft and vehicle systems (drones, planes, vehicles). The MAVLink protocol lies at the base of interaction between Pixhawk and Raspberry Pi.

Clover contains two wrappers for this protocol: MAVROS and simple_offboard.

The code for sending an arbitrary MAVLink message may be found in the examples.

The main concerts

Communication channel

The MAVLink protocol may be used on top of the following communication channels:

  • connection in series (UART, USB, etc.);
  • UDP (Wi-Fi, Ethernet, 3G, LTE);
  • TCP (Wi-Fi, Ethernet, 3G, LTE).

Message

A MAVLink message is an individual "portion" of data transmitted between devices. An individual MAVLink message contains information about the state of the drone (or another device) or a command for the drone.

Examples of MAVLink messages:

  • ATTITUDE, ATTITUDE_QUATERNION – the quadcopter orientation in the space;
  • LOCAL_POSITION_NED – local position of the quadcopter;
  • GLOBAL_POSITION_INT – global position of the quadcopter (latitude/longitude/altitude);
  • COMMAND_LONG – a command to the quadcopter (take off, land, toggle modes, etc).

A complete list of MAVLink messages is available in MAVLink documentationopen in new window.

System, system component

Each device (a drone, a base station, etc.) has an ID in the MAVLink network. In PX4 MAVLink, ID is changed using parameter MAV_SYS_ID. Each MAVLink message contains a field with the ID of the originating system. Besides, some messages (for example, COMMAND_LONG) also contain the ID of the target system.

In addition to IDs of the systems, the messages may contain IDs of the originating component and the target component. Examples of the system components: a flight controller, an external camera, a controlling onboard computer (Raspberry Pi in case of Clover), etc.

An example of a package

An example of a MAVLink package structure with message COMMAND_LONG:

FieldLengthNameComment
Header
magic1 byteStart tag0xFD for MAVLink 2.0
len1 byteData size
incompat_flags1 byteReversely incompatible flagsCurrently unused
compat_flags1 byteReversely compatible flagsCurrently unused
seq1 byteMessage sequence number
sysid1 byteOriginating system ID
compid1 byteOriginating component ID
msgid3 bytesMessage ID
Data (example)
target_system1 byteTarget system ID
target_component1 byteTarget component ID
command2 bytesCommand ID
confirmation1 byteNumber for confirmation
param14 bytesParameter 1A single-precision floating point number
param24 bytesParameter 2
param34 bytesParameter 3
param44 bytesParameter 4
param54 bytesParameter 5
param64 bytesParameter 6
param74 bytesParameter 7
checksum2 bytesChecksum
signature13 bytesSignature (optional)Allows checking that the package has not been compromised. Usually unused.

Yellow is used for highlighting the data fields(payload). An individual set of such fields exists for every message type.