ros2 foxy py_pubsub 运行时报错:‘type‘ has no attribute ‘_TYPE_SUPPORT‘

**报错**:

2martin@martinComputer:~/ros2_ws$ ros2 run py_pubsub talker 
Traceback (most recent call last):
  File "/home/martin/ros2_ws/install/py_pubsub/lib/py_pubsub/talker", line 11, in <module>
    load_entry_point('py-pubsub==0.0.0', 'console_scripts', 'talker')()
  File "/home/martin/ros2_ws/install/py_pubsub/lib/python3.8/site-packages/py_pubsub/publisher_member_function.py", line 41, in main
    minimal_publisher = MinimalPublisher()
  File "/home/martin/ros2_ws/install/py_pubsub/lib/python3.8/site-packages/py_pubsub/publisher_member_function.py", line 25, in __init__
    self.publisher_ = self.create_publisher(String, 'topic', 10)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 1144, in create_publisher
    check_for_type_support(msg_type)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 20, in check_for_type_support
    ts = msg_type.__class__._TYPE_SUPPORT
AttributeError: type object 'type' has no attribute '_TYPE_SUPPORT' This might be a ROS 1 message type but it should be a ROS 2 message type. Make sure to source your ROS 2 workspace after your ROS 1 workspace.

**原因**:在foxy tutorial官方教程中,package.xml使用的是<exec_depend>std_msgs</exec_depend>,这会导致只在运行时使用std_msgs。

**解决方法** : 修改为<depend>std_msgs</depend>

**反思**:他们的区别在于,depend实际包含了build_depend, build_export_depend 和 exec_depend,之前应该是使用ROS1有残留,所以切换之后应该制定编译依赖。在看到此类报错,应该就锁定string,看到string相关的就是<depend>std_msgs</depend>,所以排除错误。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值