ManualOperationWidget.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import inspect
  2. import sys
  3. import time
  4. from concurrent.futures import ThreadPoolExecutor
  5. from PyQt5.QtCore import QTimer, Qt
  6. from PyQt5.QtWidgets import QFrame
  7. from UI.manual_operation import Ui_manual_operation_widget
  8. from custom_define import ManualOperationType, RobotName
  9. class ManualOperationWidget(QFrame, Ui_manual_operation_widget):
  10. threadPool_ = ThreadPoolExecutor(1)
  11. def __init__(self, robot_dict: dict):
  12. super().__init__()
  13. self.setupUi(self)
  14. self.robot_dict = robot_dict
  15. self.selected_robot_name = None
  16. self.current_operation = ManualOperationType.eReady
  17. self.operation_count = dict()
  18. self.operation_count[ManualOperationType.eReady] = 0
  19. # 所选robot
  20. for robot in self.robot_dict.values():
  21. self.select_box.addItem(robot.name_)
  22. self.select_box.activated.connect(self.SelectRobot)
  23. self.selected_robot_name = self.select_box.currentText()
  24. # 逆/顺时针旋转
  25. self.Counterclockwise_Rotate_btn.pressed.connect(self.Counterclockwise_Rotate)
  26. self.Counterclockwise_Rotate_btn.released.connect(self.Cancel)
  27. self.Clockwise_Rotate_btn.pressed.connect(self.Clockwise_Rotate)
  28. self.Clockwise_Rotate_btn.released.connect(self.Cancel)
  29. # 前后左右平移
  30. self.Forward_Move_btn.pressed.connect(self.Forward_Move)
  31. self.Forward_Move_btn.released.connect(self.Cancel)
  32. self.Backward_Move_btn.pressed.connect(self.Backward_Move)
  33. self.Backward_Move_btn.released.connect(self.Cancel)
  34. self.Left_Move_btn.pressed.connect(self.Left_Move)
  35. self.Left_Move_btn.released.connect(self.Cancel)
  36. self.Right_Move_btn.pressed.connect(self.Right_Move)
  37. self.Right_Move_btn.released.connect(self.Cancel)
  38. # 夹持/抬升
  39. self.Clamp_Close_btn.pressed.connect(self.Clamp_Close)
  40. self.Clamp_Close_btn.released.connect(self.Cancel)
  41. self.Clamp_Open_btn.pressed.connect(self.Clamp_Open)
  42. self.Clamp_Open_btn.released.connect(self.Cancel)
  43. self.Lifter_Rise_btn.pressed.connect(self.Lifter_Rise)
  44. self.Lifter_Rise_btn.released.connect(self.Cancel)
  45. self.Lifter_Down_btn.pressed.connect(self.Lifter_Down)
  46. self.Lifter_Down_btn.released.connect(self.Cancel)
  47. # 设定速度
  48. self.speed_lineEdit.textChanged.connect(self.speed_lineEdit_change)
  49. # 加减速阶梯
  50. self.step_acc: int = 0
  51. # 启动界面刷新定时器
  52. self.timer = QTimer()
  53. self.timer.timeout.connect(self.Update)
  54. self.timer.start(50)
  55. # 操作计时
  56. self.manual_task_beg = 0
  57. def SelectRobot(self):
  58. if self.robot_dict[RobotName.strAGVMain].IsMainModeStatu():
  59. self.selected_robot_name = RobotName.strAGVMain
  60. else:
  61. self.selected_robot_name = self.select_box.currentText()
  62. def Counterclockwise_Rotate(self):
  63. if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
  64. return print("ManualTask is running...")
  65. if self.current_operation == ManualOperationType.eReady:
  66. print("eCounterclockwiseRotate")
  67. self.current_operation = ManualOperationType.eCounterclockwiseRotate
  68. def Clockwise_Rotate(self):
  69. if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
  70. return print("Clockwise_Rotate | ManualTask is running...")
  71. if self.current_operation == ManualOperationType.eReady:
  72. print("eCounterclockwiseRotate")
  73. self.current_operation = ManualOperationType.eClockwiseRotate
  74. def Forward_Move(self):
  75. if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
  76. return print("ManualTask is running...")
  77. if self.current_operation == ManualOperationType.eReady:
  78. self.current_operation = ManualOperationType.eForwardMove
  79. def Backward_Move(self):
  80. if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
  81. return print("ManualTask is running...")
  82. if self.current_operation == ManualOperationType.eReady:
  83. self.current_operation = ManualOperationType.eBackwardMove
  84. def Left_Move(self):
  85. if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
  86. return print("ManualTask is running...")
  87. if self.current_operation == ManualOperationType.eReady:
  88. self.current_operation = ManualOperationType.eLeftMove
  89. def Right_Move(self):
  90. if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
  91. return print("ManualTask is running...")
  92. if self.current_operation == ManualOperationType.eReady:
  93. self.current_operation = ManualOperationType.eRightMove
  94. def Lifter_Rise(self):
  95. if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
  96. return print("ManualTask is running...")
  97. if self.current_operation == ManualOperationType.eReady:
  98. print("Lifter_Rise")
  99. self.current_operation = ManualOperationType.eLifterRise
  100. def Lifter_Down(self):
  101. if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
  102. return print("ManualTask is running...")
  103. if self.current_operation == ManualOperationType.eReady:
  104. self.current_operation = ManualOperationType.eLifterDown
  105. def Clamp_Close(self):
  106. if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
  107. return print("ManualTask is running...")
  108. if self.current_operation == ManualOperationType.eReady:
  109. self.current_operation = ManualOperationType.eClampClose
  110. def Clamp_Open(self):
  111. if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
  112. return print("ManualTask is running...")
  113. if self.current_operation == ManualOperationType.eReady:
  114. self.current_operation = ManualOperationType.eClampOpen
  115. def Cancel(self):
  116. self.current_operation = ManualOperationType.eReady
  117. self.operation_count[ManualOperationType.eReady] += 1
  118. def Update(self):
  119. self.DownCmd()
  120. self.UIRefresh()
  121. def speed_lineEdit_change(self):
  122. try:
  123. if not 0 <= float(self.speed_lineEdit.text()) <= 99:
  124. self.speed_lineEdit.setText("0")
  125. except:
  126. self.speed_lineEdit.setText("0")
  127. def speed_lineEdit_check(self):
  128. try:
  129. if not 0 <= float(self.speed_lineEdit.text()) <= 99:
  130. self.speed_lineEdit.setText("0")
  131. else:
  132. return True
  133. except:
  134. self.speed_lineEdit.setText("0")
  135. return False
  136. def DownCmd(self):
  137. if ManualOperationType.eCounterclockwiseRotate <= self.current_operation <= ManualOperationType.eClockwiseRotate:
  138. speed = 0.0
  139. if self.speed_lineEdit_check():
  140. speed = float(self.speed_lineEdit.text())
  141. speed = min(speed, 3)
  142. self.speed_lineEdit.setText(str(speed))
  143. self.robot_dict[self.selected_robot_name].ManualTask(self.current_operation, self.step_acc, speed=speed)
  144. self.step_acc += 1
  145. # self.threadPool_.submit(self.robot_dict[self.selected_robot_name].ManualTask, self.current_operation)
  146. elif ManualOperationType.eForwardMove <= self.current_operation <= ManualOperationType.eRightMove:
  147. speed = 0.0
  148. if self.speed_lineEdit_check():
  149. speed = float(self.speed_lineEdit.text())
  150. speed = min(speed, 0.5)
  151. self.speed_lineEdit.setText(str(speed))
  152. self.robot_dict[self.selected_robot_name].ManualTask(self.current_operation, self.step_acc, speed=speed)
  153. self.step_acc += 1
  154. elif ManualOperationType.eClampClose <= self.current_operation <= ManualOperationType.eClampOpen:
  155. self.robot_dict[self.selected_robot_name].ManualTask(self.current_operation)
  156. elif ManualOperationType.eLifterRise <= self.current_operation <= ManualOperationType.eLifterDown:
  157. self.robot_dict[self.selected_robot_name].ManualTask(self.current_operation)
  158. elif self.current_operation == ManualOperationType.eReady and \
  159. self.operation_count[ManualOperationType.eReady] != 0:
  160. # self.threadPool_.shutdown(False)
  161. self.threadPool_.submit(self.robot_dict[self.selected_robot_name].CancelNavTask)
  162. self.current_operation = ManualOperationType.eReady
  163. self.operation_count[ManualOperationType.eReady] = 0
  164. self.step_acc = 0
  165. else:
  166. pass
  167. # self.current_operation = ManualOperationType.eReady
  168. # self.operation_count[ManualOperationType.eReady] = 0
  169. # self.step_acc = 0
  170. def UIRefresh(self):
  171. pass