Pure Rust implementation of the MAVLink UAV messaging protocol. Provides strongly typed message bindings, frame encode/decode and connection APIs for serial, UDP, TCP, file connection protocols with a rich set of features.
- Rust bindings for MAVLink dialects
- Read/write support for MAVLink v1 and v2
- TCP, UDP, Serial and File connection support.
- Signing support.
- Blocking and async support.
- std and embedded support.
- Codegen tool mavlink-bindgen for creating Rust bindings from MAVLink XML dialect definitions.
| Crate | Purpose |
|---|---|
mavlink |
Main crate with generated dialect modules and high-level APIs |
mavlink-core |
Core protocol types, parser/serializer, and connection traits |
mavlink-bindgen |
XML-to-Rust code generator used by mavlink |
Building the mavlink crate runs a build script that initializes
the bundled MAVLink definition submodule, so git must be available.
Add the crate:
[dependencies]
mavlink = "0.17.1"Simple code example:
use mavlink::{dialects::ardupilotmega, MavConnection};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let conn = mavlink::connect::<ardupilotmega::MavMessage>("udpin:0.0.0.0:14550")?;
let heartbeat = ardupilotmega::MavMessage::HEARTBEAT(ardupilotmega::HEARTBEAT_DATA {
custom_mode: 0,
mavtype: ardupilotmega::MavType::MAV_TYPE_QUADROTOR,
autopilot: ardupilotmega::MavAutopilot::MAV_AUTOPILOT_ARDUPILOTMEGA,
base_mode: ardupilotmega::MavModeFlag::empty(),
system_status: ardupilotmega::MavState::MAV_STATE_STANDBY,
mavlink_version: 3,
});
conn.send(&mavlink::MavHeader::default(), &heartbeat)?;
let (header, message) = conn.recv()?;
println!(
"received from sys={}, comp={}: {message:?}",
header.system_id, header.component_id
);
Ok(())
}tcpin:<addr>:<port>: TCP servertcpout:<addr>:<port>: TCP clientudpin:<addr>:<port>: UDP listenerudpout:<addr>:<port>: UDP senderudpbcast:<addr>:<port>: UDP broadcast senderserial:<port>:<baudrate>: serial port connectionfile:<path>: read MAVLink frames from a file
Transport and runtime:
embeddedstdtokiotransport-direct-serialtransport-tcptransport-udp
Protocol and code generation:
arbitraryformat-generated-codemav2-message-extensionsmav2-message-signingserdets-rs
Dialects:
dialect-alldialect-ardupilotmegadialect-asluavdialect-avssuasdialect-commondialect-csairlinkdialect-cubepilotdialect-developmentdialect-icarousdialect-loweheiserdialect-marshdialect-matrixpilotdialect-minimaldialect-paparazzidialect-python_array_testdialect-standarddialect-stemstudiosdialect-storm32dialect-testdialect-ualbertadialect-uavionix
Note that std and embedded features are mutually exclusive.
See mavlink/examples/ for runnable examples.
See MAINTAINERS.md for active maintainers, release managers and contact details.
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.