0
$\begingroup$

I've been following the Articulated Robotics tutorial series on a Raspberry Pi 4B with Ubuntu 22.04 after switching to ROS2 Humble. However, when it comes to using the teleop_twist_keyboard to move the robot in Gazebo, I just can't get mine to move! Running ros2 topic info /cmd_vel while both the launch files and the teleop_twist_keyboard are running tells me that there are no nodes subscribed to it. But a namespace isn't set and in the tutorial it works right away, so I don't know why this is the case. Here are my files so far:

launch_sim.launch.py:

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription, ExecuteProcess
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node

def generate_launch_description():
    package_name='robot' #<--- CHANGE ME

    rsp = IncludeLaunchDescription(
                PythonLaunchDescriptionSource([os.path.join(
                    get_package_share_directory(package_name),'launch','rsp.launch.py'
                )]), launch_arguments={'use_sim_time': 'true'}.items()
    )

    gazebo = ExecuteProcess(
        cmd=['ign', 'gazebo', 'empty.sdf'],
        output='screen'
    )

    spawn_entity = Node(package='ros_gz_sim', executable='create',
                        arguments=['-topic', 'robot_description',
                                   '-entity', 'robot'],
                        output='screen')

#    diff_drive_spawner = Node(
#        package="controller_manager",
#        executable="spawner",
#        arguments=["diff_cont"],
#    )
#
#    joint_broad_spawner = Node(
#        package="controller_manager",
#        executable="spawner",
#        arguments=["joint_broad"],
#    )

    return LaunchDescription([
        rsp,
        gazebo,
        spawn_entity,
#        diff_drive_spawner,
#        joint_broad_spawner
    ])

rsp.launch.py:

import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.substitutions import LaunchConfiguration
from launch.actions import DeclareLaunchArgument
from launch_ros.actions import Node

import xacro


def generate_launch_description():

    # Check if we're told to use sim time
    use_sim_time = LaunchConfiguration('use_sim_time')

    # Process the URDF file
    pkg_path = os.path.join(get_package_share_directory('robot'))
    xacro_file = os.path.join(pkg_path,'description','robot.urdf.xacro')
    robot_description_config = xacro.process_file(xacro_file)
    
    # Create a robot_state_publisher node
    params = {'robot_description': robot_description_config.toxml(), 'use_sim_time': use_sim_time}
    node_robot_state_publisher = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        output='screen',
        parameters=[params]
    )


    # Launch!
    return LaunchDescription([
        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use sim time if true'),

        node_robot_state_publisher
    ])

robot.urdf.xacro:

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro"  name="robot">

    <xacro:include filename="robot_core.xacro" />
    <xacro:include filename="gazebo_control.xacro"/>
    <xacro:include filename="lidar.xacro"/>

</robot>

gazebo_control.xacro:

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">

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

            <num_wheel_pairs>2</num_wheel_pairs>
            <left_joint>FL_wheel_joint</left_joint>
            <left_joint>RL_wheel_joint</left_joint>
            <right_joint>FR_wheel_joint</right_joint>
            <right_joint>RR_wheel_joint</right_joint>
            
            <max_wheel_torque>200</max_wheel_torque>
            <max_wheel_acceleration>200</max_wheel_acceleration>
            
            <odometry_frame>odom</odometry_frame>
            <robot_base_frame>base_link</robot_base_frame>
            
            <publish_odom>true</publish_odom>
            <publish_odom_tf>true</publish_odom_tf>
            <publish_wheel_tf>true</publish_wheel_tf>

        </plugin>
    </gazebo>


</robot>

As I'm working with arm64, I couldn't get Gazebo Classic, which is what's used in the tutorial, but I don't see why this would stop working.

$\endgroup$

1 Answer 1

1
$\begingroup$

Gazebo Fortress is totally different from Gazebo Classic, and so are also the plugins. Have you had a look into the documentation? It seems that you need other parameters, like the topic parameter.

Have a look at the code to get a list of all parameters.

Are there any error messages in the console output when you launch gazebo/spawn your model? Furthermore, gz topics are not available in ROS automatically, and vice versa. See the docs.

$\endgroup$
2
  • $\begingroup$ Okay, thank you. I followed the tutorials and managed to get my robot moving. But is this Gazebo system compatible with Rviz? And with Nav2? $\endgroup$ Commented Jun 29 at 13:39
  • $\begingroup$ Gazebo Classic (gazebo_ros2_control) and Gazebo (ign_ros2_control/gz_ros2_control) are both "compatible". The communication therefore is limited only to a couple of topics. $\endgroup$ Commented Jul 2 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.