Hello. I have starting to migrate from ROS1 to ROS2 and have encountered some issues trying to use the topic tools in the command line. I can use the "ros2 topic" tools just fine with message types that came installed with ROS2 humble (std_msgs, etc.). However, I discovered that some of these tools are not working for me for a package I've been porting to ROS2 that contains and uses custom-defined messages. The package which includes the custom messages builds just fine and runs, but I can't call "ros2 topic echo" or "pub" for the topics with the types defined in that package (but work fine on other types).
I've tried to follow this example as closely as possible, and present a minimal package below which replicates this issue for me. The error text when trying to call "ros2 topic pub/echo" (after sourcing the workspace) is displayed at the bottom of my question.
test_msgs/msg/TestMessage.msg
std_msgs/Int16 data
test_msgs/CMakeLists.txt
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(test_msgs)
set(CMAKE_CXX_STANDARD 17)
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)
set(MSG_FILES "msg/TestMessage.msg")
rosidl_generate_interfaces(${PROJECT_NAME} ${MSG_FILES} DEPENDENCIES std_msgs)
ament_export_dependencies(rosidl_default_runtime)
ament_package()
test_msgs/package.xml
<package format="3">
<name>test_msgs</name>
<version>0.0.0</version>
<description>No</description>
<maintainer email="[email protected]">No</maintainer>
<license>Test</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<test_depend>ament_lint_common</test_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
After building, the built interface shows up using the ros2 interface tool:
ros2 interface list | grep test
returns:
pendulum_msgs/msg/RttestResults
test_msgs/msg/TestMessage
as expected. I can also show the fields of the message from the command line without error:
ros2 interface show test_msgs/msg/TestMessage
returns:
int16 data
as expected.
I can publish a topic with a type from the nominal ROS2 distribution:
ros2 topic pub /test std_msgs/Int16 "data: 0"
publisher: beginning loop
publishing #1: std_msgs.msg.Int16(data=0)
However, I get this error when trying to publish a topic with my custom message (after sourcing the workspace, of course):
ros2 topic pub /test test_msgs/msg/TestMessage "data: {data: 0}"
Traceback (most recent call last):
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support
return importlib.import_module(module_name, package=pkg_name)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'test_msgs.test_msgs_s__rosidl_typesupport_c'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/ros/humble/bin/ros2", line 33, in <module>
sys.exit(load_entry_point('ros2cli==0.18.6', 'console_scripts', 'ros2')())
File "/opt/ros/humble/lib/python3.10/site-packages/ros2cli/cli.py", line 89, in main
rc = extension.main(parser=parser, args=args)
File "/opt/ros/humble/lib/python3.10/site-packages/ros2topic/command/topic.py", line 41, in main
return extension.main(args=args)
File "/opt/ros/humble/lib/python3.10/site-packages/ros2topic/verb/pub.py", line 222, in main
return main(args)
File "/opt/ros/humble/lib/python3.10/site-packages/ros2topic/verb/pub.py", line 240, in main
return publisher(
File "/opt/ros/humble/lib/python3.10/site-packages/ros2topic/verb/pub.py", line 275, in publisher
pub = node.create_publisher(msg_module, topic_name, qos_profile)
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/node.py", line 1290, in create_publisher
check_is_valid_msg_type(msg_type)
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/type_support.py", line 35, in check_is_valid_msg_type
check_for_type_support(msg_type)
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/type_support.py", line 29, in check_for_type_support
msg_or_srv_type.__class__.__import_type_support__()
File "/home/squid/ws/install/test_msgs/local/lib/python3.10/dist-packages/test_msgs/msg/_test_message.py", line 29, in __import_type_support__
module = import_type_support('test_msgs')
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support
raise UnsupportedTypeSupport(pkg_name)
rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'test_msgs'
The built python package in my workspace seems to have a number of built typesupport packages for test_msgs as well:
/home/squid/ws/install/test_msgs/local/lib/python3.10/dist-packages/test_msgs$ ls
__init__.py
libtest_msgs__rosidl_generator_py.so
msg
__pycache__
_test_msgs_s.ep.rosidl_typesupport_c.c
_test_msgs_s.ep.rosidl_typesupport_fastrtps_c.c
_test_msgs_s.ep.rosidl_typesupport_introspection_c.c
test_msgs_s__rosidl_typesupport_c.cpython-36m-x86_64-linux-gnu.so
test_msgs_s__rosidl_typesupport_fastrtps_c.cpython-36m-x86_64-linux-gnu.so
test_msgs_s__rosidl_typesupport_introspection_c.cpython-36m-x86_64-linux-gnu.so
Thanks in advance for any help. This issue has had me confused all day.
Originally posted by squidonthebass on ROS Answers with karma: 26 on 2023-07-13
Post score: 0
Original comments
Comment by gvdhoorn on 2023-07-14:
Quick comment: I've seen this happen whenever I forget to source
the setup.bash
(or local_setup.bash
) after building a new msg package. Just something to check.
Comment by squidonthebass on 2023-07-14:
Yeah, I have triple checked this, and unfortunately is not the issue.