ros-simulation / gazebo_ros_pkgs

Wrappers, tools and additional API's for using ROS with Gazebo
http://wiki.ros.org/gazebo_ros_pkgs
742 stars 766 forks source link

Unable to change namespace of ROS2 topics / services provided by the gazebo_ros SystemPlugins #1315

Open iche033 opened 2 years ago

iche033 commented 2 years ago

When launching an empty gazebo simulation through gazebo.launch.py, there are a few topics and services provided by the gazebo_ros SystemPlugins, e.g.

/apply_joint_effort
/apply_link_wrench
/clear_joint_efforts
/clear_link_wrenches
/delete_entity
/gazebo/describe_parameters
/gazebo/get_parameter_types
/gazebo/get_parameters
/gazebo/list_parameters
/gazebo/set_parameters
/gazebo/set_parameters_atomically
/get_model_list
/pause_physics
/reset_simulation
/reset_world
/spawn_entity
/unpause_physics

However, when trying to add a namespace to these topics / services, there does not seem to have any effect. Here is an example ros2 launch file that attempts at adding a ROS namespace:

import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.actions import GroupAction
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_ros.actions import PushRosNamespace

def generate_launch_description():
    gazebo = IncludeLaunchDescription(
                PythonLaunchDescriptionSource([os.path.join(
                    get_package_share_directory('gazebo_ros'), 'launch'), '/gazebo.launch.py']),
             )

    return LaunchDescription([
        GroupAction([
                PushRosNamespace('new_ns'),
                gazebo
        ])
    ])

The problem could be that the code is not passing the cmd line args to the SystemPlugins. https://github.com/ros-simulation/gazebo_ros_pkgs/blob/3310d0d01cfcd4a2710d834d2abf8bb6a620a888/gazebo_ros/launch/gzserver.launch.py#L220-L224

The cmd line args are used to initialize rclcpp. e.g. in the gazebo_ros_init SystemPlugin https://github.com/ros-simulation/gazebo_ros_pkgs/blob/3310d0d01cfcd4a2710d834d2abf8bb6a620a888/gazebo_ros/src/gazebo_ros_init.cpp#L151

padhupradheep commented 2 years ago

Another way to add a namespace would be just to use the -robot_namespace argument. An example of that can be seen here !