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

Problem spawning in Gazebo a simple URDF model

asked 2022-05-17 12:08:31 -0500

joseecm gravatar image

Hi there!

I'm using ROS2 Galactic and have a python package that simply spawn a robot. It works with a complex URDF model of a robot that have meshes and sensors, but what's driving me crazy is that it doesn't work with the following simple URDF model:

<?xml version="1.0"?>
<robot name="multipleshapes">
  <link name="base_link">
        <cylinder length="0.6" radius="0.2"/>

  <link name="right_leg">
        <box size="0.6 0.1 0.2"/>

  <joint name="base_to_right_leg" type="fixed">
    <parent link="base_link"/>
    <child link="right_leg"/>


The URDF files are both in the same place. When I run the launch file to spawn the model it seems to work but the model doesn't appear in Gazebo. I don't get errors.

ros@ubuntu:~/ros2_ws$ ros2 launch mars_robot
[INFO] [launch]: All log files can be found below /home/ros/.ros/log/2022-05-17-18-57-27-755134-ubuntu-24691
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [gzserver-1]: process started with pid [24693]
[INFO] [gzclient   -2]: process started with pid [24696]
[INFO] [robot_state_publisher-3]: process started with pid [24699]
[INFO] []: process started with pid [24701]
[robot_state_publisher-3] Link right_leg had 0 children
[robot_state_publisher-3] [INFO] [1652806649.104605067] [robot_state_publisher]: got segment base_link
[robot_state_publisher-3] [INFO] [1652806649.106763959] [robot_state_publisher]: got segment right_leg
[] [INFO] [1652806650.703018213] [spawn_entity]: Spawn Entity started
[] [INFO] [1652806650.707231388] [spawn_entity]: Loading entity published on topic robot_description
[] [INFO] [1652806650.711765040] [spawn_entity]: Waiting for entity xml on robot_description
[] [INFO] [1652806650.713877199] [spawn_entity]: Waiting for service /spawn_entity, timeout = 5
[] [INFO] [1652806650.717389319] [spawn_entity]: Waiting for service /spawn_entity
[] [INFO] [1652806653.745771815] [spawn_entity]: Calling service /spawn_entity
[] [INFO] [1652806653.975522539] [spawn_entity]: Spawn status: SpawnEntity: Successfully spawned entity [mars_robot]
[] /opt/ros/galactic/lib/python3.8/site-packages/rclpy/ UserWarning: DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL is deprecated. Use DurabilityPolicy.TRANSIENT_LOCAL instead.
[]   warnings.warn(
[INFO] []: process has finished cleanly [pid 24701]

The code of the launch file is the following:

import os
import xacro

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription 
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import Node
from launch.actions import SetEnvironmentVariable
from launch.substitutions import EnvironmentVariable

def generate_launch_description():

    pkg_install_path = get_package_share_directory('mars_robot')

    if 'GAZEBO_MODEL_PATH' in os.environ:
        model_path =  os.environ['GAZEBO_MODEL_PATH'] + ':' + pkg_install_path
        model_path =  pkg_install_path

    xacro_robot_pkg_path = os.path.join(

    xacro_file = os.path.join(xacro_robot_pkg_path,

    doc = xacro.parse(open(xacro_file))

    node_robot_state_publisher = Node(
        parameters=[{'robot_description': doc.toxml()}]

    spawn_entity = Node(package='gazebo_ros', executable='',
                        arguments=['-topic', 'robot_description',
                                   '-entity', 'mars_robot'],

    gazebo = IncludeLaunchDescription(
                    get_package_share_directory('gazebo_ros'), 'launch', '')]),

    return LaunchDescription([

I've been trying to solve the problem for several days but I can't find the solution. Can ... (more)

edit retag flag offensive close merge delete


It might be that Gazebo doesn't like the model, since it doesn't have any collision nor any inertial tags.

I know Gazebo can be very finicky with that stuff. I'd recommend adding some and seeing what happens. Also, start with 1 link, just to make it easier, before adding others.

Joe28965 gravatar image Joe28965  ( 2022-05-18 08:47:50 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2022-05-19 10:42:36 -0500

joseecm gravatar image

Thanks @Joe28965 for your answer, you are right. If I add the inertial and collision tags the model appears in Gazebo. What was confusing me is that there are many packages that use urdf files where these tags do not appear, I suppose because they are designed to be used with RVIZ and not with GAZEBO.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2022-05-17 12:08:31 -0500

Seen: 1,289 times

Last updated: May 19 '22