Robotics StackExchange | Archived questions

ros2 launch file does not spawing custom urdf

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 amentindexpython.packages import getpackagesharedirectory from launch import LaunchDescription from launch.actions import DeclareLaunchArgument, ExecuteProcess from launch.substitutions import LaunchConfiguration from launchros.actions import Node

def generatelaunchdescription(): # Get the package directory packagename = 'wormrobot' packagedir = getpackagesharedirectory(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': generatelaunchdescription()

```

Asked by Mubashir alam on 2023-05-20 14:24:35 UTC

Comments

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

Asked by scoeerg on 2023-05-21 05:33:47 UTC

Answers