Align PX4 local_position and Gazebo Classic reference frame

Greetings,
I am using Gazebo Classic to simulate a quad-copter running PX4 and ROS2, but I have a little issue with the coordinate systems.

The drone is spawned on Gazebo at a fixed location different from the Gazebo origin.
I either need to spawn the drone at the origin or advertise the PX4 topics to set the current location (which is initialized as x=0, y=0, z=0) at the real Gazebo coordinates.

Can you help me with this matter?

The only idea that I had was to change the parameters of the simulated drone trough QGroundControl to set up PX4 to receive an external odometry such I have done for the Vicon, but it seems to me an unnecessary convoluted solution for the matter.

1 Like

If someone face the same problem.
I found how to change the spawn location of the models in Gazebo Classic.

Go to PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/, there a file called sitl_run.sh (which the bash script which one of the bash script that is executed by the make p4_sitl gazebo-classic command).

Around line 130 (PX4 v1.14 at the time of writing) you will find the following text:

while gz model --verbose --spawn-file="${modelpath}/${model}/${model_name}.sdf" --model-name=${model} -x 1.01 -y 0.98 -z 0.83 2>&1 | grep -q "An instance of Gazebo is not running."; do
		echo "gzserver not ready yet, trying again!"
		sleep 1
	done

You can change the -x -y -z field to spawn the vehicle wherever you want!

I am still wondering if I can advertise somehow the /fmu/vechicle_odometry or /fmu/vehicle_local_position to send to it the position and attitude of the model to align them with Gazebo without spawning it right at the origin.

2 Likes