0
0
Pcb-designHow-ToBeginner · 4 min read

How to Set Up Software In The Loop (SITL) in Drone Programming

To set up Software In The Loop (SITL) for drone programming, install a compatible drone simulator like PX4 SITL or ArduPilot SITL, then run the SITL binary to simulate drone hardware on your computer. Connect your drone control software to this simulator to test flight code without real hardware.
📐

Syntax

Setting up SITL involves running the simulator command and connecting your drone software to it. The basic syntax for PX4 SITL is:

  • make px4_sitl_default jmavsim - builds and runs PX4 SITL with the JMAVSim simulator.
  • make px4_sitl_default gazebo - runs PX4 SITL with Gazebo simulator.

For ArduPilot SITL, the command is:

  • sim_vehicle.py -v ArduCopter -f quad --console --map - starts ArduPilot SITL for a quadcopter with console and map.

Each part means:

  • make px4_sitl_default: builds PX4 SITL software.
  • jmavsim/gazebo: selects the simulator environment.
  • sim_vehicle.py: ArduPilot SITL launcher script.
  • -v ArduCopter: vehicle type.
  • -f quad: frame type.
  • --console --map: optional UI tools.
bash
make px4_sitl_default jmavsim

# or for ArduPilot
sim_vehicle.py -v ArduCopter -f quad --console --map
💻

Example

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

bash
# Step 1: Clone PX4 Firmware repository
git clone https://github.com/PX4/PX4-Autopilot.git
cd PX4-Autopilot

# Step 2: Build and run SITL with JMAVSim
make px4_sitl_default jmavsim

# Step 3: Open QGroundControl on your computer
# It will auto-connect to the SITL instance

# Step 4: Use QGroundControl to arm, fly, and test your drone code safely
Output
INFO [px4] Creating symlink /home/user/src/PX4-Autopilot/build/px4_sitl_default/etc INFO [px4] Built px4_sitl_default INFO [jmavsim] Starting JMAVSim simulator INFO [commander] Startup complete INFO [mavlink] Partner IP: 127.0.0.1 INFO [mavlink] Partner port: 14550 INFO [mavlink] Mavlink is up and running
⚠️

Common Pitfalls

Common mistakes when setting up SITL include:

  • Not installing required dependencies like Java (for JMAVSim) or Gazebo simulator.
  • Running SITL without building the firmware first.
  • Firewall blocking UDP ports used by SITL and ground control software.
  • Using incompatible versions of SITL and ground control software.
  • Not starting the simulator UI, leading to no visual feedback.

Always check logs for errors and verify network connections.

bash
# Wrong: Running SITL without building
px4_sitl_default jmavsim

# Right: Build first then run
make px4_sitl_default jmavsim
📊

Quick Reference

StepCommand/ActionDescription
1git clone https://github.com/PX4/PX4-Autopilot.gitDownload PX4 firmware source code
2cd PX4-AutopilotChange to firmware directory
3make px4_sitl_default jmavsimBuild and start PX4 SITL with JMAVSim simulator
4Open QGroundControlConnect to SITL for control and monitoring
5Test flight commandsUse QGroundControl to arm and fly the simulated drone

Key Takeaways

Install and build the SITL firmware before running the simulator.
Use compatible simulators like JMAVSim or Gazebo with PX4 SITL.
Connect your ground control software to SITL via UDP ports.
Check dependencies and network settings to avoid connection issues.
Use SITL to safely test drone code without real hardware risks.