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

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">
    <visual>
      <geometry>
        <cylinder length="0.6" radius="0.2"/>
      </geometry>
    </visual>
  </link>

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

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

</robot>

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 mars_robot.launch.py
[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] [spawn_entity.py-4]: 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
[spawn_entity.py-4] [INFO] [1652806650.703018213] [spawn_entity]: Spawn Entity started
[spawn_entity.py-4] [INFO] [1652806650.707231388] [spawn_entity]: Loading entity published on topic robot_description
[spawn_entity.py-4] [INFO] [1652806650.711765040] [spawn_entity]: Waiting for entity xml on robot_description
[spawn_entity.py-4] [INFO] [1652806650.713877199] [spawn_entity]: Waiting for service /spawn_entity, timeout = 5
[spawn_entity.py-4] [INFO] [1652806650.717389319] [spawn_entity]: Waiting for service /spawn_entity
[spawn_entity.py-4] [INFO] [1652806653.745771815] [spawn_entity]: Calling service /spawn_entity
[spawn_entity.py-4] [INFO] [1652806653.975522539] [spawn_entity]: Spawn status: SpawnEntity: Successfully spawned entity [mars_robot]
[spawn_entity.py-4] /opt/ros/galactic/lib/python3.8/site-packages/rclpy/qos.py:307: UserWarning: DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL is deprecated. Use DurabilityPolicy.TRANSIENT_LOCAL instead.
[spawn_entity.py-4]   warnings.warn(
[INFO] [spawn_entity.py-4]: 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
    else:
        model_path =  pkg_install_path


    xacro_robot_pkg_path = os.path.join(
        get_package_share_directory('mars_robot'))

    xacro_file = os.path.join(xacro_robot_pkg_path,
                              'urdf',
                              'prueba.urdf')

    doc = xacro.parse(open(xacro_file))
    xacro.process_doc(doc)

    node_robot_state_publisher = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        output='screen',
        parameters=[{'robot_description': doc.toxml()}]
    )

    spawn_entity = Node(package='gazebo_ros', executable='spawn_entity.py',
                        arguments=['-topic', 'robot_description',
                                   '-entity', 'mars_robot'],
                        output='screen')

    gazebo = IncludeLaunchDescription(
                PythonLaunchDescriptionSource([os.path.join(
                    get_package_share_directory('gazebo_ros'), 'launch', 'gazebo.launch.py')]),
             )

    return LaunchDescription([
        gazebo,
        node_robot_state_publisher,
        spawn_entity,
    ])

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

Comments

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
0

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

Stats

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

Seen: 1,194 times

Last updated: May 19 '22