Skip to the content
FixTheRobot Explore Robotics / UAV / Module 6 / M6-L2

UAV Systems Engineering · M6-L2 · Hands-on lab (runs on your machine)

Run PX4 SITL

Fly a simulated vehicle running the real PX4 flight stack, and learn the shell commands you will use all module long.

  • UAV Software and Flight-Controller Integration
  • Implementation-specific
  • About 45 minutes

What you will do

PX4 SITL runs the same flight-stack code as the hardware, with a simulator providing sensors and physics. Recent PX4 releases use Gazebo as the default simulator with the x500 quadrotor model. Which make target applies to your release is documented on the simulation page of the PX4 documentation: the commands below follow the documented form for recent releases; verify them for the tag you installed in the previous lab.

Before you start

  • Lab “Install PX4” completed.
  • A machine able to run the simulator (a GPU or software rendering; headless mode is possible).
  • Lessons M6-T6 (flight modes) and M6-T14 (SITL).

Steps

  1. From the PX4-Autopilot directory run make px4_sitl gz_x500 (or the target your documentation names). The first run builds and downloads simulator assets and opens the simulation and the PX4 shell (pxh>).
  2. In the shell, run commander status to see the vehicle state, and wait for the simulated GNSS and estimator to initialise.
  3. Take off with commander takeoff; after it holds altitude, land with commander land.
  4. Run ekf2 status and listener vehicle_local_position, and record the position and the estimator’s fusion state.
  5. Stop the simulation with Ctrl+C and find the ULog file written under the build directory’s log folder.
cd PX4-Autopilot
make px4_sitl gz_x500        # Gazebo + x500 quadrotor (recent releases; check your version's docs)
# in the pxh> shell:
#   commander status
#   commander takeoff
#   listener vehicle_local_position
#   commander land
#   ekf2 status
Typical SITL session. Shell command availability can vary with version.

Questions to answer in your notes

  • Which frame is vehicle_local_position in, and what sign does altitude have?
  • What does ekf2 status tell you about which sensors are being fused?
  • Where does the autopilot write its log, and how large is it after a 2-minute flight?

How to know it worked

  • The simulated vehicle takes off, holds altitude and lands under your commands.
  • You can read position (NED, zz negative above ground) and estimator status from the shell.
  • You found the ULog file and noted its path.

If it does not work

Troubleshooting
SymptomLikely causeWhat to check
Simulator window does not openNo display or GPURun headless as documented, or use a machine with a display
“Preflight Fail” or refuses to armEstimator not yet converged or a simulated sensor not readyWait; read commander status messages
Make target unknownTarget name differs in your PX4 versionList targets with make list_config_targets and read the version’s simulation page
Slow or unstable simulationSoftware rendering or heavy host loadReduce load; run headless

References

Record your progress

Saved in this browser. This lab runs on your own machine, so the site cannot check it for you.