Waiting models to be spawned before starting simulation

asked 2019-01-23 05:42:47 -0600

kincurt gravatar image

updated 2019-01-23 05:44:53 -0600

Hello all !

I am using a World Plugin in order to spawn my models and put them and their joints in their initial pose. I am using the InserModelString function in order to insert the models (in SDF) into the world, inside the World::Load function.

If I start gazebo with gazebo myworldwithplugin.world -u --verbose, everything goes fine, gazebo launches and the GUI appears with my models spawned in the world and waiting for me to press play.

However, if i don't use the -u option, gazebo will throw a px!=0 assertion error because my world plugin tried to modify the joints positions before my models even existed.

Here is a little view of the structure of my world plugin:


  • Adding models with InsertModelString

  • Create an event connector to the update loop

Update Loop:

  • On the first iteration:

    • Getting models pointers
    • Editing the joints positions
  • Rest of the time: nothing

So it crashes on the Editing joints positions step because the pointer to the models were NULL However, if at the beginning of the update loop I put some code to sleep while the pointers are NULL, then nothing will ever happen, just like if the models were never spawned.

So it seems that when not using the -u option, gazebo start the simulation before being sure that everything is spawned.

Does someone knows how to solve this?

I tried to be as clear as possible, i will gladly answer your questions if it is not the case.

Thanks for your help !

PS: I am using Gazebo 9 (without ROS) The purpose of this is to be able launch automatically simulations in order to do multiples tests with different parameters for my controllers without having to manually launch each simulation.

edit retag flag offensive close merge delete