Robotics StackExchange | Archived questions

diff_drive_controller only drives straight, no turning

I'm testing out a two wheeled robot I designed and put in gazebo. I also have a static back wheel with very little friction that is only there for structural support. When I give linear x commands the bot drives forward and backward, however any angular z commands are completely ignored and the robot does nothing. My files are as follows:

rover_control.yaml:

rover:
# Publish all joint states -----------------------------------
joint_state_controller:
  type: joint_state_controller/JointStateController
  publish_rate: 50

mobile_base_controller:
  type: "diff_drive_controller/DiffDriveController"
  left_wheel: 'motor_wheel_left'
  right_wheel: 'motor_wheel_right'
  publish_rate: 50.0
  pose_covariance_diagonal : [0.001, .001, 1000000., 1000000., 1000000., 1000.]
  twist_covariance_diagonal: [0.001, .001, 1000000., 1000000., 1000000., 1000.]
  wheel_radius : 0.0508

rover_control.launch

<?xml version='1.0' encoding="UTF-8"?>
<launch>

<rosparam file="$(find rover_description)/config/rover_control.yaml" command="load"/>
<param name="rover/robot_description" command="cat $(find rover_description)/urdf/rover_description.urdf" />
<node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
      output="screen" ns="/rover" args="joint_state_controller
      mobile_base_controller"/>

<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
      respawn="false" output="screen">
      <remap from="/joint_states" to="rover/joint_states"/>
</node>

</launch>

rover_description.urdf

    <robot
  name="rover_description">
  <link
    name="base_link">
    <inertial>
      <origin
        xyz="-0.081461 0.072568 0.22578"
        rpy="0 0 0" />
      <mass
        value="0.02" />
      <inertia
        ixx="0.0017841"
        ixy="-2.5191E-21"
        ixz="-3.1496E-20"
        iyy="0.0031046"
        iyz="-3.5569E-22"
        izz="0.0013209" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/base_link.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="1 1 1 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/base_link.STL" />
      </geometry>
    </collision>
  </link>
  <link
    name="motor_right">
    <inertial>
      <origin
        xyz="0.025956 0.025203 1.9204E-06"
        rpy="0 0 0" />
      <mass
        value="0.11635" />
      <inertia
        ixx="2.1884E-05"
        ixy="-6.1285E-06"
        ixz="1.7317E-08"
        iyy="0.00012501"
        iyz="-1.7272E-10"
        izz="0.00012659" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/motor_right.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.79216 0.81961 0.93333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/motor_right.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="base_motor_right"
    type="fixed">
    <origin
      xyz="0.024539 -0.097801 0.074156"
      rpy="1.5708 0 3.1416" />
    <parent
      link="base_link" />
    <child
      link="motor_right" />
    <axis
      xyz="0 0 0" />
    <limit
      effort="1"
      velocity="0.05" />
  </joint>
  <link
    name="wheel_right">
    <inertial>
      <origin
        xyz="6.9389E-17 -0.0127 0"
        rpy="0 0 0" />
      <mass
        value="0.078876" />
      <inertia
        ixx="7.3551E-05"
        ixy="-5.5111E-11"
        ixz="8.4703E-21"
        iyy="0.00014131"
        iyz="-1.8331E-21"
        izz="7.3551E-05" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/wheel_right.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.79216 0.81961 0.93333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/wheel_right.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="motor_wheel_right"
    type="continuous">
    <origin
      xyz="-0.042 0.019 0"
      rpy="0 -1.413 -1.5708" />
    <parent
      link="motor_right" />
    <child
      link="wheel_right" />
    <axis
      xyz="0 -1 0" />
    <limit
      effort="1"
      velocity="0.5" />
  </joint>
  <link
    name="motor_left">
    <inertial>
      <origin
        xyz="0.0259564356340291 0.0252030785136685 1.92037148977198E-06"
        rpy="0 0 0" />
      <mass
        value="0.116347178526618" />
      <inertia
        ixx="2.18842342286251E-05"
        ixy="-6.12849702160094E-06"
        ixz="1.7316665159744E-08"
        iyy="0.000125012852845111"
        iyz="-1.72720823459765E-10"
        izz="0.000126587028640003" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/motor_left.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.792156862745098 0.819607843137255 0.933333333333333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/motor_left.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="base_motor_left"
    type="fixed">
    <origin
      xyz="-0.18746 -0.097801 0.074156"
      rpy="1.5708 0 0" />
    <parent
      link="base_link" />
    <child
      link="motor_left" />
    <axis
      xyz="0 0 0" />
  </joint>
  <link
    name="wheel_left">
    <inertial>
      <origin
        xyz="6.9389E-17 0.0127 0"
        rpy="0 0 0" />
      <mass
        value="0.078876" />
      <inertia
        ixx="7.3551E-05"
        ixy="-5.5111E-11"
        ixz="1.4385E-20"
        iyy="0.00014131"
        iyz="-2.1806E-21"
        izz="7.3551E-05" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/wheel_left.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.79216 0.81961 0.93333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/wheel_left.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="motor_wheel_left"
    type="continuous">
    <origin
      xyz="-0.042 0.019 0"
      rpy="0 0 1.5708" />
    <parent
      link="motor_left" />
    <child
      link="wheel_left" />
    <axis
      xyz="0 -1 0" />
    <limit
      effort="1"
      velocity="0.5" />
  </joint>
  <link
    name="back_motor">
    <inertial>
      <origin
        xyz="0.0090666 -0.020723 -0.0039784"
        rpy="0 0 0" />
      <mass
        value=".04" />
      <inertia
        ixx="1.1747E-05"
        ixy="3.9506E-07"
        ixz="2.5818E-06"
        iyy="1.0703E-05"
        iyz="-1.0714E-07"
        izz="1.3277E-05" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/back_motor.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.79216 0.81961 0.93333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/back_motor.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="base_motor_back"
    type="fixed">
    <origin
      xyz="-0.075086 -0.3436 0.088656"
      rpy="-3.1416 0.64862 -1.5708" />
    <parent
      link="base_link" />
    <child
      link="back_motor" />
    <axis
      xyz="0 0 0" />
  </joint>
  <link
    name="back_wheel">
    <inertial>
      <origin
        xyz="-0.079056 0.0095567 0.035224"
        rpy="0 0 0" />
      <mass
        value="0.078876" />
      <inertia
        ixx="7.3551E-05"
        ixy="-5.5111E-11"
        ixz="3.0493E-20"
        iyy="0.00014131"
        iyz="2.6765E-21"
        izz="7.3551E-05" />
    </inertial>
    <visual>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/back_wheel.STL" />
      </geometry>
      <material
        name="">
        <color
          rgba="0.79216 0.81961 0.93333 1" />
      </material>
    </visual>
    <collision>
      <origin
        xyz="0 0 0"
        rpy="0 0 0" />
      <geometry>
        <mesh
          filename="package://rover_description/meshes/back_wheel.STL" />
      </geometry>
    </collision>
  </link>
  <joint
    name="motor_back"
    type="fixed">
    <origin

      xyz="0.08 -.005 -.033"
      rpy="0 0 0" />
    <parent
      link="back_motor" />
    <child
      link="back_wheel" />
    <axis
      xyz="0 0 0" />
  </joint>

  <gazebo reference="wheel_left">
      <kp>500.0</kp>
      <kd>500.0</kd>
      <mu1>1</mu1>
      <mu2>1</mu2>
      <material>Gazebo/Black</material>
  </gazebo>

  <gazebo reference="wheel_right">
      <kp>500.0</kp>
      <kd>500.0</kd>
      <mu1>1</mu1>
      <mu2>1</mu2>
      <material>Gazebo/Black</material>
  </gazebo>

  <gazebo reference="back_wheel">
      <kp>50</kp>
      <kd>50</kd>
      <mu1>1</mu1>
      <mu2>1</mu2>
      <material>Gazebo/Black</material>
  </gazebo>

  <gazebo>
      <plugin name="diff_drive_controller" filename="libgazebo_ros_diff_drive.so">
            <alwaysOn>true</alwaysOn>
            <updateRate>50.0</updateRate>

        </plugin>
      <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
          <robotNamespace>/rover</robotNamespace>
      </plugin>
  </gazebo>

  <transmission name="left_wheel_transmission">
      <type>transmission_interface/SimpleTransmission</type>
      <joint name="motor_wheel_left">
          <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
      </joint>
      <actuator name="left_wheel_actuator">
          <hardwareInterface>VelocityJointInterface</hardwareInterface>
          <mechanicalReduction>7</mechanicalReduction>
      </actuator>
  </transmission>

  <transmission name="right_wheel_transmission">
      <type>transmission_interface/SimpleTransmission</type>
      <joint name="motor_wheel_right">
          <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
      </joint>
      <actuator name="right_wheel_actuator">
          <hardwareInterface>VelocityJointInterface</hardwareInterface>
          <mechanicalReduction>7</mechanicalReduction>
      </actuator>
  </transmission>

</robot>

Asked by Callum Gundlach on 2018-07-09 17:34:11 UTC

Comments

In what directions do your wheels spin in 1) gazebo 2) rviz when turning?

Asked by Humpelstilzchen on 2018-07-10 01:58:41 UTC

In both gazebo and rviz the wheels would both spin counter-clockwise and clockwise depending on the value of linear.x.

Asked by Callum Gundlach on 2018-07-10 08:28:44 UTC

And with rotational speed only?

Asked by Humpelstilzchen on 2018-07-10 09:35:41 UTC

Wheels do not move, in both rviz and gazebo

Asked by Callum Gundlach on 2018-07-10 09:38:53 UTC

Have you checked the tf in rviz?

Asked by Humpelstilzchen on 2018-07-10 11:24:50 UTC

Answers

I realize this is an old post, but I had the same issue and couldn't find an answer anywhere, so I'll post it here. It turned out I was missing wheel_separation : 1.0 in the yaml. It's supposed to automagically find it and the wheel radius from the urdf, but it my case it didn't and used a default of 0, which apparently led to a maths error when it calculated the differential drive equations (maybe a divide by zero?) even though it could go forwards/backwards just fine.

Asked by john.j.oneill on 2019-03-02 16:44:53 UTC

Comments