0

I have worm_robot package in ros2 which has custom urdf file in urdf folder. I have following gazebo_sim.launch.pyfile which launch gazebo and spawn the urdf in it. but it is not working.

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


def generate_launch_description():
    # Get the package directory
    package_name = 'worm_robot'
    package_dir = get_package_share_directory(package_name)

    # Declare the launch arguments
    urdf_file = LaunchConfiguration('urdf/worm_robot.urdf')
    declare_urdf_file_arg = DeclareLaunchArgument(
        'urdf_file',
        default_value=os.path.join(package_dir, 'urdf', 'worm_robot.urdf'),
        description='urdf/worm_robot.urdf'
    )

    # Launch Gazebo
    gazebo = ExecuteProcess(
        cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_init.so'],
        output='screen'
    )

    # Spawn the robot model into Gazebo
    spawn_entity = Node(
        package='gazebo_ros',
        executable='spawn_entity.py',
        arguments=['-entity', 'worm_robot', '-file', urdf_file, '-x', '0', '-y', '0', '-z', '0'],
        output='screen'
    )

    return LaunchDescription([
        declare_urdf_file_arg,
        gazebo,
        spawn_entity
    ])


if __name__ == '__main__':
    generate_launch_description()

Mubahsir
  • 45
  • 9

0 Answers0