小海龟turtle原地转圈 Python实现
/turtle1/cmd_vel
[geometry_msgs/Twist] /
linear.x
angular.z
#!/usr/bin/env python
# coding:utf-8
import rospy
from geometry_msgs.msg import Twist
def turtle_publisher():
rospy.init_node('turtle_publisher', anonymous = True)
pub = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)
rate = rospy.Rate(1)
while not rospy.is_shutdown():
msg = Twist()
msg.linear.x = 0.5
msg.angular.z = 0.2
pub.publish(msg)
rospy.loginfo('publish turtle message command [%0.2f m/s, %0.2f rad/s]', msg.linear.x , msg.angular.z )
rate.sleep()
if __name__ == '__main__':
try:
turtle_publisher()
except rospy.ROSInterruptException:
pass
运行结果: