Custom Ros 2 messages

Im writing code to control multiple aspects of a simulation from within omniverse’s python.sh. I have been able to publish and subscribe to both topics and services. The issue is that some of the services and topics I want to use need custom messages since sourcing does not modify omniverse’s python. I have found no way of having those custom messages there. Is there a way to do it?

1 Like

Hi @tomas.lobo.it. Sounds like this is more specific to Isaac Sim so I’ve moved this topic to that forum.

Hi @tomas.lobo.it - Doe this document help you? 11. Custom Message — Omniverse Robotics documentation

Hi!
I’ll ask here to avoid duplicates, but I’m facing the same issue, tho I’m working with ROS 2 and that guide would only work for ROS 1.

Is there any equivalent for ROS 2?

Hi @christianbarcelo - This document might be useful to you: ROS2 Bridge [omni.isaac.ros2_bridge] — isaac_sim 2022.2.1-beta.29 documentation

Hi @rthaker
I’m already using most of those Omni-Nodes to publish different sensors, but what I’m trying to achieve is a common use case in simulation that cannot be covered with the default messages ROS2 provides. What I need is to be able to include Custom ROS 2 messages and service messages (.msg and .srv files).
Said in a different way, what’s the workaround equivalent to this guide 11. Custom Message — Omniverse Robotics documentation but for ROS 2?

Thanks for taking the time of answering.

As someone else mentioned, that only works for ROS1, ROS2 needs the compiled messages linked

1 Like

I also think that being able to easily use custom ROS 2 messages and services is a needed feature. I think the current workaround for ROS 2 is by manually compiling the package for python 3.7, but is tedious and might lead to unexcepted errors in the future.

It’s also neccesary for packages that are ready to install using binaries in ros but they are not available in the custom builld for isaac, such as moveit_msgs. Maybe something like the repo_build but for ROS packages would be a great addition.

Isaac Sim already comes with some messages built for 3.7, even custom messages (like IsaacPose) so delivering the workspace that the Omniverse team uses to build these messages might be enough to satisfy everybody’s need, at least as a workaround.

Yes, this is the workaround I’ve found: compile the packages for 3.7 and include the binaries generated in exts/omni.isaac.ros2_bridge/config/extension.toml(more info here). However, I think the nvidia team should think of another way to simplify this process.

May I ask what’s the OS and ROS 2 distribution you used to build the messages? I’m trying (and failing in the process) to install ROS 2 using Python 3.7 and, as it’s not a supported version, I’m really struggling with it.

@christianbarcelo I’m using Humble (python 3.10) in Ubuntu 22.04.

I recommend you to compile it using a docker image to avoid messing up your local python installation. I’m gonna use ackermann_msgs package as a reference:

# Run docker container with ROS2 Humble
docker pull osrf/ros:humble-desktop
docker run -it osrf/ros:humble-desktop

# Install Python 3.7
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7

# Link Python 3.7 as default
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
sudo update-alternatives  --set python3 /usr/bin/python3.7

# Verify that the default python version is now 3.7
python3 --version

# Create a ros workspace
mkdir -p /ros2_ws/src
cd /ros2_ws/src

# Clone the pkg you want to compile, using ackermann_msgs repo as reference
git clone -b ros2 https://github.com/ros-drivers/ackermann_msgs.git

# Install distutils as is needed for colcon
sudo apt install python3.7-distutils

# Build the workspace
cd /ros2_ws
colcon build

This should build correctly for simple msg packages. However, I tried with moveit_msgs and because it has other dependencies I couldn’t resolve the issues.

You can move the build files to your local machine as follows:

# Get the DOCKER ID of the current image running
docker ps -alq

# Copy the build folder in the folder ~/python3.7_build of your local machine
docker cp DOCKERID:/ros2_ws/build/ackermann_msgs ~/python3.7_build

Then move the binary files (.so) into ~/.local/share/ov/pkg/isaac_sim-2022.2.1/exts/omni.isaac.ros2_bridge-humble/bin .

Finally, you should modify omni.add_on.ros2_bridge-humble/config/extension.toml as explained here. Although I’m stuck in this step.

@toni.sm mentioned the file ... __python.so which doens’t appear in my build. I only have ... __rosidl_generator_py.so under rosidl_generato_py/ackermann_msgs folder. I tried moving it also to /bin and to extension.toml but the package is not detected in python anyways.

I hope that helps. I finally opted to simplify the message sent to one recognized by ros isaac, but if you make it work, let me know!

Hi @christianbarcelo and @dgarcialopez . The temporary workaround is to build your custom messages with Python3.7 as @dgarcialopez described. For the next release of Isaac Sim, we will provide a framework for building custom messages with ROS2. If you face issues with the workaround, please provide repro steps so that we can take a look. Thank you!

1 Like

Can I get a rough timeline for the next release?

Thanks @rchadha for the answer.
Actually, the __python.so files that @dgarcialopez mentions are not anymore generated by ROS 2 (They were up to the version previous to Foxy if I’m not wrong) so the workaround we discussed here didn’t reach a solution yet.
If you have any instructions on how to bring up the workspace to build the messages, I’d appreciate it.

Hi @christianbarcelo if you are building your package with Python3.7, then the libs generated should be under install in your ros2 workspace. If the code in your package was in Python and it gets built with the right Python3.7, the lib files can be copied over so it can be used. If that does not work, can you please provide a repro and we can take a look

Thanks @rchadha for the reply!

I’ve tried using the binaries located in the install folder and apparently don’t work as well. As @christianbarcelo mentioned, the files __python.so are not generated, __rosidl_generator_py.so is present but I’m not sure if it’s the same.

These are the commands I used to test it:

# Run docker container with ROS2 Humble
docker pull osrf/ros:humble-desktop
docker run -it osrf/ros:humble-desktop

# Install Python 3.7
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7

# Link Python 3.7 as default
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
sudo update-alternatives  --set python3 /usr/bin/python3.7

# Verify that the default python version is now 3.7
python3 --version

# Create a ros workspace
mkdir -p /ros2_ws/src
cd /ros2_ws/src

# Clone the pkg you want to compile, using ackermann_msgs repo as reference
git clone -b ros2 https://github.com/ros-drivers/ackermann_msgs.git

# Install distutils as is needed for colcon
sudo apt install python3.7-distutils

# Build the workspace
cd /ros2_ws
colcon build

In another terminal:

# Get the DOCKER ID of the current image running
docker ps -alq

# Copy the install folder in the folder ~/python3.7_install of your local machine
docker cp DOCKERID:/ros2_ws/install/ackermann_msgs ~/python3.7_install

Then, copy all .so files within ~/python3.7_install/lib to ~/.local/share/ov/pkg/isaac_sim-2022.2.1/exts/omni.isaac.ros2_bridge-humble/bin

Add the following lines to the end of the file omni.isaac.ros2_bridge-humble/config/extension.toml:

[[native.library]]
path = "bin/libackermann_msgs__rosidl_generator_c.so"
[[native.library]]
path = "bin/libackermann_msgs__rosidl_generator_py.so"
[[native.library]]
path = "bin/libackermann_msgs__rosidl_typesupport_c.so"
[[native.library]]
path = "bin/libackermann_msgs__rosidl_typesupport_cpp.so"
[[native.library]]
path = "bin/libackermann_msgs__rosidl_typesupport_fastrtps_c.so"
[[native.library]]
path = "bin/libackermann_msgs__rosidl_typesupport_fastrtps_cpp.so"
[[native.library]]
path = "bin/libackermann_msgs__rosidl_typesupport_introspection_c.so"
[[native.library]]
path = "bin/libackermann_msgs__rosidl_typesupport_introspection_cpp.so"

Finally, in a python program, importing the msgs as from ackermann_msgs.msg import AckermannDrive yields to the error: “ModuleNotFoundError: No module named ‘ackermann_msgs’”

I also couldn’t find a way to build a more complex package, such as moveit_msgs, with Python 3.7. If you know how please let me know.

@rchadha - Please take a look.

@rchadha any news on this?

Hi @christianbarcelo and @dgarcialopez . Apologies for the late reply.

@dgarcialopez, in your docker image are your nodes able to use the Ackermann_msg? in ros2 humble, the generated libs are not placed the same way they are for foxy. If you look under omni.isaac.ros2_bridge-humble/omni/isaac/rclpy you should also paste the message files there (look at vision messages there as an example and paste Ackermann Drive files in a similar format there too). Please let me know in case that does not help. Thanks!