PX4 SITL with Gazebo: Hardware-in-the-Loop UAV Simulation for Defense and Autonomous Systems Development
Software-in-the-Loop (SITL) simulation using PX4 Autopilot paired with the Gazebo physics engine has become a cornerstone workflow for defense contractors and autonomous systems engineers developing unmanned aerial vehicles (UAVs). Unlike purely kinematic simulators, the PX4/Gazebo stack runs the actual flight-control firmware against a high-fidelity physics model, enabling engineers to validate guidance, navigation, and control (GNC) algorithms before a single airframe is assembled.
Why PX4 SITL Matters for Defense UAV Programs
Traditional hardware-in-the-loop (HIL) benches require physical autopilot boards, wiring harnesses, and dedicated lab space. SITL eliminates that overhead: the PX4 firmware binary executes natively on a developer workstation, communicating with Gazebo over a UDP MAVLink bridge. The result is a closed-loop simulation where the autopilot "believes" it is flying a real vehicle, processing synthetic IMU, GPS, barometer, and magnetometer data generated by the physics engine.
For defense programs operating under DO-178C or MIL-STD-882E constraints, SITL provides a reproducible, version-controlled test environment that can be integrated into CI/CD pipelines—something physical benches cannot easily offer.
Architecture Overview
The PX4 SITL stack consists of three primary layers:
-
PX4 Firmware (SITL target): Compiled with
make px4_sitl_default gazebo-classicor the newermake px4_sitl gz_x500for Gazebo Garden/Harmonic. The firmware exposes a MAVLink interface on UDP port 14550 (GCS) and 14540 (companion computer). -
Gazebo Physics Engine: Provides rigid-body dynamics, aerodynamic drag models, sensor noise injection, and world environments. The
irisquadrotor andstandard_vtolmodels ship with PX4 and include calibrated aerodynamic coefficients. Custom airframe plugins can be authored in C++ using the Gazebo Plugin API. -
MAVLink / MAVSDK / ROS 2 Bridge: Mission computers, ground control stations (QGroundControl, Mission Planner), and autonomy stacks communicate via MAVLink. The MAVSDK C++/Python library provides a clean abstraction for offboard control, while the
px4_ros_compackage bridges PX4 uORB topics into ROS 2 for sensor fusion and path-planning research.

Configuring a Realistic Defense Scenario
Wind and Atmospheric Disturbances
Gazebo's WindPlugin injects steady-state and turbulent wind into the simulation. For defense-relevant fidelity, engineers typically configure Dryden turbulence model parameters (MIL-HDBK-1797B) via the SDF world file:
<plugin name="wind" filename="libgazebo_wind_plugin.so">
<windVelocityMean>8.0</windVelocityMean>
<windVelocityVariance>1.5</windVelocityVariance>
<windDirectionMean>0 1 0</windDirectionMean>
</plugin>
Pairing this with PX4's EKF2 estimator allows teams to stress-test wind-rejection performance of attitude controllers without flight risk.
GPS Denial and Spoofing Emulation
A critical defense use case is evaluating UAV resilience under GPS-denied or GPS-spoofed conditions. PX4 SITL supports this through the SENS_GPS_MASK parameter and custom Gazebo sensor plugins that inject position bias or drop GPS fixes entirely. Engineers can then evaluate optical flow, VIO (Visual-Inertial Odometry), or terrain-relative navigation fallback modes under controlled, repeatable conditions.
Multi-Vehicle Swarm Simulation
PX4 SITL supports multiple simultaneous instances via the Tools/simulation/gazebo-classic/sitl_multiple_run.sh script. Each instance binds to a unique UDP port offset, enabling swarm coordination research. Combined with ROS 2 and a custom mission manager, teams can simulate 4–16 vehicle swarms executing coordinated ISR patterns—directly relevant to programs like the DoD's Replicator initiative.
Sensor Plugin Best Practices
| Sensor | Recommended Plugin | Key Parameters |
|---|---|---|
| IMU | libgazebo_imu_plugin.so |
gyroscopeNoiseDensity, accelNoiseDensity |
| GPS | libgazebo_gps_plugin.so |
gpsNoise, gpsDrift |
| Downward Camera | libgazebo_camera_plugin.so |
imageWidth, imageHeight, framerate |
| Lidar | libgazebo_ray_plugin.so |
minRange, maxRange, resolution |
Noise parameters should be calibrated against datasheet values for the target hardware (e.g., VectorNav VN-200, u-blox F9P) to ensure simulation-to-real transfer fidelity.

Integration with CI/CD for Regression Testing
One of the most powerful—and underutilized—capabilities of PX4 SITL is its suitability for automated regression testing. A typical pipeline:
- GitHub Actions / GitLab CI triggers on each firmware commit.
- A headless Gazebo instance (
HEADLESS=1 make px4_sitl_default gazebo-classic) launches the simulation. - A Python test harness using MAVSDK-Python arms the vehicle, executes a waypoint mission, and asserts position error < 2 m RMS.
- Results are logged to a JUnit XML report for dashboard visualization.
This approach catches GNC regressions before they reach hardware, reducing costly flight-test iterations—a significant advantage in defense programs with constrained flight-test windows.
Transitioning from SITL to Hardware-in-the-Loop (HIL)
Once SITL validation is complete, transitioning to HIL requires only a configuration change: the physical Pixhawk/Cube autopilot connects to the simulation host via USB/UART, and Gazebo continues to provide synthetic sensor data. PX4's HIL mode (SYS_HITL=1) disables onboard sensor drivers and routes all sensor data from the simulator. This step validates that the compiled firmware binary behaves identically on target hardware—a critical milestone for airworthiness reviews.
Limitations and Considerations
- Aerodynamic fidelity: Gazebo's default aerodynamic models are simplified. For high-speed fixed-wing or hypersonic vehicles, coupling with a dedicated CFD solver (e.g., OpenFOAM) or using JSBSim as the physics backend is recommended.
- Real-time factor: Complex worlds with many vehicles may run below 1× real-time on standard workstations. Use
--factorflags or dedicated simulation servers. - Export control: PX4 is open-source (BSD-3), but integrating classified sensor models or mission data requires careful ITAR/EAR compliance review.
Further Resources
- PX4 SITL Documentation
- Gazebo Classic Plugins Reference
- MAVSDK Python API
- PX4 ROS 2 User Guide
- MIL-HDBK-1797B: Flying Qualities of Piloted Aircraft
PX4 SITL with Gazebo represents a mature, production-ready simulation stack that bridges the gap between algorithm development and flight-ready hardware. For defense programs prioritizing repeatability, CI/CD integration, and GPS-denied resilience testing, it offers capabilities that purpose-built commercial simulators often cannot match at comparable cost.