Multiple URDF Modules Not Spawning in Gazebo with ROS2 Humble

asked 2023-05-10 02:51:04 -0500

Hello,

I am trying to launch multiple instances of two different URDF models through a Python launch file with ROS2 Humble and Gazebo. The two URDFs are simply two boxes with different colors.

I am trying to launch a specified number of each of these boxes into the Gazebo simulation, as shown by the code below. However, I am noticing that some of the entities for box1 and box2 are not spawning in. For instance, if I set the upper bound in the for loop to be 5, only 3 boxes will spawn. Essentially, the number of boxes spawning in does not always equal to the number specified in the loop. This behavior also occurs when I try to spawn only 1 URDF (only 1 of the for loops) but with a larger number in the loop (ie 10 or even greater).

For the boxes that do not spawn in the error at the bottom of this post comes up. For the boxes that do spawn in, no error appears, and the expected message of "successfully spawned entity..." appears.

Is there something missing causing only some boxes to spawn in? Is there a better way to spawn multiple instances of two different URDF models?

ROS2 Humble, Linux Jammy 22.04, Gazebo 11

for i in range(0, 5):
    box1StatePublisher = Node(
                            package='robot_state_publisher',
                            executable='robot_state_publisher',
                            output='screen',
                            namespace='box1' + str(i),
                            parameters=[{'robot_description': box1_description_raw, 'use_sim_time': True}])
    launchList.append(box1StatePublisher)

    xCoord = str(random.uniform(-7, 7))
    yCoord = str(random.uniform(-7, 7))
    zCoord = str(0)    
    spawnEntity = Node(
                    package='gazebo_ros', 
                    namespace='box1 ' + str(i), 
                    executable='spawn_entity.py',
                    arguments=['-topic', 'robot_description', '-entity', 'box1 ' + str(i), '-x', xCoord, '-y', yCoord, '-z', zCoord],
                    output='screen')
    launchList.append(spawnEntity)


for i in range(0, 5):
    box2StatePublisher = Node(
                            package='robot_state_publisher',
                            executable='robot_state_publisher',
                            output='screen',
                            namespace='box2 ' + str(i),
                            parameters=[{'robot_description': box2_description_raw, 'use_sim_time': True}])
    launchList.append(box2StatePublisher)

    xCoord = str(random.uniform(-7, 7))
    yCoord = str(random.uniform(-7, 7))
    zCoord = str(0)    
    spawnEntity = Node(
                    package='gazebo_ros', 
                    namespace='box2 ' + str(i), 
                    executable='spawn_entity.py',
                    arguments=['-topic', 'robot_description', '-entity', 'box2' + str(i), '-x', xCoord, '-y', yCoord, '-z', zCoord],
                    output='screen')
    launchList.append(spawnEntity)`

ERROR] [spawn_entity.py-16]: process has died [pid 188312, exit code -2, cmd '/opt/ros/humble/lib/gazebo_ros/spawn_entity.py -topic robot_description -entity box1 0 -x 3.0192924589213863 -y -1.5573105065033221 -z 0 --ros-args -r __ns:=/box1 0'].

edit retag flag offensive close merge delete