ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Is it possible to use relative path for mesh filename in URDF?

asked 2017-06-06 18:34:05 -0600

youngiif gravatar image

I have my mesh STL in the same directory as my URDF so I was hoping I could reference it via a relative path.

This works as expected

<mesh filename="package://urdf_tutorial/urdf/Assy_X.stl" />

But I would like to do something like this

<mesh filename="file://Assy_X.stl" />
  or this
<mesh filename="file://./Assy_X.stl" />

Where it assumes the mesh path is relative to the URDF path.

Is this possible somehow?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2017-06-07 14:44:26 -0600

youngiif gravatar image

While not a perfect answer to my original question as it requires a one time adjustment to a launch file, this post ( ) helped solve my problem pretty well by allowing me to pass an argument to the xacro, which can then be used in the xacro.

This allows the urdf/xacro to be oblivious to its location as the launch file will ensure it knows where to find the STL & DAE files I specify.

Added "meshDirectory" argument to the launch file

    <arg name="model" default="$(find urdf_tutorial)/urdf/test2.xacro meshDirectory:=$(find urdf_tutorial)/urdf/" />

Used it like this in .xacro

    <mesh filename="file://$(arg meshDirectory)Assy_X-1.stl" />
edit flag offensive delete link more

answered 2017-06-07 00:23:45 -0600

gvdhoorn gravatar image

No. Afaik that is not supported.

Do you have a specific reason for wanting to do this, or is it just convenience?

edit flag offensive delete link more


Mostly a convenience issue, to prevent modifying the filenames when I share my urdf & stl files with others loading the urdf in a different package.

youngiif gravatar image youngiif  ( 2017-06-07 11:29:12 -0600 )edit

Far from me telling you what to do / how to structure your packages, but when models are supposed to be re-usable / composable, using xacro is recommended. If you then use package:// relative urls, there should be no need to rename / modifying filenames?

gvdhoorn gravatar image gvdhoorn  ( 2017-06-07 11:49:34 -0600 )edit

Good point. I created an application to build URDF from an Autodesk Inventor model, so didn't see a need for xacro as if I needed to make any adjustments, I would do that in the Inventor model and the urdf would rebuild. Trying xacro now.

youngiif gravatar image youngiif  ( 2017-06-07 12:50:57 -0600 )edit

I tried xacro, without much success. ${cwd), prints the directory rosrun/roslaunch is ran from, so that didn't work $(find package), would appear to still require changing the xacro file to current users' package. Am I overlooking something here? I'm very new to ROS so sorry if this is silly.

youngiif gravatar image youngiif  ( 2017-06-07 12:54:57 -0600 )edit

You could probably include a parameter to you xacro file called "pacakge_name" or something like that which can then be set in one spot when someone invokes the xacro file. This at least alleviates the issue.

Dale McConachie gravatar image Dale McConachie  ( 2017-06-07 13:53:52 -0600 )edit

Thanks Dale, that would definitely make it easier. I've found another solution to my problem that involves passing an argument to the xacro from a launch file; I've posted the details in another answer to make it easier for others to find.

youngiif gravatar image youngiif  ( 2017-06-07 14:34:53 -0600 )edit

I'm still rather confused why you'd want to do what you are doing, but if it works for you then that's fine.

As a final note: urdf is not designed to be composable, xacro is. Reusable artefacts are supposed to live in reusable pkgs, and to reuse them you reference them in composite xacros ..

gvdhoorn gravatar image gvdhoorn  ( 2017-06-08 00:37:23 -0600 )edit

.. by their package://.. relative uris and then instantiate them. Any resources they might need (material defs, meshes) are placed in the containing pkg and their location resolved at tranformation time.

Following this pattern typically removes the need to edit paths completely.

gvdhoorn gravatar image gvdhoorn  ( 2017-06-08 00:39:43 -0600 )edit

answered 2022-09-21 14:37:22 -0600

Mihai gravatar image

For all those wondering why you could ever need using a relative path to point to the mesh geometry file, here is a standard use-case: you want to import into the scene an object that someone shared with you. You would normally want to copy only the geometry file (STL) and the meta-data regarding the visua/collision/inertia aspects (URDF). Creating a XACRO file or a package is superfluous.

edit flag offensive delete link more

answered 2022-08-13 01:05:55 -0600

manish.nayak gravatar image

Probably a very old question, but it indeed allows us to add the relative path in the URDF Files, as visible in several of their official examples in PyBullet. For eg. r2d2.urdf, where the mesh file is directly imported.

      <origin rpy="0.0 0 0" xyz="0.09137 0.00495 0"/>
        <mesh filename="l_finger_tip.stl"/>
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-06-06 18:34:05 -0600

Seen: 9,546 times

Last updated: Sep 21 '22