Rosanswers logo

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

Originally posted by schultza on ROS Answers with karma: 232 on 2015-11-27

Post score: 1


1 Answer 1


Rosanswers logo

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.

Originally posted by Akif with karma: 3561 on 2015-11-27

This answer was ACCEPTED on the original site

Post score: 7

Original comments

Comment by schultza on 2015-11-30:
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?

Comment by Akif on 2015-11-30:
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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.