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

Unable to move center of mass for child link

asked 2020-07-02 14:42:19 -0500

JoshuaElliott gravatar image

Ubuntu 16.04, Kinetic, Gazebo 7.16.0-1 Xenial

Hello

I am attempting to connect two links together via a revolute joint. Currently the center of mass for the child link is at the revolute joint connecting the two. I am able to modify the visual and collision location of the child link, but the center of mass does not move. I have followed a few tutorials and searched through prior questions, it seems like changing the inertia origin should fix the issue, but it seems to make no difference.

The visual is correct, there is one box, then a gap, then another box.

<?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="body_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="-1.57" upper="1.57" velocity="-1"/>
  </joint>
 </xacro:macro>



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

<!-- body two -->
<xacro:body_macro name="body_2" xyz="${-body_length/2} 0 0"/>
<xacro:body_joint_macro name="body_joint_1" parent="body_1" child="body_2" xyz="${-body_length/2} 0 0"/>


</robot>
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-07-03 13:10:57 -0500

JoshuaElliott gravatar image

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"/>
  < ...
(more)
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-07-02 14:42:19 -0500

Seen: 334 times

Last updated: Jul 03 '20