R2d2 not simulating inside gazebo

r2d2.urdf.xacro :

<?xml version="1.0"?>

r2d2_env.launch.py:

import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
from launch.actions import RegisterEventHandler
from launch.event_handlers import OnProcessExit
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution

from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from ament_index_python.packages import get_package_prefix
import xacro

def generate_launch_description():
# Launch Arguments
use_sim_time = LaunchConfiguration(‘use_sim_time’, default=True)

# PARAMS
gazebo_pkg_name = "gazebo_ros"
package_name = "custom_rob_description"
shared_pkg_name = "custom_robot_description"
rviz_file_name = "r2d2.rviz"
models_pkg = "models_package"
world_file = "simple_world.world"

# Launch the robot
pkg_description = get_package_share_directory(package_name)
xacro_file_name = "r2d2.urdf.xacro"
robot_name = "rob"

# Pose where we want to spawn the robot
spawn_x_val = '3.5'
spawn_y_val = '0.0'
spawn_z_val = '0.1'
spawn_yaw_val = '0.00'

pkg_share = FindPackageShare(package=shared_pkg_name).find(shared_pkg_name)
pkg_gazebo_ros = FindPackageShare(package=gazebo_pkg_name).find(gazebo_pkg_name) 
pkg_models = FindPackageShare(package=models_pkg).find(models_pkg) 

world_path = os.path.join(pkg_models, "worlds", world_file)
rviz_config_file = os.path.join(pkg_share, "rviz", rviz_file_name) 
xacro_file_path = os.path.join(pkg_description, "urdf", xacro_file_name)
gazebo_models_path = os.path.join(pkg_models, "models")

# GAZEBO CLASSIC
start_sim = IncludeLaunchDescription(
    PythonLaunchDescriptionSource(os.path.join(pkg_gazebo_ros, "launch", "gzserver.launch.py")),
    launch_arguments={"world": world_path, "verbose": "true", "paused": "false"}.items())

# Spawn Robot
spwn_robot = Node(
        package='gazebo_ros', 
        executable='spawn_entity.py',
        arguments=['-entity', robot_name, 
                    '-topic', 'robot_description',
                    '-timeout', '120.0',
                        '-x', spawn_x_val,
                        '-y', spawn_y_val,
                        '-z', spawn_z_val,
                        '-Y', spawn_yaw_val],
                        output='screen')

rob_state = Node(
    package='robot_state_publisher',
    executable='robot_state_publisher',
    parameters=[{'robot_description': Command(['xacro ', xacro_file_path]),'use_sim_time': use_sim_time}]
    )

start_rviz_cmd = Node(
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        output='screen',
        arguments=['-d', rviz_config_file])


gazebo_plugins_name = "gazebo_plugins"
gazebo_plugins_name_path_install_dir = get_package_prefix(
    gazebo_plugins_name)

install_dir = get_package_prefix(package_name)

if 'GAZEBO_MODEL_PATH' in os.environ:
    os.environ['GAZEBO_MODEL_PATH'] = os.environ['GAZEBO_MODEL_PATH'] + ':' + install_dir + \
        '/share' + ':' + gazebo_models_path
else:
    os.environ['GAZEBO_MODEL_PATH'] = install_dir + \
        "/share" + ':' + gazebo_models_path
if 'GAZEBO_PLUGIN_PATH' in os.environ:
    os.environ['GAZEBO_PLUGIN_PATH'] = os.environ['GAZEBO_PLUGIN_PATH'] + ':' + install_dir + '/lib' + ':' + \
        gazebo_plugins_name_path_install_dir + '/lib' + ':'
else:
    os.environ['GAZEBO_PLUGIN_PATH'] = install_dir + '/lib' + ':' + gazebo_plugins_name_path_install_dir + \
        '/lib' + ':'

return LaunchDescription([
    start_sim,
    rob_state,
    spwn_robot,

    DeclareLaunchArgument(
        'use_sim_time',
        default_value=use_sim_time,
        description='If true, use simulated clock'),
    start_rviz_cmd,
])

simple_world.world

<?xml version="1.0" ?>
<scene>
<grid>true</grid>
</scene>

<!-- Define the ambient light and background color -->
<scene>
  <ambient>0.4 0.4 0.4 1</ambient>
  <background>0.7 0.7 0.7 1</background>
  <grid>true</grid>
</scene>

<!-- Add a default light source -->
<include>
  <uri>model://sun</uri>
</include>

<!-- Add a ground plane -->
<include>
  <uri>model://ground_plane</uri>
</include>




empty gazebo , the r2d2 robot is not simulation inside gazebo , seems like all the files here are correctly copy pasted

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

Hi, please share the entire terminal output. It’s the most important thing to have while debugging.

  1. Duplicate <scene> tag in simple_world.world:
  • You have two <scene> tags in your world file, which might cause parsing issues.
  1. Potential Package Name Mismatch:
  • You’re using both "custom_rob_description" and "custom_robot_description" - make sure these are correct and consistent.
  1. Verify the robot description:
  • Make sure your r2d2.urdf.xacro file is properly formatted and contains valid robot description.

This topic was automatically closed after 13 days. New replies are no longer allowed.