# Using xacro to automate inertial calculations sequence/float error

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_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>


The error is unexpected EOF while parsing (<string>, line 1) when evaluating expression '(.82)*${mass' edit retag 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. ( 2018-06-05 16:30:54 -0600 )edit 1 This seems like a duplicate of #q293296. If it is, please close either this one, or #q293296, so we avoid split discussions. ( 2018-06-06 06:21:56 -0600 )edit ## 1 Answer Sort by » oldest newest most voted 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. 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.

( 2018-06-06 09:29:04 -0600 )edit

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

( 2018-06-07 09:15:05 -0600 )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...

( 2018-06-07 09:18:30 -0600 )edit