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

Reading from yaml file in xacro?

asked 2022-02-28 09:12:00 -0500

ram_pk gravatar image

Hi I am trying to read the parameters in a yaml file to my URDF using xacro. I understand that the values will be imported as a dictionary. I am able to retrieve the values when the yaml file has a single layer. For example if the yaml file is as follows:

val1: 0.45
val2: 0.5

then I can use the following commands in my xacro to get the parameters val1 and val2:

  <xacro:property name="yaml_file" value="$(find package)/config/paramlist.yaml" />
  <xacro:property name="dict" value="${load_yaml(yaml_file)}"/>
  <xacro:property name="val1" value="${dict['val1']}" />
  <xacro:property name="val2" value="${dict['val2']}" />

However I don't know how I can do the same when the yaml file has multiple 'layers' , for example:

Link1:
  val1: 0.45
  val2: 0.5

Link2:
  val1: 0.23
  val2: 0.33

I am new to ROS and to the dictionary format. How do I retrieve val1 and val2 for each Link in xacro? Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-03-01 05:00:04 -0500

updated 2022-03-01 05:00:47 -0500

Hi, You will read as;

<xacro:property name="val1" value="${dict['Link1'][val1]}" />
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-02-28 09:12:00 -0500

Seen: 591 times

Last updated: Mar 01 '22