ROS机器人turtlesim走玫瑰线的简单python示例代码
时间: 2023-03-31 18:00:17 浏览: 107
以下是ROS机器人turtlesim走玫瑰线的简单python示例代码:
```python
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from math import sin, cos, pi
def rose_pattern(t):
x = sin(2*pi*t)*cos(t)
y = sin(2*pi*t)*sin(t)
return (x, y)
def move_turtle():
rospy.init_node('turtle_move', anonymous=True)
velocity_publisher = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)
vel_msg = Twist()
rate = rospy.Rate(10)
t =
while not rospy.is_shutdown():
x, y = rose_pattern(t)
vel_msg.linear.x = x
vel_msg.angular.z = y
velocity_publisher.publish(vel_msg)
t += .1
rate.sleep()
if __name__ == '__main__':
try:
move_turtle()
except rospy.ROSInterruptException:
pass
```
希望对你有帮助!
阅读全文