Traceback (most recent call last): File "/home/ros/catkin_ctr/src/jiangluo/scripts/eight_zi.py", line 47, in <module> local_pos_pub3.publish(poscom_twist) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 879, in publish data = args_kwds_to_message(self.data_class, args, kwds) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/msg.py", line 121, in args_kwds_to_message raise TypeError("expected [%s] but got [%s]"%(data_class._slot_types[0], arg._type)) TypeError: expected [std_msgs/Header] but got [geometry_msgs/TwistStamped]
时间: 2023-12-13 16:03:52 浏览: 790
这个错误提示意味着在 `local_pos_pub3.publish(poscom_twist)` 这一行代码中,你正在尝试将一个 `geometry_msgs/TwistStamped` 对象发布到了 `poscom` 这个话题上,但是这两者的消息类型并不匹配。
根据错误提示,`poscom` 这个话题所期望的消息类型是 `std_msgs/Header`,而不是 `geometry_msgs/TwistStamped`。因此,你需要将 `poscom` 话题和 `poscom_twist` 话题分别发布。
修改后的代码应该类似于以下代码:
```
while not rospy.is_shutdown():
poscom.header.stamp = rospy.Time.now()
poscom.header.frame_id = "world"
poscom.pose.position.x = 2.5 * math.sin(math.pi * i / 400)
poscom.pose.position.y = 5 * math.sin(math.pi * i / 800)
poscom.pose.position.z = 2
poscom_twist = TwistStamped()
poscom_twist.header.stamp = rospy.Time.now()
poscom_twist.header.frame_id = "base_link"
poscom_twist.twist.linear.x = 0
poscom_twist.twist.linear.y = 0
poscom_twist.twist.linear.z = 0
poscom_twist.twist.angular.x = 0
poscom_twist.twist.angular.y = 0
poscom_twist.twist.angular.z = 0
local_pos_pub3.publish(poscom)
local_pos_pub4.publish(poscom_twist) # 将 poscom_twist 发布到另一个话题上
```
你需要在你的代码中找到 `local_pos_pub3` 这个发布者,并对其进行修改,使其发布到正确的话题上(也就是 `poscom_twist`)。记得要在你的代码中添加一个新的发布者 `local_pos_pub4`,并将其发布到 `poscom_twist` 这个话题上。
希望这可以帮助你解决问题。
阅读全文