Ask Your Question

Pass parameters to xacro in launch file

asked 2012-07-16 07:59:53 -0600

TomWu gravatar image

Does anybody know how to pass parameters to a xacro file from a launch file? For example, if I want to run a xacro file five times in my launch file, each time with different parameter, is there any way of achieving that? Your help would be much appreciated.


edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2013-10-18 09:15:30 -0600

kalectro gravatar image

I had the same problem and solved it using the script but we found another way now. We use the following code to circumvent using tf_prefix because support has been dropped. I am not sure if this was added in hydro but we just tested the following code and it works. Please test with groovy and reply if it worked.

<param name="robot_description" command="$(find xacro)/ '$(find my_robot_description)/urdf/my_robot.urdf.xacro' prefix:=$(arg ns)" />

in the xacro file you can simply get the passed argument using $(arg prefix)

edit flag offensive delete link more


Quick question: would you know the syntax to define a "default" value for the prefix argument in xacro? I can't run to convert the xacro file to urdf because the argument is not set. Thanks for the tip anyway, it helped a lot!

Murilo F. M. gravatar image Murilo F. M.  ( 2014-02-06 03:58:32 -0600 )edit

Oh, I found a workaround, I can pass the argument on the command line, such as: rosrun xacro file.xacro > file.urdf prefix:=test

Murilo F. M. gravatar image Murilo F. M.  ( 2014-02-06 04:02:48 -0600 )edit

Just to help anybody else who may be having an issue here. You have to define your variable as a xacro:arg instead of a xacro:property. Someone at gave an example that really helped.

ChuiV gravatar image ChuiV  ( 2018-02-22 13:28:35 -0600 )edit

This ^ comment by @ChuiV is important for @kalectro 's answer to work.

Subodh Malgonde gravatar image Subodh Malgonde  ( 2018-08-14 01:04:22 -0600 )edit

answered 2014-09-03 04:18:36 -0600

Markus Bader gravatar image

updated 2015-06-27 20:21:28 -0600

130s gravatar image

I was able to use the argument to evaluate conditional blocks e.g. load_camera:=0

<xacro:if value="$(arg load_camera)">
  <... some xml code here ...>
edit flag offensive delete link more

answered 2013-01-04 01:28:05 -0600

updated 2013-11-15 08:48:55 -0600

AFAIK xacro currently does not support this, but this would be an extremely useful enhancement.

A quick and dirty solution is to use a wrapper around xacro, and change your parameter value using sed. This is a somewhat primitive solution, though you should be able to get the correct functionality through a decently written shell script.

EDIT: Support for this feature was added in ROS Hydro. See @kalectro's answer.

edit flag offensive delete link more


example link (404) removed as segbot code was migrated and released in Hydro, where this feature is available.

piyushk gravatar image piyushk  ( 2013-03-29 09:33:19 -0600 )edit

answered 2018-02-15 16:47:49 -0600

horseatinweeds gravatar image

Is there something changed in Kinetic? If I try exactly the answer @kalectro provides, I get an error when launching the launch file: xxx.launch required the 'ns' arg to be set.

edit flag offensive delete link more



Please don't add answers to raise new questions. Also, you will need to setup the arg elsewhere in your launch file.

David Lu gravatar image David Lu  ( 2018-02-15 16:53:05 -0600 )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


Asked: 2012-07-16 07:59:53 -0600

Seen: 10,535 times

Last updated: Feb 15 '18