Creating a model population in Gazebo Garden

Run Environment

  • Ubuntu 20.04.5 LTS
  • Gazebo Garden, Binary Install
  • OGRE

Run code

<?xml version="1.0" ?>
<sdf version="1.7">
  <world name="default">

    <!-- A global light source -->
    <include>
      <uri>model://sun</uri>
    </include>

    <!-- A ground plane -->
    <include>
      <uri>model://ground_plane</uri>
    </include>

    <!-- Testing the automatic population of objects -->
    <population name="rock_population1">
      <model name="rock1">
        <include>
          <static>true</static>
          <uri>model://rock</uri>
        </include>
      </model>
      <pose>0 0 0 0 0 0</pose>
      <box>
        <size>2 2 0.01</size>
      </box>
      <model_count>10</model_count>
      <distribution>
        <type>random</type>
      </distribution>
    </population>
  </world>
</sdf>
gz sim world.sdf

Issue

Hi! I’d like to spawn multiple entities of a model in my world using the SDF world/population element following this tutorial and although the SDF element is recognized (I get an error if I dont define the population name) and I dont get any errors, nothing appears in my world nor in the entity tree. The “rock” model loads perfectly fine when I have it there on it’s own.

I’m importing <plugin filename="gz-sim-physics-system" name="gz::sim::systems::Physics"> </plugin> but I don’t see any Population.hh or PopulationParams.hh in my /usr/include/gz/physics6.

TLDR; How can I use the SDF population element in Gazebo Garden?

Hello TanguyG:

Hi! I’d like to spawn multiple entities of a model in my world using the SDF world/population element following this tutorial and although the SDF element is recognized (I get an error if I dont define the population name) and I dont get any errors, nothing appears in my world nor in the entity tree.

Please note that the tutorial is part of Gazebo Classic and you are using the new Gazebo, particularly Garden. You can check the feature comparison of the two different Gazebo in the documentation. Seems like the support for the populations is not yet implemented in the new Gazebo.

As a workaround, maybe the ERB templates can be useful for you, you have some nice examples in the gz-sim examples directory:

Hope it helps.

1 Like

Another alternative is to load an empty world, and spawn objects through the create service.

E.g. world.sdf :

<?xml version="1.0" ?>
<sdf version="1.9">
  <world name="empty_world">

    <!-- Light Source -->
    <light type="directional" name="sun">
      <cast_shadows>true</cast_shadows>
      <pose>0 0 10 0 0 0</pose>
      <diffuse>0.8 0.8 0.8 1</diffuse>
      <specular>0.2 0.2 0.2 1</specular>
      <attenuation>
        <range>1000</range>
        <constant>0.9</constant>
        <linear>0.01</linear>
        <quadratic>0.001</quadratic>
      </attenuation>
      <direction>-0.2 0.5 -0.9</direction>
    </light>

    <!-- Included model -->
    <include>
      <uri>https://fuel.gazebosim.org/1.0/OpenRobotics/models/Ground Plane</uri>
    </include>

 </world>
</sdf>

Load above sdf with gz sim world.sdf and then in another terminal call the create service (or call it from a script, varying the <pose>, if you want to spawn many):

gz service -s /world/empty_world/create \
--reqtype gz.msgs.EntityFactory \
--reptype gz.msgs.Boolean \
--timeout 300 \
--req 'sdf: '\
'"<?xml version=\"1.0\" ?>'\
'<sdf version=\"1.6\">'\
'<include>'\
'<pose>1.6 0.15 0 0 0 0</pose>'\
'<name>Model1</name>'\
'<uri>model.sdf</uri>'\
'</include>'\
'</sdf>" '\
'allow_renaming: true'

model.sdf needs to be an sdf without world, e.g.:

<?xml version="1.0" ?>
<sdf version="1.9">
  <model name="rock">
     ...
  </model>
</sdf>
2 Likes

Works great, thanks!

1 Like

To add to what @jrtg said, the EntityFactory message (https://github.com/gazebosim/gz-msgs/blob/gz-msgs9/proto/gz/msgs/entity_factory.proto) actually has a field for sdf_filename, so you should be able to point to the model .sdf file directly. It also has a pose field for changing the spawning pose.

1 Like