herrDeng網內搜尋

自訂搜尋

Ads

2022年9月26日 星期一

Mecanum Wheel麥輪Robomaster小車圓周運動解析

  1. ep_chassis.drive_wheels(w1=60, w2=0, w3=0, w4=60)
  2. time.sleep(16)


  1. #以下為教學程式
  2. from robomaster import robot
  3. import time
  4.  
  5. ep_robot = robot.Robot()
  6. ep_robot.initialize(conn_type="ap") #ap , sta兩種連線模式,都要有無線能力
  7.  
  8. ep_robot.set_robot_mode(mode=robot.CHASSIS_LEAD)
  9. print('雲台跟隨底盤模式')
  10.  
  11. ep_chassis = ep_robot.chassis
  12.  
  13. xx=[]
  14. yy=[]
  15. def sub_position_handler(position_info):
  16. x, y, z = position_info
  17. xx.append(x)
  18. yy.append(-y) #符合數學座標方向
  19.  
  20. ep_chassis.sub_position(freq=10, callback=sub_position_handler)
  21. print('訂閱position')
  22.  
  23. print('w1 右前、w2左前、w3左後、w4右後')
  24. ep_chassis.drive_wheels(w1=60, w2=0, w3=0, w4=60)
  25. time.sleep(16)
  26. ep_chassis.drive_wheels(w1=0, w2=0, w3=0, w4=0)
  27.  
  28. ep_chassis.unsub_position()
  29. print('停止訂閱position')
  30.  
  31. ep_chassis.drive_wheels(w1=0, w2=0, w3=0, w4=0)
  32. ep_robot.close()
  33.  
  34.  
  35. # 用pyplot繪出行進的軌跡
  36. import matplotlib.pyplot as plt
  37.  
  38. plt.plot(xx, yy, 'r+')
  39. ax = plt.gca() # gets the active axis
  40. ax.set_aspect(1)
  41. plt.savefig('trace.png', dpi=300)
  42. plt.show()
  43.  

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章