ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

I checked your code and can't find the errror, but you can try this other way to do the same, maybe it help you find your error:

1) Instead of using xacro file, you can create a URDF file from this XACRO file:

ros2 run xacro xacro {name_you_want}.xacro > {name_you_want}.urdf

2) Now you have an automatic URDF file created from XACRO file, if it fails on the process, maybe it tells you where the error is on the XACRO file.

3) From that URDF file you can create your gazebo model using this:

gz sdf -p {name_you_want}.urdf > ../{folder_you_want_to_keep_model}/{name_you_want}.sdf

4) Open gazebo from terminal using

gazebo

5) Import the model you created in step (4). Save the world

6) In your launch file, access your automated URDF file and gazebo world:

import os
from ament_index_python.packages import get_package_share_directory
from launch.substitutions import LaunchConfiguration
from launch.actions import DeclareLaunchArgument
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions.execute_process import ExecuteProcess

#=====================================
#             VARIABLES
#=====================================
pkg_name = 'package_test' # your package name
urdf_folder = 'description' # I saw on your code your xacro file is in a folder named description
model_name = 'robot.urdf' # The urdf created automatically by xacro conversion command. This is inside description folder
world_folder = 'world_folder_name'
world_name = 'robot_world'

#=====================================
#             LAUNCH CODE
#=====================================
def generate_launch_description():

    use_sim_time = LaunchConfiguration('use_sim_time', default='true')
    urdf_file = os.path.join(get_package_share_directory(pkg_name),urdf_folder, model_name)
    world_file = os.path.join(get_package_share_directory(pkg_name), world_folder, world_name)

    return LaunchDescription([
        DeclareLaunchArgument(
            'use_sim_time',
            default_value='false',
            description='Use simulation (Gazebo) clock if true'),

        # --------- ROBOT STATE PUBLISHER ----------
        Node(
            package="robot_state_publisher",
            executable="robot_state_publisher",
            name="robot_state_publisher",
            parameters=[{' use_sim_time': use_sim_time}],
            arguments=[urdf_file],
            ),

        # ------- Gazebo --------------
        ExecuteProcess(
                    name='START-GAZEBO-SERVER',
                    cmd=['gzserver',
                        '-s', 'libgazebo_ros_init.so',
                        '-s', 'libgazebo_ros_factory.so',
                        world_file]),

        ExecuteProcess(name='START-GAZEBO-CLIENT', cmd=['gzclient'])

    ])

Hope it helps.