Skip to content

ROS2 Troubleshooting

Damien LaRocque edited this page Nov 8, 2023 · 6 revisions

Some errors happens frequently with ROS 2. Here are a few ways to solve some errors

Cannot import name 'generate_py'

I often got the following error when I built packages that contains custom messages definitions :

Traceback (most recent call last):
  File "/opt/ros/humble/share/rosidl_generator_py/cmake/../../../lib/rosidl_generator_py/rosidl_generator_py", line 8, in <module>
    from rosidl_generator_py import generate_py
ImportError: cannot import name 'generate_py'

In the package's CMakeLists.txt, comment the following line:

find_package(rosidl_default_generators REQUIRED)
# find_package(rosidl_default_generators REQUIRED)

Python dependencies in ROS 2 packages

Here is a list of Python dependencies that are understood by rosdep

https://github.com/ros/rosdistro/blob/master/rosdep/python.yaml

More about rosbags

There is an article about rosbags in ROS 2 here

Coloured ROS 2 logging

To enable coloured ROS 2 logs in your terminal, set export RCUTILS_COLORIZED_OUTPUT=1 (or put it in your .bashrc to get it each time you boot!)

No topics listed from a remote machine

Original behaviour

No topics are listed on a remote device despite the correct ROS_DOMAIN_ID being set. This only happens for topics published by nodes started by a service.

Hotfix solution

Adding a 10-second delay to the startup script seems to solve the issue. However, a better solution is desired, understanding better what's happening under the hood with startup services.

Local topics disappear after service restart

Original behaviour:

After booting, the startup service launches correctly, and the topics can be listed locally (or through ssh). If the service is restarted manually with sudo systemctl restart startup-script.service, the topics stop being visible locally and occasionally start to appear remotely.

Solution:

(node that the reason why this works is not yet fully understood)

  • Place this .xml dds configuration into ~/.ros/fastdds.xml
  • Add these two lines to the .bashrc file after sourcing ros setup files:
export FASTRTPS_DEFAULT_PROFILES_FILE=~/.ros/fastdds.xml
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
  • Reboot
Clone this wiki locally