Ask Your Question
12

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.

Tom

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
17

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)/xacro.py '$(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

Comments

Quick question: would you know the syntax to define a "default" value for the prefix argument in xacro? I can't run xacro.py 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 imageMurilo F. M. ( 2014-02-06 03:58:32 -0600 )edit
1

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

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

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 https://github.com/ros/xacro/issues/176 gave an example that really helped.

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

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

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

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 ...>
</xacro:if>
edit flag offensive delete link more
1

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

Comments

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

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

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

Comments

3

Please don't add answers to raise new questions. Also, you will need to setup the arg elsewhere in your launch file. http://wiki.ros.org/roslaunch/XML/arg

David Lu gravatar imageDavid 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

Stats

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

Seen: 8,781 times

Last updated: Feb 15 '18