Ask Your Question

Confused about Xacro and URDF

asked 2015-11-27 04:46:20 -0500

schultza gravatar image

Hey together,

I am a little bit confused about the use case of xacro and urdf. I my case I have an robot equipped with 3 laserscanner and modeled a urdf file for it following the build your URDF tutorial. After finishing and testing this i have read that it is possible to clean up a URDF with Xacro. Thats whats confusing for me, I don't have a Xacro file and should use a Xacro file to clean up my previously made URDF?

So was it incorrect to create an URDF, should I have created a Xacro file instead? Thanks in advance

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2015-11-27 05:13:29 -0500

Akif gravatar image

updated 2015-11-28 04:13:20 -0500

In fact it is up to you to use xacro. You do not have to, but especially if you have a large URDF and possible duplicate codes it will be beneficial.

xacro provides you some advantages with URDF. As the tutorial you linked points,

It does three things that are very helpful.

  • Constants
  • Simple Math
  • Macros

This way you can use constants throughout your URDF, therefore it will be more parametrized;

<xacro:property name="width" value=".2" />

Also you can do some simple math like;

<cylinder radius="${wheeldiam/2}" length=".1"/>

And you can use macros like;

<xacro:macro name="default_origin">
    <origin xyz="0 0 0" rpy="0 0 0"/>
<xacro:default_origin />

For example in your case, you say that you have 3 laser range finders. Therefore, possibly without xacro, you are using same code block again and again with some little differences like x,y,z and r,p,y. If you use xacro at this point, you can have a macro called "laser_scanner" and you can just use it three times when you need it.

You can check PAL's repo for PMB2 in this link for such an example.

Another advantage of using xacro is that it will be interpreted and converted to URDF on run-time if you want. Therefore it will be a dynamic URDF file.

edit flag offensive delete link more


Thanks for the answer, but I understand it right that you also wirte xacro by hand and you cant create a xacro from a urdf just the other way around?

schultza gravatar image schultza  ( 2015-11-30 02:01:19 -0500 )edit

Yes, you write your xacro files and convert them to one single URDF file before run-time or use this URDF in random memory without having a file on harddrive, during run-time.

Akif gravatar image Akif  ( 2015-11-30 04:31:32 -0500 )edit

answered 2015-11-27 18:45:28 -0500

David Lu gravatar image
edit flag offensive delete link more


Thanks for the link, didnt found it while asking this question

schultza gravatar image schultza  ( 2015-11-30 01:57:24 -0500 )edit

answered 2015-11-27 17:12:08 -0500

npa gravatar image

URDF is easy to understand but difficult to modify in future...if u have a big urdf file go for xacro

edit flag offensive delete link more

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


Asked: 2015-11-27 04:46:20 -0500

Seen: 794 times

Last updated: Nov 28 '15