mavlink 0.21.0

Implements the MAVLink data interchange format for UAVs.
docs.rs failed to build mavlink-0.21.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: mavlink-0.20.0

rust-mavlink

Crate info Crate downloads Rust 1.80+ License Build status Documentation

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.

What rust-mavlink provides

  • 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.

Workspace crates

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

Quick start

Add the crate:

[dependencies]
mavlink = "0.20"

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(())
}

Supported address formats

  • tcpin:<addr>:<port>: TCP server
  • tcpout:<addr>:<port>: TCP client
  • udpin:<addr>:<port>: UDP listener
  • udpout:<addr>:<port>: UDP sender
  • udpbcast:<addr>:<port>: UDP broadcast sender
  • serial:<port>:<baudrate>: serial port connection
  • file:<path>: read MAVLink frames from a file

Dialects

Compile-time dialects

Features such as dialect-ardupilotmega and dialect-common generate strongly typed Rust messages from XML definitions during the build. Use these when the message set is known at compile time. Changing the definitions requires rebuilding the application.

Runtime dialects

The dialect-dynamic feature loads dialect XML definitions at runtime.

Runtime dialects are required when an application takes its dialect at runtime (e.g. from user configuration) and rebuilding the application for each custom dialect is not possible.

See the runtime-dialect example for usage and testing it.

Feature flags

Transport and runtime:

  • embedded
  • std
  • tokio
  • transport-direct-serial
  • transport-tcp
  • transport-udp

Protocol and code generation:

  • arbitrary
  • format-generated-code
  • mav2-message-extensions
  • mav2-message-signing
  • serde
  • ts-rs

Dialects:

  • dialect-all
  • dialect-ardupilotmega
  • dialect-asluav
  • dialect-avssuas
  • dialect-common
  • dialect-csairlink
  • dialect-cubepilot
  • dialect-development
  • dialect-dynamic (unlike the generated dialects, loads dialects at runtime)
  • dialect-icarous
  • dialect-loweheiser
  • dialect-marsh
  • dialect-minimal
  • dialect-paparazzi
  • dialect-python_array_test
  • dialect-standard
  • dialect-stemstudios
  • dialect-storm32
  • dialect-test
  • dialect-ualberta
  • dialect-uavionix

Note that std and embedded features are mutually exclusive.

Examples

See mavlink/examples/ for runnable examples.

Maintainers

See MAINTAINERS.md for active maintainers, release managers and contact details.

License

Licensed under either of: