Home | Tutorials | Wiki | Issues
Ask Your Question
0

Reuse .sdf using different mesh files

asked 2015-06-20 18:16:25 -0500

IsaacS gravatar image

Say I have an sdf file like below:

<?xml version="1.0" ?>
<sdf version="1.4">
    <model name="bookertshelf">
      <static>true</static>
      <link name="body">
        <visual name="visual">
          <geometry>
            <mesh><uri>model://bookertshelf/dummy.dae</uri></mesh>
          </geometry>
        </visual>
      </link>
    </model>
</sdf>

I have bookertshelf-%X%.dae files for all of which I like to use the same SDF config above. Is there a way to reuse this SDF file without doubling the file?

In my world file I tried the following that doesn't seem to be doing what I want (without error on console).

<include>
  <name>bookertshelf1</name>
  <pose>0 -6.0 0 1.5708 0 -1.5708</pose>
  <static>true</static>
  <uri>model://bookshelf</uri>
  <mesh><uri>model://bookertshelf/bookertshelf1.dae</uri></mesh>
</include>

I'm on Ubuntu Trusty, Gazebo 2.2.5. Upper version of Gazebo can't be an option since I'm using ROS Indigo where 2.2 seems like a must.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-06-21 21:05:12 -0500

chapulina gravatar image

updated 2015-06-21 21:06:46 -0500

You could use erb to automatically generate your SDF as in this example.

You would need a file, named for example meshes.world.erb, similar to this:

<?xml version="1.0" ?>
<%
  mesh_list = ["mesh0.dae", "mesh1.dae", "mesh2.dae"]
%>
<sdf version="1.4">
  <world name="default">
    <% # Loop through list
      i = 0
      mesh_list.each do |m|
        name = 'model_' + i.to_s
        i = i + 1
    %>
      <%= "<model name='#{name}'>" %>
        <static>true</static>
        <link name="body">
          <visual name="visual">
            <geometry>
              <mesh><uri><%= "model://bookertshelf/" + m %></uri></mesh>
            </geometry>
          </visual>
        </link>
      </model>
    <% end %>
  </world>
</sdf>

Then use erb to generate the world file (which I called meshes.world), from the command line:

erb meshes.world.erb > meshes.world

Then open the world on gazebo:

gazebo meshes.world
edit flag offensive delete link more

Comments

Thanks. Originally I was hoping for a way to "reuse" a single SDF, not replicating SDF files, but after having seen discussions at another places (e.g. this) I now understand using erb is the best available option for SDF.

IsaacS gravatar imageIsaacS ( 2015-07-03 18:02:11 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2015-06-20 18:16:25 -0500

Seen: 305 times

Last updated: Jun 21 '15