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

Pass parameters to xacro in launch file

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

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 -0500

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 -0500 )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 -0500 )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 -0500 )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 -0500 )edit

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

Markus Bader gravatar image

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

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 -0500

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

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 -0500 )edit

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

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 -0500 )edit

Question Tools


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

Seen: 14,955 times

Last updated: Feb 15 '18