1.先在beginner_tutorial这个包中定义好需要的信息
文件里的内容
2.然后返回根文件夹catkin_make,在相应文件夹生成了相应的消息py文件
3.py脚本
#!/usr/bin/env python
#coding=utf-8
#import roslib;roslib.load_manifest('beginner_tutorials')
import rospy
from beginner_tutorials.msg import Order
def talker():
pub = rospy.Publisher('chatter', Order, queue_size = 10)
rospy.init_node('talker', anonymous = True)
rate = rospy.Rate(10)
while not rospy.is_shutdown():
str = "snake"
msg = Order()
msg.order = str
rospy.loginfo(str)
pub.publish(msg)
rate.sleep()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
另外,如果pycharm一直提示no module named rospy,就按这里操作:https://www.jianshu.com/p/f1374bc008cb