ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Can't publish or echo topics with custom message types from command line

asked 2023-07-13 12:34:47 -0500

squidonthebass gravatar image

updated 2023-07-13 13:42:35 -0500

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="no@no.no">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 ...
(more)
edit retag flag offensive close merge delete

Comments

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.

gvdhoorn gravatar image gvdhoorn  ( 2023-07-14 03:28:45 -0500 )edit

Yeah, I have triple checked this, and unfortunately is not the issue.

squidonthebass gravatar image squidonthebass  ( 2023-07-14 08:08:13 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-08-02 10:12:49 -0500

squidonthebass gravatar image

updated 2023-08-02 10:13:29 -0500

I finally figured out the issue (and a solution) today. The python IDL interfaces for my version of ROS used python3.10. Despite the normal python install on my machine being python3.10, for whatever reason, when I ran colcon build it was finding a spurious python3.6 install, so the python IDL interfaces for the packages in my workspace were being built using that (and were not compatible with the CLI commands). So the IDL products would be under the path /home/user/ws/install/test_msgs/local/lib/python3.10/dist-packages/test_msgs, but the IDL libraries were test_msgs_s__rosidl_typesupport_*.cpython-3.6-*.so instead of *.cpython-3.10*.so.

I did not find a quick way to specify that colcon/cmake explicitly use python3.10, so I fixed this issue by removing python3.6 from my machine, removing the build, install, and log folders, and doing a fresh build.

edit flag offensive delete link more

Comments

Good sleuthing. Thanks for posting your findings here.

gvdhoorn gravatar image gvdhoorn  ( 2023-08-03 05:53:54 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2023-07-13 12:34:47 -0500

Seen: 1,236 times

Last updated: Aug 02 '23