Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

differential drive robot not going in a straight line.

I have a differential drive robot using the differential drive controller plugin in gazebo

This is the .gazebo file.

    <?xml version="1.0"?>
   <robot>
  <gazebo>
    <plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
      <legacyMode>false</legacyMode>
      <alwaysOn>true</alwaysOn>
      <updateRate>100</updateRate>
      <leftJoint>left_wheel_hinge</leftJoint>
      <rightJoint>right_wheel_hinge</rightJoint>
      <!--wheelSeparation>0.55</wheelSeparation>
      <wheelDiameter>0.1</wheelDiameter-->
      <torque>20</torque>
      <commandTopic>cmd_vel</commandTopic>
      <odometryTopic>mb1/odom</odometryTopic>
      <odometryFrame>odom</odometryFrame>
      <robotBaseFrame>base_link</robotBaseFrame>
    </plugin>
  </gazebo>

  <gazebo reference="base_link">
      <material>Gazebo/Orange</material>
    </gazebo>
<gazebo reference="imu_link">
      <material>Gazebo/Green</material>
    </gazebo>
<!-- hokuyo -->
  <gazebo reference="hokuyo">
    <sensor type="ray" name="head_hokuyo_sensor">
      <pose>0 0 0 0 0 0</pose>
      <visualize>true</visualize>
      <update_rate>40</update_rate>
      <ray>
        <scan>
          <horizontal>
            <samples>720</samples>
            <resolution>1</resolution>
            <min_angle>-1.570796</min_angle>
            <max_angle>1.570796</max_angle>
          </horizontal>
        </scan>
        <range>
          <min>0.10</min>
          <max>30.0</max>
          <resolution>0.01</resolution>
        </range>
        <noise>
          <type>gaussian</type>
          <!-- Noise parameters based on published spec for Hokuyo laser
               achieving "+-30mm" accuracy at range < 10m.  A mean of 0.0m and
               stddev of 0.01m will put 99.7% of samples within 0.03m of the true
               reading. -->
          <mean>0.0</mean>
          <stddev>0.01</stddev>
        </noise>
      </ray>
      <plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_laser.so">
        <topicName>/scan</topicName>
        <frameName>hokuyo</frameName>
      </plugin>
    </sensor>
</gazebo>
    <gazebo reference="imu_link">
    <gravity>true</gravity>
    <sensor name="imu_sensor" type="imu">
      <always_on>true</always_on>
      <update_rate>100</update_rate>
      <visualize>true</visualize>
      <topic>__default_topic__</topic>
      <plugin filename="libgazebo_ros_imu_sensor.so" name="imu_plugin">
        <topicName>mb1/imu</topicName>
        <bodyName>imu_link</bodyName>
        <updateRateHZ>10.0</updateRateHZ>
        <gaussianNoise>0.0</gaussianNoise>
        <xyzOffset>0 0 0</xyzOffset>
        <rpyOffset>0 0 0</rpyOffset>
        <frameName>imu_link</frameName>
      </plugin>
      <pose>0 0 0 0 0 0</pose>
    </sensor>
  </gazebo>
<!--gazebo>
    <plugin name="imu_plugin" filename="libgazebo_ros_imu.so">
      <alwaysOn>true</alwaysOn>
      <bodyName>imu_link</bodyName>
      <topicName>mb1/imu</topicName>
      <serviceName>imu_service</serviceName>
      <gaussianNoise>0.0</gaussianNoise>
      <updateRate>10.0</updateRate>
    </plugin>
  </gazebo-->
</robot>

and this is the .xacro file

<?xml version='1.0'?>

<robot name="myrobot" xmlns:xacro="http://www.ros.org/wiki/xacro"> <xacro:include filename="$(find mybot_description)/urdf/mybot.gazebo"/> <xacro:include filename="$(find mybot_description)/urdf/materials.xacro"/> <xacro:include filename="$(find mybot_description)/urdf/macros.xacro"/>

<link name="base_link"> <pose>0 0 0.1 0 0 0</pose>

<inertial>
  <mass value="10.0"/>
  <origin xyz="0.0 0 0.1" rpy=" 0 0 0"/>
  <inertia
      ixx="0.5" ixy="0" ixz="0"
      iyy="1.0" iyz="0"
      izz="0.1"
  />
</inertial>

<collision name='collision'>
  <geometry>
    <box size=".4 .2 .1"/>
  </geometry>
</collision>

<visual name='base_link_visual'>
  <origin xyz="0 0 0" rpy=" 0 0 0"/>
  <geometry>
    <box size=".4 .2 .1"/>
  </geometry>
</visual>


<collision name='caster_collision'>
  <origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
  <geometry>
    <sphere radius="0.05"/>
  </geometry>
  <surface>
    <friction>
      <ode>
        <mu>0</mu>
        <mu2>0</mu2>
        <slip1>1.0</slip1>
        <slip2>1.0</slip2>
      </ode>
    </friction>
  </surface>
</collision>

<visual name='caster_visual'>
  <origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
  <geometry>
    <sphere radius="0.05"/>
  </geometry>
</visual>

</link>

<link name="imu_link"> <collision> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <box size="0.03 0.03 0.03"/> </geometry> </collision>

<visual>
  <origin xyz="0 0 0" rpy="0 0 0"/>
  <geometry>
    <box size="0.03 0.03 0.03"/>
  </geometry>
  <material name="blue"/>
</visual>

<inertial>
  <origin xyz="0 0 0" rpy="0 0 0"/>
  <mass value="0.01"/>
  <inertia
    ixx="1.0" ixy="0.0" ixz="0.0"
    iyy="1.0" iyz="0.0"
    izz="1.0"/>
</inertial>

</link> <link name="left_wheel"> <collision name="collision"> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <geometry> <cylinder radius="0.1" length="0.05"/> </geometry> </collision> <visual name="left_wheel_visual"> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <geometry> <cylinder radius="0.1" length="0.05"/> </geometry> </visual> <inertial> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <mass value="5"/> <cylinder_inertia m="5" r="0.1" h="0.05"/> <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/> </inertial> </link>

<link name="right_wheel"> <collision name="collision"> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <geometry> <cylinder radius="0.1" length="0.05"/> </geometry> </collision> <visual name="right_wheel_visual"> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <geometry> <cylinder radius="0.1" length="0.05"/> </geometry> </visual> <inertial> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <mass value="5"/> <cylinder_inertia m="5" r="0.1" h="0.05"/> <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/> </inertial> </link> <joint type="continuous" name="left_wheel_hinge"> <origin xyz="0.1 0.15 0" rpy="0 0 0"/> <child link="left_wheel"/> <parent link="base_link"/> <axis xyz="0 1 0" rpy="0 0 0"/> <limit effort="100" velocity="100"/> <joint_properties damping="0.0" friction="0.0"/> </joint>

<joint type="continuous" name="right_wheel_hinge"> <origin xyz="0.1 -0.15 0" rpy="0 0 0"/> <child link="right_wheel"/> <parent link="base_link"/> <axis xyz="0 1 0" rpy="0 0 0"/> <limit effort="100" velocity="100"/> <joint_properties damping="0.0" friction="0.0"/> </joint>

<joint name="imu_joint" type="fixed"> <axis xyz="0 1 0"/> <origin xyz="0 0 0.065" rpy="0 0 0"/> <parent link="base_link"/> <child link="imu_link"/> </joint>

<joint name="hokuyo_joint" type="fixed"> <axis xyz="0 1 0"/> <origin xyz=".15 0 .1" rpy="0 0 0"/> <parent link="base_link"/> <child link="hokuyo"/> </joint>

<link name="hokuyo"> <collision> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <box size="0.1 0.1 0.1"/> </geometry> </collision>

<visual>
  <origin xyz="0 0 0" rpy="0 0 0"/>
  <geometry>
    <mesh filename="package://mybot_description/meshes/hokuyo.dae"/>
  </geometry>
</visual>

<inertial>
  <mass value="1e-5" />
  <origin xyz="0 0 0" rpy="0 0 0"/>
  <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
</inertial>

</link>

</robot>

The problem is that when i command it to go in a straight line(only linear velocity) it deviates right (-Y direction) after moving straight for a few meters. Is there any fix to this problem.

differential drive robot not going in a straight line.

I have a differential drive robot using the differential drive controller plugin in gazebo

This is the .gazebo file.

    <?xml version="1.0"?>
   <robot>
  <gazebo>
    <plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
      <legacyMode>false</legacyMode>
      <alwaysOn>true</alwaysOn>
      <updateRate>100</updateRate>
      <leftJoint>left_wheel_hinge</leftJoint>
      <rightJoint>right_wheel_hinge</rightJoint>
      <!--wheelSeparation>0.55</wheelSeparation>
      <wheelDiameter>0.1</wheelDiameter-->
      <torque>20</torque>
      <commandTopic>cmd_vel</commandTopic>
      <odometryTopic>mb1/odom</odometryTopic>
      <odometryFrame>odom</odometryFrame>
      <robotBaseFrame>base_link</robotBaseFrame>
    </plugin>
  </gazebo>

  <gazebo reference="base_link">
      <material>Gazebo/Orange</material>
    </gazebo>
<gazebo reference="imu_link">
      <material>Gazebo/Green</material>
    </gazebo>
<!-- hokuyo -->
  <gazebo reference="hokuyo">
    <sensor type="ray" name="head_hokuyo_sensor">
      <pose>0 0 0 0 0 0</pose>
      <visualize>true</visualize>
      <update_rate>40</update_rate>
      <ray>
        <scan>
          <horizontal>
            <samples>720</samples>
            <resolution>1</resolution>
            <min_angle>-1.570796</min_angle>
            <max_angle>1.570796</max_angle>
          </horizontal>
        </scan>
        <range>
          <min>0.10</min>
          <max>30.0</max>
          <resolution>0.01</resolution>
        </range>
        <noise>
          <type>gaussian</type>
          <!-- Noise parameters based on published spec for Hokuyo laser
               achieving "+-30mm" accuracy at range < 10m.  A mean of 0.0m and
               stddev of 0.01m will put 99.7% of samples within 0.03m of the true
               reading. -->
          <mean>0.0</mean>
          <stddev>0.01</stddev>
        </noise>
      </ray>
      <plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_laser.so">
        <topicName>/scan</topicName>
        <frameName>hokuyo</frameName>
      </plugin>
    </sensor>
</gazebo>
    <gazebo reference="imu_link">
    <gravity>true</gravity>
    <sensor name="imu_sensor" type="imu">
      <always_on>true</always_on>
      <update_rate>100</update_rate>
      <visualize>true</visualize>
      <topic>__default_topic__</topic>
      <plugin filename="libgazebo_ros_imu_sensor.so" name="imu_plugin">
        <topicName>mb1/imu</topicName>
        <bodyName>imu_link</bodyName>
        <updateRateHZ>10.0</updateRateHZ>
        <gaussianNoise>0.0</gaussianNoise>
        <xyzOffset>0 0 0</xyzOffset>
        <rpyOffset>0 0 0</rpyOffset>
        <frameName>imu_link</frameName>
      </plugin>
      <pose>0 0 0 0 0 0</pose>
    </sensor>
  </gazebo>
<!--gazebo>
    <plugin name="imu_plugin" filename="libgazebo_ros_imu.so">
      <alwaysOn>true</alwaysOn>
      <bodyName>imu_link</bodyName>
      <topicName>mb1/imu</topicName>
      <serviceName>imu_service</serviceName>
      <gaussianNoise>0.0</gaussianNoise>
      <updateRate>10.0</updateRate>
    </plugin>
  </gazebo-->
</robot>

and this is the .xacro file

<?xml version='1.0'?>

<robot name="myrobot" xmlns:xacro="http://www.ros.org/wiki/xacro"> <xacro:include filename="$(find mybot_description)/urdf/mybot.gazebo"/> mybot_description)/urdf/mybot.gazebo" /> <xacro:include filename="$(find mybot_description)/urdf/materials.xacro"/> mybot_description)/urdf/materials.xacro" /> <xacro:include filename="$(find mybot_description)/urdf/macros.xacro"/>

mybot_description)/urdf/macros.xacro" /> <link name="base_link"> name='base_link'> <pose>0 0 0.1 0 0 0</pose>

0</pose>

    <inertial>
   <mass value="10.0"/>
   <origin xyz="0.0 0 0.1" rpy=" 0 0 0"/>
   <inertia
       ixx="0.5" ixy="0" ixz="0"
       iyy="1.0" iyz="0"
       izz="0.1"
   />
 </inertial>

 <collision name='collision'>
   <geometry>
     <box size=".4 .2 .1"/>
   </geometry>
 </collision>

 <visual name='base_link_visual'>
   <origin xyz="0 0 0" rpy=" 0 0 0"/>
   <geometry>
     <box size=".4 .2 .1"/>
   </geometry>
 </visual>


 <collision name='caster_collision'>
   <origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
   <geometry>
     <sphere radius="0.05"/>
   </geometry>
   <surface>
     <friction>
       <ode>
         <mu>0</mu>
         <mu2>0</mu2>
         <slip1>1.0</slip1>
         <slip2>1.0</slip2>
       </ode>
     </friction>
   </surface>
 </collision>

 <visual name='caster_visual'>
   <origin xyz="-0.15 0 -0.05" rpy=" 0 0 0"/>
   <geometry>
     <sphere radius="0.05"/>
   </geometry>
 </visual>

</link>

</link> <link name="imu_link"> <collision> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <box size="0.03 0.03 0.03"/> </geometry> </collision>

</collision>

    <visual>
   <origin xyz="0 0 0" rpy="0 0 0"/>
   <geometry>
     <box size="0.03 0.03 0.03"/>
   </geometry>
   <material name="blue"/>
 </visual>

 <inertial>
   <origin xyz="0 0 0" rpy="0 0 0"/>
   <mass value="0.01"/>
   <inertia
     ixx="1.0" ixy="0.0" ixz="0.0"
     iyy="1.0" iyz="0.0"
     izz="1.0"/>
 </inertial>

</link> <link name="left_wheel"> <collision name="collision"> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <geometry> <cylinder radius="0.1" length="0.05"/> </geometry> </collision> <visual name="left_wheel_visual"> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <geometry> <cylinder radius="0.1" length="0.05"/> </geometry> </visual> <inertial> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <mass value="5"/> <cylinder_inertia m="5" r="0.1" h="0.05"/> <inertia <inertia ixx="1.0" ixy="0.0" ixz="0.0" ixz="0.0" iyy="1.0" iyz="0.0" iyz="0.0" izz="1.0"/> </inertial> </link>

</link> <link name="right_wheel"> <collision name="collision"> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <geometry> <cylinder radius="0.1" length="0.05"/> </geometry> </collision> <visual name="right_wheel_visual"> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <geometry> <cylinder radius="0.1" length="0.05"/> </geometry> </visual> <inertial> <origin xyz="0 0 0" rpy="0 1.5707 1.5707"/> <mass value="5"/> <cylinder_inertia m="5" r="0.1" h="0.05"/> <inertia <inertia ixx="1.0" ixy="0.0" ixz="0.0" ixz="0.0" iyy="1.0" iyz="0.0" iyz="0.0" izz="1.0"/> </inertial> </link> <joint type="continuous" name="left_wheel_hinge"> <origin xyz="0.1 0.15 0" rpy="0 0 0"/> <child link="left_wheel"/> <parent link="base_link"/> <axis xyz="0 1 0" rpy="0 0 0"/> <limit effort="100" velocity="100"/> <joint_properties damping="0.0" friction="0.0"/> </joint>

</joint> <joint type="continuous" name="right_wheel_hinge"> <origin xyz="0.1 -0.15 0" rpy="0 0 0"/> <child link="right_wheel"/> <parent link="base_link"/> <axis xyz="0 1 0" rpy="0 0 0"/> <limit effort="100" velocity="100"/> <joint_properties damping="0.0" friction="0.0"/> </joint>

</joint> <!--IMU JOINT--> <joint name="imu_joint" type="fixed"> <axis xyz="0 1 0"/> 0" /> <origin xyz="0 0 0.065" rpy="0 0 0"/> <parent link="base_link"/> <child link="imu_link"/> </joint>

</joint> <joint name="hokuyo_joint" type="fixed"> <axis xyz="0 1 0"/> 0" /> <origin xyz=".15 0 .1" rpy="0 0 0"/> <parent link="base_link"/> <child link="hokuyo"/> </joint>

</joint> <!-- Hokuyo Laser --> <link name="hokuyo"> <collision> <origin xyz="0 0 0" rpy="0 0 0"/> <geometry> <box size="0.1 0.1 0.1"/> </geometry> </collision>

</collision>

    <visual>
   <origin xyz="0 0 0" rpy="0 0 0"/>
   <geometry>
     <mesh filename="package://mybot_description/meshes/hokuyo.dae"/>
   </geometry>
 </visual>

 <inertial>
   <mass value="1e-5" />
   <origin xyz="0 0 0" rpy="0 0 0"/>
   <inertia ixx="1e-6" ixy="0" ixz="0" iyy="1e-6" iyz="0" izz="1e-6" />
 </inertial>
</link>

</robot>

</link>

</robot>

The problem is that when i command it to go in a straight line(only linear velocity) it deviates right (-Y direction) after moving straight for a few meters. Is there any fix to this problem.