Files
AutoControlSystem-G/main.py

2310 lines
116 KiB
Python
Raw Normal View History

2025-07-29 13:16:30 +08:00
import configparser
import copy
import json
import logging
import os
import queue
import random
import sys
import threading
from multiprocessing import Process
import traceback
import PySide6
import cv2
import numpy as np
from PyQt5.uic.properties import QtWidgets
from PySide6 import QtCore
from PySide6.QtCore import QThread, Signal, Slot, QObject, QEvent, QTimer
from PySide6.QtGui import QIntValidator, QStandardItemModel, QStandardItem, Qt, QMovie, QIcon, QCursor, QColor, \
QTextCursor
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QHeaderView, QTableWidget, \
2025-09-28 09:48:12 +08:00
QTableWidgetItem, QWidget, QHBoxLayout, QAbstractItemView, QMessageBox, QSizePolicy, QComboBox, QMenu, QDialog, QGridLayout
2025-07-29 13:16:30 +08:00
from datetime import datetime
from click import clear
import Util.util_pic
2025-08-15 12:08:30 +08:00
from Model.FeedModel import LineModel, PositionModel
2025-07-29 13:16:30 +08:00
from Util.util_ini import writeFeedLine_to_ini
import Constant
from CU.Command import FeedCommand
from CU.Feeding import FeedLine, FeedingConfig, Feeding, FeedStatus, FeedMidStatus, ResetStatus
from Util.util_log import QTextEditLogger
from Util.util_time import CRisOrFall
#from Vision.camera_coordinate_dete import Detection
from COM.COM_Robot import RobotClient
from Expection import Error_Code
from queue import Queue
from Model.RobotModel import *
import time
from queue import Queue
from Model.Position import Real_Position, Detection_Position
from threading import Thread
from CU.Command import Status
from Util.util_log import log
#from Vision.detect_person import DetectionPerson
from ui_MainWin import Ui_MainWindow
from view.ResetView import StopDialog
from EMV.EMV import RelayController
2025-09-28 09:48:12 +08:00
from CU.drop import DropPositionManager
2025-07-29 13:16:30 +08:00
class MainWindow(QMainWindow, Ui_MainWindow):
updateUI_seting = Signal()
def __init__(self):
super(MainWindow, self).__init__()
self.setupUi(self)
#传感器继电器加入变量
self.relay_controller = RelayController()
2025-09-28 09:48:12 +08:00
self.drop_position_manager = DropPositionManager()
2025-07-29 13:16:30 +08:00
self.sensor_thread = None
self.sensor2_thread = None
self.last_status_printed = None
self.last_pause_printed = None
2025-09-28 09:48:12 +08:00
self.cur_pushbutton_num = None
self.pushbutton_num_style = """
QPushButton { background-color: #101F3F;color:#ffffff }
"""
self.pushbutton_num_style_select = """
QPushButton { background-color: lightgreen; color: black; }
"""
2025-07-29 13:16:30 +08:00
#传感器加入变量结束
#self.setWindowFlags(Qt.WindowType.FramelessWindowHint)
self.thread_signal = True
self.init_qss()
self.init_UI()
self.init_Run()
self.init_robot_info()
self.init_IOPanel()
self.start_Runing()
self.init_log()
self.init_FeedLine()
self.init_table_lines()
self.init_table_position()
self.table_line_changed = False
self.table_position_changed = False
self.selected_line_section = ''
2025-09-28 09:48:12 +08:00
2025-07-29 13:16:30 +08:00
def init_IOPanel(self):
self.dirt_io_points = {}
self.dirt_io_points.setdefault('y1', self.widget_y1)
self.dirt_io_points.setdefault('y2', self.widget_y2)
self.dirt_io_points.setdefault('y3', self.widget_y3)
self.dirt_io_points.setdefault('y4', self.widget_y4)
self.dirt_io_points.setdefault('y5', self.widget_y5)
self.dirt_io_points.setdefault('y6', self.widget_y6)
self.dirt_io_points.setdefault('y7', self.widget_y7)
self.dirt_io_points.setdefault('y8', self.widget_y8)
self.dirt_io_points.setdefault('y9', self.widget_y9)
self.dirt_io_points.setdefault('y10', self.widget_y10)
self.dirt_io_points.setdefault('y11', self.widget_y11)
self.dirt_io_points.setdefault('y12', self.widget_y12)
self.dirt_io_points.setdefault('y13', self.widget_y13)
self.dirt_io_points.setdefault('y14', self.widget_y14)
self.dirt_io_points.setdefault('y15', self.widget_y15)
self.dirt_io_points.setdefault('y16', self.widget_y16)
self.dirt_io_points.setdefault('y17', self.widget_y17)
self.dirt_io_points.setdefault('y18', self.widget_y18)
self.dirt_io_points.setdefault('y19', self.widget_y19)
self.dirt_io_points.setdefault('y20', self.widget_y20)
self.dirt_io_points.setdefault('y21', self.widget_y21)
self.dirt_io_points.setdefault('y22', self.widget_y22)
self.dirt_io_points.setdefault('y23', self.widget_y23)
self.dirt_io_points.setdefault('y24', self.widget_y24)
self.dirt_io_points.setdefault('y25', self.widget_y25)
self.dirt_io_points.setdefault('y26', self.widget_y26)
self.dirt_io_points.setdefault('y27', self.widget_y27)
self.dirt_io_points.setdefault('y28', self.widget_y28)
self.dirt_io_points.setdefault('y29', self.widget_y29)
self.dirt_io_points.setdefault('y30', self.widget_y30)
self.dirt_io_points.setdefault('y31', self.widget_y31)
self.dirt_io_points.setdefault('y32', self.widget_y32)
self.widget_y1.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y1.index=1
self.widget_y2.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y2.index=2
self.widget_y3.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y3.index=3
self.widget_y4.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y4.index=4
self.widget_y5.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y5.index=5
self.widget_y6.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y6.index=6
self.widget_y7.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y7.index=7
self.widget_y8.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y8.index=8
self.widget_y9.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y9.index=9
self.widget_y10.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y10.index=10
self.widget_y11.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y11.index=11
self.widget_y12.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y12.index=12
self.widget_y13.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y13.index=13
self.widget_y14.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y14.index=14
self.widget_y15.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y15.index=15
self.widget_y16.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y16.index=16
self.widget_y17.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y17.index=17
self.widget_y18.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y18.index=18
self.widget_y19.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y19.index=19
self.widget_y20.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y20.index=20
self.widget_y21.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y21.index=21
self.widget_y22.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y22.index=22
self.widget_y23.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y23.index=23
self.widget_y24.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y24.index=24
self.widget_y25.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y25.index=25
self.widget_y26.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y26.index=26
self.widget_y27.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y27.index=27
self.widget_y28.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y28.index=28
self.widget_y29.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y29.index=29
self.widget_y30.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y30.index=30
self.widget_y31.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y31.index=31
self.widget_y32.clicked.connect(self.send_IO_Point_OpenOrClose)
self.widget_y32.index=32
# region 战线,点位表格初始化
def init_table_lines(self):
self.tableWidget_lines.setColumnCount(4)
self.tableWidget_lines.horizontalHeader().setStyleSheet(f"background-color: {QColor(44,44,44).name()};")
self.tableWidget_lines.verticalHeader().setStyleSheet(f"background-color: {QColor(44,44,44).name()};")
self.tableWidget_lines.verticalHeader().hide()
self.tableWidget_lines.setHorizontalHeaderLabels(["节名", "线名", "id", "操作"])
self.tableWidget_lines.setSelectionBehavior(QTableWidget.SelectRows)
self.tableWidget_lines.setAutoScroll(True)
self.tableWidget_lines. setColumnHidden(0,True)
self.tableWidget_lines. setColumnHidden(2,True)
# 自动调整列宽
header = self.tableWidget_lines.horizontalHeader()
header.setSectionResizeMode(0, PySide6.QtWidgets.QHeaderView.ResizeMode.Stretch)
header.setSectionResizeMode(1, PySide6.QtWidgets.QHeaderView.ResizeMode.Stretch)
header.setSectionResizeMode(2, PySide6.QtWidgets.QHeaderView.ResizeMode.Stretch)
self.tableWidget_lines.setContextMenuPolicy(PySide6.QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
self.tableWidget_lines.customContextMenuRequested.connect(self.show_lines_context_menu)
self.tableWidget_lines.cellChanged.connect(self.send_table_lines_cell_changed)
self.init_table_lines_data()
self.pushButton_savePosition.clicked.connect(self.send_save_lines_data)
def send_table_line_position_cell_changed(self):
self.table_position_changed = True
def send_table_lines_cell_changed(self):
self.table_line_changed = True
def send_save_lines_data(self):
if self.table_position_changed or self.table_line_changed:
section = self.selected_line_section
for row_i in range(self.tableWidget_lines.rowCount()):
if self.tableWidget_lines.item(row_i, 0).text() == section:
line_model = LineModel()
if len(self.get_table_positions()) == 0 and self.feedLine_dict.keys().__contains__(section):
line_model = self.feedLine_dict[section]
line_model.name = self.tableWidget_lines.item(row_i, 1).text()
else:
line_model.section = section
line_model.name = self.tableWidget_lines.item(row_i, 1).text()
line_model.id = int(self.tableWidget_lines.item(row_i, 2).text())
line_model.positions = self.get_table_positions()
2025-09-28 09:48:12 +08:00
if section.startswith(Constant.feedLine_set_section):
config_reader = configparser.ConfigParser()
config_reader.read(Constant.feedLine_set_file, encoding='utf-8')
if len(self.get_table_positions()) != 0 and line_model.id != self.get_table_positions()[0].lineId:
return
line_model.save_line_model(config_reader)
config_reader.write(open(Constant.feedLine_set_file, 'w', encoding='utf-8'))
elif section.startswith(Constant.dropLine_set_section):
self.drop_position_manager.save_path_points(line_model)
2025-07-29 13:16:30 +08:00
self.init_FeedLine()
break
self.init_table_lines_data()
self.table_line_changed = False
self.table_position_changed = False
def get_table_positions(self):
position_models = []
for row_i in range(self.tableWidget_line_positions.rowCount()):
section = self.tableWidget_line_positions.item(row_i, 0).text()
position_model = PositionModel(index=row_i)
position_model.section = section
position_model.X = float(self.tableWidget_line_positions.item(row_i, 1).text())
position_model.Y = float(self.tableWidget_line_positions.item(row_i, 2).text())
position_model.Z = float(self.tableWidget_line_positions.item(row_i, 3).text())
position_model.U = float(self.tableWidget_line_positions.item(row_i, 4).text())
position_model.V = float(self.tableWidget_line_positions.item(row_i, 5).text())
position_model.W = float(self.tableWidget_line_positions.item(row_i, 6).text())
combox_line_type = self.tableWidget_line_positions.cellWidget(row_i, 7)
position_model.lineType = combox_line_type.currentData()
combox_status = self.tableWidget_line_positions.cellWidget(row_i, 8)
position_model.status = combox_status.currentData()
position_model.id = int(self.tableWidget_line_positions.item(row_i, 9).text())
position_model.order = row_i
position_model.lineId = int(self.tableWidget_line_positions.item(row_i, 11).text())
position_models.append(position_model)
return position_models
def init_table_lines_data(self):
# self.tableWidget_lines.setItem(0, 0, QTableWidgetItem("线1"))
# self.tableWidget_lines.setItem(1, 0, QTableWidgetItem("线2"))
# self.tableWidget_lines.setItem()
self.tableWidget_lines.blockSignals(True)
self.selected_line_section = ''
self.table_line_changed = False
self.table_position_changed = False
self.tableWidget_lines.setRowCount(0)
2025-09-28 09:48:12 +08:00
last_item_index=len(self.feedLine_dict.items())+1
2025-07-29 13:16:30 +08:00
for key, value in self.feedLine_dict.items():
2025-09-28 09:48:12 +08:00
self.init_table_lines_item(key,value.name,value.id)
# self.init_table_lines_item('feedline'+str(last_item_index),'码垛路径',last_item_index)
2025-07-29 13:16:30 +08:00
self.tableWidget_line_positions.setRowCount(0)
self.tableWidget_lines.blockSignals(False)
2025-09-28 09:48:12 +08:00
def init_table_lines_item(self,key,name,id):
self.tableWidget_lines.insertRow(self.tableWidget_lines.rowCount())
self.tableWidget_lines.setItem(self.tableWidget_lines.rowCount()-1, 0, QTableWidgetItem(key))
self.tableWidget_lines.setItem(self.tableWidget_lines.rowCount()-1, 1, QTableWidgetItem(name))
self.tableWidget_lines.setItem(self.tableWidget_lines.rowCount()-1, 2, QTableWidgetItem(str(id)))
show_pos_btn = QPushButton("显示路径")
show_pos_btn.clicked.connect(
lambda _, index=self.tableWidget_lines.rowCount()-1: self.show_lines_pos_data(index))
self.tableWidget_lines.setCellWidget(self.tableWidget_lines.rowCount() - 1, 3, show_pos_btn)
self.selected_line_section = ''
2025-07-29 13:16:30 +08:00
def show_lines_context_menu(self):
menu = QMenu(self)
action_add = menu.addAction("添加投料线")
action_del = menu.addAction("删除投料线")
action = menu.exec(QCursor.pos())
if action == action_add:
self.add_new_line()
elif action == action_del:
self.del_line()
def del_line(self):
if self.tableWidget_lines.rowCount()==0:
return
if self.tableWidget_lines.currentRow()==-1:
return
self.tableWidget_lines.removeRow(self.tableWidget_lines.currentRow())
self.table_line_changed = True
def add_new_line(self):
add_section = f'{Constant.feedLine_set_section}{1}'
for i in range(1,Constant.MAX_Line_num):
if not self.feedLine_dict.get(f"{Constant.feedLine_set_section}{i}"):
add_section = f"{Constant.feedLine_set_section}{i}"
break
self.tableWidget_lines.insertRow(self.tableWidget_lines.rowCount())
self.tableWidget_lines.setItem(self.tableWidget_lines.rowCount()-1, 0, QTableWidgetItem(add_section))
self.tableWidget_lines.setItem(self.tableWidget_lines.rowCount()-1, 1, QTableWidgetItem("线" + str(self.tableWidget_lines.rowCount())))
self.tableWidget_lines.setItem(self.tableWidget_lines.rowCount()-1, 2, QTableWidgetItem(str(i)))
show_pos_btn = QPushButton("显示路径")
show_pos_btn.clicked.connect(lambda _, index=self.tableWidget_lines.rowCount()-1: self.show_lines_pos_data(index))
self.tableWidget_lines.setCellWidget(self.tableWidget_lines.rowCount()-1, 3,show_pos_btn)
self.table_position_changed = True
self.feedLine_dict[add_section] = LineModel(i)
def show_lines_pos_data(self,line_index):
if self.selected_line_section!='' and self.selected_line_section != self.tableWidget_lines.item(line_index,0).text():
if self.table_position_changed or self.table_line_changed:
msgBox = QMessageBox()
msgBox.setText("已修改的数据,是否保存?")
msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
result = msgBox.exec()
if result == QMessageBox.StandardButton.Ok:
self.send_save_lines_data()
return
else:
# 重新初始化·
self.init_table_lines_data()
self.table_line_changed = False
self.table_position_changed = False
line_name = self.tableWidget_lines.item(line_index,0).text()
line_model = self.feedLine_dict.get(line_name)
self.init_table_positions_data(line_model.positions)
self.selected_line_section = line_name
self.label_table_line_position_title.setText(line_model.name)
def init_table_position(self):
#self.tableWidget_line_positions.setRowCount(5)
self.tableWidget_line_positions.setColumnCount(14)
self.tableWidget_line_positions.setHorizontalHeaderLabels(["节段","X","Y","Z","U","V","W","运动类型","点位类型","序号","排序","线号","操作1","操作2"])
self.tableWidget_line_positions.setSelectionBehavior(QTableWidget.SelectRows)
self.tableWidget_line_positions.setColumnHidden(0, True)
self.tableWidget_line_positions.setColumnHidden(9,True)
self.tableWidget_line_positions.setColumnHidden(10, True)
self.tableWidget_line_positions.setColumnHidden(11, True)
self.tableWidget_line_positions.setAutoScroll(True)
self.tableWidget_line_positions.verticalHeader().hide()
# 自动调整列宽
header = self.tableWidget_line_positions.horizontalHeader()
header.setSectionResizeMode(0, PySide6.QtWidgets.QHeaderView.ResizeMode.Interactive)
self.tableWidget_line_positions.setHorizontalScrollBarPolicy(PySide6.QtCore.Qt.ScrollBarPolicy.ScrollBarAsNeeded)
for i in range(14):
header.setSectionResizeMode(i, PySide6.QtWidgets.QHeaderView.ResizeMode.Interactive)
self.tableWidget_line_positions.setContextMenuPolicy(PySide6.QtCore.Qt.ContextMenuPolicy.CustomContextMenu)
self.tableWidget_line_positions.customContextMenuRequested.connect(self.show_positions_context_menu)
self.tableWidget_line_positions.cellChanged.connect(self.send_table_line_position_cell_changed)
def init_table_positions_data(self,position_list):
self.tableWidget_line_positions.blockSignals(True)
self.tableWidget_line_positions.setRowCount(0)
for index,position_model in enumerate(position_list):
self.tableWidget_line_positions.insertRow(self.tableWidget_line_positions.rowCount())
self.set_positionModel_to_tabel(index,position_model)
self.tableWidget_line_positions.blockSignals(False)
def show_positions_context_menu(self):
menu = QMenu(self)
action_add = menu.addAction("添加位置节点")
action_del = menu.addAction("删除位置节点")
action = menu.exec(QCursor.pos())
if action == action_add:
self.add_new_position()
elif action == action_del:
self.del_position()
def del_position(self):
if self.tableWidget_line_positions.rowCount()==0:
return
if self.tableWidget_line_positions.currentRow()==-1:
return
section = self.tableWidget_line_positions.item(self.tableWidget_line_positions.currentRow(),0).text()
id = int(self.tableWidget_line_positions.item(self.tableWidget_line_positions.currentRow(), 9).text())
line_model = self.feedLine_dict.get(self.selected_line_section)
for pos_model in line_model.positions:
if pos_model.id == id:
line_model.positions.remove(pos_model)
break
self.tableWidget_line_positions.removeRow(self.tableWidget_line_positions.currentRow())
2025-09-28 09:48:12 +08:00
if self.selected_line_section.startswith(Constant.dropLine_set_section):
self.drop_position_manager.del_drop_point(section)
else:
config_writer = configparser.ConfigParser()
config_writer.read(Constant.feedLine_set_file, encoding = 'utf-8')
config_writer.remove_section(section)
config_writer.write(open(Constant.feedLine_set_file,'w',encoding='utf-8'))
2025-07-29 13:16:30 +08:00
self.table_position_changed = True
def add_new_position(self):# 选中添加
if self.selected_line_section == '': return
config_reader = configparser.ConfigParser()
config_reader.read(Constant.feedLine_set_file, encoding = 'utf-8')
position_model = PositionModel(999)
ids = []
for j in range(self.tableWidget_line_positions.rowCount()):
ids.append(int(self.tableWidget_line_positions.item(j, 9).text()))
for i in range(1,Constant.MAX_Position_num):
if not config_reader.has_section(f"{Constant.position_set_section}{i}"):
if ids.__contains__(i):
continue
position_model = PositionModel(i)
break
if self.tableWidget_line_positions.currentRow()==-1:
row_i = self.tableWidget_line_positions.rowCount()
else:
row_i = self.tableWidget_line_positions.currentRow()
# self.tableWidget_line_positions.setRowCount(self.tableWidget_line_positions.rowCount()+1)
self.tableWidget_line_positions.insertRow(row_i+1)
position_model.order = 0
position_model.status = 1
line_model = self.feedLine_dict.get(self.selected_line_section)
line_id = line_model.id
position_model.lineId = line_id
self.set_positionModel_to_tabel(row_i+1,position_model)
self.table_line_changed = True
def tabel_move_position(self,row_i):
if self.tableWidget_line_positions.currentRow()==-1:
QMessageBox.information(self, "提示", Constant.str_sys_set_position_error)
return
row_i = self.tableWidget_line_positions.currentRow()
combox_line_type = self.tableWidget_line_positions.cellWidget(row_i, 7)
lineType = combox_line_type.currentData()
p1 = Real_Position().init_position(
float(self.tableWidget_line_positions.item(row_i, 1).text()),
float(self.tableWidget_line_positions.item(row_i, 2).text()),
float(self.tableWidget_line_positions.item(row_i, 3).text()),
float(self.tableWidget_line_positions.item(row_i, 4).text()),
float(self.tableWidget_line_positions.item(row_i, 5).text()),
float(self.tableWidget_line_positions.item(row_i, 6).text()),
)
if lineType == 0: #直线
if row_i != 0:
combox_line_type_inner = self.tableWidget_line_positions.cellWidget(row_i-1, 7)
lineType_inner = combox_line_type_inner.currentData()
if lineType_inner == 2:
p2 = Real_Position().init_position(
float(self.tableWidget_line_positions.item(row_i-1, 1).text()),
float(self.tableWidget_line_positions.item(row_i-1, 2).text()),
float(self.tableWidget_line_positions.item(row_i-1, 3).text()),
float(self.tableWidget_line_positions.item(row_i-1, 4).text()),
float(self.tableWidget_line_positions.item(row_i-1, 5).text()),
float(self.tableWidget_line_positions.item(row_i-1, 6).text()),
)
self.send_position_command(x1=p1.X, x2=p1.Y, x3=p1.Z, x4=p1.U, x5=p1.V, x6=p1.W, move_type=MoveType.Cure, speed=self.robotClient.debug_speed, p2=p2)
return
self.send_position_command(x1=p1.X, x2=p1.Y, x3=p1.Z, x4=p1.U, x5=p1.V, x6=p1.W, move_type=MoveType.WORLD,speed=self.robotClient.debug_speed)
return
if lineType == 4: # 自由路径
self.send_position_command(x1=p1.X, x2=p1.Y, x3=p1.Z, x4=p1.U, x5=p1.V, x6=p1.W, move_type=MoveType.AXIS,speed=self.robotClient.debug_speed)
return
def tabel_get_position(self,row_i):
if self.tableWidget_line_positions.currentRow()==-1:
QMessageBox.information(self, "提示", Constant.str_sys_set_position_error)
return
row_i = self.tableWidget_line_positions.currentRow()
combox_line_type = self.tableWidget_line_positions.cellWidget(row_i, 7)
lineType = combox_line_type.currentData()
if lineType == 4:
self.set_position_tabel(row_i, self.status_address.getAnglePosition())
else:
self.set_position_tabel(row_i, self.status_address.getRealPosition())
self.table_line_changed = True
def tabel_delete_position(self,row_i):
self.tableWidget_line_positions.removeRow(row_i)
self.table_line_changed = True
def set_positionModel_to_tabel(self,row_i,position_model:PositionModel):
self.tableWidget_line_positions.setItem(row_i,0,QTableWidgetItem(str(position_model.section)))
self.set_position_tabel(row_i,position_model.get_position())
combox_lineType = QComboBox()
combox_lineType.addItem("直线",0)
combox_lineType.addItem("曲线中间点",2)
combox_lineType.addItem("曲线终点",3)
2025-09-10 09:16:57 +08:00
#自由路径修改成关节坐标
combox_lineType.addItem("关节",4)
2025-07-29 13:16:30 +08:00
combox_lineType.setCurrentIndex(combox_lineType.findData(position_model.lineType))
2025-09-28 09:48:12 +08:00
combox_lineType.wheelEvent=lambda e:None
2025-07-29 13:16:30 +08:00
combox_lineType.currentIndexChanged.connect(self.send_table_position_status_changed)
self.tableWidget_line_positions.setCellWidget(row_i, 7, combox_lineType)
combox = QComboBox()
combox.addItem("初始化点", 2)
combox.addItem("中间点", 3)
combox.addItem("相机/待抓点",4)
combox.addItem("抓取前点", 3)
combox.addItem("抓取",5)
combox.addItem("抓取后点", 3)
combox.addItem("破带点1",6)
2025-09-28 09:48:12 +08:00
combox.addItem("码垛前点",7)
2025-07-29 13:16:30 +08:00
combox.addItem("震动点",8)
2025-09-28 09:48:12 +08:00
combox.addItem("码垛点",9)
combox.addItem("码垛后点",10)
2025-07-29 13:16:30 +08:00
combox.setCurrentIndex(combox.findData(position_model.status))
2025-09-28 09:48:12 +08:00
combox.wheelEvent=lambda e:None
2025-07-29 13:16:30 +08:00
combox.currentIndexChanged.connect(self.send_table_position_status_changed)
self.tableWidget_line_positions.setCellWidget(row_i, 8, combox)
#self.tableWidget_line_positions.setItem(row_i, 7, QTableWidgetItem(str(position_model.status)))
self.tableWidget_line_positions.setItem(row_i, 9, QTableWidgetItem(str(position_model.id)))
self.tableWidget_line_positions.setItem(row_i, 10, QTableWidgetItem(str(position_model.order)))
self.tableWidget_line_positions.setItem(row_i, 11, QTableWidgetItem(str(position_model.lineId)))
get_pos_btn = QPushButton("获取点位")
get_pos_btn.clicked.connect(
lambda _, index=row_i: self.tabel_get_position(index))
self.tableWidget_line_positions.setCellWidget(row_i, 12, get_pos_btn)
move_pos_btn = QPushButton("移至点位")
move_pos_btn.clicked.connect(lambda _, index=row_i: self.tabel_move_position(index))
self.tableWidget_line_positions.setCellWidget(row_i, 13, move_pos_btn)
def send_table_position_status_changed(self):
self.table_position_changed = True
def set_position_tabel(self, row_i, position):
self.tableWidget_line_positions.setItem(row_i, 1, QTableWidgetItem(str(position.X)))
self.tableWidget_line_positions.setItem(row_i, 2, QTableWidgetItem(str(position.Y)))
self.tableWidget_line_positions.setItem(row_i, 3, QTableWidgetItem(str(position.Z)))
self.tableWidget_line_positions.setItem(row_i, 4, QTableWidgetItem(str(position.U)))
self.tableWidget_line_positions.setItem(row_i, 5, QTableWidgetItem(str(position.V)))
self.tableWidget_line_positions.setItem(row_i, 6, QTableWidgetItem(str(position.W)))
#endregion
def init_qss(self):
pass
def init_log(self):
log.log_info_signal.connect(self.log_info_message)
log.log_error_signal.connect(self.log_error_message)
log.log_warning_signal.connect(self.log_warning_message)
log.init_log(self.textEdit_log_info, self.textEdit_log_error, Constant.log_file_path)
log.log_message(logging.INFO, Constant.str_sys_start)
def log_info_message(self,message):
now = datetime.now()
formatted_time = now.strftime("%Y-%m-%d %H:%M:%S")
self.textEdit_log_info.append(f'{formatted_time}-提示: {message}')
def log_warning_message(self,message):
now = datetime.now()
formatted_time = now.strftime("%Y-%m-%d %H:%M:%S")
self.textEdit_log_info.append(f'{formatted_time}-注意: {message}')
self.textEdit_log_error.append(f'{formatted_time}-注意: {message}')
def log_error_message(self,message):
now = datetime.now()
formatted_time = now.strftime("%Y-%m-%d %H:%M:%S")
self.textEdit_log_info.append(f'{formatted_time}-报警: {message}')
self.textEdit_log_error.append(f'{formatted_time}-报警: {message}')
if self.tabWidget.currentIndex() != 1:
self.tabWidget.setCurrentIndex(1)
def init_UI(self):
2025-09-28 09:48:12 +08:00
# 设置样式表,自定义选中行的颜色
self.tableWidget_line_positions.setStyleSheet("""
QTableWidget::item:selected {
background-color: #888888;
}
""")
self.label_showDetection.setScaledContents(True)
if self.label_showDetection.size().width() < 100 or self.label_showDetection.size().height() < 100:
self.label_showDetection.setMinimumSize(541, 321)
self.timer_updateui=QTimer(self)
# self.pushButton_num1.clicked.connect(self.send_num_button_click)
# self.pushButton_num2.clicked.connect(self.send_num_button_click)
# self.pushButton_num3.clicked.connect(self.send_num_button_click)
# self.pushButton_num4.clicked.connect(self.send_num_button_click)
# self.pushButton_num5.clicked.connect(self.send_num_button_click)
# self.pushButton_num6.clicked.connect(self.send_num_button_click)
2025-07-29 13:16:30 +08:00
self.lineEdit_j1.returnPressed.connect(self.send_position_returnPressed)
self.lineEdit_j2.returnPressed.connect(self.send_position_returnPressed)
self.lineEdit_j3.returnPressed.connect(self.send_position_returnPressed)
self.lineEdit_j4.returnPressed.connect(self.send_position_returnPressed)
self.lineEdit_j5.returnPressed.connect(self.send_position_returnPressed)
self.lineEdit_j6.returnPressed.connect(self.send_position_returnPressed)
self.pushButton_sendMove.clicked.connect(self.send_position_returnPressed)
self.pushButton_j1_sub.clicked.connect(self.send_subOneAsix_button_click)
self.pushButton_j2_sub.clicked.connect(self.send_subOneAsix_button_click)
self.pushButton_j3_sub.clicked.connect(self.send_subOneAsix_button_click)
self.pushButton_j4_sub.clicked.connect(self.send_subOneAsix_button_click)
self.pushButton_j5_sub.clicked.connect(self.send_subOneAsix_button_click)
self.pushButton_j6_sub.clicked.connect(self.send_subOneAsix_button_click)
self.pushButton_j1_add.clicked.connect(self.send_addOneAsix_button_click)
self.pushButton_j2_add.clicked.connect(self.send_addOneAsix_button_click)
self.pushButton_j3_add.clicked.connect(self.send_addOneAsix_button_click)
self.pushButton_j4_add.clicked.connect(self.send_addOneAsix_button_click)
self.pushButton_j5_add.clicked.connect(self.send_addOneAsix_button_click)
self.pushButton_j6_add.clicked.connect(self.send_addOneAsix_button_click)
2025-09-28 09:48:12 +08:00
self.pushButton_stopFeed.clicked.connect(self.send_emergency_alarm_command)
2025-07-29 13:16:30 +08:00
self.pushButton_pauseFeed.clicked.connect(self.send_pauseFeed_button_click)
self.pushButton_get_p1.clicked.connect(self.get_p1_button_click)
self.pushButton_get_p2.clicked.connect(self.get_p2_button_click)
self.pushButton_get_p3.clicked.connect(self.get_p3_button_click)
self.pushButton_get_p4.clicked.connect(self.get_p4_button_click)
self.pushButton_get_p5.clicked.connect(self.get_p5_button_click)
self.pushButton_get_origin.clicked.connect(self.get_origin_button_click)
self.pushButton_set_p1.clicked.connect(self.set_p1_button_click)
self.pushButton_set_p2.clicked.connect(self.set_p2_button_click)
self.pushButton_set_p3.clicked.connect(self.set_p3_button_click)
self.pushButton_set_p4.clicked.connect(self.set_p4_button_click)
self.pushButton_set_p5.clicked.connect(self.set_p5_button_click)
self.pushButton_set_origin.clicked.connect(self.set_origin_button_click)
self.pushButton_clearAlarm.clicked.connect(self.send_clear_alarm_command)
2025-09-28 09:48:12 +08:00
# self.pushButton_emergency.clicked.connect(self.send_emergency_alarm_command)
2025-07-29 13:16:30 +08:00
self.pushButton_reset.clicked.connect(self.send_reset_button_click)
self.pushButton_saveSeting.clicked.connect(self.send_setSpeed_clicked)
self.pushButton_num_confirm.clicked.connect(self.send_custom_num_returnPressed)
2025-09-28 09:48:12 +08:00
self.pushButton_numkeybord.clicked.connect(self.send_numkeybord_click)
2025-07-29 13:16:30 +08:00
#self.tabWidget_control.currentChanged.connect(self.send_tabWidget_control_change)
self.frame_sys_seting.setVisible(False)
self.pushButton_sysseting.clicked.connect(self.send_click_sysmeuExpand)
self.pushButton_leftmenu_produce.clicked.connect(lambda _, index=0: self.send_click_change_stackView(index))
self.pushButton_leftmenu_robot_seting.clicked.connect(
lambda _, index=2: self.send_click_change_stackView(index))
self.pushButton_leftmenu_IO.clicked.connect(lambda _, index=1: self.send_click_change_stackView(index))
self.pushButton_leftmenu_position.clicked.connect(lambda _, index=5: self.send_click_change_stackView(index))
self.pushButton_leftmenu_baseSeting.clicked.connect(lambda _, index=3: self.send_click_change_stackView(index))
self.pushButton_leftmenu_posDebug.clicked.connect(lambda _, index=4: self.send_click_change_stackView(index))
self.pushButton_exit.clicked.connect(self.send_exit_button_click)
2025-09-28 09:48:12 +08:00
# self.pushButton_onekeyfeed.clicked.connect(self.send_onekeyfeed_button_click)
self.comboBox_lineIndex.wheelEvent=lambda e:None
2025-07-29 13:16:30 +08:00
int_validator = QIntValidator(0, 100, self.lineEdit_num)
self.lineEdit_num.setValidator(int_validator)
# self.horizontalSlider_J1.sliderReleased
self.pushButton_startFeed.clicked.connect(self.send_startFeed_button_click)
self.horizontalSlider_feedingNum.blockSignals(True)
self.horizontalSlider_feedingNum.setMinimum(0)
def init_Run(self):
self.robotClient = None
self.configReader = configparser.ConfigParser()
#TODO 关闭图像
self.command_position_quene = Queue()
self.status_address = DataAddress()
self.feedLine_dict = {}
self.command_quene = Queue()
self.main_threading = None
self.detection_person = None # DetectionPerson()
self.index = 1
self.configReader.read(Constant.set_ini)
ip = self.configReader.get('Robot_Feed', 'IPAddress')
port = int(self.configReader.get('Robot_Feed', 'Port'))
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'))
),
(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'))
),
(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'))
),
(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'))
)
]
origin_position = Real_Position().init_position(float(self.configReader.get('Origin', 'X')),
float(self.configReader.get('Origin', 'Y')),
float(self.configReader.get('Origin', 'Z')),
float(self.configReader.get('Origin', 'U')),
float(self.configReader.get('Origin', 'V')),
float(self.configReader.get('Origin', 'W')))
debug_speed = int(self.configReader.get('Speed', 'debug_speed'))
feed_speed = int(self.configReader.get('Speed', 'feed_speed'))
reset_speed = int(self.configReader.get('Speed', 'reset_speed'))
io_take_addr = int(self.configReader.get('Robot_Feed', 'io_take_addr'))
io_zip_addr = int(self.configReader.get('Robot_Feed', 'io_zip_addr'))
io_shake_addr = int(self.configReader.get('Robot_Feed', 'io_shake_addr'))
time_delay_take = float(self.configReader.get('Robot_Feed', 'takeDelay'))
time_delay_put = float(self.configReader.get('Robot_Feed', 'putDelay'))
time_delay_shake = float(self.configReader.get('Robot_Feed', 'shakeDelay'))
max_angle_interval = float(self.configReader.get('Robot_Feed', 'max_angle_interval'))
smooth = int(self.configReader.get('Robot_Feed', 'smooth'))
dynamic_height = float(self.configReader.get('Robot_Feed', 'dynamic_height'))
#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,[io_take_addr, io_zip_addr, io_shake_addr],time_delay_take,time_delay_put,time_delay_shake,origin_position)
self.robotClient.debug_speed = debug_speed
self.robotClient.feed_speed = feed_speed
self.robotClient.reset_speed = reset_speed
self.robotClient.max_angle_interval = max_angle_interval
self.robotClient.smooth = smooth
self.robotClient.dynamic_height = dynamic_height
2025-09-28 09:48:12 +08:00
self.feeding = Feeding(self.robotClient,self.relay_controller)
2025-07-29 13:16:30 +08:00
self.feeding.need_origin_signal.connect(self.show_infomessage_box)
2025-09-28 09:48:12 +08:00
self.feeding.take_photo_sigal.connect(self.show_photo_message)
# self.feeding.update_detect_image.connect(self.updateUI_label_detection)
# self.camera_img.update_camera_image.connect(self.updateUI_label_detection)
2025-07-29 13:16:30 +08:00
self.feeding.log_signal.connect(self.log_message)
2025-09-10 09:16:57 +08:00
self.feeding.stack_finish_signal.connect(self.stack_finish)
2025-09-28 09:48:12 +08:00
# self.camera_img=CameraImg(self.feeding)
# self.camera_img.update_camera_image.connect(self.updateUI_label_detection)
2025-07-29 13:16:30 +08:00
self.last_time = time.time()
self.remain_lineName = self.configReader.get('Robot_Feed', 'remain_lineName')
self.remain_Count = int(self.configReader.get('Robot_Feed', 'remain_Count'))
2025-09-28 09:48:12 +08:00
self.maduo_Count = int(self.configReader.get('Robot_Feed', 'maduo_Count'))
self.label_remain_num.setText(str(self.remain_Count))
self.label_maxNum.setText(str(self.maduo_Count))
_cur_sel_button=[button for button in self.frame_23.findChildren(QPushButton) if button.text()==str(self.maduo_Count)]
if _cur_sel_button:
_cur_sel_button[0].setStyleSheet(self.pushbutton_num_style_select)
self.cur_pushbutton_num = _cur_sel_button[0]
self.horizontalSlider_feedingNum.setMaximum(self.maduo_Count)
2025-07-29 13:16:30 +08:00
self.updateUI_seting.connect(self.update_seting_frame)
try:
self.robotClient.CreatConnect()
except:
self.set_label_status_style(False)
return Error_Code.SYS_NETERROR
if self.robotClient.connected:
return 0
else:
return Error_Code.SYS_NETERROR
def init_seting_frame(self):
rows = len(self.feedLine_dict.keys()) + 1
self.tableWidget_feedSeting.setRowCount(rows)
self.tableWidget_feedSeting.setColumnCount(20+2*6)
# 设置第一重表头的合并 (三列一组)
self.tableWidget_feedSeting_addtional_col_num = 2
self.tableWidget_feedSeting.setSpan(0, 0 + self.tableWidget_feedSeting_addtional_col_num, 1, 6) # 合并前3列
self.tableWidget_feedSeting.setSpan(0, 6 + self.tableWidget_feedSeting_addtional_col_num, 1, 6) # 合并后3列
self.tableWidget_feedSeting.setSpan(0, 12 + self.tableWidget_feedSeting_addtional_col_num, 1, 6) # 合并后3列
self.tableWidget_feedSeting.setSpan(0, 18 + self.tableWidget_feedSeting_addtional_col_num, 1, 6) # 合并后3列
self.tableWidget_feedSeting.setSpan(0, 24 + self.tableWidget_feedSeting_addtional_col_num, 1, 6) # 合并后3列
self.tableWidget_feedSeting.itemChanged.connect(self.send_tabelFeedSet_itemChanged)
btn_safe = QPushButton("获取安全位置")
widget_safe = QWidget()
layout_safe = QHBoxLayout()
layout_safe.addWidget(btn_safe)
# 调整布局的间距,使之更紧凑
layout_safe.setContentsMargins(0, 0, 0, 0)
# 将布局设置到 QWidget 容器中
widget_safe.setLayout(layout_safe)
btn_bk1 = QPushButton("获取破袋位置1")
widget_bk1 = QWidget()
layout_bk1 = QHBoxLayout()
layout_bk1.addWidget(btn_bk1)
# 调整布局的间距,使之更紧凑
layout_bk1.setContentsMargins(0, 0, 0, 0)
# 将布局设置到 QWidget 容器中
widget_bk1.setLayout(layout_bk1)
btn_bk2 = QPushButton("获取破袋位置2")
widget_bk2 = QWidget()
layout_bk2 = QHBoxLayout()
layout_bk2.addWidget(btn_bk2)
# 调整布局的间距,使之更紧凑
layout_bk2.setContentsMargins(0, 0, 0, 0)
# 将布局设置到 QWidget 容器中
widget_bk2.setLayout(layout_bk2)
btn_shake = QPushButton("获取摇晃位置")
widget_shake = QWidget()
layout_shake = QHBoxLayout()
layout_shake.addWidget(btn_shake)
layout_shake.setContentsMargins(0, 0, 0, 0)
widget_shake.setLayout(layout_shake)
btn_dropbag = QPushButton("获取丢袋位置")
widget_dropbag = QWidget()
layout_dropbag = QHBoxLayout()
layout_dropbag.addWidget(btn_dropbag)
# 调整布局的间距,使之更紧凑
layout_dropbag.setContentsMargins(0, 0, 0, 0)
# 将布局设置到 QWidget 容器中
widget_dropbag.setLayout(layout_dropbag)
btn_safe.clicked.connect(self.send_get_safe_position_button_click)
btn_bk1.clicked.connect(self.send_get_broken1_position_button_click)
btn_bk2.clicked.connect(self.send_get_broken2_position_button_click)
btn_shake.clicked.connect(self.send_get_shake_position_button_click)
btn_dropbag.clicked.connect(self.send_get_dropbag_position_button_click)
# 添加第一重表头项
self.tableWidget_feedSeting.setCellWidget(0, 0 + self.tableWidget_feedSeting_addtional_col_num, widget_safe)
self.tableWidget_feedSeting.setCellWidget(0, 6 + self.tableWidget_feedSeting_addtional_col_num, widget_bk1)
self.tableWidget_feedSeting.setCellWidget(0, 12 + self.tableWidget_feedSeting_addtional_col_num, widget_bk2)
self.tableWidget_feedSeting.setCellWidget(0, 18 + self.tableWidget_feedSeting_addtional_col_num, widget_shake)
self.tableWidget_feedSeting.setCellWidget(0, 24 + self.tableWidget_feedSeting_addtional_col_num, widget_dropbag)
self.tableWidget_feedSeting.setSelectionBehavior(QTableWidget.SelectRows)
self.tableWidget_feedSeting.setAutoScroll(True)
# 添加第二重表头
self.tableWidget_feedSeting.setHorizontalHeaderLabels(
['header', '线名', 'X1', 'Y1', 'Z1', 'U1', 'V1', 'W1', 'X2', 'Y2', 'Z2', 'U2', 'V2', 'W2', 'X3', 'Y3', 'Z3',
'U3', 'V3', 'W3', 'X4', 'Y4', 'Z4', 'U4', 'V4', 'W4', 'X5', 'Y5', 'Z5', 'U5', 'V5', 'W5'])
self.tableWidget_feedSeting.hideColumn(0)
# 填充数据行
for row, (feed_line_key, feed_line) in enumerate(self.feedLine_dict.items()):
self.tableWidget_feedSeting.setItem(row + 1, 0, QTableWidgetItem(feed_line_key))
self.tableWidget_feedSeting.setItem(row + 1, 1, QTableWidgetItem(feed_line.name))
self.set_position_to_tabel(row + 1, 0, feed_line.safe_position)
self.set_position_to_tabel(row + 1, 1, feed_line.broken1_position)
self.set_position_to_tabel(row + 1, 2, feed_line.broken2_position)
self.set_position_to_tabel(row + 1, 3, feed_line.broken2_position)
self.set_position_to_tabel(row + 1, 4, feed_line.drop_bag_position)
# 禁用自动表头
self.tableWidget_feedSeting.verticalHeader().setVisible(True)
self.pushButton_tableFeedSet_addRow.clicked.connect(self.send_tabelFeedSet_addRow)
self.pushButton_tableFeedSet_deleRow.clicked.connect(self.send_tabelFeedSet_delRow)
self.pushButton_tableFeedSet_save.clicked.connect(self.send_tabelFeedSet_save)
def init_FeedLine(self):
# line_count = self.configReader.get('Robot_Feed', 'LineCount', fallback=0)
configReader = configparser.ConfigParser()
configReader.read(Constant.feedLine_set_file, encoding='utf-8')
for i in range(1,Constant.MAX_Line_num):
line_str = f'{Constant.feedLine_set_section}{i}'
if configReader.has_section(line_str):
feed_line = LineModel()
feed_line.read_line_model(config_reader=configReader,index=i)
self.feedLine_dict[f'{Constant.feedLine_set_section}{i}'] = feed_line
2025-09-28 09:48:12 +08:00
#加载所有码垛的路径信息
for i in range(1,Constant.MAX_Line_num):
line_model = self.drop_position_manager.load_path_points(i)
if line_model:
self.feedLine_dict[f'{Constant.dropLine_set_section}{i}'] = line_model
2025-07-29 13:16:30 +08:00
self.updateUI_Select_Line()
pass
def init_robot_info(self):
j1_min = int(self.configReader.get('Robot_Feed', 'j1_min'))
j1_max = int(self.configReader.get('Robot_Feed', 'j1_max'))
j2_min = int(self.configReader.get('Robot_Feed', 'j2_min'))
j2_max = int(self.configReader.get('Robot_Feed', 'j2_max'))
j3_min = int(self.configReader.get('Robot_Feed', 'j3_min'))
j3_max = int(self.configReader.get('Robot_Feed', 'j3_max'))
j4_min = int(self.configReader.get('Robot_Feed', 'j4_min'))
j4_max = int(self.configReader.get('Robot_Feed', 'j4_max'))
j5_min = int(self.configReader.get('Robot_Feed', 'j5_min'))
j5_max = int(self.configReader.get('Robot_Feed', 'j5_max'))
j6_min = int(self.configReader.get('Robot_Feed', 'j6_min'))
j6_max = int(self.configReader.get('Robot_Feed', 'j6_max'))
self.horizontalSlider_J1.setMinimum(j1_min)
self.horizontalSlider_J1.setMaximum(j1_max)
self.horizontalSlider_J2.setMinimum(j2_min)
self.horizontalSlider_J2.setMaximum(j2_max)
self.horizontalSlider_J3.setMinimum(j3_min)
self.horizontalSlider_J3.setMaximum(j3_max)
self.horizontalSlider_J4.setMinimum(j4_min)
self.horizontalSlider_J4.setMaximum(j4_max)
self.horizontalSlider_J5.setMinimum(j5_min)
self.horizontalSlider_J5.setMaximum(j5_max)
self.horizontalSlider_J6.setMinimum(j6_min)
self.horizontalSlider_J6.setMaximum(j6_max)
self.label_j1_min.setText(j1_min.__str__())
self.label_j1_max.setText(j1_max.__str__())
self.label_j2_min.setText(j2_min.__str__())
self.label_j2_max.setText(j2_max.__str__())
self.label_j3_min.setText(j3_min.__str__())
self.label_j3_max.setText(j3_max.__str__())
self.label_j4_min.setText(j4_min.__str__())
self.label_j4_max.setText(j4_max.__str__())
self.label_j5_min.setText(j5_min.__str__())
self.label_j5_max.setText(j5_max.__str__())
self.label_j6_min.setText(j6_min.__str__())
self.label_j6_max.setText(str(j6_max))
def start_Runing(self):
#多线程启动
2025-09-28 09:48:12 +08:00
self.main_threading = Thread(target=self.run,name="feeding")#主循环
self.robot_connect_threading = Thread(target=self.robotClient.run,name="robot_connect")
# self.main_UI_threading = Thread(target=self.updateUI,name="updateUI")
self.timer_updateui.timeout.connect(self.updateUI)
self.timer_updateui.start(1000)
self.sensor_thread = Thread(
target=self.relay_controller.handle_sensor1,
name="Sensor1",
daemon=True
)
self.sensor2_thread = Thread(
target=self.relay_controller.handle_sensor2,
name="Sensor2",
daemon=True)
self.relay_controller._running=True
self.relay_controller.pause_start_sensor(True)
self.detect_person_thread = Thread(target=self.run_detect_persion,name="run_detect_persion")
# self.camera_threading = Thread(target=self.camera_img.run,name="camera",daemon=True)
2025-07-29 13:16:30 +08:00
self.main_threading.start()
2025-09-10 09:16:57 +08:00
if not Constant.DebugPosition:
self.robot_connect_threading.start()
2025-09-28 09:48:12 +08:00
# self.main_UI_threading.start()
2025-07-29 13:16:30 +08:00
self.detect_person_thread.start()
2025-09-28 09:48:12 +08:00
#启动传感器线程
self.sensor_thread.start()
self.sensor2_thread.start()
# self.camera_threading.start()
2025-07-29 13:16:30 +08:00
pass
2025-09-10 09:16:57 +08:00
2025-09-28 09:48:12 +08:00
2025-07-29 13:16:30 +08:00
def check_continue(self):
if self.remain_Count!=0:
for key in self.feedLine_dict.keys():
feed_line = self.feedLine_dict[key]
if f'FeedLine{self.remain_lineName}' == key:
#提示
remain_messageBox = QMessageBox()
remain_messageBox.setIcon(QMessageBox.Icon.Warning)
remain_messageBox.setText(f'还有{self.remain_Count}袋未投料,是否继续?') # 这里返回多少袋没有投料
2025-07-29 13:16:30 +08:00
# remain_messageBox.setStandardButtons(QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel)
ok_button = remain_messageBox.addButton("确定", PySide6.QtWidgets.QMessageBox.ButtonRole.AcceptRole)
cancel_button = remain_messageBox.addButton("取消", PySide6.QtWidgets.QMessageBox.ButtonRole.RejectRole)
result = remain_messageBox.exec()
if remain_messageBox.clickedButton() == cancel_button:
2025-09-10 09:16:57 +08:00
# self.remain_Count = 0
2025-07-29 13:16:30 +08:00
return
self.configReader.read(Constant.feedLine_set_file, encoding='utf-8')
line_name = self.configReader.get(key, 'name')
current_index = self.comboBox_lineIndex.findText(line_name)
self.comboBox_lineIndex.setCurrentIndex(current_index)
self.horizontalSlider_feedingNum.setMaximum(self.remain_Count)
self.label_maxNum.setText(str(self.remain_Count)) #目标投料袋数设置为setini文件中保存的remain_count
2025-07-29 13:16:30 +08:00
self.horizontalSlider_feedingNum.setValue(0)
self.send_startFeed_button_click()
else:
return
def send_startFeed_button_click(self):
if self.feeding.feedStatus != FeedStatus.FNone:
self.show_infomessage_box("正在执行")
return
# 触发自动运行
if self.robotClient.status_model.curMode != 7:
self.send_switch_tool_command()
log.log_message(logging.INFO, Constant.str_sys_switch_tool)
self.send_start_tool_command()
log.log_message(logging.INFO, Constant.str_sys_start_tool)
msg_box_person = QMessageBox()
msg_box_person.setIcon(QMessageBox.Icon.Information)
msg_box_person.setText("是否确认生产区域安全继续生产?")
msg_box_person.setWindowTitle("提示")
ok_button = msg_box_person.addButton("确定", PySide6.QtWidgets.QMessageBox.ButtonRole.AcceptRole)
cancel_button = msg_box_person.addButton("取消", PySide6.QtWidgets.QMessageBox.ButtonRole.RejectRole)
result = msg_box_person.exec()
if msg_box_person.clickedButton() == cancel_button:
return
log.log_message(logging.INFO, '第一层确认生产')
has_person = False
# has_person, _ = self.detection_person.get_person() # TODO
if has_person: # TODO
# self.feeding.pause = True
# self.send_pause_command(True)
#
# self.show_messagebox_of_person()
msg_box_person.setText("检测到安全区域后人是否继续生产?")
result = msg_box_person.exec()
2025-09-28 09:48:12 +08:00
if msg_box_person.clickedButton() == cancel_button:
2025-07-29 13:16:30 +08:00
return
log.log_message(logging.ERROR, '人员进入安全区')
2025-09-28 09:48:12 +08:00
#QSlide控件默认的最大值为99
2025-07-29 13:16:30 +08:00
num = self.horizontalSlider_feedingNum.maximum()
2025-09-28 09:48:12 +08:00
# if num==99:
# num = 30 #默认是30包
2025-07-29 13:16:30 +08:00
line_head = self.comboBox_lineIndex.currentData()
2025-09-28 09:48:12 +08:00
if self.feeding.feedConfig:
self.remain_Count=self.feeding.feedConfig.remain_count
msg_box_person.setText(f"确认当前是从第{self.remain_Count+1}袋开始码垛,总共需要{num}袋!!")
result = msg_box_person.exec()
if msg_box_person.clickedButton() == cancel_button:
return
self.label_button_status.setText("运行中...")
# num=25 #先默认30包码垛
2025-09-10 09:16:57 +08:00
self.command_quene.put(FeedCommand(FeedingConfig(num, FeedLine(self.feedLine_dict[line_head].id,self.feedLine_dict[line_head].name,self.feedLine_dict[line_head].positions,self.remain_Count), self.feeding.robotClient.photo_locs[:],self.remain_Count)))
2025-07-29 13:16:30 +08:00
# self.stackedWidget_num.setCurrentIndex(1)
self.set_run_status_button(True)
self.feeding.pause = False
self.feeding.onekey = False
log.log_message(logging.INFO, f'{self.feedLine_dict[line_head].name}:{Constant.str_feed_start}')
def send_num_button_click(self):
button = self.sender()
if button.text() != "自定义":
num = int(button.text())
self.horizontalSlider_feedingNum.setMaximum(num)
self.label_maxNum.setText(str(num))
self.horizontalSlider_feedingNum.setValue(0)
2025-09-28 09:48:12 +08:00
if self.cur_pushbutton_num:
self.cur_pushbutton_num.setStyleSheet(self.pushbutton_num_style)
button.setStyleSheet(self.pushbutton_num_style_select)
self.cur_pushbutton_num=button
2025-07-29 13:16:30 +08:00
else:
self.lineEdit_num.show()
def send_subOneAsix_button_click(self):
btn_str = self.sender().objectName()
Constant.manual_adjust_accuracy = float(self.lineEdit_manual_adjust_accuracy.text())
x1 = float(self.label_j1.text())
x2 = float(self.label_j2.text())
x3 = float(self.label_j3.text())
x4 = float(self.label_j4.text())
x5 = float(self.label_j5.text())
x6 = float(self.label_j6.text())
if 'j1' in btn_str:
x1 = x1 - Constant.manual_adjust_accuracy
elif 'j2' in btn_str:
x2 = x2 - Constant.manual_adjust_accuracy
pass
elif 'j3' in btn_str:
x3 = x3 - Constant.manual_adjust_accuracy
pass
elif 'j4' in btn_str:
x4 = x4 - Constant.manual_adjust_accuracy
pass
elif 'j5' in btn_str:
x5 = x5 - Constant.manual_adjust_accuracy
pass
elif 'j6' in btn_str:
x6 = x6 - Constant.manual_adjust_accuracy
self.send_position_command(x1, x2, x3, x4, x5, x6, MoveType.AXIS)
def send_addOneAsix_button_click(self, btn):
btn_str = self.sender().objectName()
Constant.manual_adjust_accuracy = float(self.lineEdit_manual_adjust_accuracy.text())
x1 = float(self.label_j1.text())
x2 = float(self.label_j2.text())
x3 = float(self.label_j3.text())
x4 = float(self.label_j4.text())
x5 = float(self.label_j5.text())
x6 = float(self.label_j6.text())
if 'j1' in btn_str:
x1 = x1 + Constant.manual_adjust_accuracy
elif 'j2' in btn_str:
x2 = x2 + Constant.manual_adjust_accuracy
pass
elif 'j3' in btn_str:
x3 = x3 + Constant.manual_adjust_accuracy
pass
elif 'j4' in btn_str:
x4 = x4 + Constant.manual_adjust_accuracy
pass
elif 'j5' in btn_str:
x5 = x5 + Constant.manual_adjust_accuracy
pass
elif 'j6' in btn_str:
x6 = x6 + Constant.manual_adjust_accuracy
self.send_position_command(x1, x2, x3, x4, x5, x6, move_type=MoveType.AXIS)
def send_custom_num_returnPressed(self):
2025-09-28 09:48:12 +08:00
#码垛开始数量
self.remain_Count=int(self.lineEdit_num.text())-1
if self.remain_Count<0:
self.remain_Count=0
if self.feeding.feedConfig:
self.feeding.feedConfig.remain_count=self.remain_Count
self.label_remain_num.setText(str(self.remain_Count))
def send_numkeybord_click(self):
# 创建数字键盘对话框
num_dialog = QDialog(self)
num_dialog.setWindowTitle("数字键盘")
num_dialog.setFixedSize(300, 400)
# 创建网格布局
grid_layout = QGridLayout(num_dialog)
# 添加1-30的数字按钮
for i in range(1, 31):
button = QPushButton(str(i), num_dialog)
button.setStyleSheet(
"""
*{background-color: #101F3F;
font: 10pt "楷体";
color:#ffffff;
border-radius: 5px;
min-height: 40px;
}
*:hover {
background-color: lightgreen;
color: black;
}
*:pressed {
background-color: red;
color: white;
}
""")
# 5行6列排列
row = (i - 1) // 6
col = (i - 1) % 6
grid_layout.addWidget(button, row, col)
# 绑定点击事件
button.clicked.connect(lambda checked, num=i: self.set_lineEdit_num_value(num, num_dialog))
# 添加取消按钮
cancel_button = QPushButton("取消", num_dialog)
cancel_button.setStyleSheet(
"""
*{background-color: #6c757d;
font: 10pt "楷体";
color:#ffffff;
border-radius: 5px;
min-height: 40px;
}
*:hover {
background-color: #5a6268;
}
""")
grid_layout.addWidget(cancel_button, 5, 0, 1, 6)
cancel_button.clicked.connect(num_dialog.close)
# 显示对话框
num_dialog.exec()
def set_lineEdit_num_value(self, num, dialog):
# 设置lineEdit_num的值并关闭对话框
self.lineEdit_num.setText(str(num))
dialog.close()
2025-07-29 13:16:30 +08:00
def send_position_button_click(self):
# if True:
# cmd_command = CMDRequest()
# cmd_command.cmdData = ['rewriteData', '800', f'{position_instruction.m0}', 0]
# request_command = vars(cmd_command)
# self.robotClient.add_sendQuene(request_command)
return
def send_position_returnPressed(self):
log.log_message(logging.INFO, Constant.str_sys_manualPosition)
try:
self.send_position_command(float(self.lineEdit_j1.text()),
float(self.lineEdit_j2.text()),
float(self.lineEdit_j3.text()),
float(self.lineEdit_j4.text()),
float(self.lineEdit_j5.text()),
float(self.lineEdit_j6.text()))
except Exception as e:
self.show_infomessage_box(Constant.str_sys_log_move_error)
def send_setSpeed_label_doubelClick(self):
pass
def send_setSpeed_clicked(self):
self.robotClient.feed_speed = int(self.lineEdit_speed_run.text())
self.robotClient.debug_speed = int(self.lineEdit_speed_debug.text())
self.robotClient.reset_speed = int(self.lineEdit_speed_reset.text())
self.robotClient.smooth = int(self.lineEdit_setting_smooth.text())
self.robotClient.dynamic_height = float(self.lineEdit_setting_height.text())
try:
take_addr = int(self.lineEdit_take_addr.text())
press_addr = int(self.lineEdit_press_addr.text())
shake_addr = int(self.lineEdit_shake_addr.text())
time_delay_take = float(self.lineEdit_timedelay_take.text())
time_delay_put = float(self.lineEdit_timedelay_put.text())
time_delay_shake = float(self.lineEdit_timedelay_shake.text())
self.robotClient.con_ios[0] = take_addr
self.robotClient.con_ios[1] = press_addr
self.robotClient.con_ios[2] = shake_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', 'io_take_addr', str(take_addr))
self.configReader.set('Robot_Feed', 'io_zip_addr', str(press_addr))
self.configReader.set('Robot_Feed', 'io_shake_addr', str(shake_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.set('Speed', 'feed_speed', str(self.robotClient.feed_speed))
self.configReader.set('Speed', 'debug_speed', str(self.robotClient.debug_speed))
self.configReader.set('Speed', 'reset_speed', str(self.robotClient.reset_speed))
self.configReader.set('Robot_Feed', 'smooth', str(self.robotClient.smooth))
self.configReader.set('Robot_Feed', 'dynamic_height', str(self.robotClient.dynamic_height))
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
except Exception as e:
log.log_message(logging.ERROR, Constant.str_sys_set_error+e)
pass
#self.pushButton_speed.setText(str(Constant.speed))
log.log_message(logging.INFO, Constant.str_sys_setSpeed + str(self.robotClient.debug_speed)+'|'+str(self.robotClient.feed_speed))
pass
def send_get_safe_position_button_click(self):
real_position = self.robotClient.status_model.getRealPosition()
row_i = self.tableWidget_feedSeting.currentRow()
head = self.tableWidget_feedSeting.item(row_i, 0).text()
self.feedLine_dict[head].safe_position.init_position(real_position.X, real_position.Y, real_position.Z,
real_position.U, real_position.V, real_position.W)
self.set_position_to_tabel(row_i, 0, real_position)
def send_get_broken1_position_button_click(self):
real_position = self.robotClient.status_model.getRealPosition()
row_i = self.tableWidget_feedSeting.currentRow()
head = self.tableWidget_feedSeting.item(row_i, 0).text()
self.feedLine_dict[head].broken1_position.init_position(real_position.X, real_position.Y, real_position.Z,
real_position.U, real_position.V, real_position.W)
self.set_position_to_tabel(row_i, 1, real_position)
def send_get_broken2_position_button_click(self):
real_position = self.robotClient.status_model.getRealPosition()
row_i = self.tableWidget_feedSeting.currentRow()
head = self.tableWidget_feedSeting.item(row_i, 0).text()
self.feedLine_dict[head].broken2_position.init_position(real_position.X, real_position.Y, real_position.Z,
real_position.U, real_position.V, real_position.W)
self.set_position_to_tabel(row_i, 2, real_position)
def send_get_shake_position_button_click(self):
real_position = self.robotClient.status_model.getRealPosition()
row_i = self.tableWidget_feedSeting.currentRow()
head = self.tableWidget_feedSeting.item(row_i, 0).text()
self.feedLine_dict[head].shake_position.init_position(real_position.X, real_position.Y, real_position.Z,
real_position.U, real_position.V, real_position.W)
self.set_position_to_tabel(row_i, 3, real_position)
def send_get_dropbag_position_button_click(self):
real_position = self.robotClient.status_model.getRealPosition()
row_i = self.tableWidget_feedSeting.currentRow()
head = self.tableWidget_feedSeting.item(row_i, 0).text()
self.feedLine_dict[head].drop_bag_position.init_position(real_position.X, real_position.Y, real_position.Z,
real_position.U, real_position.V, real_position.W)
self.set_position_to_tabel(row_i, 4, real_position)
def send_get_zipbag_position_button_click(self):
real_position = self.robotClient.status_model.getRealPosition()
row_i = self.tableWidget_feedSeting.currentRow()
head = self.tableWidget_feedSeting.item(row_i, 0).text()
self.feedLine_dict[head].zip_bag_position.init_position(real_position.X, real_position.Y, real_position.Z,
real_position.U, real_position.V, real_position.W)
self.set_position_to_tabel(row_i, 6, real_position)
2025-09-28 09:48:12 +08:00
2025-07-29 13:16:30 +08:00
def send_tabelFeedSet_addRow(self):
for i in range(1, 20):
head = f'{Constant.feedLine_set_section}{i}'
if head not in self.feedLine_dict:
row_position = self.tableWidget_feedSeting.rowCount() # 当前行数
self.tableWidget_feedSeting.insertRow(row_position)
safe_position = Real_Position()
break_1_position = Real_Position()
break_2_position = Real_Position()
shake_position = Real_Position()
drop_bag_position = Real_Position()
self.feedLine_dict[head] = FeedLine('新建', safe_position, break_1_position, break_2_position,shake_position,drop_bag_position)
self.tableWidget_feedSeting.setItem(self.tableWidget_feedSeting.rowCount() - 1, 0,
QTableWidgetItem(head))
self.tableWidget_feedSeting.setItem(self.tableWidget_feedSeting.rowCount() - 1, 1,
QTableWidgetItem('新建'))
self.set_position_to_tabel(self.tableWidget_feedSeting.rowCount() - 1, 0, safe_position)
self.set_position_to_tabel(self.tableWidget_feedSeting.rowCount() - 1, 1, break_1_position)
self.set_position_to_tabel(self.tableWidget_feedSeting.rowCount() - 1, 2, break_2_position)
self.set_position_to_tabel(self.tableWidget_feedSeting.rowCount() - 1, 3, shake_position)
self.set_position_to_tabel(self.tableWidget_feedSeting.rowCount() - 1, 4, drop_bag_position)
break
def send_tabelFeedSet_delRow(self):
selectRow = self.tableWidget_feedSeting.currentRow()
if selectRow >= 0:
for feed_line_key, feed_line in self.feedLine_dict.items():
if feed_line_key == self.tableWidget_feedSeting.item(selectRow, 0).text():
self.feedLine_dict.pop(feed_line_key)
self.tableWidget_feedSeting.removeRow(selectRow)
break
else:
QMessageBox.information(self, "提示", "请选择要删除的行")
def send_tabelFeedSet_save(self):
count = len(self.feedLine_dict.keys())
self.configReader.read(Constant.set_ini)
self.configReader.set('Robot_Feed', 'LineCount', str(count))
writeFeedLine_to_ini(self.feedLine_dict, Constant.feedLine_set_file)
pass
def send_stopFeed_button_click(self):
# 清空状态
2025-09-28 09:48:12 +08:00
self.feeding.feedStatus = FeedStatus.FNone
self.feeding.reset_status = ResetStatus.RNone
2025-07-29 13:16:30 +08:00
# 清空运行命令
self.send_clear_auto_command()
2025-09-28 09:48:12 +08:00
self.relay_controller.pause_start_sensor(True)
2025-07-29 13:16:30 +08:00
#self.feeding.feedConfig.num = 0
log.log_message(logging.INFO, Constant.str_feed_stop)
2025-09-28 09:48:12 +08:00
def stop_all_work(self):
"""停止所有工作"""
self.feeding.feedStatus = FeedStatus.FNone
self.feeding.reset_status = ResetStatus.RNone
self.relay_controller.pause_start_sensor(True)
self.feeding.pause = True #暂停,停止滚去等
stop_command = CMDRequest()
stop_command.cmdData.append("actionStop")
stop_command.cmdData.append("1")
request_command = stop_command.toString()
self.send_clear_auto_command()
self.robotClient.add_sendQuene(request_command)
# self.feeding.send_emergency_sound()
# self.feeding.feedConfig.num = 0
log.log_message(logging.INFO, Constant.str_sys_emergencyStop)
def send_emergency_alarm_command(self):
"""停止当前工作,需要启动"""
msg_box_person = QMessageBox()
msg_box_person.setIcon(QMessageBox.Icon.Question)
msg_box_person.setText("您确定要停止当前工作吗?")
msg_box_person.setWindowTitle("提示")
msg_box_person.addButton("确定", PySide6.QtWidgets.QMessageBox.ButtonRole.AcceptRole)
cancel_button = msg_box_person.addButton("取消", PySide6.QtWidgets.QMessageBox.ButtonRole.RejectRole)
msg_box_person.exec()
if msg_box_person.clickedButton() == cancel_button:
return
self.stop_all_work()
#TODO
2025-07-29 13:16:30 +08:00
def send_pauseFeed_button_click(self):
if self.pushButton_pauseFeed.text() == '暂停':
2025-09-28 09:48:12 +08:00
self.relay_controller.pause_start_sensor(True)
2025-07-29 13:16:30 +08:00
icon9 = QIcon(QIcon.fromTheme(QIcon.ThemeIcon.SystemReboot))
self.pushButton_pauseFeed.setIcon(icon9)
self.pushButton_pauseFeed.setText('继续')
2025-09-28 09:48:12 +08:00
self.label_button_status.setText("已暂停")
2025-07-29 13:16:30 +08:00
log.log_message(logging.INFO, Constant.str_feed_pause)
self.send_pause_command(True)
2025-09-28 09:48:12 +08:00
self.relay_controller.pause_start_sensor(True)
2025-07-29 13:16:30 +08:00
self.feeding.pause = True
else:
2025-09-28 09:48:12 +08:00
self.relay_controller.pause_start_sensor(False)
2025-07-29 13:16:30 +08:00
icon9 = QIcon(QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackPause))
self.pushButton_pauseFeed.setIcon(icon9)
self.pushButton_pauseFeed.setText('暂停')
2025-09-28 09:48:12 +08:00
self.label_button_status.setText("运行中...")
2025-07-29 13:16:30 +08:00
self.send_pause_command(False)
log.log_message(logging.INFO, Constant.str_feed_continue)
self.send_start_tool_command()
log.log_message(logging.INFO, Constant.str_sys_start_tool)
self.feeding.pause = False
pass
2025-09-28 09:48:12 +08:00
2025-07-29 13:16:30 +08:00
def send_tabWidget_control_change(self):
if self.robotClient.status_model.curMode != 7:
self.send_switch_tool_command()
log.log_message(logging.INFO, Constant.str_sys_switch_tool)
self.send_start_tool_command()
def send_reset_button_click(self):
# 触发自动运行
if self.robotClient.status_model.curMode != 7:
self.send_switch_tool_command()
log.log_message(logging.INFO, Constant.str_sys_switch_tool)
self.send_start_tool_command()
log.log_message(logging.INFO, Constant.str_sys_start_tool)
line_head = self.comboBox_lineIndex.currentData()
self.send_clear_auto_command()
log.log_message(logging.INFO, Constant.str_feed_reset_start)
#safe_position = self.feedLine_dict[line_head].safe_position
# self.send_position_command(safe_position.X, safe_position.Y, safe_position.Z, safe_position.U, safe_position.V, safe_position.W,move_type=MoveType.WORLD)
if self.remain_lineName != '':
2025-09-10 09:16:57 +08:00
if self.feeding.feedConfig:
#改变路径后的值进行复位
__current_feed_config=self.feeding.feedConfig
# __current_lineid=__current_feed_config.feedLine.id
# __current_linename=__current_feed_config.feedLine.name
# __current_position=
# self.feeding.feedConfig= FeedingConfig(0, FeedLine(__current_lineid, __current_linename,
# __current_feed_config.feedLine.positions,0),
# self.feeding.robotClient.photo_locs[:],0)
2025-07-29 13:16:30 +08:00
else:
2025-09-10 09:16:57 +08:00
#用配置的路径进行复位
line_head = f'{Constant.feedLine_set_section}{self.remain_lineName}'
return_positions = copy.deepcopy(self.feedLine_dict[line_head].positions)
position_origin = PositionModel()
position_origin.init_position(self.robotClient.origin_position)
position_origin.status = 1
return_positions.insert(0,position_origin)
if self.feedLine_dict.keys().__contains__(line_head):
self.feeding.feedConfig= FeedingConfig(0, FeedLine(self.feedLine_dict[line_head].id, self.feedLine_dict[line_head].name,
return_positions,self.remain_Count),
self.feeding.robotClient.photo_locs[:],self.remain_Count)
else:
log.log_message(logging.ERROR, Constant.str_feed_reset_no_line_error)
return
2025-07-29 13:16:30 +08:00
self.feeding.reset_status = ResetStatus.RStart
# dialog_reset = StopDialog()
# dialog_reset.stop_thread_signal.connect(self.stop_reset_thread)
else:
log.log_message(logging.ERROR, Constant.str_feed_reset_no_line_error)
return
# thread = threading.Thread(target=self.feeding.return_original_position())
# thread.start()
def stop_reset_thread(self):
self.feeding.reset_status = ResetStatus.ROk
self.send_clear_auto_command()
self.send_emergency_alarm_command()
def send_tabelFeedSet_itemChanged(self, item):
row = item.row()
column = item.column()
value = item.text()
head = self.tableWidget_feedSeting.item(row, 0).text()
if column == 1:
self.feedLine_dict[head].name = value
elif column == (0 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].safe_position.X = float(value)
elif column == (1 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].safe_position.Y = float(value)
elif column == (2 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].safe_position.Z = float(value)
elif column == (3 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].safe_position.U = float(value)
elif column == (4 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].safe_position.V = float(value)
elif column == (5 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].safe_position.W = float(value)
# elif column == 7:
elif column == (6 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken1_position.X = float(value)
elif column == (7 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken1_position.Y = float(value)
elif column == (8 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken1_position.Z = float(value)
elif column == (9 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken1_position.U = float(value)
elif column == (10 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken1_position.V = float(value)
elif column == (11 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken1_position.W = float(value)
elif column == (12 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken2_position.X = float(value)
elif column == (13 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken2_position.Y = float(value)
elif column == (14 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken2_position.Z = float(value)
elif column == (15 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken2_position.U = float(value)
elif column == (16 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken2_position.V = float(value)
elif column == (17 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].broken2_position.W = float(value)
elif column == (18 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].shake_position.X = float(value)
elif column == (19 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].shake_position.Y = float(value)
elif column == (20 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].shake_position.Z = float(value)
elif column == (21 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].shake_position.U = float(value)
elif column == (22 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].shake_position.V = float(value)
elif column == (23 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].shake_position.W = float(value)
elif column == (24 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].drop_bag_position.X = float(value)
elif column == (25 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].drop_bag_position.Y = float(value)
elif column == (26 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].drop_bag_position.Z = float(value)
elif column == (27 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].drop_bag_position.U = float(value)
elif column == (28 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].drop_bag_position.V = float(value)
elif column == (29 + self.tableWidget_feedSeting_addtional_col_num):
self.feedLine_dict[head].drop_bag_position.W = float(value)
def run(self):
# 主线程的逻辑就是 feeding.run() 接口和错误状态处理
while self.thread_signal:
time.sleep(0.1)
# 处理命令队列
if not self.command_quene.empty():
command = self.command_quene.get()
if isinstance(command, FeedCommand) and command.status == Status.Prepareing:
if self.feeding.feedStatus == FeedStatus.FNone:
2025-09-10 09:16:57 +08:00
#插入起始点set.ini中配置的点
2025-07-29 13:16:30 +08:00
position_origin = PositionModel()
position_origin.init_position(self.robotClient.origin_position)
position_origin.status = 1
command.feed_config.feedLine.feed_positions.insert(0, position_origin)
self.robotClient.send_emergency_sound()
time.sleep(5)
self.robotClient.send_emergency_stop()
self.feeding.feedConfig = command.feed_config
2025-09-28 09:48:12 +08:00
# 开启传感器线程检测相关
self.relay_controller.pause_start_sensor(False)
2025-07-29 13:16:30 +08:00
self.feeding.feedStatus = FeedStatus.FStart # ✅ 投料开始,会触发传感器线程启动
command.status = Status.Runing
self.record_remain_num()
# 执行 feeding 主逻辑
try:
self.feeding.run()
self.feeding.run_reset()
except Exception as e:
log.log_message(logging.ERROR, f"Feeding运行异常: {e}")
# while 循环结束,程序退出,确保线程关闭
try:
if self.sensor_thread is not None:
self.relay_controller._running = False
if self.sensor_thread.is_alive():
self.sensor_thread.join(timeout=1)
print("⏹ 主程序退出,传感器线程已关闭")
self.sensor_thread = None
except Exception as e:
log.log_message(logging.ERROR, f"主循环退出时关闭线程异常: {e}")
def run_detect_persion(self):
while self.thread_signal:
has_person = False
# has_person, _ = self.detection_person.get_person() # TODO
if has_person: # TODO
# self.feeding.pause = True
# self.send_pause_command(True)
#
# self.show_messagebox_of_person()
# msg_box_person.setText("检测到安全区域后人是否继续生产?")
# result = msg_box_person.exec()
# if result == QMessageBox.StandardButton.Cancel:
# return
log.log_message(logging.ERROR, '人员进入安全区')
time.sleep(1)
pass
def updateUI(self):
2025-09-28 09:48:12 +08:00
# 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.feeding.feedConfig.remain_count)
2025-07-29 13:16:30 +08:00
if self.feeding.feedConfig!=None:
2025-09-10 09:16:57 +08:00
self.label_remain_num.setText(str(self.feeding.feedConfig.remain_count))
2025-09-28 09:48:12 +08:00
# self.label_remain_num.setText(str(self.feeding.feedConfig.num))
else:
self.set_run_status_button(False)
if self.feeding.feedStatus == FeedStatus.FNone:
self.stackedWidget_num.setCurrentIndex(0)
else:
self.stackedWidget_num.setCurrentIndex(1)
2025-07-29 13:16:30 +08:00
2025-09-28 09:48:12 +08:00
self.label_date.setText(datetime.now().strftime("%Y-%m-%d"))
self.label_time.setText(datetime.now().strftime("%H:%M:%S"))
2025-07-29 13:16:30 +08:00
2025-09-28 09:48:12 +08:00
self.updateUI_seting.emit()
2025-07-29 13:16:30 +08:00
def update_seting_frame(self):
self.updateUI_Position()
self.updateUI_label_status()
self.updateUI_frame_sign(self.feeding.feedStatus)
self.updateUI_IOPanel()
def updateRobotSeting(self):
self.lineEdit_origin_x.setText(str(self.robotClient.origin_position.X))
self.lineEdit_origin_y.setText(str(self.robotClient.origin_position.Y))
self.lineEdit_origin_z.setText(str(self.robotClient.origin_position.Z))
self.lineEdit_origin_u.setText(str(self.robotClient.origin_position.U))
self.lineEdit_origin_v.setText(str(self.robotClient.origin_position.V))
self.lineEdit_origin_w.setText(str(self.robotClient.origin_position.W))
@Slot()
2025-09-28 09:48:12 +08:00
def show_photo_message(self):
pass
2025-09-10 09:16:57 +08:00
def stack_finish(self):
"""
码垛完成处理
"""
# self.feeding.feedConfig.remain_count=0
# self.closeEvent(None)
2025-09-28 09:48:12 +08:00
# self.send_pause_command(True)
# self.feeding.pause = True
# self.relay_controller.pause_start_sensor(True)
2025-09-10 09:16:57 +08:00
msg_box_finish = QMessageBox()
msg_box_finish.setIcon(QMessageBox.Icon.Warning)
2025-09-28 09:48:12 +08:00
msg_box_finish.setText("码垛完成,请移走拖板")
2025-09-10 09:16:57 +08:00
msg_box_finish.setWindowTitle("提示")
msg_box_finish.addButton("确定", QMessageBox.AcceptRole)
result=msg_box_finish.exec()
2025-09-28 09:48:12 +08:00
self.label_remain_num.setText(str(self.feeding.feedConfig.remain_count))
self.stop_all_work()
2025-09-10 09:16:57 +08:00
2025-07-29 13:16:30 +08:00
def updateUI_IOPanel(self):
try:
io_bits = self.robotClient.status_model.get_IO_bits()
for index, bit in enumerate(io_bits):
toggle = self.dirt_io_points[f'y{index+1}']
if toggle.is_on == bit:
continue
else:
toggle.change_status()
except Exception as e:
log.log_message(logging.ERROR, Constant.str_sys_log_IO_error)
pass
@Slot()
2025-09-28 09:48:12 +08:00
def updateUI_label_detection(self,img):
# 检查img是否为字符串路径
_backgroud_img=None
if isinstance(img, str):
try:
# 直接使用QPixmap加载图像文件避免通过cv2转换提高性能
_backgroud_img = PySide6.QtGui.QPixmap(img)
except Exception as e:
log.log_message(logging.ERROR, f"加载图像时出错: {str(e)}")
return
else:
# 如果不是字符串则尝试直接复制并转换兼容旧的np.ndarray参数
try:
_backgroud_img = Util.util_pic.cv2_to_qpixmap(img)
except Exception as e:
log.log_message(logging.ERROR, f"处理图像数据时出错: {str(e)}")
return
# 检查图像是否有效
if _backgroud_img == None:
2025-07-29 13:16:30 +08:00
return
2025-09-28 09:48:12 +08:00
_backgroud_img = _backgroud_img.scaled(self.label_showDetection.size().width(),self.label_showDetection.size().height(), Qt.AspectRatioMode.IgnoreAspectRatio,Qt.TransformationMode.SmoothTransformation)
self.label_showDetection.setPixmap(_backgroud_img)
2025-07-29 13:16:30 +08:00
@Slot()
def log_message(self,level,message):
log.log_message(level,message)
2025-08-15 12:08:30 +08:00
def updateUI_Select_Line(self):
2025-07-29 13:16:30 +08:00
self.comboBox_lineIndex.clear()
for key, value in self.feedLine_dict.items():
self.comboBox_lineIndex.addItem(value.name, key)
def updateUI_label_status(self):
if self.robotClient.status_model.isMoving==1:
self.label_move_sign.show()
if self.label_move_sign.text() == '正在移动.':
self.label_move_sign.setText('正在移动..')
else:
self.label_move_sign.setText('正在移动.')
else:
self.label_move_sign.hide()
if self.robotClient.status_model.curMode >= 0:
try:
self.label_status_model.setText(Constant.mode_array[self.robotClient.status_model.curMode])
except:
self.label_status_model.setText('未知模式')
self.label_status_remoteCmdLen.setText(str(self.robotClient.status_model.RemoteCmdLen))
if self.robotClient.status_model.curAlarm != 0:
log.log_message(logging.ERROR, Constant.str_sys_log_alarm_error+str(self.robotClient.status_model.curAlarm))
self.feeding.pause = True
self.label_status_alarmcode.setText(str(self.robotClient.status_model.curAlarm))
self.label_status_toolIndex.setText(str(self.robotClient.status_model.toolCoord))
self.label_status_speed.setText(str(self.robotClient.status_model.curSpeed_n))
def updateUI_Position(self):
self.horizontalSlider_J1.setValue(self.status_address.axis_0)
self.horizontalSlider_J2.setValue(self.status_address.axis_1)
self.horizontalSlider_J3.setValue(self.status_address.axis_2)
self.horizontalSlider_J4.setValue(self.status_address.axis_3)
self.horizontalSlider_J5.setValue(self.status_address.axis_4)
self.horizontalSlider_J6.setValue(self.status_address.axis_5)
self.label_j1.setText(str(self.status_address.axis_0))
self.label_j2.setText(str(self.status_address.axis_1))
self.label_j3.setText(str(self.status_address.axis_2))
self.label_j4.setText(str(self.status_address.axis_3))
self.label_j5.setText(str(self.status_address.axis_4))
self.label_j6.setText(str(self.status_address.axis_5))
self.horizontalSlider_J1.setValue(self.status_address.axis_0)
self.horizontalSlider_J2.setValue(self.status_address.axis_1)
self.horizontalSlider_J3.setValue(self.status_address.axis_2)
self.horizontalSlider_J4.setValue(self.status_address.axis_3)
self.horizontalSlider_J5.setValue(self.status_address.axis_4)
self.horizontalSlider_J6.setValue(self.status_address.axis_5)
def set_position_to_tabel(self, row_i, position_j, real_Position: Real_Position):
self.tableWidget_feedSeting.setItem(row_i, position_j * 6 + self.tableWidget_feedSeting_addtional_col_num,
QTableWidgetItem(str(real_Position.X)))
self.tableWidget_feedSeting.setItem(row_i, position_j * 6 + 1 + self.tableWidget_feedSeting_addtional_col_num,
QTableWidgetItem(str(real_Position.Y)))
self.tableWidget_feedSeting.setItem(row_i, position_j * 6 + 2 + self.tableWidget_feedSeting_addtional_col_num,
QTableWidgetItem(str(real_Position.Z)))
self.tableWidget_feedSeting.setItem(row_i, position_j * 6 + 3 + self.tableWidget_feedSeting_addtional_col_num,
QTableWidgetItem(str(real_Position.U)))
self.tableWidget_feedSeting.setItem(row_i, position_j * 6 + 4 + self.tableWidget_feedSeting_addtional_col_num,
QTableWidgetItem(str(real_Position.V)))
self.tableWidget_feedSeting.setItem(row_i, position_j * 6 + 5 + self.tableWidget_feedSeting_addtional_col_num,
QTableWidgetItem(str(real_Position.W)))
def updateUI_frame_sign(self,sign:FeedStatus):
# print("start")
if sign == FeedStatus.FNone:
self.set_sign_status(self.label_sign_go, self.pushButton_sign_go, False)
self.set_sign_status(self.label_sign_photo, self.pushButton_sign_photo, False)
self.set_sign_status(self.label_sign_take, self.pushButton_sign_take, False)
self.set_sign_status(self.label_sign_feed, self.pushButton_sign_feed, False)
return
if sign < FeedStatus.FPhoto:
self.set_sign_status(self.label_sign_go,self.pushButton_sign_go,True)
self.set_sign_status(self.label_sign_photo, self.pushButton_sign_photo, False)
self.set_sign_status(self.label_sign_take, self.pushButton_sign_take, False)
self.set_sign_status(self.label_sign_feed, self.pushButton_sign_feed, False)
return
if sign <= FeedStatus.FPhoto:
self.set_sign_status(self.label_sign_go, self.pushButton_sign_go, False)
self.set_sign_status(self.label_sign_photo,self.pushButton_sign_photo,True)
self.set_sign_status(self.label_sign_take, self.pushButton_sign_take, False)
self.set_sign_status(self.label_sign_feed, self.pushButton_sign_feed, False)
return
if sign <= FeedStatus.FTake:
self.set_sign_status(self.label_sign_go, self.pushButton_sign_go, False)
self.set_sign_status(self.label_sign_photo, self.pushButton_sign_photo, False)
self.set_sign_status(self.label_sign_take, self.pushButton_sign_take, True)
self.set_sign_status(self.label_sign_feed, self.pushButton_sign_feed, False)
return
2025-09-28 09:48:12 +08:00
if sign <= FeedStatus.FDropBag:
2025-07-29 13:16:30 +08:00
self.set_sign_status(self.label_sign_go, self.pushButton_sign_go, False)
self.set_sign_status(self.label_sign_photo, self.pushButton_sign_photo, False)
self.set_sign_status(self.label_sign_take, self.pushButton_sign_take, False)
self.set_sign_status(self.label_sign_feed, self.pushButton_sign_feed, True)
return
pass
def set_label_status_style(self, connected: bool):
#return
if connected and not self.label_connect_status.isEnabled():
self.label_connect_status.setEnabled(True)
if not connected and self.label_connect_status.isEnabled():
self.label_connect_status.setDisabled(True)
def set_sign_status(self,label,btn,signed:bool):
#return
try :
if signed and label.isEnabled():
label.setDisabled(True)
btn.setDisabled(True)
# if label.styleSheet().strip() != self.active_label_sign_Qss:
# label.setStyleSheet(self.active_label_sign_Qss)
# self.active_label_sign_Qss = label.styleSheet().strip()
#
# if btn.styleSheet().strip() != self.active_btn_sign_Qss:
# btn.setStyleSheet(self.active_btn_sign_Qss)
# self.active_btn_sign_Qss = btn.styleSheet().strip()
if not signed and not label.isEnabled():
label.setEnabled(True)
btn.setEnabled(True)
# if label.styleSheet().strip() != self.noactive_label_sign_Qss:
# label.setStyleSheet(self.noactive_label_sign_Qss)
# self.noactive_label_sign_Qss = label.styleSheet().strip()
# if btn.styleSheet().strip() != self.noactive_btn_sign_Qss:
# btn.setStyleSheet(self.noactive_btn_sign_Qss)
# self.noactive_btn_sign_Qss = btn.styleSheet().strip()
except Exception as e:
print(e)
def set_run_status_button(self, isRuning: bool):
self.pushButton_pauseFeed.setText("暂停")
##self.pushButton_startFeed.setEnabled(False)
# if isRuning:
# self.pushButton_pauseFeed.show()
# self.pushButton_stopFeed.show()
# self.pushButton_startFeed.hide()
# else:
# self.pushButton_pauseFeed.hide()
# self.pushButton_stopFeed.hide()
# self.pushButton_startFeed.show()
def send_clear_auto_command(self):
clear_command = CMDInstructRequest()
clear_command.emptyList = '1'
request_command = clear_command.toString()
log.log_message(logging.INFO, Constant.str_sys_clearAlarm)
self.robotClient.add_sendQuene(request_command)
# self.command_quene.put(request_command)
def send_position_command(self, x1, x2, x3, x4, x5, x6, move_type: MoveType = MoveType.WORLD,speed=5,p2=None):
#ailaimi
position_instruction = Instruction()
position_instruction.m0 = float(x1)
position_instruction.m1 = float(x2)
position_instruction.m2 = float(x3)
position_instruction.m3 = float(x4)
position_instruction.action = move_type.value
position_instruction.speed = self.robotClient.debug_speed
position_instruction.tool = 0
if position_instruction.action == 17:
position_instruction.m0_p = p2.X
position_instruction.m1_p = p2.Y
position_instruction.m2_p = p2.Z
position_instruction.m3_p = p2.U
#position_instruction.m4_p = p2.V
#position_instruction.m5_p = p2.W
instruction_command = CMDInstructRequest()
instruction_command.instructions.append(position_instruction)
request_command = instruction_command.toString()
log_str = f'移动到位置:{"自由路径" if move_type == MoveType.AXIS else "姿势直线"}' \
f'm0:{position_instruction.m0}-' \
f'm2:{position_instruction.m1}-' \
f'm3:{position_instruction.m2}-' \
f'm4:{position_instruction.m3}-'
log.log_message(logging.INFO,log_str)
print("request_command",request_command)
self.robotClient.add_sendQuene(request_command)
def send_pause_command(self, pause: bool):
pause_command = CMDRequest()
pause_command.cmdData.append("actionPause")
if pause:
pause_command.cmdData.append("1")
else:
pause_command.cmdData.append("0")
request_command = pause_command.toString()
self.robotClient.add_sendQuene(request_command)
def send_clear_alarm_command(self, pause: bool):
self.send_clear_auto_command()
pause_command = CMDRequest()
pause_command.cmdData.append("StopButton")
pause_command.cmdData.append("1")
request_command = pause_command.toString()
self.robotClient.add_sendQuene(request_command)
def send_switch_tool_command(self):
switch_command = CMDRequest()
switch_command.cmdData.append("switchTool")
switch_command.cmdData.append("2")
request_command = switch_command.toString()
self.robotClient.add_sendQuene(request_command)
def send_start_tool_command(self):
switch_command = CMDRequest()
switch_command.cmdData.append("startButton")
switch_command.cmdData.append("1")
request_command = switch_command.toString()
self.robotClient.add_sendQuene(request_command)
def show_messagebox_of_person(self):
msg_box = QMessageBox(self)
msg_box.setWindowTitle("提示")
msg_box.setText("当前有人是否继续")
msg_box.setIcon(QMessageBox.Question)
msg_box.setStandardButtons(QMessageBox.Yes)
msg_box.setDefaultButton(QMessageBox.Yes)
result = msg_box.exec()
if result == QMessageBox.Yes:
self.feeding.pause = False
self.send_pause_command(False)
### 设置界面
def get_p1_button_click(self):
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))
self.lineEdit_u1.setText(str(realPosition.U))
self.lineEdit_v1.setText(str(realPosition.V))
self.lineEdit_w1.setText(str(realPosition.W))
def get_p2_button_click(self):
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))
self.lineEdit_u2.setText(str(realPosition.U))
self.lineEdit_v2.setText(str(realPosition.V))
self.lineEdit_w2.setText(str(realPosition.W))
def get_p3_button_click(self):
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))
self.lineEdit_u3.setText(str(realPosition.U))
self.lineEdit_v3.setText(str(realPosition.V))
self.lineEdit_w3.setText(str(realPosition.W))
def get_p4_button_click(self):
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))
self.lineEdit_u4.setText(str(realPosition.U))
self.lineEdit_v4.setText(str(realPosition.V))
self.lineEdit_w4.setText(str(realPosition.W))
def get_p5_button_click(self):
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))
self.lineEdit_u5.setText(str(realPosition.U))
self.lineEdit_v5.setText(str(realPosition.V))
self.lineEdit_w5.setText(str(realPosition.W))
def get_origin_button_click(self):
realPosition = self.robotClient.status_model.getRealPosition()
self.lineEdit_origin_x.setText(str(realPosition.X))
self.lineEdit_origin_y.setText(str(realPosition.Y))
self.lineEdit_origin_z.setText(str(realPosition.Z))
self.lineEdit_origin_u.setText(str(realPosition.U))
self.lineEdit_origin_v.setText(str(realPosition.V))
self.lineEdit_origin_w.setText(str(realPosition.W))
def set_p1_button_click(self):
try:
x1 = float(self.lineEdit_x1.text())
y1 = float(self.lineEdit_y1.text())
z1 = float(self.lineEdit_z1.text())
u1 = float(self.lineEdit_u1.text())
v1 = float(self.lineEdit_v1.text())
w1 = float(self.lineEdit_w1.text())
self.robotClient.photo_locs[0] = (x1, y1, z1,u1,v1,w1)
self.configReader.read(Constant.set_ini)
self.configReader.set('Robot_Feed', 'photo_x1', str(x1))
self.configReader.set('Robot_Feed', 'photo_y1', str(y1))
self.configReader.set('Robot_Feed', 'photo_z1', str(z1))
self.configReader.set('Robot_Feed', 'photo_u1', str(u1))
self.configReader.set('Robot_Feed', 'photo_v1', str(v1))
self.configReader.set('Robot_Feed', 'photo_w1', str(w1))
self.configReader.write(open(Constant.set_ini,'w',encoding='utf-8'))
log.log_message(logging.INFO, f'设置拍照点1:{x1},{y1},{z1}')
except:
self.show_infomessage_box("设置拍照点1失败")
def set_p2_button_click(self):
try:
x2 = float(self.lineEdit_x2.text())
y2 = float(self.lineEdit_y2.text())
z2 = float(self.lineEdit_z2.text())
u2 = float(self.lineEdit_u2.text())
v2 = float(self.lineEdit_v2.text())
w2 = float(self.lineEdit_w2.text())
self.robotClient.photo_locs[1] = (x2, y2, z2,u2,v2,w2)
self.configReader.read(Constant.set_ini)
self.configReader.set('Robot_Feed', 'photo_x2', str(x2))
self.configReader.set('Robot_Feed', 'photo_y2', str(y2))
self.configReader.set('Robot_Feed', 'photo_z2', str(z2))
self.configReader.set('Robot_Feed', 'photo_u2', str(u2))
self.configReader.set('Robot_Feed', 'photo_v2', str(v2))
self.configReader.set('Robot_Feed', 'photo_w2', str(w2))
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
log.log_message(logging.INFO, f'设置拍照点2:{x2},{y2},{z2}')
except:
self.show_infomessage_box("设置拍照点2失败")
def set_p3_button_click(self):
try:
x3 = float(self.lineEdit_x3.text())
y3 = float(self.lineEdit_y3.text())
z3 = float(self.lineEdit_z3.text())
u3 = float(self.lineEdit_u3.text())
v3 = float(self.lineEdit_v3.text())
w3 = float(self.lineEdit_w3.text())
self.robotClient.photo_locs[2] = (x3, y3, z3,u3,v3,w3)
self.configReader.read(Constant.set_ini)
self.configReader.set('Robot_Feed', 'photo_x3', str(x3))
self.configReader.set('Robot_Feed', 'photo_y3', str(y3))
self.configReader.set('Robot_Feed', 'photo_z3', str(z3))
self.configReader.set('Robot_Feed', 'photo_u3', str(u3))
self.configReader.set('Robot_Feed', 'photo_v3', str(v3))
self.configReader.set('Robot_Feed', 'photo_w3', str(w3))
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
log.log_message(logging.INFO, f'设置拍照点3:{x3},{y3},{z3}')
except:
self.show_infomessage_box("设置拍照点3失败")
def set_p4_button_click(self):
try:
x4 = float(self.lineEdit_x4.text())
y4 = float(self.lineEdit_y4.text())
z4 = float(self.lineEdit_z4.text())
u4 = float(self.lineEdit_u4.text())
v4 = float(self.lineEdit_v4.text())
w4 = float(self.lineEdit_w4.text())
self.robotClient.photo_locs[3] = (x4, y4, z4,u4,v4,w4)
self.configReader.read(Constant.set_ini)
self.configReader.set('Robot_Feed', 'photo_x4', str(x4))
self.configReader.set('Robot_Feed', 'photo_y4', str(y4))
self.configReader.set('Robot_Feed', 'photo_z4', str(z4))
self.configReader.set('Robot_Feed', 'photo_u4', str(u4))
self.configReader.set('Robot_Feed', 'photo_v4', str(v4))
self.configReader.set('Robot_Feed', 'photo_w4', str(w4))
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
log.log_message(logging.INFO, f'设置拍照点4:{x4},{y4},{z4}')
except:
self.show_infomessage_box("设置拍照点4失败")
def set_p5_button_click(self):
try:
x5 = float(self.lineEdit_x5.text())
y5 = float(self.lineEdit_y5.text())
z5 = float(self.lineEdit_z5.text())
u5 = float(self.lineEdit_u5.text())
v5 = float(self.lineEdit_v5.text())
w5 = float(self.lineEdit_w5.text())
self.robotClient.photo_locs[4] = (x5, y5, z5,u5,v5,w5)
self.configReader.read(Constant.set_ini)
self.configReader.set('Robot_Feed', 'photo_x5', str(x5))
self.configReader.set('Robot_Feed', 'photo_y5', str(y5))
self.configReader.set('Robot_Feed', 'photo_z5', str(z5))
self.configReader.set('Robot_Feed', 'photo_u5', str(u5))
self.configReader.set('Robot_Feed', 'photo_v5', str(v5))
self.configReader.set('Robot_Feed', 'photo_w5', str(w5))
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
log.log_message(logging.INFO, f'设置拍照点5:{x5},{y5},{z5}')
except:
self.show_infomessage_box("设置拍照点5失败")
def set_origin_button_click(self):
try:
x = float(self.lineEdit_origin_x.text())
y = float(self.lineEdit_origin_y.text())
z = float(self.lineEdit_origin_z.text())
u = float(self.lineEdit_origin_u.text())
v = float(self.lineEdit_origin_v.text())
w = float(self.lineEdit_origin_w.text())
origin_position = Real_Position()
origin_position.init_position(x,y,z,u,v,w)
self.robotClient.origin_position = origin_position
self.configReader.read(Constant.set_ini)
self.configReader.set('Origin', 'X', str(x))
self.configReader.set('Origin', 'Y', str(y))
self.configReader.set('Origin', 'Z', str(z))
self.configReader.set('Origin', 'U', str(u))
self.configReader.set('Origin', 'V', str(v))
self.configReader.set('Origin', 'W', str(w))
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
log.log_message(logging.INFO, f'设置原点:{x},{y},{z}')
except:
log.log_message(logging.ERROR, f'设置原点失败')
self.show_infomessage_box("设置原点失败")
def updateUI_Photo_Set(self):
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(self.robotClient.feed_speed))
self.lineEdit_speed_debug.setText(str(self.robotClient.debug_speed))
self.lineEdit_speed_reset.setText(str(self.robotClient.reset_speed))
self.lineEdit_take_addr.setText(str(self.robotClient.con_ios[0]))
self.lineEdit_press_addr.setText(str(self.robotClient.con_ios[1]))
self.lineEdit_shake_addr.setText(str(self.robotClient.con_ios[2]))
self.lineEdit_setting_smooth.setText(str(self.robotClient.smooth))
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))
self.lineEdit_setting_height.setText(str(self.robotClient.dynamic_height))
def show_infomessage_box(self,message):
print('显示弹窗')
msg_box = QMessageBox(self)
msg_box.setWindowTitle("提示")
msg_box.setText(message)
msg_box.setIcon(QMessageBox.Icon.Information)
msg_box.setStandardButtons(QMessageBox.StandardButton.Ok)
msg_box.show()
def send_click_change_stackView(self,index):
self.stackedWidget_view.setCurrentIndex(index)
if index == 0:
self.updateUI_Select_Line()
if index == 2:
self.updateRobotSeting()
self.updateUI_Photo_Set()
if index == 3:
self.updateUI_Base_Set()
2025-09-28 09:48:12 +08:00
#修改点2设置一键投料的目标袋数从999设置到30袋
2025-07-29 13:16:30 +08:00
def send_onekeyfeed_button_click(self):
# if self.feeding.feedStatus != FeedStatus.FNone:
# self.show_infomessage_box("正在执行")
# return
2025-09-28 09:48:12 +08:00
self.horizontalSlider_feedingNum.setMaximum(30)
self.label_maxNum.setText(str(30))
2025-07-29 13:16:30 +08:00
self.horizontalSlider_feedingNum.setValue(0)
self.send_startFeed_button_click()
self.feeding.onekey = True
def send_exit_button_click(self):
2025-09-10 09:16:57 +08:00
self.close()
# self.closeEvent(None)
# QApplication.quit()
# sys.exit(app.exec())
2025-07-29 13:16:30 +08:00
def send_click_sysmeuExpand(self):
self.frame_sys_seting.setVisible(not self.frame_sys_seting.isVisible())
if self.frame_2.sizePolicy().verticalPolicy() == QSizePolicy.Policy.Fixed:
self.frame_2.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
else:
self.frame_2.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
def send_IO_Point_OpenOrClose(self,index,togger):
if togger:
self.feeding.sendIOControl(index-1, 1)
log.log_message(logging.INFO, f'打开IO{index}')
else:
self.feeding.sendIOControl(index-1, 0)
log.log_message(logging.INFO, f'关闭IO{index}')
def showEvent(self, event):
super().showEvent(event)
2025-09-10 09:16:57 +08:00
# QTimer.singleShot(2000, self.check_continue)
2025-07-29 13:16:30 +08:00
def closeEvent(self, event):
2025-09-10 09:16:57 +08:00
#关闭窗口事件
2025-07-29 13:16:30 +08:00
self.record_remain_num()
# self.feeding.is_detected = False
# self.feeding.detect_thread.join()
self.feeding.close_feed()
2025-09-28 09:48:12 +08:00
# self.camera_img.stop()
2025-07-29 13:16:30 +08:00
self.thread_signal = False
self.robotClient.close()
2025-09-10 09:16:57 +08:00
if self.relay_controller:
self.relay_controller.stop_sensor(self.sensor_thread,self.sensor2_thread)
# self.relay_controller.close(conveyor2=True)
2025-07-29 13:16:30 +08:00
log.log_message(logging.INFO, Constant.str_sys_exit)
2025-09-10 09:16:57 +08:00
#显示接受关闭事件
event.accept()
2025-07-29 13:16:30 +08:00
#记录投料袋数
2025-07-29 13:16:30 +08:00
def record_remain_num(self):
try:
self.configReader = configparser.ConfigParser()
self.configReader.read(Constant.set_ini)
2025-09-28 09:48:12 +08:00
if self.feeding.feedConfig:
self.configReader.set('Robot_Feed', 'remain_linename', str(self.feeding.feedConfig.feedLine.id))
self.configReader.set('Robot_Feed', 'remain_count', str(self.feeding.feedConfig.remain_count))
if self.cur_pushbutton_num:
self.configReader.set('Robot_Feed', 'maduo_count', self.cur_pushbutton_num.text())
2025-07-29 13:16:30 +08:00
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
except:
log.log_message(logging.ERROR, Constant.str_sys_log_feedNum)
class MyApplication(QApplication):
def __init__(self, argv):
super().__init__(argv)
def notify(self, receiver, event):
try:
return super().notify(receiver, event)
except Exception as e:
log.log_message(logging.ERROR, e)
# 可以在这里记录日志或者执行其他操作
return False
def handle_exception(exc_type, exc_value, exc_tb):
if issubclass(exc_type, KeyboardInterrupt):
log.log_message(logging.INFO, "用户主动退出程序")
return
log.log_message(logging.ERROR, exc_value)
traceback.print_exception(exc_type, exc_value, exc_tb)
if __name__ == "__main__":
app = MyApplication(sys.argv)
window = MainWindow()
window.show()
sys.excepthook = handle_exception
try :
sys.exit(app.exec())
except Exception as e:
log.log_message(logging.ERROR, e)