ROS 2 Python Custom Messages#
Note
ROS 2 Python Custom Messages with Isaac Sim is fully supported on Linux. On Windows (WSL), this workflow is not supported.
Learning Objectives#
In this example, we will learn how to
Use ROS 2
rclpy
Python interface with Isaac Sim for using a custom message
Getting Started#
Prerequisite
Basic understanding of building ROS 2 packages
Using Custom Messages with Python#
For using rclpy
with Isaac Sim the packages must be built with Python3.10
. You can create your own package and build it with the ROS 2 workspace
For demonstrating the workflow, we will use a custom_message
package which is a part of the Isaac Sim ROS Workspace repository.
This repository contains a custom message under custom_message/msg/SampleMsg.msg
with the following definition:
std_msgs/String my_string
int64 my_num
For Ubuntu 22, Python3.10
is the default version. Hence, packages built can be used directly with rclpy
in Isaac Sim. Make sure ROS 2 Humble has been installed Running Native ROS.
Clone Isaac Sim ROS Workspace
Source your existing ROS 2 Humble Installation
source /opt/ros/humble/setup.bash
Build ROS 2 workspace
cd IsaacSim-ros_workspaces/humble_ws colcon build
Source built workspace and run Isaac Sim from the same terminal
source install/setup.bash
Follow the same process for building your ROS 2 Humble custom message package. Ensure that you source the built workspace before running Isaac Sim from the same terminal.
Warning
ROS 2 Foxy is no longer tested or supported. This may result in potential issues when ROS 2 Foxy is used in conjunction with Isaac Sim 4.2 or later. ROS 2 Foxy Isaac Sim tutorial packages will be removed in a future release.
We provide a sample dockerfile to build a ROS 2 workspace with Python3.10
.
The steps are similar to Building ROS 2 Workspaces with Python3.10, we will also source our custom_message
package workspace at the end before running Isaac Sim.
We will use the minimal dockerfile to build our workspace with Python3.10
. Ensure that docker
is installed on your system (In Container Setup refer to #2 Install Docker)
Clone Isaac Sim ROS Workspace
Build dockerfile
cd IsaacSim-ros_workspaces ./build_foxy.sh
The minimal
foxy_ws
needed to run Isaac Sim is underbuild_ws/foxy/foxy_ws
. Additional workspaces can also be created and built in this dockerfile.Now source the ROS 2 workspace
source build_ws/foxy/foxy_ws/install/setup.bash source build_ws/foxy/isaac_sim_ros_ws/install/setup.bash
Note
If you see the warning:
not found: "/workspace/foxy_ws/install/local_setup.bash"
, you can ignore it.Run Isaac Sim from the same terminal, the sourced workspace contains the minimal ROS 2 Foxy dependencies to enable the ROS 2 bridge and the
custom_message
package which contains our sample message.
For building your own ROS 2 Foxy custom message packages to use with Isaac Sim, you can place the package under foxy_ws/src
in your Isaac Sim ROS Workspace
folder. Then run ./build_foxy.sh
and source your workspaces before running Isaac Sim.
We will use the minimal dockerfile to build our workspace with Python3.10
. Ensure that docker
is installed on your system (In Container Setup refer to #2 Install Docker)
Clone Isaac Sim ROS Workspace
Build dockerfile
cd IsaacSim-ros_workspaces ./build_humble.sh
The minimal
humble_ws
needed to run Isaac Sim is underbuild_ws/humble/humble_ws
. Additional workspaces can also be created and built in this dockerfile.Now source the ROS 2 workspace
source build_ws/humble/humble_ws/install/setup.bash source build_ws/humble/isaac_sim_ros_ws/install/setup.bash
Note
If you see the warning:
not found: "/workspace/humble_ws/install/local_setup.bash"
, you can ignore it.Run Isaac Sim from the same terminal, the sourced workspace contains the minimal ROS 2 Humble dependencies needed to enable the ROS 2 bridge and the
custom_message
package which contains our sample message.
For building your own ROS 2 Humble custom message packages to use with Isaac Sim, you can place the package under humble_ws/src
in your Isaac Sim ROS Workspace
folder. Then run ./build_humble.sh
and source your workspaces before running Isaac Sim.
Using the custom_message
package with Python in Isaac Sim
Launch Isaac Sim from the sourced terminal containing the custom_message
package, enable the ROS 2 Bridge (Window-Extensions-ROS2 Bridge)
Open the Script Editor (Window-Script Editor) and type
import rclpy
from custom_message.msg import SampleMsg
# Create message
sample_msg = SampleMsg()
# assign data in the string part and integer part of the message
sample_msg.my_string.data = "hello from Isaac Sim!"
sample_msg.my_num = 23
print("Message assignment completed!")
Press Run and the Message assignment completed
should be logged on your console, indicating that the message import and interaction was successful.
You can use standalone a Python script to enable the ROS 2 bridge and import your custom_message
.
Navigate to your Isaac Sim installation directory and create a file named ros2_custom_message.py
, paste the following content into it
import carb
from isaacsim import SimulationApp
simulation_app = SimulationApp({"renderer": "RayTracedLighting", "headless": True})
import omni
from omni.isaac.core.utils.extensions import enable_extension
# enable ROS2 bridge extension
enable_extension("omni.isaac.ros2_bridge")
# Make the rclpy imports
import rclpy
from custom_message.msg import SampleMsg
# Create message
sample_msg = SampleMsg()
# assign data in the string part and integer part of the message
sample_msg.my_string.data = "hello from Isaac Sim!"
sample_msg.my_num = 23
print("Message assignment completed!")
Run this script with (make sure your ROS 2 workspace with the custom_message
package is sourced in the same terminal before running the script and you are in the right directory which contains ./python.sh
)
./python.sh ros2_custom_message.py
Message assignment completed
should be logged on your console, indicating that the message import and interaction was successful.
Summary#
This tutorial covered the following topics:
Building a ROS 2 custom message package with
Python3.10
Using the custom message with
rclpy
in Isaac SimOverview of steps to build and use your own custom message package with
rclpy
and Isaac Sim
Next Steps#
Continue on to the next tutorial in our ROS2 Tutorials series, ROS 2 Python Custom OmniGraph Node.