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.
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
- 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>). - In the shell, run
commander statusto see the vehicle state, and wait for the simulated GNSS and estimator to initialise. - Take off with
commander takeoff; after it holds altitude, land withcommander land. - Run
ekf2 statusandlistener vehicle_local_position, and record the position and the estimator’s fusion state. - 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 statusQuestions to answer in your notes
- Which frame is
vehicle_local_positionin, and what sign does altitude have? - What does
ekf2 statustell 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, negative above ground) and estimator status from the shell.
- You found the ULog file and noted its path.
If it does not work
| Symptom | Likely cause | What to check |
|---|---|---|
| Simulator window does not open | No display or GPU | Run headless as documented, or use a machine with a display |
| “Preflight Fail” or refuses to arm | Estimator not yet converged or a simulated sensor not ready | Wait; read commander status messages |
| Make target unknown | Target name differs in your PX4 version | List targets with make list_config_targets and read the version’s simulation page |
| Slow or unstable simulation | Software rendering or heavy host load | Reduce 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.