MAVSDK

Introduction

MAVSDK is a collection of libraries for various programming languages to interface with the MAVLink systems such as in drones, cameras or ground systems.

The libraries provides a simple API for managing one or more vehicles, providing programmatic access to vehicle information and telemetry, and control over missions, movement and other operations.

The libraries can be used onboard a drone on a companion computer or on the ground for a ground station or mobile device.

Currently, there is use-in-production support for:

Access the website here.

Installation

The mavsdk-python library can be installed through the pip Python module.

python3 -m pip install mavsdk

The GitHub repository to this library can be found here.

Tutorials and Examples

Sample codes for usage of this library can be found in the repository under the examples directory.

Boilerplate

import asyncio

from mavsdk import System

async def run():
   drone = System()
await drone.connect(system_address="udp://:14540")

print("Waiting for drone to connect...")
async for state in drone.core.connection_state():
   if state.is_connected:
       print(f"-- Connected to drone!")
       break

print("Waiting for drone to have a global position estimate...")
async for health in drone.telemetry.health():
   if health.is_global_position_ok and health.is_home_position_ok:
       print("-- Global position estimate OK")
       break

## The rest of the code runs here
## ...
## ______________________________

return

if __name__ == "__main__":
   # Run the asyncio loop
   asyncio.run(run())

Asynchronicity

As seen in the section above, the MAVSDK Python library uses asynchronous functions.
This is primarily due to the nature of communication and control in drone
operations.

  1. Non-blocking Operations - Drone control involves a lot of real-time operations, like sending commands to the drone, receiving telemetry data, and processing sensor inputs. Async functions allow these operations to occur without blocking the execution of other parts of the program.
  2. Concurrency - Drones need to handle multiple tasks simultaneously, such as flying, capturing images, and communicating with the control station.
  3. Network Communication - MAVSDK is used for interacting with drones over a network (often wireless). Network communication is inherently asynchronous, as it involves waiting for responses without knowing the exact timing.
  4. Improved Performance - By using async functions, MAVSDK can manage multiple drones or multiple tasks for a single drone without the overhead of traditional multi-threading or multi-processing.
  5. Scalability - Asynchronous programming provides better scalability, enabling MAVSDK to handle more complex operations and larger numbers of drones without a significant increase in resource usage.