McuDebug.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import time
  2. class McuDebug(object):
  3. def __init__(self, mcu, is_debug=True, is_deviation=False):
  4. self.mcu = mcu
  5. self.is_debug = 1 if is_debug else 0
  6. self.is_deviation = 1 if is_deviation else 0
  7. def camera_high_motor(self, value):
  8. # 相机电机
  9. self.mcu.to_device_move(
  10. device_name="camera_high_motor",
  11. value=value,
  12. max_speed=1400,
  13. up_speed=400,
  14. down_speed=100,
  15. _is_debug=self.is_debug,
  16. is_deviation=self.is_deviation,
  17. )
  18. def camera_steering(self, value):
  19. # 相机舵机
  20. self.mcu.to_device_move(
  21. device_name="camera_steering",
  22. value=value,
  23. _is_debug=self.is_debug,
  24. is_deviation=self.is_deviation,
  25. )
  26. def turntable_steering(self, value):
  27. # 转盘舵机
  28. self.mcu.to_device_move(
  29. device_name="turntable_steering",
  30. value=value,
  31. _is_debug=self.is_debug,
  32. is_deviation=self.is_deviation,
  33. )
  34. def turntable_position_motor(self, value):
  35. # 转盘舵机
  36. self.mcu.to_device_move(
  37. device_name="turntable_position_motor",
  38. value=value,
  39. max_speed=1400,
  40. up_speed=400,
  41. down_speed=100,
  42. _is_debug=self.is_debug,
  43. is_deviation=self.is_deviation,
  44. )
  45. def overturn_steering(self, value):
  46. # 翻板舵机中位
  47. self.mcu.to_device_move(
  48. device_name="overturn_steering",
  49. value=value,
  50. _is_debug=self.is_debug,
  51. is_deviation=self.is_deviation,
  52. )
  53. def camera_zoom(self, value, max_speed=None, up_speed=None, down_speed=None, times=1, is_response=False):
  54. # 相机焦段
  55. self.mcu.to_device_move(device_name="camera_zoom_motor",
  56. value=value,
  57. max_speed=max_speed,
  58. up_speed=up_speed,
  59. down_speed=down_speed,
  60. _is_debug=self.is_debug,
  61. is_deviation=self.is_deviation,
  62. times=times,
  63. is_response=is_response,
  64. )
  65. def to_deal_device(self, device_name, value=1, _type=0, times=1):
  66. self.mcu.to_deal_device(
  67. device_name, value=value, _type=_type, times=times
  68. )
  69. def photograph(self, goods_art_no=None):
  70. self.mcu.photograph(goods_art_no=goods_art_no)
  71. def __move_equipment(self, data):
  72. func_class = {
  73. "相机电机": self.camera_high_motor,
  74. "相机舵机": self.camera_steering,
  75. "转盘舵机": self.turntable_steering,
  76. "转盘前后电机": self.turntable_position_motor,
  77. }
  78. for key, value in data.items():
  79. if key in func_class:
  80. func_class[key](value=value)
  81. time.sleep(0.1)