Use custom world with ROS2 and Gazebo11

Hello, I would like to use my custom world in a simulation.
With ROS1 and mavros is straightforward and I can do it, but how can I do it with

make px4_sitl_default gazebo-classic

I have try with the standard PX4 worlds and I can use them like

make px4_sitl_default gazebo-classic__wharehouse

But if I try with another one like simple_obstacle.world from the PX4-Avoidance package I get the following error:

ninja: error: unknown target 'gazebo-classic_iris__simple_obstacle'
make: *** [Makefile:227: px4_sitl_default] Error 1

I have use this command:

make px4_sitl_default gazebo-classic_iris__simple_obstacle

and I have add (after PX4 model generation) the files in the worlds and models PX4-Avoidance folders inside the PX4 respective ones.

What is the correct procedure to use custom worlds?

Have you added your custom world to the list of targets?

Thanks I was missing that part!

Hey I am having a similar issue, except I am not using gazebo-classic, I’m using gz. I put my custom world to the worlds directory, but I cannot find the list of targets cmake file for gz. Do you have any idea where this file exists? Or if there is a different step that i am missing?

According to the documentation on adding new worlds and models, all you should need is to add the sdf to the gz worlds directory. No need to modify a cmake file like with gazebo-classic.
You may need to specify the world using the environment variable PX4_GZ_WORLD in your make command. For example: PX4_GZ_WORLD=custom make px4_sitl gz_x500
Though it seems make px4_sitl gz_x500_custom should also work.

That doesn’t work. I tried to put the world into directory and make clean, make again, still, self-defined sdf cannot be used. Only modifying the original sdf to change the world.

You need to put your new world here PX4-Autopilot/Tools/simulation/gz (for ROS2)/ worlds and create here ROMFS/px4fmu_common/init.d-posix/airframes/ a file named 4229_gz_<model_name> (you can use 4001_gz_x500 as template). In this file, you need to put something like this at the top to refer to your world and to a custom model. If you also have a custom model you need to copy this file to build/px4_sitl_default/rootfs/etc/init.d-posix/airframes.

PX4_SIMULATOR=${PX4_SIMULATOR:=gz}
PX4_GZ_WORLD=${PX4_GZ_WORLD:=baylands}
PX4_SIM_MODEL=${PX4_SIM_MODEL:=<custom model>}
PX4_GZ_MODEL_POSE="0,0,0.3,0,0,0"
...