Gazebo | Ignition | Community
Ask Your Question

Does setModelState block such that the next sensor readings account for the modified scene?

asked 2020-12-11 03:30:29 -0500

wongrufus gravatar image

I am running a simulation involving many different configurations of a large number of objects. For each "cycle", I read the required object configuration and move the objects in the scene via the /setModelState ROS service. I wait (using simulated time) for what is equivalent to the sensor's publish rate (to make sure I receive the sensor measurements after moving the objects)

I am trying to track down a bug where my sensors in the scene occasionally don't register the new object positions. This does not happen every time, and the probability of it happening seems to decrease as I increase the wait time between moving the objects and getting the sensor readings.

To help narrow down the possibilities, I'd like to know if setModelState block (or stop time) until the next sensor readings. I.e. once setModelState returns, is it guaranteed that the next reading returned by the sensor uses the updated scene?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2021-01-04 22:23:55 -0500

wongrufus gravatar image

This does not seem to be the case. setModelState calls Entity::SetWorldPose which calls Entity::SetWorldPoseModel which calls Entity::PublishPose which calls World::PublishModelPose which only queues up the requested change in the model.

The actual change is applied in World::Step which calls World::ProcessMessages where the requested changes is propagated to the rendering scene via updateScenePose.

In my case, my sensor (Gpu Laser) uses the rendering Scene for updates. Hence it cannot be guaranteed that the scene is updated when setModelState returns. Instead, one needs to wait for the next World::Step call. This may also explain why my waits seem to stop working when my computer is heavily loaded.

edit flag offensive delete link more

answered 2020-12-13 11:47:20 -0500

It does, sort of: But of course when you call this ros service, there's possibly some delay due to IPC, so you might be better off first calling the pause service, then calling setModelState. Hope that helps

edit flag offensive delete link more


I thought calling pause before moving and unpausing afterwards fixed the problem, but further testing showed the problem is still there. After unpausing, I see the objects' positions have been updated when querying /gazebo/model_states, but somehow, some sensors (GPU lidars) are still showing previous locations for some of the objects (around 5% of the moved objects) even after waiting for a few sensor publishes..

wongrufus gravatar imagewongrufus ( 2020-12-30 04:01:31 -0500 )edit

It seems calling setModelState too rapidly models to fail to move on occasion

wongrufus gravatar imagewongrufus ( 2020-12-30 23:12:27 -0500 )edit

Alas, it seems pausing and unpausing also needs to be followed by a short wait

wongrufus gravatar imagewongrufus ( 2020-12-31 00:29:47 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-12-11 03:30:29 -0500

Seen: 24 times

Last updated: Jan 04