ros2 / ros2cli

ROS 2 command line interface tools
Apache License 2.0
173 stars 159 forks source link

ros2 topic echo does not support messages generated directly from IDL #277

Open davidhodo opened 5 years ago

davidhodo commented 5 years ago

Bug report

Steps to reproduce issue

ROS2 topic echo currently hardcodes '.msg' for importing message python modules. Message packages created directly from idl files as supported in Dashing use a '.idl' name. Running 'ros2 topic echo' on a topic that uses a message generated from idl fails.

An example package that creates a simple string message using idl can be found at: ros2_idl_demo. Building the message (idl_msgs) and sample publisher (idl_pub) packages and then running ros2 run idl_pub idl_pub and ros2 topic echo /chatter results in a crash.

Expected behavior

---
var_string: 'ROS2: Hello'
---
var_string: 'ROS2: Hello'

Actual behavior

davidhodo@Davids-MacBook-Pro:idl_test_ws∫ ros2 topic echo /chatter
Traceback (most recent call last):
  File "/opt/ros/dashing/bin/ros2", line 11, in <module>
    load_entry_point('ros2cli==0.7.0', 'console_scripts', 'ros2')()
  File "/opt/ros/dashing/lib/python3.7/site-packages/ros2cli/cli.py", line 69, in main
    rc = extension.main(parser=parser, args=args)
  File "/opt/ros/dashing/lib/python3.7/site-packages/ros2topic/command/topic.py", line 43, in main
    return extension.main(args=args)
  File "/opt/ros/dashing/lib/python3.7/site-packages/ros2topic/verb/echo.py", line 69, in main
    return main(args)
  File "/opt/ros/dashing/lib/python3.7/site-packages/ros2topic/verb/echo.py", line 79, in main
    node.node, args.topic_name, args.message_type, callback)
  File "/opt/ros/dashing/lib/python3.7/site-packages/ros2topic/verb/echo.py", line 106, in subscriber
    msg_module = import_message_type(topic_name, message_type)
  File "/opt/ros/dashing/lib/python3.7/site-packages/ros2topic/api/__init__.py", line 71, in import_message_type
    module = importlib.import_module(package_name + '.' + middle_module)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'idl_msgs.msg'

Additional information

The error comes from the import_message_type method in ros2topic/ros2topic/api/init.py. It currently hardcodes a middle_module name of '.msg'. For message packages created from idl this should be '.idl'.

dirk-thomas commented 5 years ago

Thanks for reporting this. #223 described s new command which should be able to handle all kinds including .idl based interfaces.