Gazebo | Ignition | Community
Ask Your Question

Wait For the API calls in a world plugin

asked 2018-06-18 09:37:38 -0500

TTDM gravatar image


It's pretty clear that the API calls are asynchronous when called inside the worldUpdate function.

I was wondering if there a exist a function that can be used to wait for the end of the calls ?

The idee behind it would be to pause the simulation, call a few function from the API, advance from one step while knowing that the previous calls have been executed, then call new API functions, etc.

Thanks a lot for anyone that can help, TTDM

edit retag flag offensive close merge delete


What API calls are you referring to? Usually things which don't use transport shouldn't be asynchronous.

chapulina gravatar imagechapulina ( 2018-06-18 12:42:17 -0500 )edit

For exemple a spawn model. If I do the 2 following step: - "spawn a heigthmap using insertModelSdf (or string)" - "get the height of the heigthmap", this function crash because the heightmap does not exit. What i do at the moment is if start it right after OR on the next "au update" callback. What I currently do is to wait for 500 iterations before using the heigthmap.

TTDM gravatar imageTTDM ( 2018-06-19 03:00:55 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-06-19 12:23:17 -0500

chapulina gravatar image

So what's happening is that Gazebo is putting your insert instructions in a queue this->dataPtr->factoryMsgs which gets processed in a future iteration, based on this->dataPtr->processMsgsPeriod.

It looks like you'll need to step a few iterations while checking that the model has been inserted, you could check World::Models() to see if the model has been inserted.

edit flag offensive delete link more


Sorry for the delay of my answer. I wonder if there are not multiple queue such as this one which could create a behavior that appears asynchronous. At some point, I insert a model which contains a sensor (camera). When I destroy them, I start by calling SensorManager::RemoveSensors() then I call World::ClearModels(). I sometimes ( not systematic behavior ) get an error which basically says that the sensor cannot be remove because it does not exists. I guess it has been destroyed with the model

TTDM gravatar imageTTDM ( 2018-06-22 08:17:18 -0500 )edit

My main issue is that I repeat this Model+Sensor creation + destruction process and that sometimes, still not systematic, when I try to create the pair Model+Sensor, I have a core dump. It might not be clear without the code. If that's the case I will update my question in a few month when I will release the code as a part of an open source ros package. Anyway, thanks for the first answer !

TTDM gravatar imageTTDM ( 2018-06-22 08:24:06 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-06-18 09:37:38 -0500

Seen: 74 times

Last updated: Jun 19 '18