Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Making a differential drive robot move

Hello all,

I am new to Gazebo in general and I require some assistance. I have the following .xacro file that describes links and joints of a differential drive robot. I need to move this robot around in ROS and I found the differential_drive_controller (libgazebo_ros_diff_drive.so) plugin. However, when I launch the simulation and although I publish a message to the /trs/cmd_vel topic (rostopic pub -1 /trs/cmd_vel geometry_msgs/Twist '{linear: {x: 1.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.0}}') the robot is not moving. Can someone help me on how to fix this?

<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="trs_base">

<xacro:macro name="inertia_cylinder" params="mass radius length"> <mass value="${mass}"/> <inertia ixx="${1 / 12 * mass * (3 * radius * radius + length * length)}" ixy="0.0" ixz="0.0" iyy="${1 / 12 * mass * (3 * radius * radius + length * length)}" iyz="0.0" izz="${mass * radius * radius / 2}"/> </xacro:macro>

<xacro:macro name="trs_base" params="prefix">

<link name="robot"/>
<joint name="${prefix}robot_to_chassis" type="fixed">
  <parent link="robot"/>
  <child link="${prefix}chassis_link"/>
  <origin rpy="0 0 0" xyz="0 0 0"/>
</joint>

<link name="${prefix}chassis_link">
  <inertial>
    <mass value="120.911"/>
    <origin rpy="0 0 0" xyz="-0.1832 0.0 0.15"/>
    <inertia ixx="3.50889411882" ixy="0.0" ixz="0.0" iyy="9.06900169571" iyz="0.0" izz="11.7718257055"/>
  </inertial>
  <collision name="base">
    <origin rpy="0.0 0.0 1.57" xyz="-0.2032 0.0 0.15"/>
    <geometry>
      <box size="0.3652 0.8374 0.15"/>
    </geometry>
  </collision>
  <collision name="front_sensor_bar_high">
    <origin xyz="0.1026 0.0 0.20"/>
    <geometry>
      <cylinder length=".075" radius=".2826"/>
    </geometry>
  </collision>
  <collision name="front_sensor_bar_low">
    <origin xyz="0.1026 0.0 0.075"/>
    <geometry>
      <cylinder length=".075" radius=".2826"/>
    </geometry>
  </collision>
  <collision name="rear_sensor_bar_high">
    <origin xyz="-0.498 0.0 0.20"/>
    <geometry>
      <cylinder length=".075" radius=".2826"/>
    </geometry>
  </collision>
  <collision name="rear_sensor_bar_low">
    <origin xyz="-0.498 0.0 0.075"/>
    <geometry>
      <cylinder length=".075" radius=".2826"/>
    </geometry>
  </collision>
  <!-- This model was changed to have a single central caster to remove a contact point and reduce the qcbot model jitter. \
    This change was based on successful, jitter-reducing changes to the RPR model, and is partially made of black magic. -->
  <collision name="center_caster_collision">
    <origin xyz="-0.37 0.0 0.1018"/>
    <geometry>
      <sphere radius=".1018"/>
    </geometry>
  </collision>
  <visual>
    <origin rpy="1.5708 0 1.5708" xyz="0 0 0.2159"/>
    <!-- uncomment to use a lower-resolution stl which includes the bottom of qcbot and its wheels -->
    <geometry>
      <mesh filename="package://trs/meshes/base.stl" scale="0.001 0.001 0.001"/>
    </geometry>
    <!-- uncomment to use a higher-resolution stl which does not include the bottom of qcbot or its wheels -->
    <material name="LightGrey">
      <color rgba="0.4 0.4 0.4 1.0"/>
    </material>
  </visual>


</link>

<link name="${prefix}left_wheel_link">
  <inertial>
    <origin xyz="0 0 0" rpy="0 0 0" />
    <xacro:inertia_cylinder mass="2" radius="0.1018" length="0.04"/>
  </inertial>
  <collision name="collision">
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <geometry>
      <cylinder radius=".1018" length=".04"/>
    </geometry>
  </collision>
  <visual name="left_wheel_visual">
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <geometry>
      <cylinder radius=".1018" length=".04"/>
    </geometry>
  </visual>
</link>
<joint type="continuous" name="${prefix}left_wheel_joint">
  <origin rpy="-1.5707 0 0" xyz="0.0 0.23 0.1018"/>
  <axis xyz="0 0 1"/>
  <parent
    link="${prefix}chassis_link" />
  <child
    link="${prefix}left_wheel_link" />
  <limit effort="1000" velocity="1000000000" />
</joint>

<link name="${prefix}right_wheel_link">
  <inertial>
    <origin xyz="0 0 0" rpy="0 0 0" />
    <xacro:inertia_cylinder mass="2" radius="0.1018" length="0.04"/>
  </inertial>
  <collision name="collision">
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <geometry>
      <cylinder radius=".1018" length=".04"/>
    </geometry>
  </collision>
  <visual name="right_wheel_visual">
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <geometry>
      <cylinder radius=".1018" length=".04"/>
    </geometry>
  </visual>
</link>
<joint type="continuous" name="${prefix}right_wheel_joint">
  <origin xyz="0.0 -0.23 0.1018" rpy="1.5707 0 0"/>
  <parent
    link="${prefix}chassis_link" />
  <child
    link="${prefix}right_wheel_link" />
  <axis
    xyz="0 0 -1" />
  <limit effort="1000" velocity="1000000000" />
</joint>

<!-- Currently, only data used from transmission tags is joint name. -->
<transmission name="tran_left_wheel_joint">
  <type>transmission_interface/SimpleTransmission</type>
  <joint name="${prefix}left_wheel_joint">
    <hardwareInterface>EffortJointInterface</hardwareInterface>
  </joint>
  <actuator name="motor_left_wheel_joints">
    <mechanicalReduction>1</mechanicalReduction>
  </actuator>
</transmission>

<transmission name="tran_right_wheel_joint">
  <type>transmission_interface/SimpleTransmission</type>
  <joint name="${prefix}right_wheel_joint">
    <hardwareInterface>EffortJointInterface</hardwareInterface>
  </joint>
  <actuator name="motor_right_wheel_joints">
    <mechanicalReduction>1</mechanicalReduction>
  </actuator>
</transmission>


<!-- Simulation dynamics parameters -->
<gazebo reference="${prefix}chassis_link">
  <mu1>0</mu1>
  <mu2>0</mu2>
  <kp value="1.0e+9"/>
  <kd value="5.0e+6"/>
</gazebo>

<gazebo reference="${prefix}right_wheel_link">
  <mu1 value="1.0e+6"/>
  <mu2 value="1.0e+6"/>
  <kp value="1.0e+9"/>
  <kd value="5.0e+6"/>
</gazebo>

<gazebo reference="${prefix}left_wheel_link">
  <mu1 value="1.0e+6"/>
  <mu2 value="1.0e+6"/>
  <kp value="1.0e+9"/>
  <kd value="5.0e+6"/>
</gazebo>

 <gazebo>
  <plugin name='differential_drive_controller'
          filename='libgazebo_ros_diff_drive.so'>
    <publishWheelTF>false</publishWheelTF>
    <robotNamespace>/trs</robotNamespace>
    <publishTf>1</publishTf>
    <publishWheelJointState>false</publishWheelJointState>
    <alwaysOn>true</alwaysOn>
    <updateRate>100</updateRate>
    <leftJoint>${prefix}left_wheel_joint</leftJoint>
    <rightJoint>${prefix}right_wheel_joint</rightJoint>
    <wheelSeparation>0.46</wheelSeparation>
    <wheelDiameter>0.2036</wheelDiameter>
    <broadcastTF>1</broadcastTF>
    <torque>5</torque>
    <commandTopic>cmd_vel</commandTopic>
    <odometryTopic>odom</odometryTopic>
    <odometryFrame>odom</odometryFrame>
    <robotBaseFrame>${prefix}chassis_link</robotBaseFrame>
  </plugin>
</gazebo>

Making a differential drive robot move

Hello all,

I am new to Gazebo in general and I require some assistance. I have the following .xacro file that describes links and joints of a differential drive robot. I need to move this robot around in ROS and I found the differential_drive_controller (libgazebo_ros_diff_drive.so) plugin. However, when I launch the simulation and although I publish a message to the /trs/cmd_vel topic (rostopic pub -1 /trs/cmd_vel geometry_msgs/Twist '{linear: {x: 1.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.0}}') the robot is not moving. Can someone help me on how to fix this?

<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="trs_base">

<xacro:macro name="inertia_cylinder" params="mass radius length"> <mass value="${mass}"/> <inertia ixx="${1 / 12 * mass * (3 * radius * radius + length * length)}" ixy="0.0" ixz="0.0" iyy="${1 / 12 * mass * (3 * radius * radius + length * length)}" iyz="0.0" izz="${mass * radius * radius / 2}"/> </xacro:macro>

<xacro:macro name="trs_base" params="prefix">

params="prefix">
    <link name="robot"/>
 <joint name="${prefix}robot_to_chassis" type="fixed">
   <parent link="robot"/>
   <child link="${prefix}chassis_link"/>
   <origin rpy="0 0 0" xyz="0 0 0"/>
</joint>

    </joint>

<link name="${prefix}chassis_link">
  <inertial>
    <mass value="120.911"/>
    <origin rpy="0 0 0" xyz="-0.1832 0.0 0.15"/>
    <inertia ixx="3.50889411882" ixy="0.0" ixz="0.0" iyy="9.06900169571" iyz="0.0" izz="11.7718257055"/>
  </inertial>
  <collision name="base">
    <origin rpy="0.0 0.0 1.57" xyz="-0.2032 0.0 0.15"/>
    <geometry>
      <box size="0.3652 0.8374 0.15"/>
    </geometry>
  </collision>
  <collision name="front_sensor_bar_high">
    <origin xyz="0.1026 0.0 0.20"/>
    <geometry>
      <cylinder length=".075" radius=".2826"/>
    </geometry>
  </collision>
  <collision name="front_sensor_bar_low">
    <origin xyz="0.1026 0.0 0.075"/>
    <geometry>
      <cylinder length=".075" radius=".2826"/>
    </geometry>
  </collision>
  <collision name="rear_sensor_bar_high">
    <origin xyz="-0.498 0.0 0.20"/>
    <geometry>
      <cylinder length=".075" radius=".2826"/>
    </geometry>
  </collision>
  <collision name="rear_sensor_bar_low">
    <origin xyz="-0.498 0.0 0.075"/>
    <geometry>
      <cylinder length=".075" radius=".2826"/>
    </geometry>
  </collision>
  <!-- This model was changed to have a single central caster to remove a contact point and reduce the qcbot model jitter. \
    This change was based on successful, jitter-reducing changes to the RPR model, and is partially made of black magic. -->
  <collision name="center_caster_collision">
    <origin xyz="-0.37 0.0 0.1018"/>
    <geometry>
      <sphere radius=".1018"/>
    </geometry>
  </collision>
  <visual>
    <origin rpy="1.5708 0 1.5708" xyz="0 0 0.2159"/>
    <!-- uncomment to use a lower-resolution stl which includes the bottom of qcbot and its wheels -->
    <geometry>
      <mesh filename="package://trs/meshes/base.stl" scale="0.001 0.001 0.001"/>
    </geometry>
    <!-- uncomment to use a higher-resolution stl which does not include the bottom of qcbot or its wheels -->
    <material name="LightGrey">
      <color rgba="0.4 0.4 0.4 1.0"/>
    </material>
  </visual>


</link>

<link name="${prefix}left_wheel_link">
  <inertial>
    <origin xyz="0 0 0" rpy="0 0 0" />
    <xacro:inertia_cylinder mass="2" radius="0.1018" length="0.04"/>
  </inertial>
  <collision name="collision">
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <geometry>
      <cylinder radius=".1018" length=".04"/>
    </geometry>
  </collision>
  <visual name="left_wheel_visual">
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <geometry>
      <cylinder radius=".1018" length=".04"/>
    </geometry>
  </visual>
</link>
<joint type="continuous" name="${prefix}left_wheel_joint">
  <origin rpy="-1.5707 0 0" xyz="0.0 0.23 0.1018"/>
  <axis xyz="0 0 1"/>
  <parent
    link="${prefix}chassis_link" />
  <child
    link="${prefix}left_wheel_link" />
  <limit effort="1000" velocity="1000000000" />
</joint>

<link name="${prefix}right_wheel_link">
  <inertial>
    <origin xyz="0 0 0" rpy="0 0 0" />
    <xacro:inertia_cylinder mass="2" radius="0.1018" length="0.04"/>
  </inertial>
  <collision name="collision">
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <geometry>
      <cylinder radius=".1018" length=".04"/>
    </geometry>
  </collision>
  <visual name="right_wheel_visual">
    <origin xyz="0 0 0" rpy="0 0 0"/>
    <geometry>
      <cylinder radius=".1018" length=".04"/>
    </geometry>
  </visual>
</link>
<joint type="continuous" name="${prefix}right_wheel_joint">
  <origin xyz="0.0 -0.23 0.1018" rpy="1.5707 0 0"/>
  <parent
    link="${prefix}chassis_link" />
  <child
    link="${prefix}right_wheel_link" />
  <axis
    xyz="0 0 -1" />
  <limit effort="1000" velocity="1000000000" />
</joint>

<!-- Currently, only data used from transmission tags is joint name. -->
<transmission name="tran_left_wheel_joint">
  <type>transmission_interface/SimpleTransmission</type>
  <joint name="${prefix}left_wheel_joint">
    <hardwareInterface>EffortJointInterface</hardwareInterface>
  </joint>
  <actuator name="motor_left_wheel_joints">
    <mechanicalReduction>1</mechanicalReduction>
  </actuator>
</transmission>

<transmission name="tran_right_wheel_joint">
  <type>transmission_interface/SimpleTransmission</type>
  <joint name="${prefix}right_wheel_joint">
    <hardwareInterface>EffortJointInterface</hardwareInterface>
  </joint>
  <actuator name="motor_right_wheel_joints">
    <mechanicalReduction>1</mechanicalReduction>
  </actuator>
</transmission>


<!-- Simulation dynamics parameters -->
<gazebo reference="${prefix}chassis_link">
  <mu1>0</mu1>
  <mu2>0</mu2>
  <kp value="1.0e+9"/>
  <kd value="5.0e+6"/>
</gazebo>

<gazebo reference="${prefix}right_wheel_link">
  <mu1 value="1.0e+6"/>
  <mu2 value="1.0e+6"/>
  <kp value="1.0e+9"/>
  <kd value="5.0e+6"/>
</gazebo>

<gazebo reference="${prefix}left_wheel_link">
  <mu1 value="1.0e+6"/>
  <mu2 value="1.0e+6"/>
  <kp value="1.0e+9"/>
  <kd value="5.0e+6"/>
</gazebo>

 <gazebo>
  <plugin name='differential_drive_controller'
          filename='libgazebo_ros_diff_drive.so'>
    <publishWheelTF>false</publishWheelTF>
    <robotNamespace>/trs</robotNamespace>
    <publishTf>1</publishTf>
    <publishWheelJointState>false</publishWheelJointState>
    <alwaysOn>true</alwaysOn>
    <updateRate>100</updateRate>
    <leftJoint>${prefix}left_wheel_joint</leftJoint>
    <rightJoint>${prefix}right_wheel_joint</rightJoint>
    <wheelSeparation>0.46</wheelSeparation>
    <wheelDiameter>0.2036</wheelDiameter>
    <broadcastTF>1</broadcastTF>
    <torque>5</torque>
    <commandTopic>cmd_vel</commandTopic>
    <odometryTopic>odom</odometryTopic>
    <odometryFrame>odom</odometryFrame>
    <robotBaseFrame>${prefix}chassis_link</robotBaseFrame>
  </plugin>
</gazebo>