This commit is contained in:
2026-01-16 15:21:54 +08:00
parent 69361c5d5b
commit 1fd14cf7d8
41 changed files with 1133 additions and 26131 deletions

276
main.py
View File

@ -48,6 +48,7 @@ from ui_MainWin import Ui_MainWindow
from view.ResetView import StopDialog
from EMV.EMV import RelayController
from CU.drop import DropPositionManager
import re
class MainWindow(QMainWindow, Ui_MainWindow):
@ -58,7 +59,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.setupUi(self)
#传感器继电器加入变量
self.relay_controller = RelayController()
self.drop_position_manager = DropPositionManager()
self.drop_position_manager = DropPositionManager(Constant.dropLine_set_file)
self.feed_reset_obj=None
self.sensor_thread = None
self.sensor2_thread = None
@ -248,7 +249,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
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)
loc_dropline_file=Constant.dropLine_set_file
if section.endswith('-35'):
loc_dropline_file=Constant.dropLine_set_file_35
DropPositionManager(loc_dropline_file).save_path_points(line_model)
self.init_FeedLine()
break
self.init_table_lines_data()
@ -414,7 +418,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.tableWidget_line_positions.removeRow(self.tableWidget_line_positions.currentRow())
if self.selected_line_section.startswith(Constant.dropLine_set_section):
self.drop_position_manager.del_drop_point(section)
loc_dropline_file=Constant.dropLine_set_file
if self.selected_line_section.endswith('-35'):
loc_dropline_file=Constant.dropLine_set_file_35
DropPositionManager(loc_dropline_file).del_drop_point(section)
else:
config_writer = configparser.ConfigParser()
config_writer.read(Constant.feedLine_set_file, encoding = 'utf-8')
@ -603,6 +610,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
}
""")
self.label_showDetection.setScaledContents(True)
self.comboBox_dropWeight.wheelEvent=lambda e:None
if self.label_showDetection.size().width() < 100 or self.label_showDetection.size().height() < 100:
self.label_showDetection.setMinimumSize(541, 321)
@ -767,14 +775,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.last_time = time.time()
self.remain_lineName = self.configReader.get('Robot_Feed', 'remain_lineName')
self.remain_drop_weight = self.configReader.get("Robot_Feed", "remain_dropweight_kg") # 9/29 投料重量, 单位kg
self.remain_Count = int(self.configReader.get('Robot_Feed', 'remain_Count'))
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]
# _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)
self.updateUI_seting.connect(self.update_seting_frame)
try:
@ -915,11 +924,21 @@ class MainWindow(QMainWindow, Ui_MainWindow):
feed_line.read_line_model(config_reader=configReader,index=i)
self.feedLine_dict[f'{Constant.feedLine_set_section}{i}'] = feed_line
#加载所有码垛的路径信息
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
self.updateUI_Select_Line()
# 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
line_model = DropPositionManager(Constant.dropLine_set_file).load_path_points(1)
if line_model:
self.feedLine_dict[f'{Constant.dropLine_set_section}-50'] = line_model
line_model = DropPositionManager(Constant.dropLine_set_file_35).load_path_points(1)
if line_model:
self.feedLine_dict[f'{Constant.dropLine_set_section}-35'] = line_model
# self.updateUI_Select_Line()
# 9/29 初始化线名选择框 和 重量选择框
self.updateui_select_line_by_feedLine_ini()
self.updateui_select_dropweight_by_drop_ini()
pass
def init_robot_info(self):
@ -987,18 +1006,18 @@ class MainWindow(QMainWindow, Ui_MainWindow):
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.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)
self.main_threading.start()
self.reset_threading.start()
if not Constant.DebugPosition:
self.robot_connect_threading.start()
# self.main_UI_threading.start()
self.detect_person_thread.start()
self.emergency_thread.start()
#self.detect_person_thread.start()
self.emergency_thread.start()
#启动传感器线程
self.sensor_thread.start()
self.sensor2_thread.start()
self.sensor_thread.start()
self.sensor2_thread.start()
# self.camera_threading.start()
@ -1070,18 +1089,22 @@ class MainWindow(QMainWindow, Ui_MainWindow):
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()
if msg_box_person.clickedButton() == cancel_button:
return
log.log_message(logging.ERROR, '人员进入安全区')
# 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 msg_box_person.clickedButton() == cancel_button:
# return
# log.log_message(logging.ERROR, '人员进入安全区')
msg_box_person.setText(f"确认当前码垛重量是 {self.remain_drop_weight}KG")
result = msg_box_person.exec()
if msg_box_person.clickedButton() == cancel_button:
return
#QSlide控件默认的最大值为99
num = self.horizontalSlider_feedingNum.maximum()
# if num==99:
@ -1089,14 +1112,32 @@ class MainWindow(QMainWindow, Ui_MainWindow):
line_head = self.comboBox_lineIndex.currentData()
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("运行中...")
if self.remain_drop_weight == '35':
self.drop_position_manager=DropPositionManager(Constant.dropLine_set_file_35)
self.relay_controller.set_drop_35(True)
else:
self.drop_position_manager=DropPositionManager(Constant.dropLine_set_file)
self.relay_controller.set_drop_35(False)
# num=25 #先默认30包码垛
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)))
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.drop_position_manager
)
, self.feeding.robotClient.photo_locs[:],self.remain_Count
)))
# self.stackedWidget_num.setCurrentIndex(1)
self.set_run_status_button(True)
self.feeding.pause = False
@ -1184,7 +1225,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def send_numkeybord_click(self):
# 创建数字键盘对话框
num_dialog = QDialog(self)
num_dialog.setWindowTitle("字键盘")
num_dialog.setWindowTitle("选择已码垛")
num_dialog.setWindowFlags(num_dialog.windowFlags() & ~Qt.WindowCloseButtonHint)
num_dialog.setFixedSize(400, 500)
@ -1454,14 +1495,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.show_infomessage_box("急停按钮已按下,不能暂停,请先松开急停按钮")
return
if self.feeding.feedStatus == FeedStatus.FNone:
self.show_infomessage_box("当前没有运行中的工作,不能暂停")
self.show_infomessage_box("没有启动,不能暂停")
return
self.send_pauseFeed_click()
pass
def send_pauseFeed_click(self):
"""暂停/继续工作"""
if self.pushButton_pauseFeed.text() == '暂停':
if self.pushButton_pauseFeed.text() == '暂停':
self.relay_controller.pause_start_sensor(True)
icon9 = QIcon(QIcon.fromTheme(QIcon.ThemeIcon.SystemReboot))
self.pushButton_pauseFeed.setIcon(icon9)
@ -1471,16 +1512,24 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.send_pause_command(True)
self.feeding.pause = True
else:
self.relay_controller.pause_start_sensor(False)
icon9 = QIcon(QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackPause))
self.pushButton_pauseFeed.setIcon(icon9)
self.pushButton_pauseFeed.setText('暂停')
self.label_button_status.setText("运行中...")
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
#暂停后pushButton_pauseFeed的值是继续再按急停,停止传感器和机械臂
#is_emergency_pressed True没按下False按下
if self.is_emergency_pressed:
#已暂停,按急停
self.relay_controller.pause_start_sensor(True)
self.send_pause_command(True)
self.feeding.pause = True
else:
self.relay_controller.pause_start_sensor(False)
icon9 = QIcon(QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackPause))
self.pushButton_pauseFeed.setIcon(icon9)
self.pushButton_pauseFeed.setText('暂停')
self.label_button_status.setText("运行中...")
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
def send_tabWidget_control_change(self):
@ -1727,8 +1776,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
else:
if self.feeding.feedStatus == FeedStatus.FNone:
self.stackedWidget_num.setCurrentIndex(0)
self.comboBox_dropWeight.setDisabled(False)
else:
self.stackedWidget_num.setCurrentIndex(1)
self.comboBox_dropWeight.setDisabled(True)
self.label_date.setText(datetime.now().strftime("%Y-%m-%d"))
@ -1766,6 +1817,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# self.feeding.pause = True
# self.relay_controller.pause_start_sensor(True)
self.stop_all_work()
self.relay_controller.close(blow_sensor2=True)
msg_box_finish = QMessageBox()
msg_box_finish.setIcon(QMessageBox.Icon.Warning)
msg_box_finish.setText("码垛完成,请移走拖板")
@ -1816,8 +1868,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if emergency_pressed:
if not self.is_emergency_pressed:
print('急停按钮按下')
self.send_pauseFeed_click()
self.is_emergency_pressed = True
self.send_pauseFeed_click()
self.label_button_status.setText("急停中,禁止操作")
else:
if self.is_emergency_pressed:
@ -1873,6 +1925,127 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.comboBox_lineIndex.clear()
for key, value in self.feedLine_dict.items():
self.comboBox_lineIndex.addItem(value.name, key)
# 9/29: 只需要加载FeedLine.ini中的name 作为comboBox_lineIndex的选项
def updateui_select_line_by_feedLine_ini(self):
self.comboBox_lineIndex.clear()
configReader = configparser.ConfigParser()
configReader.read(Constant.feedLine_set_file, encoding="utf-8")
for index in range(1, Constant.MAX_Line_num):
section = f"{Constant.feedLine_set_section}{index}"
if configReader.has_section(section):
line_name = configReader.get(section, "name")
self.comboBox_lineIndex.addItem(line_name, section)
# 设置初始化选中,初始选中 f'{Constant.feedLine_set_section}{self.remain_linename}'
if self.remain_lineName:
selected_value = f"{Constant.feedLine_set_section}{self.remain_lineName}"
selected_index = self.comboBox_lineIndex.findData(selected_value)
if selected_index >= 0:
self.comboBox_lineIndex.setCurrentIndex(selected_index)
# 9/29 初始化加载 drop.ini 中的name获取预先设置的重量
def updateui_select_dropweight_by_drop_ini(self):
self.comboBox_dropWeight.clear()
configReader = configparser.ConfigParser()
# 读取重量路径配置文件 drop.ini
configReader.read(Constant.dropLine_set_file, encoding="utf-8")
# drop_name匹配xxxkg获取重量
weight_pattern = re.compile(r'(\d+kg)')
for index in range(1, Constant.MAX_Line_num):
section = f"{Constant.dropLine_set_section}{index}"
if configReader.has_section(section):
drop_name = configReader.get(section, "name")
match = weight_pattern.search(drop_name)
if match:
# 提取匹配到的内容(如"50kg"
weight_text = match.group(1)
else:
# 无法匹配xxxkg 则使用"未知重量"
weight_text = "未知重量"
# userData: 如 DropLine50kg
userData = f"{Constant.dropLine_set_section}{weight_text}"
self.comboBox_dropWeight.addItem(weight_text, userData)
# 连接槽函数
self.comboBox_dropWeight.activated.connect(self.on_drop_weight_changed)
# 设置初始化选中的重量
if self.remain_drop_weight:
# selected_value: 如 DropLine50kg
selected_value = f"{Constant.dropLine_set_section}{self.remain_drop_weight}kg"
selected_index = self.comboBox_dropWeight.findData(selected_value)
if selected_index >= 0:
self.comboBox_dropWeight.setCurrentIndex(selected_index)
self.drop_weight_index=selected_index
# 初始化重量提示标签
self.weight_label_info.setText(f"{self.remain_drop_weight}kg码垛")
"""9/29 重量下拉框选中项变化时, 更新self.remain_drop_weight"""
def on_drop_weight_changed(self, index):
#提示
msgBox = QMessageBox(self)
msgBox.setIcon(QMessageBox.Icon.Information)
msgBox.setText("会从第1包开始是否继续")
msgBox.setWindowTitle("提示")
font=QFont("Microsoft YaHei UI",40)
msgBox.setFont(font)
ok_button = msgBox.addButton("", PySide6.QtWidgets.QMessageBox.ButtonRole.AcceptRole)
cancel_button = msgBox.addButton("", PySide6.QtWidgets.QMessageBox.ButtonRole.RejectRole)
ok_button.setStyleSheet("QPushButton { color: #fff; background-color: red;margin-right: 80px;padding:15px;font-size:40px }")
cancel_button.setStyleSheet("QPushButton { margin-right: 10px;padding:15px;font-size:40px }")
# msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
result = msgBox.exec()
if msgBox.clickedButton() == cancel_button:
self.comboBox_dropWeight.setCurrentIndex(self.drop_weight_index)
return
else:
self.drop_weight_index=index
# 默认的重量为 50 kg
default_weight = '50'
if index < 0: # 没有选中项时(如下拉框为空)
self.remain_drop_weight = default_weight
return
# 获取当前选中项的显示文本(如"50kg"
selected_text = self.comboBox_dropWeight.currentText()
# 提取重量数值(从"50kg"中提取"50"
weight_pattern = re.compile(r'(\d+)kg')
match = weight_pattern.search(selected_text)
if match:
# 提取数字部分(如"50"
self.remain_drop_weight = match.group(1)
else:
# 若为"未知重量"remain_drop_weight 也为 default_weight
self.remain_drop_weight = default_weight
# 更新上方的码垛重量提示Tips
self.weight_label_info.setText(f"{selected_text}码垛")
self.remain_Count=0
if self.feeding.feedConfig:
self.feeding.feedConfig.remain_count = 0
self.label_remain_num.setText('0')
#35KG
if self.remain_drop_weight=='35':
self.label_maxNum.setText('40')
self.horizontalSlider_feedingNum.setMaximum(40)
self.maduo_Count=40
else:
self.label_maxNum.setText('30')
self.horizontalSlider_feedingNum.setMaximum(30)
self.maduo_Count=30
self.record_weight_ini(self.remain_Count,self.maduo_Count,self.remain_drop_weight)
def updateUI_label_status(self):
if self.robotClient.status_model.isMoving==1:
self.label_move_sign.show()
@ -2369,6 +2542,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.feeding.onekey = True
def send_exit_button_click(self):
if self.feeding.feedStatus != FeedStatus.FNone:
self.show_infomessage_box("请先停止后,再退出程序")
return
self.close()
# self.closeEvent(None)
# QApplication.quit()
@ -2426,6 +2602,18 @@ class MainWindow(QMainWindow, Ui_MainWindow):
except:
log.log_message(logging.ERROR, Constant.str_sys_log_feedNum)
#记录投料袋数
def record_weight_ini(self,remain_count,maduo_count,drop_weight):
try:
self.configReader = configparser.ConfigParser()
self.configReader.read(Constant.set_ini)
self.configReader.set('Robot_Feed', 'remain_count', str(remain_count))
self.configReader.set('Robot_Feed', 'maduo_count', str(maduo_count))
self.configReader.set('Robot_Feed', 'remain_dropweight_kg', str(drop_weight))
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
except:
log.log_message(logging.ERROR, Constant.str_sys_log_feedNum+"2")
class MyApplication(QApplication):
def __init__(self, argv):