Home | Tutorials | Wiki | Issues
Ask Your Question

InsertModelSDF potential race condition

asked 2014-12-16 00:47:23 -0600

mkoval gravatar image

I am trying to programmatically add objects to an environment with InsertModelSDF. There seems to be a race condition that causes this to sporadically fail if InsertModelSDF is called too quickly after init_world. This test script reliably fails on the first iteration and, additionally, sometimes fails on the second iteration of the loop:

Additionally, I noticed a few other quirks that are potentially relevant:

  1. GetModel only returns the new model after runWorld has run for at least one timestep.
  2. There is no reliable way of telling if InsertModelSDF failed.

Am I doing something wrong in my test script (e.g. neglecting acquire a lock)? Also, is there any way to force this data to refresh without running a simulation timestep?

edit retag flag offensive close merge delete


In your test script you don't declare `model_path`. Can you fix it?

NickDP gravatar imageNickDP ( 2014-12-16 15:31:33 -0600 )edit

I accidentally removed that line when cleaning up the code. It's fixed now (same URL).

mkoval gravatar imagemkoval ( 2014-12-17 01:26:51 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-12-16 14:05:57 -0600

NickDP gravatar image

Regarding your additional questions, my question and nkoenig's answer here is relevant.

edit flag offensive delete link more


This is likely the source of the issue. However, I am not sure why. I am manually triggering simulation timesteps with the gazebo::runWorld function. Shouldn't this force processing of the queue?

mkoval gravatar imagemkoval ( 2014-12-16 14:54:59 -0600 )edit

answered 2014-12-17 10:31:59 -0600

nkoenig gravatar image

This happens because we don't process messages every iteration of simulation. Our strategy is to let messages that don't need immediate processing to linger a bit. The effect is a small delay in things like inserting new models, with more time given to the physics engine.

edit flag offensive delete link more


Thanks! What is the recommended way of waiting for the model to be inserted? @NickDP's post uses a spinlock to wait until GetModelCount() increases. I am attempting to use Gazebo programmatically (in-process), so it is undesirable to trigger several physics updates every time I add a model. Ideally, I'd like to run the message processing manually (without also triggering a simulation step).

mkoval gravatar imagemkoval ( 2014-12-17 11:07:37 -0600 )edit

You should be able to listen to the ~/model/info topic. Or you can connect to the addEntity event.

nkoenig gravatar imagenkoenig ( 2014-12-17 11:14:04 -0600 )edit

Thanks. The `AddEntry` event looks like what I want. Is there any way to process the message queue without also triggering a simulation step?

mkoval gravatar imagemkoval ( 2014-12-17 11:35:33 -0600 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-12-16 00:47:23 -0600

Seen: 177 times

Last updated: Dec 17 '14