from concurrent.futures import ThreadPoolExecutor from PyQt5.QtCore import QTimer from PyQt5.QtWidgets import QFrame from UI.manual_operation import Ui_manual_operation_widget from custom_define import ManualOperationType, RobotName class ManualOperationWidget(QFrame, Ui_manual_operation_widget): threadPool_ = ThreadPoolExecutor(1) def __init__(self, robot_dict:dict): super().__init__() self.setupUi(self) self.robot_dict = robot_dict self.selected_robot_name = None self.current_operation = ManualOperationType.eReady self.operation_count = dict() self.operation_count[ManualOperationType.eReady] = 0 # 所选robot for robot in self.robot_dict.values(): self.select_box.addItem(robot.name_) self.select_box.activated.connect(self.SelectRobot) self.selected_robot_name = self.select_box.currentText() # 逆/顺时针旋转 self.Counterclockwise_Rotate_btn.pressed.connect(self.Counterclockwise_Rotate) self.Counterclockwise_Rotate_btn.released.connect(self.Cancel) self.Clockwise_Rotate_btn.pressed.connect(self.Clockwise_Rotate) self.Clockwise_Rotate_btn.released.connect(self.Cancel) # 前后左右平移 self.Forward_Move_btn.pressed.connect(self.Forward_Move) self.Forward_Move_btn.released.connect(self.Cancel) self.Backward_Move_btn.pressed.connect(self.Backward_Move) self.Backward_Move_btn.released.connect(self.Cancel) self.Left_Move_btn.pressed.connect(self.Left_Move) self.Left_Move_btn.released.connect(self.Cancel) self.Right_Move_btn.pressed.connect(self.Right_Move) self.Right_Move_btn.released.connect(self.Cancel) # 加减速阶梯 self.step_acc: int = 0 # 启动界面刷新定时器 self.timer = QTimer() self.timer.timeout.connect(self.DownCmd) self.timer.start(50) def SelectRobot(self): if self.robot_dict[RobotName.strAGVMain].IsMainModeStatu(): self.selected_robot_name = RobotName.strAGVMain else: self.selected_robot_name = self.select_box.currentText() def Counterclockwise_Rotate(self): self.current_operation = ManualOperationType.eCounterclockwiseRotate def Clockwise_Rotate(self): self.current_operation = ManualOperationType.eClockwiseRotate def Forward_Move(self): self.current_operation = ManualOperationType.eForwardMove def Backward_Move(self): self.current_operation = ManualOperationType.eBackwardMove def Left_Move(self): self.current_operation = ManualOperationType.eLeftMove def Right_Move(self): self.current_operation = ManualOperationType.eRightMove def Cancel(self): self.current_operation = ManualOperationType.eReady self.operation_count[ManualOperationType.eReady] += 1 def DownCmd(self): if self.current_operation != ManualOperationType.eReady: self.robot_dict[self.selected_robot_name].ManualTask(self.current_operation, self.step_acc) self.step_acc += 1 # self.threadPool_.submit(self.robot_dict[self.selected_robot_name].ManualTask, self.current_operation) elif self.operation_count[ManualOperationType.eReady] != 0: # self.threadPool_.shutdown(False) self.threadPool_.submit(self.robot_dict[self.selected_robot_name].CancelNavTask) self.current_operation = ManualOperationType.eReady self.operation_count[ManualOperationType.eReady] = 0 self.step_acc = 0 else: self.current_operation = ManualOperationType.eReady self.operation_count[ManualOperationType.eReady] = 0 self.step_acc = 0