9. ROS2 Bridge in Standalone Workflow¶

9.1. Learning Objectives¶

Prerequisite

• Completed Isaac Sim Workflows and Hello World to understand the two workflows (Standalone and Extension).

• Set the environment variables needed to enable ROS2 messaging with the following steps.

1. Create a file named fastdds.xml under ~/.ros/ if you haven’t already, paste the following snippet link into the file.

<?xml version="1.0" encoding="UTF-8" ?>

NVIDIA CORPORATION and its licensors retain all intellectual property
and proprietary rights in and to this software, related documentation
and any modifications thereto.  Any use, reproduction, disclosure or
distribution of this software and related documentation without an express

<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles" >
<transport_descriptors>
<transport_descriptor>
<transport_id>UdpTransport</transport_id>
<type>UDPv4</type>
</transport_descriptor>
</transport_descriptors>

<participant profile_name="udp_transport_profile" is_default_profile="true">
<rtps>
<userTransports>
<transport_id>UdpTransport</transport_id>
</userTransports>
<useBuiltinTransports>false</useBuiltinTransports>
</rtps>
</participant>
</profiles>

2. In every terminal that Isaac Sim will be launched by the script, run unset LD_LIBRARY_PATH and export FASTRTPS_DEFAULT_PROFILES_FILE=~/.ros/fastdds.xml.

9.2. Manually Stepping ROS2 Components¶

One major usage for standalone scripting is to manually control the simulation steps. An OnImpulseEvent OmniGraph node can be connected to any ROS2 OmniGraph node so that the frequency of the publishers and subscribers can be carefully controlled.

An example of how a new action graph with a ROS2 Publish Clock node can be setup to be precisely controlled with a ROS2 Domain ID of 1:

import omni.graph.core as og
# Create a new graph with the path /ActionGraph
og.Controller.edit(
{"graph_path": "/ActionGraph", "evaluator_name": "execution"},
{
og.Controller.Keys.CREATE_NODES: [
("Context", "omni.isaac.ros2_bridge.ROS2Context"),
("PublishClock", "omni.isaac.ros2_bridge.ROS2PublishClock"),
("OnImpulseEvent", "omni.graph.action.OnImpulseEvent"),
],
og.Controller.Keys.CONNECT: [
# Connecting execution of OnImpulseEvent node to PublishClock so it will only publish when an impulse event is triggered
("OnImpulseEvent.outputs:execOut", "PublishClock.inputs:execIn"),
# Connecting simulationTime data of ReadSimTime to the clock publisher node
# Connecting the ROS2 Context to the clock publisher node so it will run under the specified ROS2 Domain ID
("Context.outputs:context", "PublishClock.inputs:context"),
],
og.Controller.Keys.SET_VALUES: [
# Assigning topic name to clock publisher
("PublishClock.inputs:topicName", "/clock"),
# Assigning a Domain ID of 1 to Context node
("Context.inputs:domain_id", 1),
],
},
)


On any frame, run the following to set an impulse event which will tick the clock publisher once:

og.Controller.set(og.Controller.attribute("/ActionGraph/OnImpulseEvent.state:enableImpulse"), True)


Note

Due to the explicit control of rendering and physics simulation steps in standalone scripting, the time it takes to complete each step will depend on the computation load and will likely not match real time. This may cause discrepancy in observed speed of action when running the same application via standalone scripting versus using the GUI. When that occurs, use the simulation clock as reference.

9.3. Examples¶

We converted a few of the tutorial examples into standalone python examples. Here are the instructions for running them.

9.3.1. ROS2 Clock¶

This sample demonstrates how to create a action graph with ROS2 component nodes and then tick them at different rates.

The sample can be executed by running the following:

./python.sh standalone_examples/api/omni.isaac.ros2_bridge/clock.py


9.3.2. ROS2 Camera¶

The following 2 samples demonstrates how to create a action graph with ROS2 Camera Helper OmniGraph nodes which are used to setup ROS2 RGB image, depth image and camera info publishers. Both samples accomplish the same outcome of publishing ROS2 image data at different rates but use different solutions.

• On each frame:

• Camera Info is published

• Every 5 frames:

• RGB image is published

• Every 60 frames:

• Depth image is published

9.3.2.1. Periodic Image Publishing¶

The execution rate (every N frames) for each of the ROS2 image and camera info publishers are set by modifying their respective Isaac Simulation Gate OmniGraph nodes in the SDGPipeline graph. By setting the execution rate, an image publisher will automatically be ticked every N rendered frames.

The sample can be executed by running the following:

./python.sh standalone_examples/api/omni.isaac.ros2_bridge/camera_periodic.py


To exit the sample you can terminate via the terminal with CTRL-C

9.3.2.2. Manual Image Publishing¶

The ROS2 image and camera info publishers are manually controlled by injecting Branch OmniGraph nodes between each publisher node and their respective Isaac Simulation Gate OmniGraph node. The Branch nodes act like a custom gate and can be enabled/disabled at any time. Whenever a Branch node is enabled, the connected ROS2 publisher node will be ticked.

The sample can be executed by running the following:

./python.sh standalone_examples/api/omni.isaac.ros2_bridge/camera_manual.py


To exit the sample you can terminate via the terminal with CTRL-C

9.3.2.3. Visualizing Results¶

To visualize the result of either sample in RViz2, in a new ROS2-sourced terminal navigate to the Isaac Sim package directory and run the following command:

rviz2 -d ros2_workspace/src/isaac_tutorials/rviz2/camera_manual.rviz


Note

Due to an issue with RViz2, black frames may appear for depth image displays. To verify that Isaac Sim is correctly publishing depth images, run ros2 run rqt_image_view rqt_image_view and set the topic to /depth.

9.3.3. Carter Stereo¶

This sample demonstrates how to take an existing USD stage with an action graph containing ROS2 component nodes and modifying the default settings. The stereo camera pair is automatically enabled and the second viewport window is docked in the UI.

• On each frame:

• The ROS2 clock is published

• Lidar message is published

• Odometry is published

• The Twist subscriber is spun

• TF messages are published

• Left and right cameras are published

• Every Two Frames:

• The Twist command message is published

The sample can be executed by running the following:

./python.sh standalone_examples/api/omni.isaac.ros2_bridge/carter_stereo.py


To exit the sample you can terminate via the terminal with CTRL-C

To visualize the result:

In a new terminal, run the following command to load RViz2:

ros2 run rviz2 rviz2 -d ros2_workspace/src/isaac_tutorials/rviz2/carter_stereo.rviz


Make sure Left Camera - Depth, Right Camera - Depth, Right Camera - RGB and Left Camera - RGB within the Displays are enabled to visualize RGB and Depth images.

Note

If some of the images don’t show up on RViz2, press Stop and Play in the simulator for the images to show up.

This sample shows how to run an existing USD stage.

To visualize the output see the interactive version of the sample:

• On each frame:

• The ROS clock component is published

• Lidar messages are published

• Odometry is published

• The Twist subscriber is spun

• TF messages are published

The sample can be executed with both the hospital and office environments. Run either of the following commands to run the sample with the specified environment:

./python.sh standalone_examples/api/omni.isaac.ros2_bridge/carter_multiple_robot_navigation.py hospital


OR

./python.sh standalone_examples/api/omni.isaac.ros2_bridge/carter_multiple_robot_navigation.py office


To exit the sample you can terminate via the terminal with CTRL-C

9.3.5. MoveIt2¶

This sample shows how to add multiple USD stages. It also demonstrates how to manually create a action graph with ROS2 component nodes and then manually tick them.

To visualize the output see the interactive version of the sample:

• On each frame:

• The ROS clock is published

• Joint State messages are published

• Joint State subscriber is spun

• TF messages are published

The sample can be executed by running the following:

./python.sh standalone_examples/api/omni.isaac.ros2_bridge/moveit.py


To exit the sample you can terminate via the terminal with CTRL-C

9.3.6. Receiving ROS2 Messages¶

This is a simple subscriber example where upon receiving an empty ROS2 message, a cube in the scene teleports to a random location. This one is running with rendering enabled, so you should be able to see the scene and the cube moving. To run this example

./python.sh standalone_examples/api/omni.isaac.ros2_bridge/subscriber.py


To exit the sample you can terminate via the terminal with CTRL-C

Once the scene with cube is loaded, you can publish the empty message manually from another terminal. We’ll do it at rate of 1Hz.

ros2 topic pub -r 1 /move_cube std_msgs/msg/Empty


9.4. Summary¶

In this tutorial we learned how to manually step ROS2 components and run standalone ROS2 python examples.

9.4.1. Next Steps¶

Continue on to the next tutorial in our ROS2 Tutorials series, The Ignition-Omniverse connector with Gazebo.