ROS机器人turtlesim绘制心形轨迹的Python代码
时间: 2023-03-29 07:04:34 浏览: 182
以下是绘制心形轨迹的Python代码:
```python
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from math import pi, sin, cos
def draw_heart():
rospy.init_node('draw_heart', anonymous=True)
pub = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)
rate = rospy.Rate(10)
vel = Twist()
t =
while not rospy.is_shutdown():
vel.linear.x = 6 * (sin(t) ** 3)
vel.linear.y =
vel.linear.z =
vel.angular.x =
vel.angular.y =
vel.angular.z = 6 * (cos(t) ** 2) * sin(t)
pub.publish(vel)
t += .1
rate.sleep()
if __name__ == '__main__':
try:
draw_heart()
except rospy.ROSInterruptException:
pass
```
希望对你有帮助!
阅读全文