我是小鱼,欢迎关注公众号鱼香ROS,一起学习机器人。
BUG表现如下
自定义消息,编译不报错,运行就出错
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-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.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 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
File "<frozen importlib._bootstrap>", line 556, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1166, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: /home/ros2/code/town_ws/install/village_interfaces/lib/libvillage_interfaces__rosidl_generator_c.so: undefined symbol: sensor_msgs__msg__Image__init
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ros2/code/town_ws/install/village_li/lib/village_li/li4_node", line 11, in <module>
load_entry_point('village-li==0.0.0', 'console_scripts', 'li4_node')()
File "/home/ros2/code/town_ws/install/village_li/lib/python3.8/site-packages/village_li/li4.py", line 46, in main
node = Li4Node() # 新建一个节点
File "/home/ros2/code/town_ws/install/village_li/lib/python3.8/site-packages/village_li/li4.py", line 23, in __init__
self.borrow_server = self.create_service(BorrowMoney,"borrow_money",self.borrow_money_callback)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 1295, in create_service
check_for_type_support(srv_type)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 29, in check_for_type_support
msg_type.__class__.__import_type_support__()
File "/home/ros2/code/town_ws/install/village_interfaces/lib/python3.8/site-packages/village_interfaces/srv/_borrow_money.py", line 316, in __import_type_support__
module = import_type_support('village_interfaces')
File "/opt/ros/foxy/lib/python3.8/site-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 'village_interfaces'
原因:
自定义消息未添加对其他消息的依赖
解决办法,添加依赖在CMakeists.txt中
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
#---msg---
"msg/Novel.msg"
#---srv---
"srv/BorrowMoney.srv"
"srv/SellNovel.srv"
DEPENDENCIES std_msgs sensor_msgs
)