Gazebo | Ignition | Community
Ask Your Question
5

URI paths to packages in the SDF model file?

asked 2014-07-07 16:06:44 -0500

silentwf gravatar image

updated 2014-07-07 16:17:54 -0500

Hi All,

I'm trying to create a SDF from COLLADA files I have already. However, the files I'm trying to link to are located in different files (I'm trying to load a sensor on the robot). In URDFs I could use the ($find package_name) method to get a location. How would I do that with the SDF file? This is part of what I have right now in the SDF file.

<visual name='base_link_visual'>
    <pose>0 0 0 0 0 0</pose>
    <geometry>
      <mesh>
        <scale>1 1 1</scale>
        <uri>package://my_package/Media/models/textured.dae</uri>
      </mesh>
    </geometry>
  </visual>

This won't link to my package.

Also, is it possible to use XACRO files with the SDF?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
5

answered 2014-12-10 12:14:18 -0500

peci1 gravatar image

It is possible using a weird hack.

In the package.xml of the package where you want to load the model (or just any package that gets loaded before your models are needed), declare the following export:

<export>
    <!-- gazebo_ros_paths_plugin automatically adds these to
        GAZEBO_PLUGIN_PATH and GAZEBO_MODEL_PATH when you do this export inside
        the package.xml file. You can than use URIs of type model://my_package/stuff. -->
    <gazebo_ros                                                                 
        gazebo_plugin_path="${prefix}/lib"
        gazebo_model_path="${prefix}/.." /> 
</export>

After doing this and loading the package (running a node from it? don' know exactly), you're allowed to specify things like <uri>model://my_package/models/foo.dae</uri>.

The ${prefix}/.. means to add the parent of your package directory to the model path, which should usually be the workspace itself. So then you can reference all packages from that workspace. If you need models from a different workspace, I think you have to declare the export in all needed workspaces somewhere.

I've learnt this knowledge from http://answers.gazebosim.org/question/6416/usingaurdfingazebo-package-uris-not-described/?answer=6419#post-id-6419 .

edit flag offensive delete link more

Comments

1

Note that you need to add an exec_depend on gazebo_ros to your package. test_depend didn't do the export properly for me. You can check that the exports are found correctly with rospack plugins --attrib=gazebo_model_path gazebo_ros

arprice gravatar imagearprice ( 2020-06-16 15:17:39 -0500 )edit
1

answered 2016-12-28 03:20:51 -0500

prasad gravatar image

Typically, there are 3 methods to let Gazebo software load a model.

  1. Export GAZEBO_MODEL_PATH properly. (If Gazebo doesn't start at all, then setup Gazebo and environment variables and then export GAZEBO_MODEL_PATH)

  2. Move the models to "gazebo/models" folder directly and include the URI in launch file.

  3. In case this is being used with ROS (which is the typical case), make sure that the models and the code is withinthe workspace. (I was struggling with this and I was attempting multi-robot simulation. I realised that the environment variables are sourced in the first instance and sourcing them again from second workspace or any other folder can be difficult. Reference : http://wiki.ros.org/catkin/Tutorials/... )

[Note: I am posting this to help people; I myself struggled to get a working solution (for about 10 hours) and I haven't found any similar information as in this answer]

edit flag offensive delete link more
0

answered 2023-07-20 16:09:02 -0500

Asif Khan gravatar image

updated 2023-07-20 16:10:10 -0500

For New users In case of using ros2 and colcon set:

<export>
<gazebo_ros gazebo_model_path="${prefix}/../../../../src/pkg_name/models"/>
</export>

for example in my case all models (including meshes) are in models/ folder, And this works as expected. tested in gazebo 11 and ros2 foxy. The reasons is {prefix} gives path to install/pkg/share/blah-blah.... directory in newer versions.

edit flag offensive delete link more
0

answered 2014-07-07 18:24:37 -0500

nkoenig gravatar image

SDF uses file instead of package:

<visual name='base_link_visual'>
    <pose>0 0 0 0 0 0</pose>
    <geometry>
      <mesh>
        <scale>1 1 1</scale>
        <uri>file://path_to_dae/textured.dae</uri>
      </mesh>
    </geometry>
  </visual>

or you can use the model uri:

<visual name='base_link_visual'>
    <pose>0 0 0 0 0 0</pose>
    <geometry>
      <mesh>
        <scale>1 1 1</scale>
        <uri>model://model_name/meshes/textured.dae</uri>
      </mesh>
    </geometry>
  </visual>

SDF will use ERB in the near furture. This will essentially add ruby scripting into SDF. Here is an example.

edit flag offensive delete link more

Comments

So basically saying that it is impossible to have the functionality to search for package path like the way URDF does it then?

silentwf gravatar imagesilentwf ( 2014-07-07 19:12:11 -0500 )edit

I think you may be able to use the uri tag to get similar functionality along with the `GAZEBO_MODEL_PATH` environment variable.

scpeters gravatar imagescpeters ( 2014-07-07 19:24:33 -0500 )edit

@scpeters I was also thinking something like that, but that kind of means lack of portability if I'm developing with ROS?

silentwf gravatar imagesilentwf ( 2014-07-07 21:27:39 -0500 )edit

can i use absolute path for <uri> tag?

LR gravatar imageLR ( 2020-10-18 06:20:58 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2014-07-07 16:06:44 -0500

Seen: 33,030 times

Last updated: Jul 20 '23