Way to change SITL starting GPS coordinates?

Hi, I’m looking for a convenient way to change the initial GPS coordinates of the firmware in SITL mode with Gazebo so it does not always begin in Zurich. Ideally, I’d like to be able to set a couple environment variables with my desired GPS coordinates that the sim will use to start with a custom GPS location. I’m no expert at the way the gps in the simulator is handled, but I did some digging in the code to see that the sim gps in PX4 is essentially getting HIL MAVLink messages from Gazebo’s MAVLink interface lib. Looking at PX4’s SITL Gazebo repo I noticed Zurich Irchel Park was hardcoded in there, when I changed that I was able to get my desired custom starting location. Is there a way to start the sim with a different latitude, longitude, and altitude without actually modifying this source code?

Thanks.

2 Likes

Read it from an SDF?

http://dev.px4.io/en/simulation/gazebo.html#set-custom-takeoff-location

@Geo where is this file located in the Gazebo. Mavlink interface lib to change the home location

Updated location of documentation:

1 Like

If you are using PX4 1.14 and are using new SITL (not classic), then there are two params you can set on the drone to change it

SIM_GZ_HOME_LAT and SIM_GZ_HOME_LON

I do not see them in newest main documentation, so perhaps the change was only temporary

1 Like

Newbie here.
When running “HEADLESS=1 make px4_sitl gz_x500” can’t set spawn location to anything other than default. Tried setting PX4_HOME_LAT/LON/ALT, SIM_GZ_HOME_LAT/LON - no effect. When setting SIH_LOC_LAT0/LON0 in script file I see logging saying “SIH_LOC_LAT0: curr: 47.3977 → new: new_location”, but then the instance reports the same default location.