ros2 launch file does not spawing custom urdf

asked 2023-05-20 14:24:35 -0500

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. ```python 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()

```

edit retag flag offensive close merge delete

Comments

Could you post your file structure? There might be something wrong with your paths. Maybe use Tree Package to generate it.

scoeerg gravatar image scoeerg  ( 2023-05-21 05:33:47 -0500 )edit