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

micro-ROS:publish custom message by ros2 topic pub

asked 2022-01-26 20:29:38 -0500

KojiYoshioka gravatar image

updated 2022-01-30 18:07:44 -0500

Hi,

I'm trying to create simple node which subscribe custom message(on topic named /customby 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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-01-28 16:38:31 -0500

ljaniec gravatar image

By this issue - there is a video with step by step session of creating a custom message in micro-ROS.

Timestamps:

  • Message creation 5:40
  • Header check 11:28
  • Library .a check 12:08

I would check the most important places - CMakeLists.txt with rosidl_generate_interfaces with your custom message:

rosidl_generate_interfaces(${PROJECT_NAME}

    "msg/MyCustomMessage.msg"
)

Then package.xml:

<build_depend>rosidl_default_generators</build_depend> <exec_depend>rosidl_default_runtime</exec_depend> <member_of_group>rosidl_interface_packages</member_of_group>

There is this ros2 run micro_ros_setup configure_firmware.sh int32_publisher -t udp -i 192.168.1.100 -p 8888 too.

When you find the missing step, please write it in the comment or edit it in the questions. It will be helpful for everybody later.

edit flag offensive delete link more

Comments

1

Thank you ljaniec, I found solution.

My problem was not in micro-ROS side, I should copy package (which has custom message) to somewhere colcon can detect.

KojiYoshioka gravatar image KojiYoshioka  ( 2022-01-30 18:10:42 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2022-01-26 20:29:38 -0500

Seen: 688 times

Last updated: Jan 30 '22