Gazebo | Ignition | Community
Ask Your Question

Technique for spawning and deleting large number of models quickly

asked 2020-10-11 22:13:56 -0600

wongrufus gravatar image

updated 2020-10-11 22:32:16 -0600

We are trying to run some tests in simulation. The procedures are roughly as follows

  1. Spawn a large number of models (currently simple spheres) at random positions
  2. Run some tests
  3. Delete the spawned models so we return to the initial state
  4. Repeat

Currently, I am using the ros services /gazebo/spawn_sdf_model and /gazebo/delete_model to spawn and delete models respectively.

The problem is, spawning a single model takes 200ms, deleting a single model takes 400ms. Since I need to do this many times, this takes an extremely long time.

Am I doing something wrong that it takes so long to spawn a simple sphere? Is are there better ways to spawn and delete large number of models, e.g. bulk spawn, or reload the environment?

I am currently running on a system without a GPU but with a fairly powerful CPU and CPU usage isn't maxed out. Would using a GPU help?

The sdf file is as simple as it gets

<?xml version="1.0" ?>
<sdf version="1.5">
  <model name="tiny sphere">
    <link name="link">
      <pose>0 0 0 0 0 0</pose>

      <collision name="collision">

      <visual name="visual">

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-10-12 05:42:20 -0600

A model is spawned by sending a message to ~/factory, and deleted by sending a request to entity_delete. The services you mention build on top of those. They do some preprocessing, handle the request, and then wait for the model to (dis)appear.

You can write a world plugin to manage your models as a whole. I.e. provide an interface that processes the models altogether and waits for them in the end. You will get some speedup, but it's still going to take a non-trivial amount of time to complete.

See gazebo_ros_api_plugin for reference.

Alternatively, assuming the models are always the same, you could spawn them once, and then only randomize their poses in each iteration. This can happen instantaneously.

edit flag offensive delete link more


It seems gazebo gui gets messed up when rapidly calling /gazebo/set_model_state for many objects

wongrufus gravatar imagewongrufus ( 2020-10-13 05:09:47 -0600 )edit

Create a world plugin to which you can send all model names and poses. Then the plugin can reposition all models in one simulation step in its update callback.

nlamprian gravatar imagenlamprian ( 2020-10-13 05:18:50 -0600 )edit

Question Tools

1 follower


Asked: 2020-10-11 22:13:56 -0600

Seen: 769 times

Last updated: Oct 12 '20