turtlebot3_simulations icon indicating copy to clipboard operation
turtlebot3_simulations copied to clipboard

Problem to set custom namespace when to try to spawn a robot on gazebo

Open federicociresola opened this issue 2 years ago • 0 comments

Hi guys, while I was working on my project on ROS2 with Galatic version, I found a little problem while trying to set a custom namespace when calling the launch spawn_turtlebot3.launch.py for Gazebo. My aim is to set a custom namespace as the prefix on the topics published by the node of turtlebot3.

In the initial step, I tried to use the GroupAction to set the namespace through the method PushRosNamespace but it doesn't work in the correct way and I am still trying to figure out the why of this.

So I decided to modify the file and I added the following code:

  • Add the new launch parameter here
    ns = LaunchConfiguration('ns',default='')
    dec_ns = DeclareLaunchArgument(
        'ns', 
        default_value   = '',
        description     = 'robot namespace')
  • Add new parameter when the spawn Node is called, here:
    start_gazebo_ros_spawner_cmd = Node(
        package = 'gazebo_ros',
        executable = 'spawn_entity.py',
        arguments = [
            '-entity', model_robot,
            '-file', urdf_path,
            '-x', x_pose,
            '-y', y_pose,
            '-z', '0.01',
            '-robot_namespace', ns,
        ],
        output = 'screen',
    )
  • Add the new parameter on LaunchDescription here:
 ld.add_action(dec_ns)

In this way, when somebody calls the launch file from CLI, or from another Launch file, the custom namespace can be set in easy way.

Is it normal that i have to go through all of these steps to achieve the result i want? Is there a better way to do this, which doesn't involve modifying the file in this repository? If there is not, maybe these changes can be included, maybe with a pull request by me? Thanks your understanding

federicociresola avatar Mar 03 '22 21:03 federicociresola