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
])
])
When launching an empty gazebo simulation through
gazebo.launch.py
, there are a few topics and services provided by thegazebo_ros
SystemPlugins, e.g.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:
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