Documentation/F410 WikiEnglish · V6C
Browse documentation
Additional documentation

PC Control UAV

Maintain mavsdk python version 1.4.5 (or higher)

6 min read · English documentation

PC Control UAV

Maintain mavsdk-python version 1.4.5 (or higher)

Official website

http://mavsdk-python-docs.s3-website.eu-central-1.amazonaws.com/

PC-SDK is a Python SDK library optimized and maintained by Amov Laboratory to simplify the MAVLink control protocol for open source flight controllers, supporting MAVSDK operation on PC (Windows and Ubuntu). It enables simple UAV development where developers don't need to learn complex drone technologies, just Python programming and basic coordinate system principles to implement UAV control development, significantly reducing development difficulty.

PC-SDK is based on MAVSDK source code, adapted to PC-side Python development environments to lower UAV development barriers. Users can control UAV flight via ground station links by installing Python environment and functional package modules on a PC. Only requiring knowledge of Python and UAV control coordinate systems/flight mode concepts enables easy UAV flight control. Compared with traditional UAV control development, users don't need deep C/C++ or ROS knowledge.

MAVSDK Introduction

MAVSDK is a collection of libraries in various programming languages for interacting with MAVLink systems like UAVs, cameras, or ground systems. These libraries provide a simple API for managing one or multiple vehicles, offering programmatic access to vehicle information/telemetry and control over missions, movements and other operations. The libraries can be used on companion computers onboard UAVs or on ground stations/mobile devices.

MAVSDK Features:

Cross-platform: Linux, macOS, Windows, Android, iOS

Multi-language: C++, Swift, Python, Java, Go, JavaScript, C#, Rust

Connect via serial port, TCP or UDP to control Pixhawk flight controllers. Can build Pixhawk source code in Ubuntu and create simulators to control simulated aircraft through MAVSDK.

Currently provides:

Automatic takeoff/landing demo Point-to-point flight demo Waypoint mission demo Also provides Ubuntu simulation development VM for rapid algorithm development and quick UAV development onboarding.

Note

Beginners without UAV knowledge or coordinate system concepts should not run other demos. Recommended to first understand UAV control coordinate systems through our simulation system, become familiar with UAV operational characteristics before attempting other complex demos.

Basic Concepts of UAV Control Coordinate Systems

Understanding NED Coordinates in UAVs

Body Coordinate System: Fixed to aircraft with origin at center of gravity. X-axis points forward along aircraft symmetry plane. Z-axis perpendicular downward in symmetry plane. Y-axis determined by right-hand rule.

Earth-Fixed Coordinate System: Typically uses takeoff position as origin. X-axis points North (NED: North-East-Down), Y-axis East, Z-axis Down. Euler angles describe transformation between these systems: pitch+ is nose up, roll+ is right roll, yaw+ is right yaw.

Yaw vs Compass Heading: Compass heading is absolute: 0°=North, 90°=East, 180°=South, 270°=West. Yaw angle is relative to North in NED system. When providing yaw angle to flight controller through vision system, it directly corresponds to compass heading if Earth system is NED.

This example uses the END coordinate system with the power-on position as the origin (0.0.0). Based on the WGS84 system: E=East (Y-axis), N=North (X-axis), and D=Down (Z-axis). Positive values indicate the corresponding directions. Note: Z-axis (height) processing is inverted in the example.

ENU vs NED Differences

As shown:

Terminology

  1. MAVLink: Lightweight messaging protocol for communication between ground stations and UAVs (and between onboard components). Uses hybrid pub-sub and point-to-point patterns.

  2. MAVSDK: Collection of libraries for interacting with MAVLink systems.

  3. Body Coordinate System: Right-hand rule system fixed to aircraft, origin at CG. X-axis forward, Y-axis right, Z-axis down. Fundamental for IMU data and inertial navigation. Coordinate transformations convert between NED (inertial) and body systems.

  4. Position Control: Controls UAV position in 3D space through x,y,z coordinates. Horizontal (x,y) and vertical (z) control combined.

  5. Velocity Control: Inner-loop PID controller using velocity error (desired - measured) to calculate attitude setpoints.

  6. Attitude Control: Manages pitch, roll and yaw angles from various inputs (RC sticks, position controller outputs, etc). Maintains stability at desired attitudes.

Quick Start (Verified on Windows 11)

Verify normal communication and development environment.

Note

Test in open outdoor areas, maintain 10m+ distance from UAV. Requires basic skills (UAV operation/Ubuntu/Python). Recommend starting with simulation.
Hardware & Communication Diagram

Prerequisites: Python3.7+, pip, QGC, mavsdk_server, VSCode, git

Install MAVSDK:

 pip3 install mavsdk

Clone demo:

git clone https://gitee.com/amovlab1/pcsdk

Download mavsdk_server:

https://github.com/mavlink/mavsdk/releases

For F410 base model:

  • Connect ground station Ethernet to PC (static IP 192.168.1.123)
  • Run mavsdk_server to establish communication node
  • Refer to "Data Link Configuration" in Extended Help for detailed setup

Successful connection:

In VSCode, open takeoff-and-land.py, uncomment specified sections (see code notes), run:

python ./takeoff-and-land.py

Executes automated takeoff, 10s hover, landing. Displays GPS, battery status etc. Remote control can intervene during process.

Demo video:

Simulation Environment Setup

Two methods: Environment setup or VM image. Recommended image.

VM Image

Download:

https://download.amovlab.com/F410/pixhawk%206c/Ubuntu/

Install via VM software, dual-boot or bare metal. Contains all required software.

Environment Setup

  1. Ubuntu 20.04, install PX4-Autopilot

  2. Clone source:

    git clone http://github.com/PX4/PX4-Autopilot

  3. Update submodules:

    cd PX4-Autopilot/ git submodule update --init --recursive

  4. Run setup script:

    cd
    bash ./PX4-Autopilot/Tools/setup/ubuntu.sh

  5. Reboot, then update:

    sudo apt-get update sudo apt-get upgrade

  6. Build:

    cd PX4-Autopilot/ make px4_sitl jmavsim

  7. Install QGC: Download:

    https://download.amovlab.com/F410/pixhawk%206c/UBUNTU20.04%E5%9C%B0%E9%9D%A2%E7%AB%99/

Or official:

https://docs.qgroundcontrol.com/master/en/getting_started/download_and_install.html

Install dependencies:

sudo usermod -a -G dialout $USER
sudo apt-get remove modemmanager -y
sudo apt install gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-gl -y
sudo apt install libqt5gui5 -y
sudo apt install libfuse2 -y

Run QGC:

chmod +x ./QGroundControl.AppImage
./QGroundControl.AppImage

8. Install MAVSDK:

pip3 install mavsdk

9. Install VSCode:

https://code.visualstudio.com/Download

10. Clone demo:

git clone https://gitee.com/amovlab1/pcsdk

Code Overview

Note

Real UAV operation requires position mode and emergency stop function. Simulation recommended first.

Demo1 - Takeoff/Landing: takeoff-and-land.py

Automatic takeoff, 10s hover, landing. Displays GPS, battery status. Simulation:

Demo2 - Waypoint Mission: miss.py

Waypoint flight mode. Input X,Y,Z coordinates, speed, loiter time, yaw. Simulation:

Demo3 - Offboard Control: offboard-position.py

Offboard mode for intelligent flight. Position control in NED system. Contains velocity/attitude/body-frame control (commented by default). Simulation:

Warning

The example contains body-frame velocity control, attitude control, and velocity control in the END coordinate system. These three control modes are dangerous and are commented out by default. Switching control modes requires enabling the required section and disabling the others. Only position control is enabled by default; do not use the other modes except in simulation whenever possible.

Warning

RC cannot intervene in offboard mode.

Communication Setup

Note

Recommend dual data links for QGC and MAVSDK monitoring.

For F410V6C with MiniHomer:

Default Windows Setup:

MAVSDK: UDP 14540
QGC: UDP 8080

MAVSDK Connection:

mavsdk_server bridges UAV-PC communication. Download:

https://github.com/mavlink/mavsdk/releases

Warning

If an emergency occurs, terminate the `mavsdk_server` connection by pressing `Ctrl+C`.

QGC Connection:

UDP port 8080

Custom Connection Configuration (Not Recommended):

Download the MAVLink MAVSDK source code:

https://github.com/mavlink/MAVSDK

The required toolchain and environment are not covered by this Wiki.

Real UAV Operation

Note

Verify position mode and emergency stop function. Keep safe distance during ARM tests.

After confirming normal RC operation and manual flight, run Python scripts through VSCode:

https://code.visualstudio.com/Download

Install MAVSDK and clone the demo repository:

pip3 install mavsdk
git clone https://gitee.com/amovlab1/pcsdk

Demo video:

Some programs send an ARM command once to verify command transmission. Keep people away from the aircraft and do not approach it while running these programs.

Note

Real-drone and simulation operations are the same. For real-drone tests, verify the function of every remote-controller switch, ensure that the aircraft is in Position mode, and confirm that an emergency motor-stop function is available to prevent accidents.

Common APIs