0
0
Pcb-designHow-ToBeginner · 4 min read

How to Use PX4 SITL Simulator for Drone Development

To use the PX4 SITL simulator, first install PX4 and its dependencies, then run make px4_sitl_default jmavsim to start the simulation with the JMAVSim GUI. You can control the simulated drone using QGroundControl or command line tools while PX4 runs the autopilot software in a virtual environment.
📐

Syntax

The basic command to start PX4 SITL simulation is:

make px4_sitl_default [simulator]

Where:

  • make runs the build system.
  • px4_sitl_default builds the PX4 firmware for SITL (Software In The Loop).
  • [simulator] is the simulation environment, e.g., jmavsim or gazebo.

This command compiles PX4 and launches the SITL with the chosen simulator.

bash
make px4_sitl_default jmavsim
💻

Example

This example shows how to start PX4 SITL with JMAVSim and connect to QGroundControl for drone control.

bash
cd ~/PX4-Autopilot
make px4_sitl_default jmavsim
Output
INFO [px4] Creating symlink /home/user/src/PX4-Autopilot/ROMFS/px4fmu_common -> /home/user/src/PX4-Autopilot/build/px4_sitl_default/tmp/rootfs/ROMFS/px4fmu_common INFO [px4] Built target px4_sitl_default INFO [simulator] Starting jmavsim simulator INFO [commander] Startup complete INFO [mavlink] Partner IP: 127.0.0.1 INFO [mavlink] Partner port: 14550 INFO [mavlink] Mavlink on UDP port 14540 INFO [mavlink] Mavlink on UDP port 14557 INFO [mavlink] Mavlink on UDP port 14560 INFO [mavlink] Mavlink on UDP port 14580 INFO [mavlink] Mavlink on UDP port 14600 INFO [mavlink] Mavlink on UDP port 14640 INFO [mavlink] Mavlink on UDP port 14680 INFO [mavlink] Mavlink on UDP port 14720 INFO [mavlink] Mavlink on UDP port 14760 INFO [mavlink] Mavlink on UDP port 14800 INFO [mavlink] Mavlink on UDP port 14840 INFO [mavlink] Mavlink on UDP port 14880 INFO [mavlink] Mavlink on UDP port 14920 INFO [mavlink] Mavlink on UDP port 14960 INFO [mavlink] Mavlink on UDP port 15000
⚠️

Common Pitfalls

  • Missing dependencies: PX4 SITL requires Java, Maven, and simulator tools like JMAVSim or Gazebo installed.
  • Wrong directory: Run make commands inside the PX4 firmware folder.
  • Port conflicts: Multiple MAVLink connections can cause port conflicts; close other apps using the same ports.
  • Simulator not launching: Check if Java is installed and simulator environment variables are set.
bash
Wrong:
make px4_sitl_default

Right:
make px4_sitl_default jmavsim
📊

Quick Reference

  • Start SITL with JMAVSim: make px4_sitl_default jmavsim
  • Start SITL with Gazebo: make px4_sitl_default gazebo
  • Connect QGroundControl: Use UDP port 14550 to control the simulated drone.
  • Stop simulation: Press Ctrl+C in terminal.

Key Takeaways

Run PX4 SITL inside the PX4 firmware directory using the make command with a simulator argument.
Install all required dependencies like Java and simulator tools before running SITL.
Use QGroundControl connected to UDP port 14550 to control the simulated drone.
Check for port conflicts and ensure the simulator launches properly to avoid common errors.