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

How to pass parameters loaded from a yaml file into a xacro?

asked 2014-01-06 13:14:40 -0600

lucasw gravatar image

updated 2020-11-21 11:26:44 -0600

If I do this:

 <rosparam command="load" file="$(find mypkg)/config/example.yaml" />

Can I then use values set in the yaml as arguments going into a xacro file?

(I haven't experimented much here and I'll update this when I do try it tomorrow, but it seems like the documentation says only the other direction is possible: values can be set on the parameter server from within a launch file, and the local copies of those values can be used inside that same launch file and used as arguments, but there is no read access to the parameter server?)

edit retag flag offensive close merge delete

Comments

I'm not sure this is possible. You may get better answers if you elaborate on why you want to do this.

ahendrix gravatar image ahendrix  ( 2014-01-06 13:19:25 -0600 )edit
1

I'd like to have a centralized place (the yaml file) defining critical robot dimensions, then pass these into a xacro file defining the robot, but also allow certain nodes to get some of the same dimensions from the parameter server.

lucasw gravatar image lucasw  ( 2014-01-08 11:44:45 -0600 )edit

How did you end up solving this? Did you find a satisfactory solution?

fvd gravatar image fvd  ( 2017-06-04 20:10:03 -0600 )edit

I saw another question similar to this http://answers.ros.org/question/26376... and then starting trying out using eval in kinetic to try to access the parameter server (see the comments), but so far no luck.

lucasw gravatar image lucasw  ( 2017-06-13 12:27:45 -0600 )edit
1

It would be nice if there was a $(load_param /foo/x) but maybe there would be race conditions with <param ... setting in the same launch files?

lucasw gravatar image lucasw  ( 2017-06-13 12:28:59 -0600 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2017-06-13 15:31:36 -0600

gvdhoorn gravatar image

updated 2017-06-13 15:32:41 -0600

Not entirely sure this is what you are looking for, but have you seen the yaml support in the Jade+ version of xacro?

Properties can be dictionaries or lists too - manually declared with python syntax, like so:

<xacro:property name="props" value="${dict(a=1, b=2, c=3)}"/>
<xacro:property name="numbers" value="${[1,2,3,4]}"/>

or loaded from YAML files like so:

<xacro:property name="props" value="${load_yaml('props.yaml')}"/>

You can do some pretty complex things with this, especially when you combine it with the other new features xacro gained. See ubi-agni/human_hand for an example.

edit flag offensive delete link more

Comments

I hadn't heard about that so I'm now subscribed to the xacro wiki page. I wonder if it would be more straight-forward at this point to originate a robot_description in python instead of xacro.

lucasw gravatar image lucasw  ( 2017-06-13 16:52:45 -0600 )edit
1

re: python: well, that's the age old debate on whether a general purpose language could do things 'easier' or 'more efficient' than a DSL. I don't know. Both have their (dis)advantages.

There have been earlier attempts at using Python for this.

gvdhoorn gravatar image gvdhoorn  ( 2017-06-14 02:29:12 -0600 )edit
3

answered 2014-01-08 13:40:11 -0600

ahendrix gravatar image

I think the better solution here is for any node that needs the dimensions of the robot should pull them from the URDF that's already on the parameter server, or from one of the static transforms that's published based on the URDF.

edit flag offensive delete link more

Comments

I agree. Just as a pointer to inexperienced users, there are URDF parsers for both Python and C++ here: https://github.com/ros/urdfdom .

Martin Günther gravatar image Martin Günther  ( 2014-01-08 21:51:41 -0600 )edit

It looks like following http://wiki.ros.org/urdf/Tutorials/Parse%20a%20urdf%20file but with initParam("/robot_description") instead of initFile() would work. Traversing the urdf data structure to find a dimension seems like a lot of work compared to using the input dimension from the source.

lucasw gravatar image lucasw  ( 2014-01-10 06:33:20 -0600 )edit

Using the tf provided by robot_state_publisher avoids a lot of parsing work, and I could create artificial links in the urdf that exist only to be measured through tf. It can be an error check to define a value, create something from it, and then measure it again as opposed to using the original.

lucasw gravatar image lucasw  ( 2014-01-10 06:38:11 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-01-06 13:14:40 -0600

Seen: 4,216 times

Last updated: Jun 13 '17