123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- import inspect
- import sys
- import time
- from concurrent.futures import ThreadPoolExecutor
- from PyQt5.QtCore import QTimer, Qt
- 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.speed_lineEdit.setText("0.5")
- 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.Clamp_Close_btn.pressed.connect(self.Clamp_Close)
- self.Clamp_Close_btn.released.connect(self.Cancel)
- self.Clamp_Open_btn.pressed.connect(self.Clamp_Open)
- self.Clamp_Open_btn.released.connect(self.Cancel)
- self.Lifter_Rise_btn.pressed.connect(self.Lifter_Rise)
- self.Lifter_Rise_btn.released.connect(self.Cancel)
- self.Lifter_Down_btn.pressed.connect(self.Lifter_Down)
- self.Lifter_Down_btn.released.connect(self.Cancel)
- # 设定速度
- self.speed_lineEdit.textChanged.connect(self.speed_lineEdit_change)
- # 加减速阶梯
- self.step_acc: int = 0
- # 启动界面刷新定时器
- self.timer = QTimer()
- self.timer.timeout.connect(self.Update)
- self.timer.start(50)
- # 操作计时
- self.manual_task_beg = 0
- 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):
- if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
- return print("ManualTask is running...")
- if self.current_operation == ManualOperationType.eReady:
- print("eCounterclockwiseRotate")
- self.current_operation = ManualOperationType.eCounterclockwiseRotate
- def Clockwise_Rotate(self):
- if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
- return print("Clockwise_Rotate | ManualTask is running...")
- if self.current_operation == ManualOperationType.eReady:
- print("eCounterclockwiseRotate")
- self.current_operation = ManualOperationType.eClockwiseRotate
- def Forward_Move(self):
- if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
- return print("ManualTask is running...")
- if self.current_operation == ManualOperationType.eReady:
- self.current_operation = ManualOperationType.eForwardMove
- def Backward_Move(self):
- if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
- return print("ManualTask is running...")
- if self.current_operation == ManualOperationType.eReady:
- self.current_operation = ManualOperationType.eBackwardMove
- def Left_Move(self):
- if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
- return print("ManualTask is running...")
- if self.current_operation == ManualOperationType.eReady:
- self.current_operation = ManualOperationType.eLeftMove
- def Right_Move(self):
- if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
- return print("ManualTask is running...")
- if self.current_operation == ManualOperationType.eReady:
- self.current_operation = ManualOperationType.eRightMove
- def Lifter_Rise(self):
- if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
- return print("ManualTask is running...")
- if self.current_operation == ManualOperationType.eReady:
- print("Lifter_Rise")
- self.current_operation = ManualOperationType.eLifterRise
- def Lifter_Down(self):
- if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
- return print("ManualTask is running...")
- if self.current_operation == ManualOperationType.eReady:
- self.current_operation = ManualOperationType.eLifterDown
- def Clamp_Close(self):
- if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
- return print("ManualTask is running...")
- if self.current_operation == ManualOperationType.eReady:
- self.current_operation = ManualOperationType.eClampClose
- def Clamp_Open(self):
- if self.robot_dict[self.selected_robot_name].IsManualTaskRunning():
- return print("ManualTask is running...")
- if self.current_operation == ManualOperationType.eReady:
- self.current_operation = ManualOperationType.eClampOpen
- def Cancel(self):
- self.current_operation = ManualOperationType.eReady
- self.operation_count[ManualOperationType.eReady] += 1
- def Update(self):
- self.DownCmd()
- self.UIRefresh()
- def speed_lineEdit_change(self):
- try:
- if not 0 <= float(self.speed_lineEdit.text()) <= 99:
- self.speed_lineEdit.setText("0")
- except:
- self.speed_lineEdit.setText("0")
- def speed_lineEdit_check(self):
- try:
- if not 0 <= float(self.speed_lineEdit.text()) <= 99:
- self.speed_lineEdit.setText("0")
- else:
- return True
- except:
- self.speed_lineEdit.setText("0")
- return False
- def DownCmd(self):
- if ManualOperationType.eCounterclockwiseRotate <= self.current_operation <= ManualOperationType.eClockwiseRotate:
- speed = 0.0
- if self.speed_lineEdit_check():
- speed = float(self.speed_lineEdit.text())
- speed = min(speed, 30)
- self.speed_lineEdit.setText(str(speed))
- self.robot_dict[self.selected_robot_name].ManualTask(self.current_operation, self.step_acc, speed=speed)
- self.step_acc += 1
- # self.threadPool_.submit(self.robot_dict[self.selected_robot_name].ManualTask, self.current_operation)
- elif ManualOperationType.eForwardMove <= self.current_operation <= ManualOperationType.eRightMove:
- speed = 0.0
- if self.speed_lineEdit_check():
- speed = float(self.speed_lineEdit.text())
- speed = min(speed, 2.0)
- self.speed_lineEdit.setText(str(speed))
- self.robot_dict[self.selected_robot_name].ManualTask(self.current_operation, self.step_acc, speed=speed)
- self.step_acc += 1
- elif ManualOperationType.eClampClose <= self.current_operation <= ManualOperationType.eClampOpen:
- self.robot_dict[self.selected_robot_name].ManualTask(self.current_operation)
- elif ManualOperationType.eLifterRise <= self.current_operation <= ManualOperationType.eLifterDown:
- self.robot_dict[self.selected_robot_name].ManualTask(self.current_operation)
- elif self.current_operation == ManualOperationType.eReady and \
- self.operation_count[ManualOperationType.eReady] != 0:
- speed = float(self.speed_lineEdit.text())
- self.robot_dict[self.selected_robot_name].ManualTask(self.current_operation, speed=speed)
- # 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:
- pass
- # self.current_operation = ManualOperationType.eReady
- # self.operation_count[ManualOperationType.eReady] = 0
- # self.step_acc = 0
- def UIRefresh(self):
- pass
|