复位-急停
This commit is contained in:
150
main.py
150
main.py
@ -29,7 +29,7 @@ from Model.FeedModel import LineModel, PositionModel
|
||||
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 CU.Feeding import FeedLine, FeedingConfig, Feeding, FeedStatus, FeedMidStatus, ResetStatus,FeedReset
|
||||
from Util.util_log import QTextEditLogger
|
||||
from Util.util_time import CRisOrFall
|
||||
#from Vision.camera_coordinate_dete import Detection
|
||||
@ -59,6 +59,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
#传感器继电器加入变量
|
||||
self.relay_controller = RelayController()
|
||||
self.drop_position_manager = DropPositionManager()
|
||||
self.feed_reset_obj=None
|
||||
self.sensor_thread = None
|
||||
self.sensor2_thread = None
|
||||
self.emergency_thread = None
|
||||
@ -78,7 +79,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.thread_signal = True
|
||||
self.init_qss()
|
||||
self.init_UI()
|
||||
|
||||
self.init_Run()
|
||||
self.init_Reset()
|
||||
self.init_robot_info()
|
||||
self.init_IOPanel()
|
||||
self.start_Runing()
|
||||
@ -91,6 +94,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.selected_line_section = ''
|
||||
|
||||
|
||||
|
||||
|
||||
def init_IOPanel(self):
|
||||
self.dirt_io_points = {}
|
||||
@ -651,7 +655,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
self.pushButton_clearAlarm.clicked.connect(self.send_clear_alarm_command)
|
||||
# self.pushButton_emergency.clicked.connect(self.send_emergency_alarm_command)
|
||||
self.pushButton_reset.clicked.connect(self.send_reset_button_click)
|
||||
self.pushButton_reset.clicked.connect(self.send_reset_button_click_new)
|
||||
|
||||
|
||||
self.pushButton_saveSeting.clicked.connect(self.send_setSpeed_clicked)
|
||||
@ -757,6 +761,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.relay_controller.log_signal.connect(self.log_message)
|
||||
self.relay_controller.emergency_signal.connect(self.emergency_press_notify)
|
||||
self.feeding.feed_error_signal.connect(self.feed_error_notify)
|
||||
self.feeding.feed_nums_signal.connect(self.update_remain_num)
|
||||
# self.camera_img=CameraImg(self.feeding)
|
||||
# self.camera_img.update_camera_image.connect(self.updateUI_label_detection)
|
||||
|
||||
@ -782,6 +787,17 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
else:
|
||||
return Error_Code.SYS_NETERROR
|
||||
|
||||
def init_Reset(self):
|
||||
configReader = configparser.ConfigParser()
|
||||
configReader.read(Constant.resetLine_set_file, encoding='utf-8')
|
||||
#加载复位信息
|
||||
line_str = f'{Constant.feedLine_set_section}1'
|
||||
reset_line = LineModel()
|
||||
if configReader.has_section(line_str):
|
||||
reset_line.read_line_model(config_reader=configReader,index=1)
|
||||
self.feed_reset_obj = FeedReset(self.robotClient,self.relay_controller,reset_line.positions)
|
||||
|
||||
|
||||
def init_seting_frame(self):
|
||||
|
||||
rows = len(self.feedLine_dict.keys()) + 1
|
||||
@ -903,7 +919,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
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()
|
||||
pass
|
||||
|
||||
@ -952,9 +967,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
name="emergency",
|
||||
daemon=True
|
||||
)
|
||||
self.emergency_thread.start()
|
||||
|
||||
|
||||
self.main_threading = Thread(target=self.run,name="feeding")#主循环
|
||||
self.reset_threading = Thread(target=self.reset_run,name="reset",daemon=True)#复位线程
|
||||
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)
|
||||
@ -974,10 +990,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
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.sensor_thread.start()
|
||||
self.sensor2_thread.start()
|
||||
@ -1018,6 +1036,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
return
|
||||
|
||||
def send_startFeed_button_click(self):
|
||||
|
||||
if self.is_emergency_pressed:
|
||||
self.show_infomessage_box("急停按钮已按下,不能启动,请先松开急停按钮")
|
||||
return
|
||||
@ -1034,14 +1053,17 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
msg_box_person = QMessageBox()
|
||||
msg_box_person.setIcon(QMessageBox.Icon.Information)
|
||||
msg_box_person.setText("是否确认生产区域安全继续生产?")
|
||||
msg_box_person.setText("是否确认生产区域安全?")
|
||||
msg_box_person.setWindowTitle("提示")
|
||||
font=QFont("Microsoft YaHei UI",20)
|
||||
font=QFont("Microsoft YaHei UI",40)
|
||||
msg_box_person.setFont(font)
|
||||
|
||||
|
||||
ok_button = msg_box_person.addButton("确定", PySide6.QtWidgets.QMessageBox.ButtonRole.AcceptRole)
|
||||
cancel_button = msg_box_person.addButton("取消", PySide6.QtWidgets.QMessageBox.ButtonRole.RejectRole)
|
||||
|
||||
ok_button.setStyleSheet("QPushButton { color: #fff; background-color: red;margin-right: 80px;padding:15px }")
|
||||
cancel_button.setStyleSheet("QPushButton { margin-right: 10px;padding:15px }")
|
||||
result = msg_box_person.exec()
|
||||
|
||||
if msg_box_person.clickedButton() == cancel_button:
|
||||
@ -1067,7 +1089,7 @@ 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}袋!!")
|
||||
msg_box_person.setText(f"当前是从第{self.remain_Count+1}袋开始,总共需要{num}袋")
|
||||
result = msg_box_person.exec()
|
||||
if msg_box_person.clickedButton() == cancel_button:
|
||||
return
|
||||
@ -1151,29 +1173,31 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
def send_custom_num_returnPressed(self):
|
||||
#码垛开始数量
|
||||
self.remain_Count=int(self.lineEdit_num.text())-1
|
||||
if self.remain_Count<0:
|
||||
self.remain_Count=int(self.lineEdit_num.text())
|
||||
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))
|
||||
self.record_remain_num()
|
||||
|
||||
def send_numkeybord_click(self):
|
||||
# 创建数字键盘对话框
|
||||
num_dialog = QDialog(self)
|
||||
num_dialog.setWindowTitle("数字键盘")
|
||||
num_dialog.setFixedSize(300, 400)
|
||||
num_dialog.setWindowFlags(num_dialog.windowFlags() & ~Qt.WindowCloseButtonHint)
|
||||
num_dialog.setFixedSize(400, 500)
|
||||
|
||||
# 创建网格布局
|
||||
grid_layout = QGridLayout(num_dialog)
|
||||
|
||||
# 添加1-30的数字按钮
|
||||
for i in range(1, 31):
|
||||
for i in range(0, 30):
|
||||
button = QPushButton(str(i), num_dialog)
|
||||
button.setStyleSheet(
|
||||
"""
|
||||
*{background-color: #101F3F;
|
||||
font: 20pt "楷体";
|
||||
font: 30pt "楷体";
|
||||
color:#ffffff;
|
||||
border-radius: 5px;
|
||||
min-height: 40px;
|
||||
@ -1188,8 +1212,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
}
|
||||
""")
|
||||
# 5行6列排列
|
||||
row = (i - 1) // 6
|
||||
col = (i - 1) % 6
|
||||
row = i // 6
|
||||
col = i % 6
|
||||
grid_layout.addWidget(button, row, col)
|
||||
|
||||
# 绑定点击事件
|
||||
@ -1200,7 +1224,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
cancel_button.setStyleSheet(
|
||||
"""
|
||||
*{background-color: #6c757d;
|
||||
font: 20pt "楷体";
|
||||
font: 30pt "楷体";
|
||||
color:#ffffff;
|
||||
border-radius: 5px;
|
||||
min-height: 40px;
|
||||
@ -1398,7 +1422,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
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)
|
||||
log.log_message(logging.INFO,"stop_all_work")
|
||||
|
||||
|
||||
def send_emergency_alarm_command(self):
|
||||
if self.is_emergency_pressed:
|
||||
@ -1407,13 +1432,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
"""停止当前工作,需要启动"""
|
||||
msg_box_person = QMessageBox()
|
||||
msg_box_person.setIcon(QMessageBox.Icon.Question)
|
||||
msg_box_person.setText("您确定要停止当前工作吗?")
|
||||
msg_box_person.setText("要停止当前工作吗?")
|
||||
msg_box_person.setWindowTitle("提示")
|
||||
font = msg_box_person.font()
|
||||
font.setPointSize(20)
|
||||
font.setPointSize(30)
|
||||
msg_box_person.setFont(font)
|
||||
msg_box_person.addButton("确定", PySide6.QtWidgets.QMessageBox.ButtonRole.AcceptRole)
|
||||
ok_button=msg_box_person.addButton("确定", PySide6.QtWidgets.QMessageBox.ButtonRole.AcceptRole)
|
||||
cancel_button = msg_box_person.addButton("取消", PySide6.QtWidgets.QMessageBox.ButtonRole.RejectRole)
|
||||
ok_button.setStyleSheet("QPushButton { color: #fff; background-color: red;margin-right: 80px;padding:15px }")
|
||||
cancel_button.setStyleSheet("QPushButton { margin-right: 10px;padding:15px }")
|
||||
msg_box_person.exec()
|
||||
if msg_box_person.clickedButton() == cancel_button:
|
||||
return
|
||||
@ -1433,6 +1460,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
pass
|
||||
|
||||
def send_pauseFeed_click(self):
|
||||
"""暂停/继续工作"""
|
||||
if self.pushButton_pauseFeed.text() == '暂停':
|
||||
self.relay_controller.pause_start_sensor(True)
|
||||
icon9 = QIcon(QIcon.fromTheme(QIcon.ThemeIcon.SystemReboot))
|
||||
@ -1441,7 +1469,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.label_button_status.setText("已暂停")
|
||||
log.log_message(logging.INFO, Constant.str_feed_pause)
|
||||
self.send_pause_command(True)
|
||||
self.relay_controller.pause_start_sensor(True)
|
||||
self.feeding.pause = True
|
||||
else:
|
||||
self.relay_controller.pause_start_sensor(False)
|
||||
@ -1511,6 +1538,21 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
# thread = threading.Thread(target=self.feeding.return_original_position())
|
||||
# thread.start()
|
||||
|
||||
def send_reset_button_click_new(self):
|
||||
if self.is_emergency_pressed:
|
||||
self.show_infomessage_box("急停按钮已按下,不能启动,请先松开急停按钮")
|
||||
return
|
||||
|
||||
if self.feed_reset_obj.reset_status != ResetStatus.RNone:
|
||||
self.show_infomessage_box("复位进行中,请不要重复操作")
|
||||
return
|
||||
|
||||
if self.feeding.feedStatus != FeedStatus.FNone:
|
||||
self.show_infomessage_box("请先停止运行,再进行复位")
|
||||
return
|
||||
self.send_clear_auto_command()
|
||||
self.feed_reset_obj.reset_status = ResetStatus.RStart
|
||||
|
||||
def stop_reset_thread(self):
|
||||
self.feeding.reset_status = ResetStatus.ROk
|
||||
self.send_clear_auto_command()
|
||||
@ -1616,7 +1658,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
# 执行 feeding 主逻辑
|
||||
try:
|
||||
self.feeding.run()
|
||||
self.feeding.run_reset()
|
||||
# self.feeding.run_reset()
|
||||
except Exception as e:
|
||||
log.log_message(logging.ERROR, f"Feeding运行异常: {e}")
|
||||
|
||||
@ -1631,6 +1673,21 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
except Exception as e:
|
||||
log.log_message(logging.ERROR, f"主循环退出时关闭线程异常: {e}")
|
||||
|
||||
def reset_run(self):
|
||||
#加载复位信息
|
||||
# 复位线程的逻辑就是 feeding.run_reset() 接口和错误状态处理
|
||||
while self.thread_signal:
|
||||
|
||||
try:
|
||||
self.feed_reset_obj.run_reset()
|
||||
|
||||
# self.feeding.run_reset()
|
||||
except Exception as e:
|
||||
log.log_message(logging.ERROR, f"Feeding运行异常: {e}")
|
||||
finally:
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
def run_detect_persion(self):
|
||||
while self.thread_signal:
|
||||
has_person = False
|
||||
@ -1713,9 +1770,10 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
msg_box_finish.setIcon(QMessageBox.Icon.Warning)
|
||||
msg_box_finish.setText("码垛完成,请移走拖板")
|
||||
msg_box_finish.setWindowTitle("提示")
|
||||
msg_box_finish.addButton("确定", QMessageBox.AcceptRole)
|
||||
loc_font=QFont("Microsoft YaHei UI",20)
|
||||
ok_button=msg_box_finish.addButton("确定", QMessageBox.AcceptRole)
|
||||
loc_font=QFont("Microsoft YaHei UI",40)
|
||||
msg_box_finish.setFont(loc_font)
|
||||
ok_button.setStyleSheet("QPushButton { color: #fff; background-color: red;margin-right: 80px;padding:15px }")
|
||||
result=msg_box_finish.exec()
|
||||
self.label_remain_num.setText(str(self.feeding.feedConfig.remain_count))
|
||||
|
||||
@ -1727,19 +1785,29 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.relay_controller.open(alarm=True)
|
||||
self.send_pauseFeed_click()
|
||||
msg_box_finish = QMessageBox()
|
||||
msg_box_finish.setIcon(QMessageBox.Icon.Warning)
|
||||
msg_box_finish.setIcon(QMessageBox.Icon.Critical)
|
||||
msg_box_finish.setText(error_msg)
|
||||
msg_box_finish.setWindowTitle("提示")
|
||||
msg_box_finish.addButton("确定", QMessageBox.AcceptRole)
|
||||
loc_font=QFont("Microsoft YaHei UI",20)
|
||||
ok_button=msg_box_finish.addButton("确定", QMessageBox.AcceptRole)
|
||||
loc_font=QFont("Microsoft YaHei UI",40)
|
||||
msg_box_finish.setFont(loc_font)
|
||||
ok_button.setStyleSheet("QPushButton { color: #fff; background-color: red;margin-right: 80px;padding:15px }")
|
||||
result=msg_box_finish.exec()
|
||||
if error_code==1:
|
||||
msg_box_finish.setText("是否打开滚筒让料带滚出?")
|
||||
msg_box_finish.addButton("取消", QMessageBox.RejectRole)
|
||||
result=msg_box_finish.exec()
|
||||
if result == QMessageBox.AcceptRole:
|
||||
self.relay_controller.open(conveyor2=True)
|
||||
if result == QMessageBox.AcceptRole:
|
||||
self.relay_controller.close(alarm=True)
|
||||
# if error_code==1:
|
||||
# msg_box_finish.setText("是否打开滚筒让料带滚出?")
|
||||
# cancel_button=msg_box_finish.addButton("取消", QMessageBox.RejectRole)
|
||||
# cancel_button.setStyleSheet("QPushButton { color: #fff; background-color: #007bff;margin-left: 80px;padding:15px }")
|
||||
# result=msg_box_finish.exec()
|
||||
# if result == QMessageBox.AcceptRole:
|
||||
# self.relay_controller.open(conveyor2=True)
|
||||
# msg_box_finish.removeButton(msg_box_finish.button(QMessageBox.RejectRole))
|
||||
# msg_box_finish.setText("请务必确认滚出后再继续程序!!!")
|
||||
# self.relay_controller.close(conveyor2=True)
|
||||
|
||||
def update_remain_num(self,remain_num):
|
||||
self.record_remain_num()
|
||||
|
||||
def emergency_press_notify(self,emergency_pressed):
|
||||
"""
|
||||
@ -1747,11 +1815,13 @@ 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.label_button_status.setText("急停中,禁止操作")
|
||||
else:
|
||||
if self.is_emergency_pressed:
|
||||
print('已暂停,可操作工控机')
|
||||
self.label_button_status.setText("已暂停,可操作工控机")
|
||||
|
||||
self.is_emergency_pressed = False
|
||||
@ -2267,15 +2337,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
def show_infomessage_box(self,message):
|
||||
print('显示弹窗')
|
||||
msg_box = QMessageBox(self)
|
||||
msg_box = QMessageBox()
|
||||
msg_box.setWindowTitle("提示")
|
||||
msg_box.setText(message)
|
||||
msg_box.setIcon(QMessageBox.Icon.Information)
|
||||
msg_box.setStandardButtons(QMessageBox.StandardButton.Ok)
|
||||
font = msg_box.font()
|
||||
font.setPointSize(20)
|
||||
msg_box.setFont(font)
|
||||
msg_box.show()
|
||||
loc_font=QFont("Microsoft YaHei UI",40)
|
||||
msg_box.setFont(loc_font)
|
||||
ok_button = msg_box.addButton("确定", PySide6.QtWidgets.QMessageBox.ButtonRole.AcceptRole)
|
||||
ok_button.setStyleSheet("QPushButton { color: #fff; background-color: red;margin-right: 80px;padding:15px }")
|
||||
msg_box.exec()
|
||||
def send_click_change_stackView(self,index):
|
||||
self.stackedWidget_view.setCurrentIndex(index)
|
||||
if index == 0:
|
||||
@ -2348,6 +2418,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
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))
|
||||
else:
|
||||
self.configReader.set('Robot_Feed', 'remain_count', str(self.remain_Count))
|
||||
if self.cur_pushbutton_num:
|
||||
self.configReader.set('Robot_Feed', 'maduo_count', self.cur_pushbutton_num.text())
|
||||
self.configReader.write(open(Constant.set_ini, 'w', encoding='utf-8'))
|
||||
@ -2379,7 +2451,9 @@ if __name__ == "__main__":
|
||||
window = MainWindow()
|
||||
# window.show()
|
||||
# window.showFullScreen()
|
||||
window.setWindowFlags(window.windowFlags() & ~Qt.WindowCloseButtonHint)
|
||||
window.showMaximized()
|
||||
window.setStyleSheet("QPushButton#qt_close_button {visibility: collapse;}")
|
||||
sys.excepthook = handle_exception
|
||||
try :
|
||||
sys.exit(app.exec())
|
||||
|
||||
Reference in New Issue
Block a user