MAVSDK-Python Documentation

repository·main·Indexed 19 days ago

https://github.com/mavlink/mavsdk-python

A Python wrapper for MAVSDK that provides an asynchronous interface to control drones via gRPC. It communicates with a C++ backend (mavsdk_server) to interact with MAVLink-enabled systems. The library includes various plugins for vehicle control, such as action, camera, calibration, events, failure, and FTP, and supports installation on platforms including Raspberry Pi and Jetson Nano.

Tokens
6.1K
Snippets
22
Records
43
Agent score
16%

What's inside MAVSDK-Python

  1. Explore MAVSDK-Python plugins

    main

    MAVSDK-Python is organized into specialized plugins that provide access to different drone capabilities and MAVLink features. Instead of a single monolithic API, you interact with specific plugins for tasks such as mission management, telemetry, camera control, and offboard mode.

    Common plugin categories include:

    • Core & System: core, info, param, telemetry
    • Flight Control: action, offboard, manual_control, mission
    • Hardware/Peripherals: camera, gimbal, gripper, winch
    • Data & Logs: log_files, log_streaming, ftp
    • Advanced/Specialized: mocap, rtk, transponder, mavlink_direct

    Note that some plugins follow a client/server pattern (e.g., action vs action_server), where the _server variants are typically used when the MAVSDK-Python application is acting as the provider of a service rather than the consumer.

  2. Use the Action plugin to control vehicle behavior

    main

    The mavsdk.action module provides an interface to control various high-level actions of a drone or vehicle. This includes commands for takeoff, landing, returning to launch, and managing flight modes.

    Note: The available actions depend on the capabilities of the connected vehicle and the specific MAVSDK plugin implementation.

  3. Use the Offboard plugin for autonomous control

    main

    The offboard plugin in MAVSDK-Python allows you to control a vehicle in 'Offboard' mode. This mode is used for autonomous flight where the vehicle follows commands (such as setpoints for position, velocity, or attitude) sent from an external computer rather than following a pilot's manual inputs.

    To use this plugin, you typically interact with the Offboard class provided by the mavsdk.offboard module. Note that for offboard mode to be successfully engaged, the vehicle must be receiving a continuous stream of setpoints.

  4. Use the Geofence plugin in MAVSDK-Python

    main

    The mavsdk.geofence module provides an interface to manage geofences on a drone. Geofences are virtual boundaries that define safe operating areas. This plugin allows you to interact with the geofence subsystem of the drone via MAVSDK.

    Note: The internal methods translate_from_rpc and translate_to_rpc are used for communication with the MAVSDK server and are not part of the public API.

  5. How MAVSDK-Python and mavsdk_server work together

    main

    MAVSDK-Python is a gRPC client that communicates with a gRPC server written in C++ called mavsdk_server (the "backend").

    • Embedded Mode (Default): When you call await drone.connect() without specifying a mavsdk_server_address, the Python wrapper automatically starts the embedded mavsdk_server binary.
    • External Mode: If you set mavsdk_server_address to a specific address (e.g., 'localhost'), the wrapper assumes a server is already running and connects to it directly. This is recommended for resource-constrained devices like Raspberry Pi where you might need to manage the mavsdk_server process manually.
  6. Use the MissionRaw plugin

    main
    The mission_raw plugin provides low-level access to mission management in MAVSDK. Unlike the standard mission plugin which uses high-level abstractions, mission_raw allows you to interact with mission items using raw MAVLink mission item structures. This is useful when you need to upload specific mission items that are not covered by the high-level API or when you need precise control over the mission data being sent to the vehicle.
  7. Use the Gripper plugin to control a robotic gripper

    main

    The mavsdk.gripper module provides an interface to control a robotic gripper on a drone. It allows you to command the gripper to open or close and monitor its current state. This plugin is part of the MAVSDK plugin system and requires a compatible flight controller and hardware setup.

    from mavsdk import System
    from mavsdk.gripper import Gripper
    
    async def run():
        drone = System()
        await drone.connect()
    
        gripper = Gripper(drone)
        # Use gripper methods here
  8. Manage drone missions with the Mission plugin

    main

    The mavsdk.mission module provides an interface for managing waypoints and missions on a drone. It allows you to upload mission waypoints, start a mission, and monitor the mission progress.

    Note: The module contains internal translation methods (translate_from_rpc and translate_to_rpc) which are not intended for direct use by end-users.

  9. Use the ManualControl plugin

    main

    The ManualControl plugin in MAVSDK-Python allows you to manually control the attitude (pitch, roll, and yaw) of a vehicle. This is typically used for manual flight modes where the user or an external system provides direct orientation commands.

    Note: This plugin is part of the MAVSDK plugin system and requires a connection to a vehicle via a System instance.