Ask Your Question
0

Using xacro to automate inertial calculations sequence/float error

asked 2018-06-05 11:10:06 -0500

Mrhinelander gravatar image

updated 2018-06-05 14:09:12 -0500

Running Ubuntu 16.04 with ROS-Kinetic I am trying to automatically calculate inertial values for a simulated robot. The purpose is to be able to change the dimensions and have the inertia automatically calculated. Here is my macro

  <xacro:macro name="cuboid_inertial" params="mass length width height">
    <inertial>
      <mass value="${mass}"/>
      <inertia 
                ixx="${0.83*mass*(${width}+${height})}" 
                ixy="0.0" 
                ixz="0.0" 
                iyy="${0.83*mass*(${length}+${height})}" 
                iyz="0.0" 
                izz="${0.83*mass*(${width}+${length})}" />
    </inertial>
</xacro:macro>

I have xacro properties as follows.

  <xacro:property name="base_link_length" value="0.50"/>
  <xacro:property name="base_link_width" value="0.30"/>
  <xacro:property name="base_link_height" value="0.35"/>
  <xacro:property name="base_link_length_sqrd" value="${base_link_length}*${base_link_length}"/>
  <xacro:property name="base_link_width_sqrd" value="${base_link_width}*${base_link_width}"/>
  <xacro:property name="base_link_height_sqrd" value="${base_link_height}*${base_link_height}"/>

When I try to run the macro it comes up with an error. My link tags...

  <link name="base_link">
    <visual>
      <geometry>
        <box size="${base_link_length} ${base_link_width} ${base_link_height}"/>
      </geometry>
      <material name="grey"/>
    </visual>
    <collision>
      <geometry>
        <box size="${base_link_length} ${base_link_width} ${base_link_height}"/>
      </geometry>
    </collision>
        <xacro:cuboid_inertial mass="{base_link_mass}" length="{base_link_length_sqrd}" width="{base_link_width_sqrd}" height="{base_link_height_sqrd}"/>
  </link>

The error is unexpected EOF while parsing (<string>, line 1) when evaluating expression '(.82)*${mass'

edit retag flag offensive close merge delete

Comments

Somehow the error you posted doesn't seem to correspond to the code you posted in your macro. Your numbers are different and your parentheses and braces are different.

jarvisschultz gravatar imagejarvisschultz ( 2018-06-05 16:30:54 -0500 )edit
1

This seems like a duplicate of #q293296. If it is, please close either this one, or #q293296, so we avoid split discussions.

gvdhoorn gravatar imagegvdhoorn ( 2018-06-06 06:21:56 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-06-05 16:32:00 -0500

updated 2018-06-05 16:35:00 -0500

The following for your macro works on my system:

  <xacro:macro name="cuboid_inertial" params="mass length width height">
    <inertial>
      <mass value="${mass}"/>
      <inertia 
                ixx="${0.83*mass*(width+height)}" 
                ixy="0.0" 
                ixz="0.0" 
                iyy="${0.83*mass*(length+height)}" 
                iyz="0.0" 
                izz="${0.83*mass*(width+length)}" />
    </inertial>
  </xacro:macro>

I also changed the property block:

<xacro:property name="base_link_length" value="0.50"/>
<xacro:property name="base_link_width" value="0.30"/>
<xacro:property name="base_link_height" value="0.35"/>
<xacro:property name="base_link_length_sqrd" value="${base_link_length*base_link_length}"/>
<xacro:property name="base_link_width_sqrd" value="${base_link_width*base_link_width}"/>
<xacro:property name="base_link_height_sqrd" value="${base_link_height*base_link_height}"/>

Notice that I've changed the location of the ${} sets in your calculations.

edit flag offensive delete link more

Comments

Thank you! Just as a followup, in xacro. When you use ${} is everything inbetween the brackets in the xacro namespace so all variables are essentially global variables? Sorry if that does not make sense.

Mrhinelander gravatar imageMrhinelander ( 2018-06-06 09:29:04 -0500 )edit

The ${} is used for math expressions and for substituting property values. For math expressions, anything inside the braces is evaluated with Python

jarvisschultz gravatar imagejarvisschultz ( 2018-06-07 09:15:05 -0500 )edit

By default all properties and macro arguments are locally scoped (properties only visible within the single xacro file and macro args only visible within the macro). However you can pass a scope attribute to expand these to the parent scope: http://wiki.ros.org/xacro#Local_prope...

jarvisschultz gravatar imagejarvisschultz ( 2018-06-07 09:18:30 -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

1 follower

Stats

Asked: 2018-06-05 11:09:04 -0500

Seen: 163 times

Last updated: Jun 05 '18