Issues with differential drive plugin in Gazebo Sim

Hello

I am on unit 3.6 in this course.
I added the differential plugin to the urdf file :

    <!-- Hubcap -->
        <visual>
            <origin rpy="1.5707 0 0" xyz="0 -0.18 0" />
            <geometry>
                <box size="0.02 0.5 0.02" />
            </geometry>
            <material name="Grey">
                <color rgba="0.6 0.6 0.6 1" />
            </material>
        </visual>
    </link>

    <!-- Differential Drive Plugin -->
    <gazebo>
        <plugin
            filename="gz-sim-diff-drive-system"
            name="gz::sim::systems::DiffDrive">
            <left_joint>joint_chassis_left_wheel</left_joint>
            <right_joint>joint_chassis_right_wheel</right_joint>
            <wheel_separation>1.66</wheel_separation>
            <wheel_radius>0.4</wheel_radius>
            <odom_publish_frequency>20</odom_publish_frequency>
            <topic>cmd_vel</topic>
            <odom_topic>odom</odom_topic>
            <tf_topic>tf</tf_topic>
            <frame_id>odom</frame_id>
            <child_frame_id>link_chassis</child_frame_id>
        </plugin>
    </gazebo>

</robot>

Then I build the package, source it and launch the empty.world

Then when I launch the spawn_robot.launch.py I get the following error message:

[ign gazebo-1] [Err] [SystemLoader.cc:64] Failed to load system plugin [gz-sim-diff-drive-system] : couldn't find shared library.

Then the robot appears in the gazebo simulation. But even while doing the ros bridge for the cmd_vel topic, it is not possible to move the robot by publishing to the cmd_vel topic.

Does someone know, how to correctly integrate the differential drive plugin?

Thanks in advance

Hi @Dkae ,

Thanks for bringing this issue to our notice. I did not face this issue when I created this course.
I used Gazebo Fortress for creating this course and was later upgraded to use Gazebo Garden.

Please post your empty_world.launch.py and spawn.launch.py file contents here as code-block.
I will look into this issue and provide you with a solution as soon as I can.

Regards,
Girish

Hi @girishkumar.kannan

Thanks for your response.
I tried to do export GZ_VERSION=garden, but it still gives the same error. I also tried with another plugin name:
plugin name=‘diff_drive’ filename=‘libgazebo_ros_diff_drive.so’
but this did also not work.

Here the launch files:
empty_world

import os
from ament_index_python.packages import (get_package_prefix, get_package_share_directory)
from launch import LaunchDescription
from launch.actions import (DeclareLaunchArgument, IncludeLaunchDescription)
from launch.substitutions import (PathJoinSubstitution, LaunchConfiguration)
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import SetParameter

# ROS2 Launch System will look for this function definition #
def generate_launch_description():

    # Get Package Description and Directory #
    package_description = "robot_description"
    package_directory = get_package_share_directory(package_description)

    # Set the Path to Robot Mesh Models for Loading in Gazebo Sim #
    # NOTE: Do this BEFORE launching Gazebo Sim #
    install_dir_path = (get_package_prefix(package_description) + "/share")
    robot_meshes_path = os.path.join(package_directory, "meshes")
    gazebo_resource_paths = [install_dir_path, robot_meshes_path]
    if "IGN_GAZEBO_RESOURCE_PATH" in os.environ:
        for resource_path in gazebo_resource_paths:
            if resource_path not in os.environ["IGN_GAZEBO_RESOURCE_PATH"]:
                os.environ["IGN_GAZEBO_RESOURCE_PATH"] += (':' + resource_path)
    else:
        os.environ["IGN_GAZEBO_RESOURCE_PATH"] = (':'.join(gazebo_resource_paths))

    # Load Empty World SDF from Gazebo Sim Package #
    world_file = "empty.sdf"
    world_config = LaunchConfiguration("world")
    declare_world_arg = DeclareLaunchArgument("world",
                                              default_value=["-r ", world_file],
                                              description="SDF World File")
    
    # Declare GazeboSim Launch #
    gzsim_pkg = get_package_share_directory("ros_gz_sim")
    gz_sim = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            PathJoinSubstitution([gzsim_pkg, "launch", "gz_sim.launch.py"])),
            launch_arguments={"gz_args": world_config}.items(),
    )

    # Create and Return the Launch Description Object #
    return LaunchDescription(
        [
            declare_world_arg,
            # Sets use_sim_time for all nodes started below (doesn't work for nodes started from ignition gazebo) #
            SetParameter(name="use_sim_time", value=True),
            gz_sim,
        ]
    )

and spawn_robot

import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import (Command, LaunchConfiguration)
from launch_ros.actions import (Node, SetParameter)

# ROS2 Launch System will look for this function definition #
def generate_launch_description():

    # Get Package Description and Directory #
    package_description = "robot_description"
    package_directory = get_package_share_directory(package_description)

    # Load URDF File #
    urdf_file = 'robot.urdf'
    robot_desc_path = os.path.join(package_directory, "urdf", urdf_file)
    print("URDF Loaded !")

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

    # Spawn the Robot #
    declare_spawn_model_name = DeclareLaunchArgument("model_name", default_value="my_robot",
                                                     description="Model Spawn Name")
    declare_spawn_x = DeclareLaunchArgument("x", default_value="0.0",
                                            description="Model Spawn X Axis Value")
    declare_spawn_y = DeclareLaunchArgument("y", default_value="0.0",
                                            description="Model Spawn Y Axis Value")
    declare_spawn_z = DeclareLaunchArgument("z", default_value="0.5",
                                            description="Model Spawn Z Axis Value")
    gz_spawn_entity = Node(
        package="ros_gz_sim",
        executable="create",
        name="my_robot_spawn",
        arguments=[
            "-name", LaunchConfiguration("model_name"),
            "-allow_renaming", "true",
            "-topic", "robot_description",
            "-x", LaunchConfiguration("x"),
            "-y", LaunchConfiguration("y"),
            "-z", LaunchConfiguration("z"),
        ],
        output="screen",
    )

    # Create and Return the Launch Description Object #
    return LaunchDescription(
        [
            # Sets use_sim_time for all nodes started below (doesn't work for nodes started from ignition gazebo) #
            SetParameter(name="use_sim_time", value=True),
            robot_state_publisher_node,
            declare_spawn_model_name,
            declare_spawn_x,
            declare_spawn_y,
            declare_spawn_z,
            gz_spawn_entity,
        ]
    )

Hi @Dkae ,

You don’t have to do this since the only version that is installed in the course environment is Gazebo Garden version 7.6.0.

This will NEVER work since this line is for Gazebo Classic version and not for the new Gazebo Sim (Ignition).

I tried using your launch files. They run fine. The problem is sometimes you need to rebuild and start again.
So compile the package by deleting build, install and log folders.
In terminal 1, run the empty_world.launch.py.
In terminal 2, source your ros2_ws and then run the spawn_launch.py.

Once Gazebo Sim is fully loaded along with the Robot,
In terminal 3, start the ROS_GZ bridge command for cmd_vel,
In terminal 4, run the teleop program.

Everything should work fine.
If you still have issues, I will be happy to setup a screen share session with you and help you out live.
That way I can know what problem you have and I can fix the bug if it needs to be fixed.

Regards,
Girish

Hi @girishkumar.kannan

I rebuild the package and tried again and I still got the same error.

[ign gazebo-1] [Err] [SystemLoader.cc:64] Failed to load system plugin [gz-sim-diff-drive-system] : couldn't find shared library.

So I changed the plugin name from

filename="gz-sim-diff-drive-system"
            name="gz::sim::systems::DiffDrive">

to

filename="libignition-gazebo-diff-drive-system.so"
            name="ignition::gazebo::systems::DiffDrive">

and it worked! I could do the ros_gz_bridge and then move the robot around with the keyboard.

Therefore it can load the libignition-gazebo plugin, but not the gz-sim plugin.
I tried the same on a Ubuntu VMware with the same result. Ignition worked and gz-sim did not work.

So I don’t know why the gz-sim is not working.

Well if you want, we can do a screen sharing session.

Cheers

1 Like

Hi @Dkae ,

Thanks for sharing that information. I must agree that Gazebo Sim (after transitioning from the old Ignition name) has become quite confusing. Your case being one example.

The good news is that Gazebo Sim is designed to be backwards compatible. So if any Gazebo Sim plugin does not work, then its alternative Ignition plugin should work.

You can refer the plugin definitions here:
Garden: Gazebo Garden Diff Drive Plugin
Fortress: Gazebo Fortress Diff Drive Plugin

Now that Diff Drive caused that issue, I am sure the other two plugins might also cause some issues.

So here are the references for Diff Drive, Laser Scanner and IMU:

Diff Drive:

filename="libignition-gazebo-diff-drive-system.so"
name="ignition::gazebo::systems::DiffDrive"

Laser Scanner:

filename="libignition-gazebo-sensors-system.so"
name="ignition::gazebo::systems::Sensors"

IMU:

filename="libignition-gazebo-imu-system.so"
name="ignition::gazebo::systems::Imu"

I hope this helps.

Regards,
Girish

2 Likes

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