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

Xacro Error: NoneType object has no attribute getitem

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

luketheduke gravatar image

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

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>
    xacro.main()
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 696, in main
    eval_self_contained(doc)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 626, in eval_self_contained
    eval_all(doc.documentElement, macros, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 553, in eval_all
    eval_all(body, macros, scoped)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 609, in eval_all
    result = eval_text(at[1], symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 483, in eval_text
    results.append(handle_expr(lex.next()[1][2:-1]))
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 470, in handle_expr
    return eval_expr(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 444, in eval_expr
    result = eval_term(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 418, in eval_term
    result = eval_factor(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", line 402, in eval_factor
    result = eval_expr(lex, symbols)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/xacro/__init__.py", 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="http://www.ros.org/wiki/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">
        <inertial>
            <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}"/>
        </inertial>
    </xacro:macro>

    <xacro:macro name="inertia_sphere" params="mass radius">
        <inertial>
            <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}"/>
        </inertial>
    </xacro:macro>

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

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

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

Comments

1

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 -0600 )edit
1

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 -0600 )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 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

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

Comments

Thanks that fixed the issue!

luketheduke gravatar image luketheduke  ( 2017-05-27 12:56:46 -0600 )edit

Question Tools

Stats

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

Seen: 601 times

Last updated: May 27 '17