How to change PX4 Gazebo (last version) home point when launching a simulation

I am writing a python script to simulate several flights of drones and send their telemetry to a mqtt broker.
I have already used the make command to create the environment and I am able to start the simulator in the origin of the default world in Gazebo. The problem is I am not able to establish the initial position of the vehicle when launching the simulator afterwards.
I launch the simulator like this:

    px4_path = "/home/davmasero/PX4-Autopilot/build/px4_sitl_default/bin/px4"
    
    env = os.environ.copy()
    env["PX4_SYS_AUTOSTART"] = "4001"  # Ajusta esto segĂșn tu configuraciĂłn
    env["PX4_SIM_MODEL"] = "gz_x500"  # Ajusta esto segĂșn tu modelo
    x, y, z = latlon_to_cartesian(latitude, longitude, altitude)
    env["PX4_GZ_MODEL_POSE"] = f"{x},{y},0,0,0,0"
    env["PX4_SIMULATOR"] = "gz"
    env["HEADLESS"] = "1"
    
    subprocess.Popen([px4_path], env=env)

The “PX4_GZ_MODEL_POSE” is supposed to reset the starting position of the vehicle with respect to the gazebo origin (which I have modified in the file, btw). Since the gazebo world coordinates have the x,y,z format, I am projecting the lat lon coordinates and setting them up with respect to the origin of the world. The problem is that, although the simulator starts correctly when launching it, for positions like:

[init] PX4_GZ_MODEL_POSE set, spawning at: 1985.7363611118635,-3075.866821288131,0,0,0,0

I find the following error:

pxh> WARN  [health_and_arming_checks] Preflight Fail: ekf2 missing data

Or other arming errors which make the simulator crash.

I really don’t know what the problem might be, since I’m just setting a POSE wrt to the origin of the world and the format is correct. Is there any other way to set the home point correctly?

Do you mean Gazebo Classic by “last version”?

@Jaeyoung-Lim Is this something you can advise on?

I mean the version installed in Ubuntu 22.04
I’d say it is the garden version (?)

I am having trouble with this too. I see there are instructions for setting the takeoff location for gazebo classic here: Gazebo Classic Simulation | PX4 User Guide (v1.14)

However I did not see any similar documentation for gazebo sim.

I am using Ubuntu 22
PX4 v 1.14
Gazebo Garden

Things I have tried:
I tried implementing the instructions for gazebo classic by setting these variables in my bashrc

export PX4_HOME_LAT=28.452386
export PX4_HOME_LON=-13.867138
export PX4_HOME_ALT=28.5

However this did not work.

I tried modifying the .sdf for the default world to have spherical coordinates as defined in Gazebo Sim: Spherical coordinates

<spherical_coordinates>
  <surface_model>EARTH_WGS84</surface_model>
  <world_frame_orientation>ENU</world_frame_orientation>
  <latitude_deg>-22.9</latitude_deg>
  <longitude_deg>-43.2</longitude_deg>
  <elevation>0</elevation>
  <heading_deg>0</heading_deg>
</spherical_coordinates>

However this did not work either

I also tried modifying ~/PX4-Autopilot/ROMFS/px4fmu_common/init.d-posic/airframes

PX4_HOME_LAT=${PX4_HOME_LAT:=34.174528}
PX4_HOME_LON==${PX4_HOME_LON:=-118.481175}
PX4_HOME_ALT==${PX4_HOME_ALT:=0}

and then running

make px4_sitl gz_x500

However this also did not work :frowning:

Can someone please shed some light on how to do this?

Hey! I got a solution that works.

You need to modify the airframe:
~/PX4-Autopilot/ROMFS/px4fmu_common/init.d-posic/airframes

and add the following:

param set-default SIM_GZ_HOME_LAT 47.397742
param set-default  SIM_GZ_HOME_LON 8.545594
param set-default SIM_GZ_HOME_ALT 10

However, I cannot take credit for it, Benja said the solution in this post:

And it sounds like another way to solve this is to modify the world file as described in the above post

1 Like

If you have previously attempted to modify the environment variables to change the location, setting the default world center location will have no effect and the environment variables will overwrite your changes.

Just a note that things changed on 1.15.4. Now you need to change the home pos via the gazebo world file:

1 Like