MAVSDK Documentation

repository·main·Indexed 19 days ago

https://github.com/mavlink/mavsdk

Documentation for MAVSDK, including MAVSDK-Kotlin (a Kotlin Multiplatform wrapper with JNI bindings for Android and Desktop JVM), the MAVSDK C API and its ownership model, and the mavsdk_server. Includes guides on building C wrappers with CMake, creating iOS fat binaries, and deploying the server via Docker.

Tokens
196.3K
Snippets
721
Records
901
Agent score
74%

What's inside MAVSDK

  1. Overview of MAVSDK

    main

    MAVSDK is a collection of libraries designed to interface with MAVLink systems, such as drones, cameras, or ground systems. It provides a simplified API for managing one or more vehicles, accessing telemetry and vehicle information, and controlling missions, movement, and other operations.

    MAVSDK can be deployed:

    • Onboard a drone via a companion computer.
    • On the ground via a ground station or mobile device.

    It is cross-platform, supporting Linux, macOS, Windows, Android, and iOS.

  2. Overview of MAVSDK Python wrappers

    main

    The MAVSDK Python wrappers provide a Python interface to the C implementation of MAVSDK. Unlike the standalone MAVSDK-Python package, these wrappers call the C wrapper directly and do not depend on gRPC.

    Key characteristics:

    • No gRPC dependency: Calls the C wrapper directly.
    • Threading model: Uses traditional threads and callbacks rather than an asyncio API.
    • Asyncio support: If you require an asyncio API, use the aiomavsdk wrapper, which wraps this library to provide asynchronous capabilities.
  3. Overview of MAVSDK features

    main

    MAVSDK is a developer toolset designed to provide the easiest way to control drones using MAVLink. Key capabilities include:

    • Multi-Vehicle Support: Connect to up to 255 PX4-based Unmanned Aircraft Systems (UAS), including copters, planes, and VTOLs, to fetch telemetry and control movement.
    • Cross-Platform Development: Support for multiple languages (Python, Java, Objective C) and operating systems (Linux, macOS, Windows, Android).
    • Plugin Architecture: Ability to integrate custom hardware over MAVLink (such as cameras or gimbals) or add custom MAVLink APIs.
  4. Overview of aiomavsdk (Python asyncio wrappers)

    main

    aiomavsdk provides asyncio wrappers around the py/mavsdk wrapper of MAVSDK.

    Key characteristics:

    • Asyncio API: Designed to provide an asynchronous interface, aiming for similarity with MAVSDK-Python to facilitate transitions.
    • No gRPC dependency: Unlike MAVSDK-Python, this implementation calls the C wrapper directly, meaning the resulting Python package has no gRPC dependency.
    • Underlying implementation: It wraps py/mavsdk, which uses a traditional thread-and-callback model rather than asyncio.
  5. Overview of the MAVSDK C++ Library

    main

    MAVSDK C++ is a performant library designed for managing one or more vehicles via MAVLink. It provides programmatic access to vehicle telemetry, information, and control over missions, movement, and other operations. It is suitable for high-performance tasks such as computer vision, obstacle avoidance, and route planning.

    Note on Stability: While the library is robust and used in production, the API is still evolving, and the project does not guarantee future compatibility.

  6. Project Structure of the MAVSDK-Kotlin Example App

    main

    The example app is a Kotlin Multiplatform project currently targeting Android. It is organized into the following modules:

    • /androidApp: The Android entry point containing a single activity that hosts the shared Compose UI.
    • /shared: The Compose Multiplatform module containing the core application logic.
      • commonMain: Contains code common to all targets.
      • androidMain: Contains Android-specific implementations.

    To add a new platform, you must declare the target in shared/build.gradle.kts and provide the corresponding actual declarations in a platform-specific source set.

  7. Use the LogFiles plugin to manage vehicle logs

    main

    The mavsdk::LogFiles plugin allows you to download log files from a vehicle after a flight is complete.

    Note: For log streaming during a flight, use the logging plugin instead.

    To use this plugin, include the header:

    #include <mavsdk/plugins/log_files/log_files.hpp>

    To instantiate the plugin, pass a System object or a std::shared_ptr<System> to the constructor.

    auto log_files = LogFiles(system);
  8. MAVSDK C++ Documentation Overview

    main
    The MAVSDK C++ library provides a high-level API for interacting with MAVLink-enabled systems (like drones and rovers). The documentation covers installation, connection management, core flight capabilities (telemetry, missions, offboard control), and advanced features like camera and gimbal control. It includes guides for various platforms (Linux, macOS, Windows) and detailed API references for all core classes and plugins.
  9. Use the Telemetry plugin to get vehicle data

    main

    The Telemetry class is used to retrieve vehicle telemetry, including state and flight mode information. It provides access to a wide range of data types such as Position, Battery, Health, FlightMode, and more.

    All telemetry methods have both synchronous and asynchronous versions. You can also control the frequency of updates using set_rate_* methods.

    // Example of subscribing to position updates
    telemetry.subscribe_position([](Telemetry::Position position) {
        std::cout << "Altitude: " << position.relative_altitude_m << " m" << std::endl
                  << "Latitude: " << position.latitude_deg << std::endl
                  << "Longitude: " << position.longitude_deg << '\n';
    });
  10. Explore MAVSDK C++ Examples

    main

    MAVSDK provides a variety of C++ examples to demonstrate different capabilities, ranging from basic telemetry to complex multi-drone coordination.

    Key Example Categories:

    • Basic Flight: Takeoff and Land, Fly Mission, Offboard Velocity Control.
    • Vehicle Control: VTOL Transitions, Follow Me Mode, GeoFence Inclusion.
    • Multi-Vehicle: Fly Multiple Drones, Multiple Drones (parallel takeoff/land).
    • System/Maintenance: Battery (imitation), Calibrate (gyro/accel/mag), MAVShell (interactive shell), Tune.
    • Protocols: MAVLink FTP Client, MAVLink FTP Server.

    Note: Some examples define flight behavior relative to the default home position in the simulator. Use caution when running these on real hardware.

  11. Use the mavsdk::CameraServer class

    main

    The mavsdk::CameraServer class provides an interface for handling camera-related operations on a drone. It allows for controlling camera modes, managing video streaming, taking photos, controlling zoom, and handling tracking commands.

    To use this class, you must include the header:

    #include <mavsdk/plugins/camera_server/camera_server.hpp>

    Key capabilities include:

    • Mode Control: Switching between different camera modes.
    • Media Capture: Taking photos and monitoring capture status.
    • Video Management: Starting/stopping video and video streaming.
    • Zoom Control: Managing zoom levels and ranges.
    • Tracking: Responding to tracking point or rectangle commands.
    • Storage Management: Accessing storage information and formatting storage.
    #include <mavsdk/plugins/camera_server/camera_server.hpp>
  12. Overview of the Mission API

    main

    The Mission API (plugin) allows you to create, upload, download, run, pause, restart, jump to items in, and track missions. A mission is defined as a vector of MissionItem objects. Each item can specify parameters such as position, altitude, fly-through behavior, camera actions, gimbal position, and travel speed.

    Note: The Mission plugin supports only a subset of MAVLink mission commands. If you require the full MAVLink mission specification or need to import missions from QGroundControl, use the MissionRaw plugin instead.