admin管理员组文章数量:1130349
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一下,程序得以顺利运行
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一下,程序得以顺利运行
版权声明:本文标题:rospy基础--订阅与发布 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1754578434a2703824.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论