更新控制
This commit is contained in:
155
main.py
155
main.py
@ -41,6 +41,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
super(MainWindow, self).__init__()
|
||||
self.setupUi(self)
|
||||
#self.setWindowFlags(Qt.WindowType.FramelessWindowHint)
|
||||
self.thread_signal = True
|
||||
self.init_qss()
|
||||
self.init_UI()
|
||||
self.init_Run()
|
||||
@ -310,32 +311,35 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.configReader.read(Constant.set_ini)
|
||||
ip = self.configReader.get('Robot_Feed', 'IPAddress')
|
||||
port = int(self.configReader.get('Robot_Feed', 'Port'))
|
||||
photo_locs = [(int(self.configReader.get('Robot_Feed', 'photo_x1')),
|
||||
int(self.configReader.get('Robot_Feed', 'photo_y1')), int(self.configReader.get('Robot_Feed', 'photo_z1')),
|
||||
int(self.configReader.get('Robot_Feed', 'photo_u1')),int(self.configReader.get('Robot_Feed', 'photo_v1')),int(self.configReader.get('Robot_Feed', 'photo_w1'))),
|
||||
(int(self.configReader.get('Robot_Feed', 'photo_x2')),
|
||||
int(self.configReader.get('Robot_Feed', 'photo_y2')), int(self.configReader.get('Robot_Feed', 'photo_z2')),
|
||||
int(self.configReader.get('Robot_Feed', 'photo_u2')),int(self.configReader.get('Robot_Feed', 'photo_v2')),int(self.configReader.get('Robot_Feed', 'photo_w2'))
|
||||
photo_locs = [(float(self.configReader.get('Robot_Feed', 'photo_x1')),
|
||||
float(self.configReader.get('Robot_Feed', 'photo_y1')), float(self.configReader.get('Robot_Feed', 'photo_z1')),
|
||||
float(self.configReader.get('Robot_Feed', 'photo_u1')),float(self.configReader.get('Robot_Feed', 'photo_v1')),float(self.configReader.get('Robot_Feed', 'photo_w1'))),
|
||||
(float(self.configReader.get('Robot_Feed', 'photo_x2')),
|
||||
float(self.configReader.get('Robot_Feed', 'photo_y2')), float(self.configReader.get('Robot_Feed', 'photo_z2')),
|
||||
float(self.configReader.get('Robot_Feed', 'photo_u2')),float(self.configReader.get('Robot_Feed', 'photo_v2')),float(self.configReader.get('Robot_Feed', 'photo_w2'))
|
||||
),
|
||||
(int(self.configReader.get('Robot_Feed', 'photo_x3')),
|
||||
int(self.configReader.get('Robot_Feed', 'photo_y3')),int(self.configReader.get('Robot_Feed', 'photo_z3')),
|
||||
int(self.configReader.get('Robot_Feed', 'photo_u3')),int(self.configReader.get('Robot_Feed', 'photo_v3')),int(self.configReader.get('Robot_Feed', 'photo_w3'))
|
||||
(float(self.configReader.get('Robot_Feed', 'photo_x3')),
|
||||
float(self.configReader.get('Robot_Feed', 'photo_y3')),float(self.configReader.get('Robot_Feed', 'photo_z3')),
|
||||
float(self.configReader.get('Robot_Feed', 'photo_u3')),float(self.configReader.get('Robot_Feed', 'photo_v3')),float(self.configReader.get('Robot_Feed', 'photo_w3'))
|
||||
),
|
||||
(int(self.configReader.get('Robot_Feed', 'photo_x4')),
|
||||
int(self.configReader.get('Robot_Feed', 'photo_y4')),int(self.configReader.get('Robot_Feed', 'photo_z4')),
|
||||
int(self.configReader.get('Robot_Feed', 'photo_u4')),int(self.configReader.get('Robot_Feed', 'photo_v4')),int(self.configReader.get('Robot_Feed', 'photo_w4'))
|
||||
(float(self.configReader.get('Robot_Feed', 'photo_x4')),
|
||||
float(self.configReader.get('Robot_Feed', 'photo_y4')),float(self.configReader.get('Robot_Feed', 'photo_z4')),
|
||||
float(self.configReader.get('Robot_Feed', 'photo_u4')),float(self.configReader.get('Robot_Feed', 'photo_v4')),float(self.configReader.get('Robot_Feed', 'photo_w4'))
|
||||
),
|
||||
(int(self.configReader.get('Robot_Feed', 'photo_x5')),
|
||||
int(self.configReader.get('Robot_Feed', 'photo_y5')),int(self.configReader.get('Robot_Feed', 'photo_z5')),
|
||||
int(self.configReader.get('Robot_Feed', 'photo_u5')),int(self.configReader.get('Robot_Feed', 'photo_v5')),int(self.configReader.get('Robot_Feed', 'photo_w5'))
|
||||
(float(self.configReader.get('Robot_Feed', 'photo_x5')),
|
||||
float(self.configReader.get('Robot_Feed', 'photo_y5')),float(self.configReader.get('Robot_Feed', 'photo_z5')),
|
||||
float(self.configReader.get('Robot_Feed', 'photo_u5')),float(self.configReader.get('Robot_Feed', 'photo_v5')),float(self.configReader.get('Robot_Feed', 'photo_w5'))
|
||||
)
|
||||
]
|
||||
solenoid_valve1_addr = int(self.configReader.get('Robot_Feed', 'solenoid_valve1_addr'))
|
||||
solenoid_valve2_addr = int(self.configReader.get('Robot_Feed', 'solenoid_valve2_addr'))
|
||||
solenoid_valve3_addr = int(self.configReader.get('Robot_Feed', 'solenoid_valve3_addr'))
|
||||
time_delay_take = int(self.configReader.get('Robot_Feed', 'takeDelay'))
|
||||
time_delay_put = int(self.configReader.get('Robot_Feed', 'putDelay'))
|
||||
time_delay_shake = int(self.configReader.get('Robot_Feed', 'shakeDelay'))
|
||||
#TODO
|
||||
#dropDelay_time = int(self.configReader.get('Robot_Feed', 'dropDelay_time'))
|
||||
self.robotClient = RobotClient(ip, port, photo_locs, self.command_position_quene, self.status_address,[solenoid_valve1_addr, solenoid_valve2_addr, solenoid_valve3_addr])
|
||||
self.robotClient = RobotClient(ip, port, photo_locs, self.command_position_quene, self.status_address,[solenoid_valve1_addr, solenoid_valve2_addr, solenoid_valve3_addr],time_delay_take,time_delay_put,time_delay_shake)
|
||||
self.feeding = Feeding(self.robotClient, self.detection) # 临时
|
||||
self.last_time = time.time()
|
||||
self.remain_lineName = self.configReader.get('Robot_Feed', 'remain_lineName')
|
||||
@ -555,6 +559,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.main_threading.start()
|
||||
self.robot_connect_threading.start()
|
||||
|
||||
self.main_UI_threading = Thread(target=self.updateUI)
|
||||
self.main_UI_threading.start()
|
||||
|
||||
self.check_continue()
|
||||
pass
|
||||
def check_continue(self):
|
||||
@ -754,14 +761,23 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
solenoid1_addr = int(self.lineEdit_solenoid1_addr.text())
|
||||
solenoid2_addr = int(self.lineEdit_solenoid2_addr.text())
|
||||
solenoid3_addr = int(self.lineEdit_solenoid3_addr.text())
|
||||
time_delay_take = int(self.lineEdit_timedelay_take.text())
|
||||
time_delay_put = int(self.lineEdit_timedelay_put.text())
|
||||
time_delay_shake = int(self.lineEdit_timedelay_shake.text())
|
||||
self.robotClient.con_ios[0] = solenoid1_addr
|
||||
self.robotClient.con_ios[1] = solenoid2_addr
|
||||
self.robotClient.con_ios[2] = solenoid3_addr
|
||||
self.robotClient.time_delay_take = time_delay_take
|
||||
self.robotClient.time_delay_put = time_delay_put
|
||||
self.robotClient.time_delay_shake = time_delay_shake
|
||||
self.configReader = configparser.ConfigParser()
|
||||
self.configReader.read(Constant.set_ini)
|
||||
self.configReader.set('Robot_Feed', 'solenoid_valve1_addr', str(solenoid1_addr))
|
||||
self.configReader.set('Robot_Feed', 'solenoid_valve2_addr', str(solenoid2_addr))
|
||||
self.configReader.set('Robot_Feed', 'solenoid_valve3_addr', str(solenoid3_addr))
|
||||
self.configReader.set('Robot_Feed', 'takeDelay', str(time_delay_take))
|
||||
self.configReader.set('Robot_Feed', 'putDelay', str(time_delay_put))
|
||||
self.configReader.set('Robot_Feed', 'shakeDelay', str(time_delay_shake))
|
||||
|
||||
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
|
||||
except Exception as e:
|
||||
@ -972,7 +988,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.feedLine_dict[head].drop_bag_position.W = float(value)
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
while self.thread_signal:
|
||||
time.sleep(0.1)
|
||||
if not self.command_quene.empty():
|
||||
command = self.command_quene.get()
|
||||
@ -986,42 +1002,41 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.feeding.run()
|
||||
except:
|
||||
print(Error_Code.SYS_NONEPoint)
|
||||
self.updateUI()
|
||||
|
||||
|
||||
# pass #主线程
|
||||
|
||||
|
||||
def updateUI(self):
|
||||
if self.robotClient.connected:
|
||||
self.set_label_status_style(True)
|
||||
else:
|
||||
self.set_label_status_style(False)
|
||||
if self.feeding.feedStatus != FeedStatus.FNone:
|
||||
self.horizontalSlider_feedingNum.setValue(
|
||||
self.horizontalSlider_feedingNum.maximum() - self.feeding.feedConfig.num)
|
||||
self.label_remain_num.setText(str(self.feeding.feedConfig.num))
|
||||
try:
|
||||
self.configReader.read(Constant.set_ini)
|
||||
self.configReader.set('Robot_Feed', 'remain_linename', str(self.feeding.feedConfig.feedLine.id))
|
||||
self.configReader.set('Robot_Feed', 'remain_count', str(self.feeding.feedConfig.num))
|
||||
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
|
||||
except:
|
||||
log.log_message(logging.ERROR, Constant.str_sys_log_feedNum)
|
||||
else:
|
||||
self.set_run_status_button(False)
|
||||
if self.feeding.feedStatus == FeedStatus.FNone:
|
||||
self.stackedWidget_num.setCurrentIndex(0)
|
||||
else:
|
||||
self.stackedWidget_num.setCurrentIndex(1)
|
||||
while self.thread_signal:
|
||||
time.sleep(0.2)
|
||||
if self.robotClient.connected:
|
||||
self.set_label_status_style(True)
|
||||
else:
|
||||
self.set_label_status_style(False)
|
||||
if self.feeding.feedStatus != FeedStatus.FNone:
|
||||
self.horizontalSlider_feedingNum.setValue(
|
||||
self.horizontalSlider_feedingNum.maximum() - self.feeding.feedConfig.num)
|
||||
# self.label_remain_num.setText(str(self.feeding.feedConfig.num))
|
||||
else:
|
||||
self.set_run_status_button(False)
|
||||
if self.feeding.feedConfig!=None:
|
||||
self.label_remain_num.setText(str(self.feeding.feedConfig.num))
|
||||
|
||||
if self.feeding.feedStatus == FeedStatus.FNone:
|
||||
self.stackedWidget_num.setCurrentIndex(0)
|
||||
else:
|
||||
self.stackedWidget_num.setCurrentIndex(1)
|
||||
|
||||
|
||||
self.label_date.setText(datetime.now().strftime("%Y-%m-%d"))
|
||||
self.label_time.setText(datetime.now().strftime("%H:%M:%S"))
|
||||
self.label_date.setText(datetime.now().strftime("%Y-%m-%d"))
|
||||
self.label_time.setText(datetime.now().strftime("%H:%M:%S"))
|
||||
|
||||
self.updateUI_Position()
|
||||
self.updateUI_label_detection()
|
||||
self.updateUI_label_status()
|
||||
self.updateUI_frame_sign(self.feeding.feedStatus)
|
||||
self.updateUI_IOPanel()
|
||||
self.updateUI_Position()
|
||||
self.updateUI_label_detection()
|
||||
self.updateUI_label_status()
|
||||
self.updateUI_frame_sign(self.feeding.feedStatus)
|
||||
self.updateUI_IOPanel()
|
||||
|
||||
def updateUI_IOPanel(self):
|
||||
try:
|
||||
@ -1287,7 +1302,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
realPosition = self.robotClient.status_model.getRealPosition()
|
||||
self.lineEdit_x1.setText(str(realPosition.X))
|
||||
self.lineEdit_y1.setText(str(realPosition.Y))
|
||||
self.lineEdit_z1.setText(str(realPosition.Z)+"1")
|
||||
self.lineEdit_z1.setText(str(realPosition.Z))
|
||||
self.lineEdit_u1.setText(str(realPosition.U))
|
||||
self.lineEdit_v1.setText(str(realPosition.V))
|
||||
self.lineEdit_w1.setText(str(realPosition.W))
|
||||
@ -1297,7 +1312,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
realPosition = self.robotClient.status_model.getRealPosition()
|
||||
self.lineEdit_x2.setText(str(realPosition.X))
|
||||
self.lineEdit_y2.setText(str(realPosition.Y))
|
||||
self.lineEdit_z2.setText(str(realPosition.Z)+"2")
|
||||
self.lineEdit_z2.setText(str(realPosition.Z))
|
||||
self.lineEdit_u2.setText(str(realPosition.U))
|
||||
self.lineEdit_v2.setText(str(realPosition.V))
|
||||
self.lineEdit_w2.setText(str(realPosition.W))
|
||||
@ -1307,7 +1322,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
realPosition = self.robotClient.status_model.getRealPosition()
|
||||
self.lineEdit_x3.setText(str(realPosition.X))
|
||||
self.lineEdit_y3.setText(str(realPosition.Y))
|
||||
self.lineEdit_z3.setText(str(realPosition.Z)+"3")
|
||||
self.lineEdit_z3.setText(str(realPosition.Z))
|
||||
self.lineEdit_u3.setText(str(realPosition.U))
|
||||
self.lineEdit_v3.setText(str(realPosition.V))
|
||||
self.lineEdit_w3.setText(str(realPosition.W))
|
||||
@ -1316,7 +1331,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
realPosition = self.robotClient.status_model.getRealPosition()
|
||||
self.lineEdit_x4.setText(str(realPosition.X))
|
||||
self.lineEdit_y4.setText(str(realPosition.Y))
|
||||
self.lineEdit_z4.setText(str(realPosition.Z)+"4")
|
||||
self.lineEdit_z4.setText(str(realPosition.Z))
|
||||
self.lineEdit_u4.setText(str(realPosition.U))
|
||||
self.lineEdit_v4.setText(str(realPosition.V))
|
||||
self.lineEdit_w4.setText(str(realPosition.W))
|
||||
@ -1325,7 +1340,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
realPosition = self.robotClient.status_model.getRealPosition()
|
||||
self.lineEdit_x5.setText(str(realPosition.X))
|
||||
self.lineEdit_y5.setText(str(realPosition.Y))
|
||||
self.lineEdit_z5.setText(str(realPosition.Z)+"5")
|
||||
self.lineEdit_z5.setText(str(realPosition.Z))
|
||||
self.lineEdit_u5.setText(str(realPosition.U))
|
||||
self.lineEdit_v5.setText(str(realPosition.V))
|
||||
self.lineEdit_w5.setText(str(realPosition.W))
|
||||
@ -1442,12 +1457,33 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.lineEdit_x1.setText(str(self.robotClient.photo_locs[0][0]))
|
||||
self.lineEdit_y1.setText(str(self.robotClient.photo_locs[0][1]))
|
||||
self.lineEdit_z1.setText(str(self.robotClient.photo_locs[0][2]))
|
||||
self.lineEdit_u1.setText(str(self.robotClient.photo_locs[0][3]))
|
||||
self.lineEdit_v1.setText(str(self.robotClient.photo_locs[0][4]))
|
||||
self.lineEdit_w1.setText(str(self.robotClient.photo_locs[0][5]))
|
||||
self.lineEdit_x2.setText(str(self.robotClient.photo_locs[1][0]))
|
||||
self.lineEdit_y2.setText(str(self.robotClient.photo_locs[1][1]))
|
||||
self.lineEdit_z2.setText(str(self.robotClient.photo_locs[1][2]))
|
||||
self.lineEdit_u2.setText(str(self.robotClient.photo_locs[1][3]))
|
||||
self.lineEdit_v2.setText(str(self.robotClient.photo_locs[1][4]))
|
||||
self.lineEdit_w2.setText(str(self.robotClient.photo_locs[1][5]))
|
||||
self.lineEdit_x3.setText(str(self.robotClient.photo_locs[2][0]))
|
||||
self.lineEdit_y3.setText(str(self.robotClient.photo_locs[2][1]))
|
||||
self.lineEdit_z3.setText(str(self.robotClient.photo_locs[2][2]))
|
||||
self.lineEdit_u3.setText(str(self.robotClient.photo_locs[2][3]))
|
||||
self.lineEdit_v3.setText(str(self.robotClient.photo_locs[2][4]))
|
||||
self.lineEdit_w3.setText(str(self.robotClient.photo_locs[2][5]))
|
||||
self.lineEdit_x4.setText(str(self.robotClient.photo_locs[3][0]))
|
||||
self.lineEdit_y4.setText(str(self.robotClient.photo_locs[3][1]))
|
||||
self.lineEdit_z4.setText(str(self.robotClient.photo_locs[3][2]))
|
||||
self.lineEdit_u4.setText(str(self.robotClient.photo_locs[3][3]))
|
||||
self.lineEdit_v4.setText(str(self.robotClient.photo_locs[3][4]))
|
||||
self.lineEdit_w4.setText(str(self.robotClient.photo_locs[3][5]))
|
||||
self.lineEdit_x5.setText(str(self.robotClient.photo_locs[4][0]))
|
||||
self.lineEdit_y5.setText(str(self.robotClient.photo_locs[4][1]))
|
||||
self.lineEdit_z5.setText(str(self.robotClient.photo_locs[4][2]))
|
||||
self.lineEdit_u5.setText(str(self.robotClient.photo_locs[4][3]))
|
||||
self.lineEdit_v5.setText(str(self.robotClient.photo_locs[4][4]))
|
||||
self.lineEdit_w5.setText(str(self.robotClient.photo_locs[4][5]))
|
||||
pass
|
||||
def updateUI_Base_Set(self):
|
||||
self.lineEdit_speed_run.setText(str(Constant.speed))
|
||||
@ -1455,6 +1491,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.lineEdit_solenoid1_addr.setText(str(self.robotClient.con_ios[0]))
|
||||
self.lineEdit_solenoid2_addr.setText(str(self.robotClient.con_ios[1]))
|
||||
self.lineEdit_solenoid3_addr.setText(str(self.robotClient.con_ios[2]))
|
||||
self.lineEdit_timedelay_take.setText(str(self.robotClient.time_delay_take))
|
||||
self.lineEdit_timedelay_put.setText(str(self.robotClient.time_delay_put))
|
||||
self.lineEdit_timedelay_shake.setText(str(self.robotClient.time_delay_shake))
|
||||
|
||||
def show_infomessage_box(self,message):
|
||||
msg_box = QMessageBox(self)
|
||||
@ -1492,9 +1531,23 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
log.log_message(logging.INFO, f'关闭IO{index}')
|
||||
|
||||
def closeEvent(self, event):
|
||||
self.record_remain_num()
|
||||
self.detection.release()
|
||||
self.thread_signal = False
|
||||
self.robotClient.close()
|
||||
log.log_message(logging.INFO, Constant.str_sys_exit)
|
||||
|
||||
|
||||
def record_remain_num(self):
|
||||
try:
|
||||
self.configReader = configparser.ConfigParser()
|
||||
self.configReader.read(Constant.set_ini)
|
||||
self.configReader.set('Robot_Feed', 'remain_linename', str(self.feeding.feedConfig.feedLine.id))
|
||||
self.configReader.set('Robot_Feed', 'remain_count', str(self.feeding.feedConfig.num))
|
||||
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
|
||||
except:
|
||||
log.log_message(logging.ERROR, Constant.str_sys_log_feedNum)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = MainWindow()
|
||||
|
||||
Reference in New Issue
Block a user