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

Parse error when using a xacro property loaded through a yaml file.

asked 2016-10-14 08:22:30 -0500

bluehash gravatar image

Environment: Ubuntu 16, ROS Kinetic.

I have a robot_parameters.yaml file with robot parameters: wheel_separation : 0.235 PI : 3.142

In a xacro file I have:

<?xml version="1.0"?>
<robot name="robot_name" xmlns:xacro="http://ros.org/wiki/xacro">
  <xacro:property name="PI" value="${load_yaml('robot_parameters.yaml')}" />

  <link name="left_front_wheel_link">
    <visual>
      <origin xyz="0.123 0.456 0.101" rpy="${PI/2} 0 0" />
      <geometry>
        <cylinder radius="0.101" length = "0.0254"/>
      </geometry>
    </visual>
  </link>
</robot>

When I do a --check-order on the xacro, I get the following error:

unsupported operand type(s) for /: 'dict' and 'int' 
when evaluating expression 'PI/2'
XacroException(None,)

How would I use an imported name(in this case, PI) via yaml and use it for xacro calculations.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-10-14 15:57:26 -0500

bluehash gravatar image

With help from a colleague:

When a xacro property is read from a yaml file, it is in a dictionary format.

When used for xacro calculations, the parameter needs to be extracted from the dictionary:

<?xml version="1.0"?>
<robot name="robot_name" xmlns:xacro="http://ros.org/wiki/xacro">
  <xacro:property name="a" value="${load_yaml('robot_parameters.yaml')}" />

  <link name="left_front_wheel_link">
    <visual>
      <origin xyz="0.123 0.456 0.101" rpy="${a['PI']/2} 0 0" />
      <geometry>
        <cylinder radius="0.101" length = "0.0254"/>
      </geometry>
    </visual>
  </link>
</robot>
edit flag offensive delete link more

Comments

Awesome! Thanks so much. This simplifies the code drastically being able to load in YAML files.

djiglesias gravatar image djiglesias  ( 2017-09-13 11:20:09 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2016-10-14 08:21:30 -0500

Seen: 1,121 times

Last updated: Oct 14 '16