micro-ROS:publish custom message by ros2 topic pub
Hi,
I'm trying to create simple node which subscribe custom message(on topic named /custom
by follow below micro-ROS tutorial but having trouble.
https://micro.ros.org/docs/tutorials/...
I have successfully build/run micro-ROS firmware on device and now is time to test.
But ros2 topic pub
fails with ModuleNotFoundError.
I can print some details of custom message(ros2 topic info
and ros2 interface show
) so I believe message definition was loaded successfully.
Am I missing something?
root@kojix1:/# . /opt/ros/foxy/setup.bash
root@kojix1:/# . /microros_ws/firmware/mcu_ws/install/local_setup.bash
root@kojix1:/# ros2 topic info /custom
Type: my_custom_message/msg/MyCustomMessage
Publisher count: 0
Subscription count: 1
root@kojix1:/# ros2 interface show my_custom_message/msg/MyCustomMessage
bool bool_test
byte byte_test
char char_test
float32 float32_test
float64 double_test
int8 int8_test
uint8 uint8_test
int16 int16_test
uint16 uint16_test
int32 int32_test
uint32 uint32_test
int64 int64_test
uint64 uint64_test
root@kojix1:/# ros2 topic pub -r 2 /custom my_custom_message/msg/MyCustomMessage "bool_test:true"
Traceback (most recent call last):
File "/opt/ros/foxy/bin/ros2", line 11, in <module>
load_entry_point('ros2cli==0.9.10', 'console_scripts', 'ros2')()
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2cli/cli.py", line 67, in main
rc = extension.main(parser=parser, args=args)
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/command/topic.py", line 41, in main
return extension.main(args=args)
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 97, in main
return main(args)
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 107, in main
return publisher(
File "/opt/ros/foxy/lib/python3.8/site-packages/ros2topic/verb/pub.py", line 131, in publisher
msg_module = get_message(message_type)
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_runtime_py/utilities.py", line 28, in get_message
interface = import_message_from_namespaced_type(get_message_namespaced_type(identifier))
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_runtime_py/import_message.py", line 30, in import_message_from_namespaced_type
module = importlib.import_module(
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'my_custom_message'
--------SOLVED!----------------
I should have copy of my_custom_message packaged folder in src directory of workspace! Then,
colcon build
. install/local_setup.bash
So now ros2 can load my_custom_message and I have successfully publish my custom message.