Ask Your Question
0

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

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

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

2 Answers

Sort by ยป oldest newest most voted
2

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

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 ( http://answers.ros.org/question/38956... ) 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

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

Used it like this in .xacro

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

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

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

Comments

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 imageyoungiif ( 2017-06-07 11:29:12 -0500 )edit
2

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 imagegvdhoorn ( 2017-06-07 11:49:34 -0500 )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 imageyoungiif ( 2017-06-07 12:50:57 -0500 )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 imageyoungiif ( 2017-06-07 12:54:57 -0500 )edit
1

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 imageDale McConachie ( 2017-06-07 13:53:52 -0500 )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 imageyoungiif ( 2017-06-07 14:34:53 -0500 )edit
1

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 imagegvdhoorn ( 2017-06-08 00:37:23 -0500 )edit
1

.. 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 imagegvdhoorn ( 2017-06-08 00:39:43 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 2,185 times

Last updated: Jun 07 '17