1.按照roswiki上的教程,rospy/Tutorials,我们先把代码粘贴过来运行一下发布者和订阅者的代码
talker代码:
import rospy from std_msgs.msg import String def talker(): pub = rospy.Publisher('chatter', String, queue_size=10) rospy.init_node('talker', anonymous=True) rate = rospy.Rate(10) # 10hz while not rospy.is_shutdown(): hello_str = "hello world %s" % rospy.get_time() rospy.loginfo(hello_str) pub.publish(hello_str) rate.sleep() if __name__ == '__main__': try: talker() except rospy.ROSInterruptException: pass
运行代码会出现标红
[ERROR] [1585751789.057178]: Unable to immediately register with master node [http://localhost:11311]: master may not be running yet. Will keep trying.
熟悉的11311,是提示我们没有开大网管roscore,我们新开个终端roscore一下,程序得以顺利运行