Ask Your Question

Xacro Error: NoneType object has no attribute getitem

asked 2017-05-26 15:12:16 -0500

luketheduke gravatar image

updated 2017-05-27 07:55:34 -0500

I'm trying to convert my tortoisebot.urdf.xacro file to a tortoisebot.urdf file by running rosrun xacro xacro tortoisebot.urdf.xacro > tortoisebot.urdf When I run this command I get this error:

~/tortoisebot_ws/src/tortoisebot_description/robots$ rosrun xacro xacro tortoisebot.urdf.xacro > tortoisebot.urdf
Traceback (most recent call last):
  File "/opt/ros/indigo/lib/xacro/xacro", line 55, in <module>
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/", line 696, in main
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/", line 626, in eval_self_contained
    eval_all(doc.documentElement, macros, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/", line 553, in eval_all
    eval_all(body, macros, scoped)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/", line 609, in eval_all
    result = eval_text(at[1], symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/", line 483, in eval_text
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/", line 470, in handle_expr
    return eval_expr(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/", line 444, in eval_expr
    result = eval_term(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/", line 418, in eval_term
    result = eval_factor(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/", line 402, in eval_factor
    result = eval_expr(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/", line 439, in eval_expr
    if lex.peek()[0] == lex.OP:
TypeError: 'NoneType' object has no attribute '__getitem__'

Here is my Xacro file:

<?xml version="1.0"?>

<robot name="tortoisebot" xmlns:xacro="" >
    <xacro:property name="pi" value="3.14159265" />
    <xacro:property name="body_radius" value="0.17" />
    <xacro:property name="body_height" value="0.2" />
    <xacro:property name="body_mass" value="2.0" />

    <xacro:property name="rear_caster_radius" value="0.01" />
    <xacro:property name="rear_caster_mass" value="0.1" />

    <xacro:property name="wheel_radius" value="0.036" />
    <xacro:property name="wheel_height" value="0.025" />
    <xacro:property name="wheel_mass" value="0.1" />

    <xacro:property name="right_wheel_color" value="${red}" />
    <xacro:property name="left_wheel_color" value="${white}" />

    <xacro:macro name="inertia_cylinder" params="mass radius height">
            <mass value="${mass}"/>
            <inertia ixx="${(${mass} / 12)*((3 * ${radius} * ${radius}) + (${height} * ${height}))}"
                ixy="0.0" ixz="0.0" iyy="${(${mass} / 12)*((3 * ${radius} * ${radius}) + (${height} * ${height}))}"
                iyz="0.0" izz="${(${mass} * ${radius} * ${radius}) / 2}"/>

    <xacro:macro name="inertia_sphere" params="mass radius">
            <mass value="${mass}"/>
            <inertia ixx="${2 * ${mass} * ${radius} * ${radius} / 5}"
                ixy="0.0" ixz="0.0" iyy="${2 * ${mass} * ${radius} * ${radius} / 5}"
                iyz="0.0" izz="${2 * ${mass} * ${radius} * ${radius} / 5}"/>

    <xacro:property name="white">
        <material name="white">
            <color rgba="1, 1, 1, 1"/>

    <xacro:property name="green">
        <material name="green">
            <color rgba="0.05 0.75 0.05 1"/>

    <xacro:property name="black">
        <material name="black">
            <color rgba="1, 1, 1, 1"/>
    </xacro ...
edit retag flag offensive close merge delete



When I run this command I get this error: I couldn't get it to format correctly

for error text, console copy-pastes, code and urdf/xacros: please use the Preformatted Text button. It's the one with 101010 on it.

Could you please move the contents of the gists to your question body? Thanks.

gvdhoorn gravatar image gvdhoorn  ( 2017-05-27 02:54:04 -0500 )edit

A quick look at your xacro shows that you are trying to mix urdf and sdf. That is not supported. I wouldn't be surprised if that is the cause of your error.

gvdhoorn gravatar image gvdhoorn  ( 2017-05-27 02:55:41 -0500 )edit

I've updated my question with the code inserted. Thanks for your input on sdf I removed the section of the file that I think was SDF and tried rerunning the code with the same error. Any idea as to what is causing this?

luketheduke gravatar image luketheduke  ( 2017-05-27 07:54:09 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-05-27 12:43:05 -0500

marguedas gravatar image

Xacro evaluates everything that is inside ${} so the variables inside an expression will be evaluated automatically. As a result xacro doesn't support nested ${}.

For example: this fails:
<origin rpy="${${pi} / 2 * -1} 0 0" xyz="0 ${${reflect} * 0.1175} -0.074"/>

but this succeeds with the expected result:
<origin rpy="${pi / 2 * -1} 0 0" xyz="0 ${reflect * 0.1175} -0.074"/>

Hope this helps

edit flag offensive delete link more


Thanks that fixed the issue!

luketheduke gravatar image luketheduke  ( 2017-05-27 12:56:46 -0500 )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


Asked: 2017-05-26 15:12:16 -0500

Seen: 437 times

Last updated: May 27 '17