QGroundControl and AirSim Integration Guide - Establishing STIL (Software-In-The-Loop)
Article Series
A total of two articles
QGroundControl and AirSim Integration Guide - Establishing STIL (Software-In-The-Loop)
QGroundControl and AirSim Integration Guide - Setting Up Ground Station Control for Virtual Aircraft
Tip:AirSim、SITL、QGroundControl、PX4、Ardupilot
Introduction
[AirSim] ←→ (TCP) ←→ [PX4 SITL(Software-In-The-Loop)] ←→ (UDP) ←→ [QGroundControl(QGC)]
This article explores how to achieve data transmission and control between AirSim, PX4 SITL, and QGroundControl. This architecture is designed for drone simulation environments, allowing developers to test flight control algorithms, navigation strategies, and automated flight plans in a virtual setting. It enables development and validation without requiring physical hardware.
| Term | Definition |
| AirSim | A drone simulation environment responsible for rendering the virtual world and providing physics simulation |
| PX4 SITL | The core of the flight control system, exchanging sensor data and control commands with AirSim via TCP |
| QGC | The ground station, communicating with PX4 SITL via UDP, providing a UI interface to monitor the drone's status and send control commands |
AirSim ↔ PX4 SITL AirSim simulates the physical environment of the drone and connects to PX4 SITL via TCP, while PX4 SITL is used to simulate the PX4 flight controller.
PX4 SITL ↔ QGroundControll Through UDP communication, PX4 SITL sends MAVLink messages to QGroundControl for monitoring, while PX4 SITL allows QGroundControl to send flight commands (such as takeoff, landing, and navigation).
This architecture allows developers to simulate complete drone missions within a software environment, and further integrate AI, autonomous navigation, and image processing technologies to enhance the intelligence capabilities of drones. This article will provide a detailed guide on how to set up this system.
Tips:Here is the main content of this article. The following examples are provided for reference.
一、WSL Ubuntu 22.04 Installation
- Installing WSL and Ubuntu 22.04 on Windows
Open PowerShell (run as administrator) and enter the following command to install WSL and the latest Ubuntu distribution.
wsl --install - Update and Upgrade the System
Enter the following command in the terminal to update the package list and upgrade the installed packages
sudo apt update sudo apt upgrade -y - WSL2 Virtual Network Interface Not Created Check if you have vEthernet (WSL)
Go to [Control Panel] >> [Network and Internet] > [View Network Status and Tasks] > [Change Adapter Settings]
If there is no vEthernet, check if the WSL version is set to version 2.
wsl --list --verbose
You need to check if WSL is version 2. If not, it needs to be upgraded.
Run the following in PowerShell:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -NoRestart
Then, restart the system, open CMD, and enter the following command to upgrade to version 2:
wsl --set-version Ubuntu-22.04 2
After the upgrade is complete, you should be able to see vEthernet.

二、Install Python, pip, and Create a Virtual Environment
1.Install Python and pip
- Check Python Version
python3 --version - If Python is not installed or needs to be updated, run the following commands:
sudo apt install python3 sudo apt install python3-pi2.Set Up Python Virtual Environment
- 安裝
venv模組sudo apt install python3-venv - Create and Activate a Virtual Environment
python3 -m venv px4env source px4env/bin/activate
三、Download PX4-Autopilot
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
cd PX4-Autopilot
git submodule update --init --recursive
四、Compile STIL (Software-In-The-Loop) for PX4
- Compile and Build SITL (Software-In-The-Loop) for PX4
bash ./Tools/setup/ubuntu.sh make px4_sitl_default - Relevant PX4 SITL (Software-In-The-Loop) Information
- ⭐Gazebo Classic Simulation (Here are some make commands for building)
- ⭐PX4 development environment on Windows 10 or 11
五、Install Packages and Resolve Dependency Errors
- Install the necessary dependencies for PX4
make px4_sitl_default - Install the system dependencies for PX4
Install the necessary Python modules in the virtual environment
sudo apt install git zip qtbase5-dev libqt5opengl5-dev \ python3-dev python3-pyqt5 python3-numpy python3-pip \ python3-empy python3-toml python3-jinja2 python3-setuptools \ ninja-build exiftool - Common Errors and Solutions
error:ModuleNotFoundError: No module named 'genmsg'
pip install pyros-genmsg
error:ModuleNotFoundError: No module named 'em' error:AttributeError: module 'em' has no attribute 'RAW_OPT'
pip install empy==3.3.4
error:ModuleNotFoundError: No module named 'menuconfig'
pip install kconfiglib
warning:Failed to import lxml module etree
sudo apt install libxml2 libxml2-dev libxslt1-dev
pip install lxml
六、Start SITL
Setting PX4 Host IP
vim .bashrc
export PX4_SIM_HOST_ADDR=172.17.144.1
Start SITL
make px4_sitl_default none_iris

Summary
PX4 SITL provides a powerful drone flight control simulation environment, allowing developers to test flight control algorithms, navigation strategies, and integration with ground stations (QGroundControl) or AI systems (MAVSDK) without the need for physical hardware. Through TCP/UDP communication, SITL can interact with simulators such as AirSim, Gazebo, or others, enabling virtual testing and validation.