ManualOperationWidget.py 8.9 KB

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