Technique for spawning and deleting large number of models quickly
We are trying to run some tests in simulation. The procedures are roughly as follows
- Spawn a large number of models (currently simple spheres) at random positions
- Run some tests
- Delete the spawned models so we return to the initial state
- 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">
<static>true</static>
<link name="link">
<pose>0 0 0 0 0 0</pose>
<inertial>
<mass>1.0</mass>
</inertial>
<collision name="collision">
<geometry>
<sphere>
<radius>0.01</radius>
</sphere>
</geometry>
</collision>
<visual name="visual">
<geometry>
<sphere>
<radius>0.01</radius>
</sphere>
</geometry>
</visual>
</link>
</model>
</sdf>