Robot not turning right or left - Gazebo Differential drive

Hi, I have been trying to implement my own robot. I ma using Ros2 and gazebo simulation. my robot is only moving forward and backward but not left or right. Below an example of my URDF file. Any help would be appreciated …

<link name="front_right_wheel">
    <visual>
        <geometry>
            <cylinder radius="0.1" length="0.05"/>
        </geometry>
        <material name="blue"/>
    </visual>
    <collision>
        <geometry>
            <cylinder radius="0.1" length="0.05"/>
        </geometry>
    </collision>
    <inertial>
        <mass value="2"/>
        <inertia ixx="0.005416667" ixy="0" ixz="0" iyy="0.005416667" iyz="0" izz="0.01" />
    </inertial>
</link>
<gazebo reference="front_right_wheel">
<material>Gazebo/Green</material>
<kp>1000000000000000000000000000.0</kp>
<kd>1000000000000000000000000000.0</kd>
<mu1>1000</mu1>
<mu2>100</mu2>
</gazebo>
<joint name="front_right_wheel_joint" type="continuous">
    <origin rpy="0 1.5707 1.5707" xyz="0.4 0.35 0"/>
    <parent link="chassis"/>
    <child link="front_right_wheel"/>
    <axis xyz="0 0 1"/>
    <limit effort="1" velocity="1"/>
    <joint_properties damping="1.0" friction="0.2"/>
</joint>
<gazebo>
    <plugin filename="libgazebo_ros_diff_drive.so" name="differential_drive_controller">

        <!-- wheels -->
        <left_joint>front_left_wheel_joint</left_joint>
        <right_joint>front_right_wheel_joint</right_joint>

        <!-- kinematics -->
        <wheel_separation>0.7</wheel_separation>
        <wheel_diameter>0.2</wheel_diameter>

        <!-- limits -->
        <max_wheel_torque>20</max_wheel_torque>
        <max_wheel_acceleration>2.0</max_wheel_acceleration>

        <!-- output -->
        <publish_odom>true</publish_odom>
        <publish_odom_tf>true</publish_odom_tf>
        <publish_wheel_tf>true</publish_wheel_tf>

        <odometry_frame>odom</odometry_frame>
        <robot_base_frame>base_link</robot_base_frame>

    </plugin>
</gazebo>

Hi @haifaksh
Which specific course are you taking? And what unit are you on?

Hi Bayodesegun.
I am taking the course " URDF for robot modeling ROS2". However I was trying to build my own robot follwoing the instructions in the course but using my own laptop where I installed all needed software and tools.

The model that I built is spawned in Gazebo but trying to control it using teleop_twist_keyboard is very slow and does not turn left or right easily. So I don’t know what is the issue.

Also I have tried to replicate the same robot that is in the course but with bigger dimensions. in Gazebo my robot is showing upside down and when I select “Edit → Reset Model Poses” the robot orientation is fixed. However I need to know what is the reason that my simulated robot comes upside down? Below my URDF File:

<?xml version="1.0"?>
<collision>
  <origin rpy="0 0 0" xyz="0 0 0" />
  <geometry>
    <box size="1.0 1.0 1.0"/>
  </geometry>
</collision>

<inertial>
  <mass value="5.0"/>
  <origin rpy="0 0 0" xyz="0 0 0"/>
  <inertia ixx="0.8333333333333335" ixy="0" ixz="0" iyy="0.8333333333333335" iyz="0" izz="0.8333333333333335"/>
</inertial>
Gazebo/Blue
  <collision>
    <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
    <geometry>
      <cylinder length="0.01" radius="0.35"/>
    </geometry>
  </collision>

  <inertial>
    <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
    <mass value="0.5"/>
    <inertia ixx="1.531666666666667e-02" ixy="0" ixz="0" iyy="1.531666666666667e-02" iyz="0" izz="3.0625000000000006e-02"/>
  </inertial>
1000000000000000000000000000.0 1000000000000000000000000000.0 10.0 10.0 Gazebo/Green
  <collision>
    <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
    <geometry>
      <cylinder length="0.01" radius="0.35"/>
    </geometry>
  </collision>

  <inertial>
    <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
    <mass value="0.5"/>
    <inertia ixx="1.531666666666667e-02" ixy="0" ixz="0" iyy="1.531666666666667e-02" iyz="0" izz="3.0625000000000006e-02"/>
  </inertial>
1000000000000000000000000000.0 1000000000000000000000000000.0 10.0 10.0 Gazebo/Orange
  <collision>
    <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
    <geometry>
      <cylinder length="0.01" radius="0.045000000000000005"/>
    </geometry>
  </collision>

  <inertial>
      <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
      <mass value="0.01"/>
      <inertia ixx="5.145833333333334e-06" ixy="0" ixz="0" iyy="5.145833333333334e-06" iyz="0" izz="1.0125000000000003e-05"/>
  </inertial>
<gazebo reference="front_yaw_link">
    <material>Gazebo/Blue</material>
</gazebo>
  <collision>
    <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
    <geometry>
      <cylinder length="0.01" radius="0.045000000000000005"/>
    </geometry>
  </collision>

  <inertial>
      <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
      <mass value="0.01"/>
      <inertia ixx="5.145833333333334e-06" ixy="0" ixz="0" iyy="5.145833333333334e-06" iyz="0" izz="1.0125000000000003e-05"/>
  </inertial>
<gazebo reference="front_roll_link">
    <material>Gazebo/Red</material>
</gazebo>
<collision>
  <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
  <geometry>
    <sphere radius="0.10"/>
  </geometry>
</collision>

<inertial>
    <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
    <mass value="0.01"/>
    <inertia ixx="4e-05" ixy="0" ixz="0" iyy="4e-05" iyz="0" izz="4e-05"/>
</inertial>
1000000000000000000000000000.0 1000000000000000000000000000.0 0.5 0.5 Gazebo/Purple
  <collision>
    <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
    <geometry>
      <cylinder length="0.01" radius="0.045000000000000005"/>
    </geometry>
  </collision>

  <inertial>
      <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
      <mass value="0.01"/>
      <inertia ixx="5.145833333333334e-06" ixy="0" ixz="0" iyy="5.145833333333334e-06" iyz="0" izz="1.0125000000000003e-05"/>
  </inertial>
<gazebo reference="back_yaw_link">
    <material>Gazebo/Blue</material>
</gazebo>
  <collision>
    <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
    <geometry>
      <cylinder length="0.01" radius="0.045000000000000005"/>
    </geometry>
  </collision>

  <inertial>
      <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
      <mass value="0.01"/>
      <inertia ixx="5.145833333333334e-06" ixy="0" ixz="0" iyy="5.145833333333334e-06" iyz="0" izz="1.0125000000000003e-05"/>
  </inertial>
<gazebo reference="back_roll_link">
    <material>Gazebo/Red</material>
</gazebo>
<collision>
  <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
  <geometry>
    <sphere radius="0.10"/>
  </geometry>
</collision>

<inertial>
    <origin rpy="0 1.5707 1.5707" xyz="0 0 0"/>
    <mass value="0.01"/>
    <inertia ixx="4e-05" ixy="0" ixz="0" iyy="4e-05" iyz="0" izz="4e-05"/>
</inertial>
1000000000000000000000000000.0 1000000000000000000000000000.0 0.5 0.5 Gazebo/Yellow ~/out:=joint_states 30 joint_left_wheel joint_right_wheel
<joint_name>front_yaw_joint</joint_name>
<joint_name>back_yaw_joint</joint_name>
<joint_name>front_roll_joint</joint_name>
<joint_name>back_roll_joint</joint_name>
<joint_name>front_pitch_joint</joint_name>
<joint_name>back_pitch_joint</joint_name>

</plugin>
  <!-- wheels -->
  <left_joint>joint_left_wheel</left_joint>
  <right_joint>joint_right_wheel</right_joint>

  <!-- kinematics -->
  <wheel_separation>1</wheel_separation>
  <wheel_diameter>0.7</wheel_diameter>

  <!-- limits -->
  <max_wheel_torque>1.0</max_wheel_torque>
  <max_wheel_acceleration>2.0</max_wheel_acceleration>

  <!-- output -->
  <publish_odom>true</publish_odom>
  <publish_odom_tf>true</publish_odom_tf>

  <odometry_frame>odom</odometry_frame>
  <robot_base_frame>base_link</robot_base_frame>

</plugin>
<collision>
   <origin rpy="0 0 0" xyz="0 0 0.0204"/>
  <geometry>
    <box size="0.74986 0.74935 0.408"/>
  </geometry>
</collision>

<inertial>

  <mass value="0.1"/>
  <origin rpy="0 0 0" xyz="0 0 0.204"/>
  <inertia ixx="6.066578520833334e-03" ixy="0" ixz="0" iyy="6.072950163333333e-03" iyz="0" izz="9.365128684166666e-03"/>
</inertial>
0 0 0 0 0 0 200 1.0 -3.14 3.14 0.1 5.0 true true 100.0 /rmod3 ~/out:=laser_scan sensor_msgs/LaserScan

Hi,

I would highly advise you to share the file through a git or ROSject so that we can at least see the file without strange formating issues.

That your robot appears upside down, based on the fact that it could be many things ( the whole model? one mesh? ) if you define the model in sdf then sometime this happens if its defined in the world directly. It could be just that you are spawning it wrong.

I would highly reccomdn you to first make the example in the course work in your PC. Once you have it. Then modify it one part at a time, and see how it changes, if it triggers an issue the changes you make… Otherwise this can escalate really fast to a lot of problems.

And please post some images, something that we can help you better.

Hi duckfrost2,

I have uploaded the URDF file under GitHub - haifaksh/ROS2_h
Kindly check , I made it very simple only to get the simulated robot moving smoothly in Gazebo but I have issues controlling it through the differential drive

Let me check it and I’ll give you an answer

I tried it and worked without any issue. The only thing is that the non fixed joints have to be published their state ( angle) otherwise, the RVIZ doesn’t know where to put them.

You have to launch this joint_state_publisher publish through the command:

ros2 run joint_state_publisher_gui joint_state_publisher_gui

test

And the launch should be something like this:

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.substitutions import Command
from launch_ros.actions import Node

def generate_launch_description():

####### DATA INPUT ##########
urdf_file = 'range.urdf'
#xacro_file = "box_bot.xacro"
package_description = "my_box_bot_description"

####### DATA INPUT END ##########
print("Fetching URDF ==>")
robot_desc_path = os.path.join(get_package_share_directory(
    package_description), "urdf", urdf_file)

# Robot State Publisher

robot_state_publisher_node = Node(
    package='robot_state_publisher',
    executable='robot_state_publisher',
    name='robot_state_publisher_node',
    emulate_tty=True,
    parameters=[{'use_sim_time': True, 'robot_description': Command(
        ['xacro ', robot_desc_path])}],
    output="screen"
)

# RVIZ Configuration
rviz_config_dir = os.path.join(get_package_share_directory(
    package_description), 'rviz', 'urdf_vis.rviz')

rviz_node = Node(
    package='rviz2',
    executable='rviz2',
    output='screen',
    name='rviz_node',
    parameters=[{'use_sim_time': True}],
    arguments=['-d', rviz_config_dir])

# create and return launch description object
return LaunchDescription(
    [
        robot_state_publisher_node,
        rviz_node
    ]
)

Hi Duckfrost2
Thank you so much for checking my urdf file. The problem I am facing is with Gazebo. I tried to record a video
turning right or left is not smooth, very slow and not accurate at all. The video can be found in the below link: https://drive.google.com/file/d/19M_388KfNG0_HwliRr-htgyU2T9fPrzQ/view?usp=sharing

I also uploaded all my python files in the same github directory.
Kindly help , I am not able to move forward with the course since I am not able to make my simulated robot move as expected.

Hi,

So you are trying to move a four wheel robot with FIXED axis like it was a differential drive two wheel robot. If the friction in the non motorised wheels is too high, it will be very difficult .

I suggest you two options:

A) Remove the friction from the back wheels
B) Add steering motion to the front wheels. In this case also it will be better to use Ackerman to have better steering angle.

Here you have an example of a Car in ROS2 from our git: BOX CAR

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.