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

Revision history [back]

click to hide/show revision 1
initial version

I have come up with a very crude work around but still hope someone else has a more enlightened answer.

Since every child link's center of mass is co located with the joint from it's parent, I created a dummy link in between the two links with a joint then leading to body_2. This joint to body_2 has the correct offset to put body_2's center of mass at the center of geometry where I want it. Ideally this dummy link would be massless and connected to body_2 with a fixed joint, but then gazebo would interpret the dummy link and body_2 as the same link and nothing would be fixed. To get around this I give the dummy link a very low but non zero mass (0.001 kg in this case) and use a revolute joint with very small limits (+/- 0.001 radians).

---------- Successfully Parsed XML ---------------
root Link: body_1 has 1 child(ren)
    child(1):  dummy_1
        child(1):  body_2

The updated Xacro file is below. I don't think it mattered but I gave the dummy link a visual to easily see where the revolute joint is.

<?xml version='1.0'?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="train3">
 <xacro:property name="body_length" value="2.5" />
 <xacro:property name="axel_offset" value="0.5" />
 <xacro:property name="axel_z_offset" value="-0.25" />


<xacro:macro name="body_macro" params="xyz name">
 <link name="${name}">  
  <inertial>
   <origin rpy="0 0 0" xyz="${xyz}"/>
   <mass value="55"/>
   <inertia ixx="0.166667" ixy="0" ixz="0" iyy="0.166667" iyz="0" izz="0.166667"/>
  </inertial>
  <collision name="collision">
   <origin rpy="0 0 0" xyz="${xyz}"/>
   <geometry>    
     <box size="2 0.5 0.5" />    
   </geometry>
  </collision>
  <visual name="visual">
   <origin rpy="0 0 0" xyz="${xyz}"/>
   <geometry>    
     <box size="2 0.5 0.5" />    
   </geometry>
   <material name="silver">
    <color rgba="0.75 0.75 0.75 1"/>
   </material>
  </visual>
  </link>
 </xacro:macro>

<xacro:macro name="dummy_link_macro" params="xyz name">
 <link name="${name}">  
  <inertial>
   <mass value="0.001"/>
   <inertia ixx="0.001" ixy="0" ixz="0" iyy="0.001" iyz="0" izz="0.001"/>
  </inertial>
  <collision name="collision">
   <origin rpy="0 0 0" xyz="${xyz}"/>
   <geometry>    
     <sphere radius="0.25"/>    
   </geometry>
  </collision>
  <visual name="visual">
   <origin rpy="0 0 0" xyz="${xyz}"/>
   <geometry>    
     <sphere radius="0.25"/>    
   </geometry>
   <material name="silver">
    <color rgba="0.75 0.75 0.75 1"/>
   </material>
  </visual>
  </link>
 </xacro:macro>


 <xacro:macro name="body_joint_macro" params="xyz axis name parent child">
  <joint name="${name}" type="revolute">
   <parent link="${parent}"/>
   <child link="${child}"/>
   <origin rpy="0 0 0" xyz="${xyz}"/>
   <axis xyz="${axis}"/>
   <limit effort="-1" lower="-1.57" upper="1.57" velocity="-1"/>
  </joint>
 </xacro:macro>

 <xacro:macro name="fixed_joint_macro" params="xyz name parent child">
  <joint name="${name}" type="revolute">
   <parent link="${parent}"/>
   <child link="${child}"/>
   <origin rpy="0 0 0" xyz="${xyz}"/>
   <axis xyz="0 0 1"/>
   <limit effort="-1" lower="-0.0001" upper="0.0001" velocity="-1"/>
  </joint>
 </xacro:macro>



<!-- body one -->
<xacro:body_macro name="body_1" xyz="0 0 0"/>

<!-- 1->2 link -->
<xacro:body_joint_macro name="body_joint_1" parent="body_1" child="dummy_1" xyz="-1.25 0 0" axis="0 0 1"/>
<xacro:dummy_link_macro name="dummy_1" xyz="0 0 0"/>
<xacro:fixed_joint_macro name="fixed_joint_1" parent="dummy_1" child="body_2" xyz="-1.25 0 0"/>

<!-- body two -->
<xacro:body_macro name="body_2" xyz="0 0 0"/>

</robot>