MAVLink: The Lingua Franca of Drone Communication
Every piece of technology speaks to its creator/operator; in instances where the operator does not necessarily understand this lingo, a translator gets involved to make the communication simpler. Today, we explore one such crucial language which we have applied to vegetation analysis, aerial surveillance, construction monitoring, and many such mission critical application, in order to communicate with unmanned aerial vehicles. That language is MAVLink. MAVLink, or Micro Air Vehicle Link, isn't just any communication protocol; it's the universal translator for drones, allowing them to chat with flight controllers, ground control stations (GCS), and other hardware components used in any aerial missions.
Using Codemonk's recent exploration around vegetation analysis and the autonomous capabilities developed around a custom build quadcopter, we try and understand the kind of value that MAVLink provides to pilots, ground control units/stations, and mission planners alike. We also try to uncover multiple failsafe protocols that are hyper-beneficial from a sustainability and social safety perspective, ensuring strict adherence to regional and national laws around piloting drones.
With definitions out of the way, lets now understand, Why we should consider MAVLink communication protocol:
Well, the below 5 reasons (or benefits of MAVLink) speak for themselves.
- Lightweight: With just 8 bytes overhead, 2-way communication is like sending a postcard using a pigeon rather than a chunky novel, keeping the data flow quick and efficient.
- Reliable: MAVLink validates every information packet sent/received with a checksum protocol, ensuring your drone's messages aren't lost in transmission like a message in a bottle.
- Flexible: You can customize messages, which is great if you want your drone to say something unique like, "Hey, the crops are receiving good sunlight today, compared to the last week's data."
- Bidirectional: MAVLink is similar to having a walkie-talkie between you and your autonomous vehicle, where both parties can talk and listen, ensuring real-time interaction.
- Well-documented: XML-based definitions mean messages are always interpreted correctly and never lost in translation.
Understanding MAVLink's Packet StructureHere's what a MAVLink packet looks like:
markdown
[STX] [LEN] [INC] [CMP] [SYS] [COMP] [MSG] [PAYLOAD] [CHECKSUM]
- STX: The start signal, like the first note in a symphony (v1.0: 0xFE, v2.0: 0xFD), which indicates what could follow within the message.
- LEN: How long the message will be, measured in bytes.
- INC: A sequence number, helping to piece together the story if packets arrive out of order. When multiple packets are sent together to convey a message, this indexing helps stitch the right information packets together to make the receive decipher the message correctly.
- CMP: An indicator that tells the receiver about the exact component of the drone that is communicating with the GCS using the message string.
- SYS: The system ID, like the drone's name tag at a drone party.
- MSG: The message type, telling you what kind of info is coming.
- PAYLOAD: The actual data, like the content of an email.
- CHECKSUM: Ensures the message hasn't been garbled during transmission.
Common MAVLink Messages for Your Agro-Drone:
Let's delve deeper into different message types from the provided code snippets to explain their significance, structure, and usage in an agricultural drone scenario:
1. Heartbeat Message (Message ID: 0)
Structure:python
{
'type': 'HEARTBEAT',
'autopilot': 3, # 3 = ArduPilot
'base_mode': 81, # Armed, autonomous mode
'custom_mode': 4,
'system_status': 4
}
Explanation:
- type: Indicates the heartbeat message type, which is essential for maintaining connection status between the drone and the GCS or any other component.
- autopilot: Specifies the autopilot software in use. Here, 3 represents ArduPilot, which is popular for its open-source nature and flexibility.
- base_mode: A bitmask where each bit represents a specific state or mode of the drone. 81 in binary could be dissected to mean the drone is armed (0x40) and in autonomous mode (0x01).
- custom_mode: This can be set to represent specific flight modes or behaviors unique to the autopilot system.
- system_status: Indicates the status of the system. 4 might mean the system is in manual control or a specific operational state.
Business Relevance: The Heartbeat message is crucial for monitoring the health and readiness of your drone, ensuring that your agricultural surveillance flights can commence and continue without interruption.
2. Global Position Message (Message ID: 33)
Structure:python
{
'time_boot_ms': 0,
'lat': 473947383, # Latitude in 1e7 degrees
'lon': 85739347, # Longitude in 1e7 degrees
'alt': 1000, # Altitude in mm
'relative_alt': 1000,
'vx': 0, # Ground X Speed
'vy': 0, # Ground Y Speed
'vz': 0 # Ground Z Speed
}
Explanation:
- time_boot_ms: Time since system boot in milliseconds, useful for synchronizing time-dependent data or logs.
- lat & lon: These are the latitude and longitude in degrees multiplied by 10^7 for precision. For instance, 473947383 could represent 47.3947383 degrees north.
- alt: Altitude above sea level in millimeters. Here, 1000 mm equals 1 meter.
- relative_alt: Altitude relative to the home position in millimeters.
- vx, vy, vz: Velocities in the X, Y, and Z directions respectively, in cm/s. If all are zero, the drone is presumably hovering or stationary.
Business Relevance: For agricultural applications, knowing the exact position of your drone is vital for mapping fields, identifying crop health zones, and navigating autonomously over vast areas. This data helps in creating precise agricultural maps and managing variable rate applications.
- Custom CROP_STATUS Message
Structure in XML:xml
<message id="150" name="CROP_STATUS">
<field type="uint32_t" name="timestamp">Timestamp of the measurement</field>
<field type="float" name="ndvi_index">Normalized Difference Vegetation Index</field>
<field type="float" name="moisture_level">Soil moisture level</field>
<field type="uint8_t" name="alert_level">Alert level (0-3)</field>
</message>
Explanation:
- timestamp: When the measurement was taken, crucial for correlating data with real-world events or farming schedules.
- ndvi_index: NDVI (Normalized Difference Vegetation Index) is a key indicator of plant health, calculated from spectral reflectance. It helps in assessing crop vigor and detecting stress.
- moisture_level: Indicates soil moisture, which is essential for managing irrigation and predicting crop health.
- alert_level: A simple scale to quickly communicate the urgency of any issues detected, like severe drought or pest infestation.
Business Relevance: This custom message is specifically tailored for agricultural surveillance. It allows for immediate feedback on crop conditions, enabling farmers to react promptly to issues like water stress, disease, or nutrient deficiencies, thus optimizing farm management practices.
Engineers at Codemonk have found great success in customising such messages for real time monitoring of crops, irrigation activities, sunlight and shade analysis, and fertiliser spraying functions, alongside construction use cases such as live updates on construction activities, stockpile relocation, material movement, volumetric analysis for excavations and more.
Stay tuned as we showcase many more technological explorations, and as always, do reach out to us to build such mission critical products and services.