# URI paths to packages in the SDF model file?

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 close merge delete ## 3 Answers Sort by » oldest newest most voted 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.

more

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

( 2020-06-16 15:17:39 -0500 )edit

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]

more

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.

more

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

( 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.

( 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?

( 2014-07-07 21:27:39 -0500 )edit

can i use absolute path for <uri> tag?

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