herrDeng網內搜尋

自訂搜尋

Ads

2022年11月20日 星期日

Robomaster SDK紅外線感測器測距 python pyplot.polar畫地圖

 
Python code 如下:
  1. import time
  2. import numpy as np
  3. from robomaster import robot
  4.  
  5. ep_robot = robot.Robot()
  6. ep_robot.initialize(conn_type="ap")
  7.  
  8. ep_gimbal = ep_robot.gimbal
  9. ep_sensor = ep_robot.sensor
  10.  
  11.  
  12. ep_robot.set_robot_mode(mode='free')
  13.  
  14.  
  15.  
  16. dd=[]
  17. aa=[]
  18. def sub_data_handler(sub_info):
  19. d = sub_info
  20. dd.append(d[0])
  21. # print(d)
  22.  
  23. def sub_angle_handler(angle_info):
  24. pitch_angle, yaw_angle, pitch_ground_angle, yaw_ground_angle = angle_info
  25. a=-yaw_ground_angle/180*np.pi
  26. aa.append(a)
  27. # print("gimbal angle: pitch_angle:{0}, yaw_angle:{1}, pitch_ground_angle:{2}, yaw_ground_angle:{3}".format(
  28. # pitch_angle, yaw_angle, pitch_ground_angle, yaw_ground_angle))
  29.  
  30. ep_gimbal.moveto(pitch=0, yaw=-180).wait_for_completed()
  31.  
  32. ep_sensor.sub_distance(freq=10, callback=sub_data_handler)
  33. ep_gimbal.sub_angle(freq=10, callback=sub_angle_handler)
  34. ep_gimbal.moveto(pitch=0, yaw=180, yaw_speed=10).wait_for_completed()
  35.  
  36. ep_gimbal.unsub_angle()
  37. ep_sensor.unsub_distance()
  38.  
  39. ep_gimbal.moveto(pitch=0, yaw=0).wait_for_completed()
  40.  
  41. ll=min(len(aa), len(dd))
  42. ll
  43.  
  44.  
  45. import matplotlib.pyplot as plt
  46. plt.polar(aa[:ll], dd[:ll], 'b+')
  47. ax = plt.gca() # gets the active axis
  48. ax.set_rmax(700)
  49. ax.set_aspect(1)
  50. plt.savefig('polar.png', dpi=300)
  51. plt.show()

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章