PX4 simulation

Simulators allow PX4 Autopilot to control a modeled drone in a simulated environment.

Why simulate?

Simulation is a quick, easy, and most importantly, safe way to test changes to PX4 code before attempting to fly in the real world. It is also a good way to start flying with PX4 when you haven't yet got a vehicle to experiment with. -- PX4 Developer Guide

Many PX4 developers test their code changes in a simulator before flying a real drone with the modified software. It is much safer (and cheaper) to crash your drone in a simulator than in real-life. It is strongly recommended that you also do this if you start making changes to the PX4 firmware.


PX4 supports both Software In the Loop (SITL) simulation, where the flight stack runs on computer (either the same computer or another computer on the same network) and Hardware In the Loop (HITL) simulation using a simulation firmware on a real flight controller board. -- PX4 Developer Guide

Software-In-The-Loop simulation is the most used setup. It is best supported and more straightforward to use. It is actually more representative of how the software would behave in a real world flight than when using Hardware-In-The-Loop, because in HITL several software components are being bypassed. More information is available in the PX4 Developer Guide.

What the PX4 developers refer to as Hardware-In-The-Loop (HITL) is often called Processor-In-The-Loop (PITL or PIL) in industry. The term Hardware-In-The-Loop is applicable when also other parts of the real hardware are being used (e.g. sensors), not just the processor with simulated inputs.

Supported simulators

There are multiple simulators that work with PX4 Autopilot. Most simulators support SITL, some also support HITL. Gazebo is the recommended choice, it is a very powerful simulation tool and is often used together with ROS. Other options include jMAVSim and Microsoft Airsim. A complete overview and up-to-date of simulators that support PX4 is available in the PX4 Developer Guide.

Simulators in a virtual machine

Many HoverGames participants will be using a virtual machine for (PX4) software development. The preconfigured virtual machine does NOT come with a simulator installed and the step-by-step guide also does not explain how to setup a simulator. It is left to the user to install one if desired.

Be aware that most simulators are resource heavy and may not run very will in a virtual machine, especially if your computer is not the most powerful. If possible, it is always better to install the simulator in a native Linux setup.

Decent results have been achieved with Gazebo on a virtual machine running Ubuntu. The virtual machine was assigned 2 processor cores of a modern Intel Core i7 and 8 out of 16 GB of RAM.

Setup instructions and further reading

The PX4 Developer Guide has a whole chapter dedicated to simulation, including some basic instructions on how to setup the simulator. It is the best resource available about simulating PX4 and it is strongly recommend that you base your simulation setup on their instructions and information:

If you have any questions or issues when using PX4 with a supported simulator, you can reach out to the PX4 community on Discuss, Slack or GitHub. Many people are using these simulation environments for PX4 development and it is likely that somebody will be able to help you.