Drone spawn position setup

Hi, I am sorrz for stupid question, but I am totally new in the field. I would like to ask how to setup drone spawning position for simulation with gazebo. I am using Ubuntu 22.04 so I use the new gazebo simulator and I am confused by the documentation.
It says ( Gazebo Simulation | PX4 User Guide) the make command make px4_sitl gz_x500 shall start the simulation. But I am able to change the location where the drone shall appear? Few lines bellow there is description how to start the simulation with some parameters Gazebo Simulation | PX4 User Guide, but I dont understand it. There is no .build folder in repo. Shall I run some make command to create a build. Can anybody, pls, provide example how to spawn a drone at specific coordinates? In old gazebo there was the possibility to use expose latitude and longitude variables. How can I achieve something like this with new gazebo?
Thanks in advance.

Hi @Lukas !
You are almost there, to use the advanced startup options you just need to compile (without running) PX4 once:

make px4_sitl

and then you can start the simulation with your customizations, like in the first example of the guide:

PX4_SYS_AUTOSTART=4001 PX4_GZ_MODEL=x500 ./build/px4_sitl_default/bin/px4

Use PX4_GZ_MODEL_POSE to set “x,y,z,roll,pitch,yaw” of the spawned drone. Note that this is the LOCAL Gazebo coordinate: the local PX4 position will always start from zero.

Hi @Benja, thank you for quick response :slight_smile:
ok, so I need to compile it first, got it, then the command for starting the simulation has to be launched from repo root folder? or from some specific folder? (not familier with the structure yet, since building it in docker)
and about those coordinates, if those are local gazebo, it meens it is where in the world model the drone is spawned. But If I connect to it via QGroundControl, I can see satelite map and I would like to spawn the drone on specific gps location, lets say on Times Square in NY city. Does it mean that I need to tell to gazebo where to spawn the world? if yes, how?
In old gazebo classic this was possible Gazebo Classic Simulation | PX4 User Guide and this allowed to spawn the drone at selected location in the world and the map in QGS shown the place right? How can I achieve something like this with new gazebo?

Yes! But you can adapt it and run it from anywhere.


Yes, you need to use the parameters SIM_GZ_HOME_LAT, SIM_GZ_HOME_LON, SIM_GZ_HOME_ALT Parameter Reference | PX4 User Guide (main)

Note that the pipeline is the following: PX4 receives the true pose (position and orientation) of the model w.r.t. the Gazebo origin. Then it converts it to global coordinates (lat long alt) and share it in the local_position_groundtruth topic. The GPS simulator module and the MAG simulator module subscribe to this topic, add white noise and simulate true GPS and MAG measurements that are then used as they were coming from actual sensors.


thank you very much. This is excellent.

Hello can i know more deatils about how to set these parameters @Benja

You can set them as you set any other parameter, using QGC and the rebooting

Or, you can add them permanently in your airframe file

in the same way it is done for the other parameters there

1 Like

Thank You so much it worked

1 Like

It’s been a while from this post, but coming from another one I’ve found this and I’ve noticed these parameters are not in the reference page anymore… is this on purpose?

You are right, the interface changed it seems but the documentation was not updated (feel free to open an issue here Issues · PX4/PX4-user_guide · GitHub)
PX4 retrieves the GPS location direclty from Gazebo now, and the GPS origin is set in the world file:
PX4-gazebo-models/worlds/default.sdf at 6b4ed09d1b495fbff663f098979cc046df013abd · PX4/PX4-gazebo-models · GitHub

I’m able to change the spawning position by changing the default world file. Is there another way to change it without modifying the world file ?