每天一个小知识
在代码中创建了 Publisher 的实例化对象后,不能立即使用该对象向外广播数据,应有一定的时间间隔!
如果没有间隔,会有两种情况:
1.sub到的数据不全,pub 6个数据,却只sub到5个。
2.在终端运行roslaunch …时。会有
[WARN] [1675906787.969832]: Inbound TCP/IP connection failed: connection from sender terminated before handshake header received. 0 bytes were received. Please check sender for additional details.
**
最终代码
**
import rospy
from std_msgs.msg import String
pub = rospy.Publisher("test", String, queue_size=10)
time.sleep(1)
pub.publish("this is test!")