Automatic ROS 2 Namespace Generation#

Learning Objectives#

In this tutorial we will:

  • Learn how to configure your Isaac Sim assets to automatically generate ROS2 namespaces for each ROS 2 OmniGraph node

Getting Started#

Important

Make sure to source your ROS 2 installation from the terminal before running Isaac Sim. If sourcing ROS 2 is a part of your bashrc then Isaac Sim can be run directly.

Prerequisite

ROS2 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.

  1. Manually set namespaces in the namespace field in the nodeNamespace field.

  2. (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#

  1. Open a new stage. And then open the Script Editor (Window > Script Editor) and 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))
    
  2. Add a RTX lidar sensor by going to Create > Sensors > RTX Lidar > Rotating and drag it under /mock_robot/base_link/lidar_link.

  3. 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.

  4. Create a Generic Publisher by going to Tools > Robotics > ROS 2 OmniGraphs > Generic Publisher. Set Generic Publisher Graph as Publish String and the Graph Path to /mock_robot/base_link/wheel_left/String_graph. Then hit OK.

  5. Create a TF Publisher by going to Tools > Robotics > ROS 2 OmniGraphs > TF Publisher. Set the Target Prim to /mock_robot and the Graph Path to /mock_robot/base_link/wheel_left/TF_graph. Then hit OK.

  6. 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_left and the Graph Path to /mock_robot/base_link/camera_link/Hawk/Camera_Left_Graph. Uncheck the Depth topic and then hit OK.

  7. 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_right and the Graph Path to /mock_robot/base_link/camera_link/Hawk/Camera_Right_Graph. Uncheck the Depth topic and then hit OK.

  8. Create a RTX Lidar Publisher by going to Tools > Robotics > ROS 2 OmniGraphs > RTX Lidar. Set the Lidar Prim to /mock_robot/base_link/lidar_link/Rotating and 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 should be located under only that particular robot’s namespace (i.e. 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.

To add a isaac:namespace attribute to a prim follow these steps:

  1. Select the prim and in the property window click Add. Then, click Attribute.

  2. Fill in the window as such:

  3. Click Add.

  4. Once added, go back to the property window of the prim and fill in the isaac:namespace field with a string value.

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

  1. Click Play and start simulation.

  2. Open a ROS-sourced terminal and type ros2 topic list, verify that you see the following:

    • /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

    • /parameter_events

    • /rosout

    • /wheel_left/tf

    • /wheel_left/topic

    From the above list you can see the topics have been generated automatically. If your namespace needs to have a custom naming scheme, you can fill in the nodeNamespace input field for each ROS OmniGraph node.

  3. Stop simulation. Select the /mock_robot prim and add the isaac:namespace attribute to it. Then, set the namespace value to the prim name.

  4. Duplicate /mock_robot prim by selecting, right-clicking and pressing Duplicate. For the newly generated /mock_robot_01: select the prim, go to the property panel and change the isaac:namespace attribute to mock_robot_01.

  5. Hit Play to start simulation.

  6. Open a ROS-sourced terminal and type ros2 topic list, verify that you see the following:

    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

    • parameter_events

    • rosout

    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

    • parameter_events

    • rosout

    Important

    From the above list you can see the topics have been generated automatically. If your namespace needs to have a custom naming scheme, you can fill in the nodeNamespace input field for each ROS OmniGraph node.

Summary#

This tutorial covered:

  • Demonstrating how the isaac:namespace attribute can be set to prims on a robot to automatically generate namespaces

Next Steps#

Continue on to the next tutorial in our ROS 2 Tutorials series, ROS 2 Bridge in Standalone Workflow to learn how to run the ROS 2 Bridge in the standalone workflow.