Automatic ROS 2 Namespace Generation#
Learning Objectives#
In this tutorial we will:
Learn how to configure your Isaac Sim assets to automatically generate ROS 2 namespaces for each ROS 2 OmniGraph node
Getting Started#
Prerequisite
Completed ROS 2 Installation so that the necessary environment variables are set and sourced before launching NVIDIA Isaac Sim, and ROS 2 extension is enabled.
Read about ROS 2 Namespaces.
ROS 2 Namespaces#
Managing namespaces in ROS 2 is crucial for multi-robot simulations to ensure that each robot’s topics are uniquely identifiable.
There are currently two main ways within OmniGraph to set a namespace for ROS publisher, subscribers and services.
Manually set namespaces in the namespace field in the nodeNamespace field.
(Recommended) Configure assets to automatically generate namespaces for all Isaac Sim ROS OmniGraph nodes. This tutorial will guide you through the process of setting up namespaces in Isaac Sim, enabling efficient topic management and avoiding conflicts.
Configuring the Asset#
Setting Up the Base Asset#
Open a new stage. Open the Script Editor (
Window > Script Editor), then add and run the following snippet. This will create a set of XForms that arranged to mimic a robot articulation.# Import necessary modules from pxr import UsdGeom import omni.usd # Retrieve the current stage stage = omni.usd.get_context().get_stage() # Ensure a stage is loaded if not stage: print("No stage is currently loaded. Please load a stage and try again.") else: # Create the mock_robot Xform as the root mock_robot = UsdGeom.Xform.Define(stage, "/mock_robot") # Create the base_link Xform under mock_robot base_link = UsdGeom.Xform.Define(stage, "/mock_robot/base_link") # Create lidar_link and position it 0.4 meters above the base_link (Z-axis) lidar_link = UsdGeom.Xform.Define(stage, "/mock_robot/base_link/lidar_link") lidar_link.AddTranslateOp().Set(value=(0, 0, 0.4)) # Offset along Z-axis # Create camera_link and position it 0.2 meters above the base_link (Z-axis) camera_link = UsdGeom.Xform.Define(stage, "/mock_robot/base_link/camera_link") camera_link.AddTranslateOp().Set(value=(0, 0, 0.2)) # Offset along Z-axis # Create wheel_left and wheel_right Xforms under base_link wheel_left = UsdGeom.Xform.Define(stage, "/mock_robot/base_link/wheel_left") wheel_right = UsdGeom.Xform.Define(stage, "/mock_robot/base_link/wheel_right") # Position wheel_left 0.2 meters to the left of the center (X-axis) wheel_left.AddTranslateOp().Set(value=(-0.2, 0, 0)) # Position wheel_right 0.2 meters to the right of the center (X-axis) wheel_right.AddTranslateOp().Set(value=(0.2, 0, 0))
Add a 2D RTX Lidar sensor by going to Create > Sensors > RTX Lidar > NVIDIA > Example Rotary 2D and drag it under
/mock_robot/base_link/lidar_link.Add a Hawk stereo camera system by going to Create > Sensors > Camera and Depth Sensors > LeopardImaging > Hawk and drag it under
/mock_robot/base_link/camera_link.Create a Generic Publisher by going to Tools > Robotics > ROS 2 OmniGraphs > Generic Publisher. Set Generic Publisher Graph as
Publish Stringand the Graph Path to/mock_robot/base_link/wheel_left/String_graph. Then hit OK.Create a TF Publisher by going to Tools > Robotics > ROS 2 OmniGraphs > TF Publisher. Set the Target Prim to
/mock_robotand the Graph Path to/mock_robot/base_link/wheel_left/TF_graph. Then hit OK.Create a Camera Publisher by going to Tools > Robotics > ROS 2 OmniGraphs > Camera. Set the Camera Prim to
/mock_robot/base_link/camera_link/Hawk/left/camera_leftand the Graph Path to/mock_robot/base_link/camera_link/Hawk/Camera_Left_Graph. Uncheck the Depth topic and then hit OK.Create a second Camera Publisher by going to Tools > Robotics > ROS 2 OmniGraphs > Camera. Set the Camera Prim to
/mock_robot/base_link/camera_link/Hawk/right/camera_rightand the Graph Path to/mock_robot/base_link/camera_link/Hawk/Camera_Right_Graph. Uncheck the Depth topic and then hit OK.Create a 2D RTX Lidar Publisher by going to Tools > Robotics > ROS 2 OmniGraphs > RTX Lidar. Set the Lidar Prim to
/mock_robot/base_link/lidar_link/Example_Rotary_2Dand the Graph Path to/mock_robot/base_link/lidar_link/Lidar_Graph. Ensure only Laser Scan is enabled and then hit OK.
Configuring Namespace Attributes#
Now that the base asset is setup, a isaac:namespace attribute must be added for each prim that a namespace value is desired. The namespace will be generated by appending each isaac:namespace attribute value that has been set from the top of the prim hierarchy down to each ROS publisher. The namespace generation behavior depends on the type of ROS publisher and where in the stage it is located.
ROS 2 TF OmniGraph Nodes: The namespace generated will only include the namespace value from the top level prim with a namespace attribute set. This is because all TFs published from within one robot are located under only that particular robot’s namespace (that is, robot1/tf).
ROS 2 Camera & Lidar OmniGraph Helper Nodes: The Camera or Lidar render product path is used to identify the path the namespace search algorithm takes and appends namespace values accordingly. Therefore in this case the location of the Camera/Lidar Helper node is not relevant and rather the location of the Camera/Lidar sensor prim is used.
All other OmniGraph nodes: The path to the OmniGraph node is used to identify the path the namespace search algorithm takes and appends namespace values accordingly. In this case the location of these OmniGraph node is relevant.
Adding the isaac:namespace Prim Attribute#
To add a isaac:namespace attribute to a prim follow these steps:
Select the prim and in the property window, click Add. In the popup menu, go to Isaac > Namespace. This will apply this attribute to the prim.
In the property panel, add your namespace value in the Namespace field.
Testing the isaac:namespace Prim Attribute#
Apply a isaac:namespace attribute to the following prims. For this tutorial set each namespace value to the prim name (although you are welcome to try any custom namespace value):
/mock_robot/base_link/lidar_link
/mock_robot/base_link/camera_link
/mock_robot/base_link/camera_link/Hawk
/mock_robot/base_link/camera_link/Hawk/left
/mock_robot/base_link/camera_link/Hawk/right
/mock_robot/base_link/wheel_left
Click Play and start the simulation.
Open a ROS-sourced terminal and type
ros2 topic list, verify that you observe, at least, the following topics:/camera_link/Hawk/left/camera_info/camera_link/Hawk/left/rgb/camera_link/Hawk/right/camera_info/camera_link/Hawk/right/rgb/lidar_link/laser_scan/wheel_left/tf/wheel_left/topic
From the above list you can observe the topics that have been generated automatically. If your namespace needs to have a custom naming scheme, you can fill in the
nodeNamespaceinput field for each ROS OmniGraph node.Stop the simulation. Select the
/mock_robotprim and add theisaac:namespaceattribute to it. Then, set the namespace value to the prim name.Duplicate
/mock_robotprim by selecting, right-clicking, and pressing Duplicate. For the newly generated/mock_robot_01, select the prim, go to the property panel, and change theisaac:namespaceattribute tomock_robot_01.Hit Play to start the simulation.
Open a ROS-sourced terminal and type
ros2 topic list. Verify that you observe, at least, the following topics:Topics from mock_robot
/mock_robot/camera_link/Hawk/left/camera_info/mock_robot/camera_link/Hawk/left/rgb/mock_robot/camera_link/Hawk/right/camera_info/mock_robot/camera_link/Hawk/right/rgb/mock_robot/lidar_link/laser_scan/mock_robot/tf/mock_robot/wheel_left/topic
Topics from mock_robot_01
/mock_robot_01/camera_link/Hawk/left/camera_info/mock_robot_01/camera_link/Hawk/left/rgb/mock_robot_01/camera_link/Hawk/right/camera_info/mock_robot_01/camera_link/Hawk/right/rgb/mock_robot_01/lidar_link/laser_scan/mock_robot_01/tf/mock_robot_01/wheel_left/topic
Important
From the above list you can observe the topics have been generated automatically. If your namespace needs to have a custom naming scheme, you can fill in the
nodeNamespaceinput field for each ROS OmniGraph node.
Summary#
This tutorial covered:
Demonstrating how the
isaac:namespaceattribute can be set to prims on a robot to automatically generate namespaces
Next Steps#
Continue on to the following tutorials in our ROS 2 Tutorials series:
Running a Reinforcement Learning Policy through ROS 2 and Isaac Sim to learn about running a reinforcement learning policy through ROS 2 and Isaac Sim
ROS 2 Bridge in Standalone Workflow to learn how to run the ROS 2 Bridge in the standalone workflow.