复位-急停

This commit is contained in:
2025-11-12 07:11:09 +08:00
parent cbda29e270
commit ed6cc098df
15 changed files with 365 additions and 84 deletions

View File

@ -36,9 +36,16 @@ from Mv3D.calculate_diff2 import calculate_offset_from_image
class ResetStatus(Enum):
RNone = 0
#开始复位
RStart = 1
#复位向上移到最高点
RRunging = 2
#扔包点
ROk =3
#复位点
RRestPoint = 5
#复位完成
RFinish = 4
class FeedStatus(IntEnum):
FNone = 0
@ -325,6 +332,8 @@ class Feeding(QObject):
stack_finish_signal=Signal()
#误差过大,通知用户
feed_error_signal=Signal(int,str)
#数量保存信号
feed_nums_signal=Signal(int)
def __init__(self, robotClient: RobotClient,relay_controller:RelayController):
super().__init__()
@ -496,6 +505,10 @@ class Feeding(QObject):
#self.catch.catch_status = CatchStatus.CTake
elif self.feedStatus == FeedStatus.FPhoto:
if not real_position.compare(self.robotClient.origin_position,is_action=True):
return
#码垛的数量和配置的数量一致时
if self.feedConfig.remain_count >=self.feedConfig.num:
#关闭,暂停
@ -506,7 +519,7 @@ class Feeding(QObject):
self.feedConfig.feedLine.origin2start_pos_index = len(self.feedConfig.feedLine.origin_to_start) - 2
#码垛数量重置
self.feedConfig.remain_count=0
self.next_position(self.is_reverse)
# self.next_position(self.is_reverse)
#码垛完成信号通知
self.stack_finish_signal.emit()
self.log_signal.emit(logging.INFO, Constant.str_feed_photo)
@ -521,6 +534,8 @@ class Feeding(QObject):
return
#初始点无论如何先打开夹爪
self.relay_controller.close(clamp=True)
self.relay_controller.close(blow_sensor2=True)
#重新抓去信号料带
self.take_sensor_signal=False
self.relay_controller.sensor2_ready=True
@ -570,10 +585,11 @@ class Feeding(QObject):
print(f"视频模型异常:{loc_image_path}",e)
# loc_is_next=False
loc_offsetX=0
if not Constant.DebugPosition:
self.feed_error_signal.emit(2,"视频模型异常")
self.log_signal.emit(logging.ERROR, f"视频模型异常:{e}")
finally:
if loc_is_next:
if loc_is_next or Constant.DebugPosition:
self.feedConfig.feedLine.set_feeding_to_end(loc_offsetX)
self.next_position()
self.log_signal.emit(logging.INFO, Constant.str_sys_runing2)
@ -677,9 +693,10 @@ class Feeding(QObject):
# (后续增加) 视觉确认: 拍照确认袋子已放置
# self.detection.get_position(...)
# self.feedConfig.feedLine.set_take_position(...)
self.relay_controller.open(blow_sensor2=True)
# 码垛数量增加
self.feedConfig.remain_count = self.feedConfig.remain_count + 1
self.feed_nums_signal.emit(self.feedConfig.remain_count)
# self.feedConfig.num = self.feedConfig.num - 1
self.log_signal.emit(logging.INFO, f'{Constant.str_feed_feed_num}{self.feedConfig.remain_count}')
# 5. *** 关键步骤 ***: 移动到路径中的下一个点
@ -909,6 +926,7 @@ class Feeding(QObject):
print(request_command)
self.robotClient.add_sendQuene(request_command)
pass
# def get_take_position(self):
# if Constant.Debug:
# return self.robotClient.status_model.getRealPosition()
@ -1033,3 +1051,109 @@ class Feeding(QObject):
return True
pass
class FeedReset(QObject):
def __init__(self,robotClient: RobotClient,relay_controller:RelayController,positions):
super().__init__()
self.robotClient = robotClient
self.relay_controller = relay_controller
self.reversed_positions = positions
self.reset_status = ResetStatus.RNone
def run_reset(self):
if self.reset_status == ResetStatus.RNone:
return
real_position = Real_Position()
real_position.init_position_joint_and_world(self.robotClient.status_model.world_0,
self.robotClient.status_model.world_1,
self.robotClient.status_model.world_2,
self.robotClient.status_model.world_3,
self.robotClient.status_model.world_4,
self.robotClient.status_model.world_5,
self.robotClient.status_model.axis_0,
self.robotClient.status_model.axis_1,
self.robotClient.status_model.axis_2,
self.robotClient.status_model.axis_3,
self.robotClient.status_model.axis_4,
self.robotClient.status_model.axis_5)
if self.reset_status == ResetStatus.RStart:
#当前位置
self.reverse_index = 0
self.current_position = PositionModel()
self.current_position.init_position(real_position)
self.reset_status = ResetStatus.RRunging
elif self.reset_status == ResetStatus.RRunging:
#到达当前位置-》移到机械臂最上方
if not real_position.compare(self.current_position.get_position(),is_action=True):
return
self.current_position.X=real_position.Axis_0
self.current_position.Y=-59.997
self.current_position.Z=real_position.Axis_2
self.current_position.U=real_position.Axis_3
self.current_position.V=real_position.Axis_4
self.current_position.W=real_position.Axis_5
self.current_position.lineType=4
# pos_model.get_position().Y = pos_model.get_position().Y + 10000
#linetype 4是关节移动
self.sendTargPosition(pos_model= self.current_position,speed=60)
self.reset_status=ResetStatus.ROk
elif self.reset_status == ResetStatus.ROk:
#到达机械臂最上方--》扔包点
if not real_position.compare(self.current_position.get_position(),is_action=True):
return
pos_model=self.reversed_positions[self.reverse_index]
self.current_position = pos_model
self.sendTargPosition(pos_model=pos_model,speed=60)
self.reverse_index = self.reverse_index + 1
self.reset_status = ResetStatus.RRestPoint
elif self.reset_status == ResetStatus.RRestPoint:
#到达扔包点-》发送复位点
if real_position.compare(self.current_position.get_position(),is_action=True):
self.relay_controller.close(clamp=True)
pos_model=self.reversed_positions[self.reverse_index]
self.current_position = pos_model
self.sendTargPosition(pos_model=pos_model,speed=60)
self.reset_status = ResetStatus.RFinish
elif self.reset_status == ResetStatus.RFinish:
#到达复位点-》RNone
if not real_position.compare(self.current_position.get_position(),is_action=True):
return
self.reset_status = ResetStatus.RNone
def sendTargPosition(self, pos_model:PositionModel, speed=5):
real_position=pos_model.get_position()
position_instruction = Instruction()
position_instruction.speed = speed
position_instruction.m0 = real_position.X
position_instruction.m1 = real_position.Y
position_instruction.m2 = real_position.Z
position_instruction.m3 = real_position.U
position_instruction.m4 = real_position.V
position_instruction.m5 = real_position.W
position_instruction.smooth = self.robotClient.smooth
if pos_model.lineType == 4:
#linetype 4是关节移动
position_instruction.action = MoveType.AXIS.value
else:
position_instruction.action = MoveType.WORLD.value
if position_instruction.action == 17:
position_instruction.m0_p = real_position1.X
position_instruction.m1_p = real_position1.Y
position_instruction.m2_p = real_position1.Z
position_instruction.m3_p = real_position1.U
position_instruction.m4_p = real_position1.V
position_instruction.m5_p = real_position1.W
instruction_command = CMDInstructRequest()
instruction_command.instructions.append(position_instruction)
request_command = instruction_command.toString()
self.robotClient.add_sendQuene(request_command)
pass

34
Config/reset_line.ini Normal file
View File

@ -0,0 +1,34 @@
[FeedLine1]
id = 1
name = 1号线
[Position1]
x = -24.063
y = -42.650
z = -52.472
u = 21.969
v = 0.0
w = 0.0
id = 1
order = 1
lineid = 1
status = 1
linetype = 4
[Position2]
x = -44.430
y = -59.997604
z = -80.499
u = 51.386665
v = 0.0
w = -0.0
id = 2
order = 2
lineid = 1
status = 2
linetype = 4

View File

@ -3,7 +3,7 @@ import os
# 调试变量
Debug = False # 控制不加图像的Fphoto False是不加
Debug1 = False # 打印很多日志节点
DebugPosition = True # 调试位置,关闭机器人和传感器及判断
DebugPosition = False # 调试位置,关闭机器人和传感器及判断
# Debug2 = False
feedStatus = True #feedStatus的状态打印
@ -20,8 +20,10 @@ manual_adjust_accuracy = 1
feedLine_set_section = 'FeedLine'
dropLine_set_section = 'DropLine'
position_set_section = 'Position'
reset_line_set_section = 'ResetLine'
feedLine_set_file = f'.{os.sep}Config{os.sep}FeedLine.ini'
dropLine_set_file = f'.{os.sep}Config{os.sep}drop.ini'
resetLine_set_file = f'.{os.sep}Config{os.sep}reset_line.ini'
MAX_Position_num = 40
MAX_Line_num = 10
set_ini = 'Seting.ini'

View File

@ -55,6 +55,7 @@ class RelayController(QObject):
self.SENSOR2 = 'sensor2'
self.BELT = 'belt'
self.ALARM = 'alarm'
self.BLOW_SENSOR2 = 'blow_sensor2'
self.valve_commands = {
#包装机皮带
@ -71,6 +72,8 @@ class RelayController(QObject):
self.BELT: {'open': '00000000000601050006FF00', 'close': '000000000006010500060000'},
#D01 声控报警
self.ALARM: {'open': '00000000000601050000FF00', 'close': '000000000006010500000000'},
#DO6 吹传感器2
self.BLOW_SENSOR2: {'open': '00000000000601050005FF00', 'close': '000000000006010500050000'},
#滚筒反转
self.CONVEYOR2_REVERSE: {'open': '000100000006020620000022', 'close': '000100000006020620000001'}
}
@ -91,6 +94,7 @@ class RelayController(QObject):
self.CONVEYOR2_REVERSE: 5,
self.BELT: 6,
self.ALARM: 7,
#self.BLOW_SENSOR2: 8
}
self.sensor_bit_map = {
@ -99,14 +103,15 @@ class RelayController(QObject):
}
self.device_name_map = {
self.CONVEYOR1: "传送带1",
self.CONVEYOR1: "包装机皮带",
self.PUSHER: "推板开",
self.CONVEYOR2: "传送带2",
self.CONVEYOR2: "滚筒",
self.CLAMP: "机械臂夹爪",
self.PUSHER1: "推板关",
self.CONVEYOR2_REVERSE: "传送带2反转",
self.CONVEYOR2_REVERSE: "滚筒反转",
self.BELT: "皮带",
self.ALARM: "声控报警",
self.BLOW_SENSOR2: "吹传感器2"
}
self.sensor_name_map = {
@ -142,7 +147,7 @@ class RelayController(QObject):
sock.connect((self.host, self.port))
sock.send(byte_data)
response = sock.recv(1024)
hex_response = binascii.hexlify(response).decode('utf-8')
# hex_response = binascii.hexlify(response).decode('utf-8')
#if source == 'sensor':
#print(f"[传感器响应] {hex_response}")
#elif source == 'device':
@ -163,8 +168,8 @@ class RelayController(QObject):
# ===================== 状态读取方法 =====================
def get_all_device_status(self, command_type='devices'):
if Constant.DebugPosition:
return {self.SENSOR2:True}
# if Constant.DebugPosition:
# return {self.SENSOR2:True}
command = self.read_status_command.get(command_type)
if not command:
print(f"未知的网络继电器读取类型: {command_type}")
@ -178,7 +183,7 @@ class RelayController(QObject):
status_byte = response[9]
status_bin = f"{status_byte:08b}"[::-1]
bit_map = self.device_bit_map if command_type == 'devices' else self.sensor_bit_map
name_map = self.device_name_map if command_type == 'devices' else self.sensor_name_map
# name_map = self.device_name_map if command_type == 'devices' else self.sensor_name_map
for key, bit_index in bit_map.items():
status_dict[key] = status_bin[bit_index] == '1'
@ -234,7 +239,6 @@ class RelayController(QObject):
return loc_is_pressed
def parse_status_code(self, response):
"""
从 Modbus 响应字符串中提取状态码(后两位)
@ -364,36 +368,39 @@ class RelayController(QObject):
time.sleep(check_interval)
return False
# ===================== 动作控制方法 =====================
def open(self, conveyor1=False, pusher=False, conveyor2=False, clamp=False, pusher1=False, conveyor2_reverse=False,belt=False,alarm=False):
if Constant.DebugPosition:
return
status = self.get_all_device_status()
if conveyor1 and not status.get(self.CONVEYOR1, False):
def open(self, conveyor1=False, pusher=False, conveyor2=False, clamp=False, pusher1=False, conveyor2_reverse=False,belt=False,alarm=False,blow_sensor2=False):
# if Constant.DebugPosition:
# return
# status = self.get_all_device_status()
if conveyor1:
self.send_command(self.valve_commands[self.CONVEYOR1]['open'])
time.sleep(self.delay_conveyor)
if pusher and not status.get(self.PUSHER, False):
if pusher:
self.send_command(self.valve_commands[self.PUSHER]['open'])
time.sleep(self.delay_pusher)
if conveyor2 and not status.get(self.CONVEYOR2, False):
if conveyor2:
self.send_command(self.valve_commands[self.CONVEYOR2]['open'])
time.sleep(self.delay_conveyor)
if clamp and not status.get(self.CLAMP, False):
if clamp:
self.send_command(self.valve_commands[self.CLAMP]['open'])
time.sleep(self.delay_clamp)
if pusher1 and not status.get(self.PUSHER1, False):
if pusher1:
self.send_command(self.valve_commands[self.PUSHER1]['open'])
time.sleep(self.delay_pusher)
if conveyor2_reverse:
self.send_command(self.valve_commands[self.CONVEYOR2_REVERSE]['open'])
time.sleep(self.delay_conveyor)
if belt and not status.get(self.BELT, False):
if belt:
self.send_command(self.valve_commands[self.BELT]['open'])
# time.sleep(self.delay_belt)
if alarm and not status.get(self.ALARM, False):
if alarm:
self.send_command(self.valve_commands[self.ALARM]['open'])
# time.sleep(self.delay_alarm)
if blow_sensor2:
self.send_command(self.valve_commands[self.BLOW_SENSOR2]['open'])
# time.sleep(self.delay_blow_sensor2)
def close(self, conveyor1=False, pusher=False, conveyor2=False, clamp=False, pusher1=False, conveyor2_reverse=False,belt=False,alarm=False):
def close(self, conveyor1=False, pusher=False, conveyor2=False, clamp=False, pusher1=False, conveyor2_reverse=False,belt=False,alarm=False,blow_sensor2=False):
if conveyor1:
self.send_command(self.valve_commands[self.CONVEYOR1]['close'])
time.sleep(self.delay_conveyor)
@ -418,6 +425,9 @@ class RelayController(QObject):
if alarm:
self.send_command(self.valve_commands[self.ALARM]['close'])
# time.sleep(self.delay_alarm)
if blow_sensor2:
self.send_command(self.valve_commands[self.BLOW_SENSOR2]['close'])
# time.sleep(self.delay_blow_sensor2)
# ===================== 传感器处理线程 =====================
def handle_sensor1(self):
@ -497,11 +507,16 @@ class RelayController(QObject):
# 发送信号通知机器人取走物品
self.take_robot_signal.emit()
_is_signal=False
self.sensor2_ready=False #打开滚洞标识
self.sensor2_ready=False #打开滚洞标识FPhoto控制打开
else:
if self.sensor2_ready:
#只有在FPhoto处才有效
_is_signal=True
if self.motor_stopped_by_sensor2:
print('开滚筒')
self.open(conveyor2=True)
self.motor_stopped_by_sensor2 = False
# time.sleep(0.1)
continue
elif self.sensor2_ready:
@ -524,6 +539,13 @@ class RelayController(QObject):
"""
self._ispause = is_pause
if is_pause:
"""暂停皮带"""
self.close(belt=True)
else:
"""开启皮带"""
self.open(belt=True)
def stop_sensor(self,sensor1_thread,sensor2_thread):
if not self._running:
@ -539,15 +561,21 @@ class RelayController(QObject):
def handle_emergency_pressed(self):
"处理急停按钮信号状态线程"
print('检查急停按钮状态1')
while self._running:
try:
print('检查急停按钮状态')
loc_is_pressed =self.get_emergency_is_pressed()
if loc_is_pressed:
# 处理急停按钮信号状态
if not self.emergency_is_pressed:
print('急停按钮被按下')
self.log_signal.emit(logging.INFO,f"急停按钮被按下")
self.emergency_is_pressed=True
self.emergency_signal.emit(True)
else:
print('急停按钮未被按下')
self.emergency_is_pressed=False
self.emergency_signal.emit(False)
time.sleep(0.5)

View File

@ -1,4 +1,7 @@
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from EMV import RelayController
import time
import threading
@ -35,6 +38,18 @@ def test_device(device_name, action):
'clamp': {
'open': lambda: relay_controller.open(clamp=True),
'close': lambda: relay_controller.close(clamp=True)
},
'alarm': {
'open': lambda: relay_controller.open(alarm=True),
'close': lambda: relay_controller.close(alarm=True)
},
'belt': {
'open': lambda: relay_controller.open(belt=True),
'close': lambda: relay_controller.close(belt=True)
},
'blow_sensor2': {
'open': lambda: relay_controller.open(blow_sensor2=True),
'close': lambda: relay_controller.close(blow_sensor2=True)
}
}
@ -83,16 +98,18 @@ if __name__ == "__main__":
# print(sensors)
# time.sleep(3)
# test_device('conveyor2', 'open')
test_device('conveyor2_reverse', 'open')
# test_device('belt', 'close')
# time.sleep(3)
# test_device('conveyor2', 'open')
test_device('conveyor2', 'close')
# test_device('belt', 'close')
# sensors = relay_controller.get_all_device_status('sensors')
# sensor2_value = sensors.get(relay_controller.SENSOR2, False)
# relay_controller._running=True
# relay_controller.handle_sensor2()
# test_device('conveyor2', 'close')
test_device('blow_sensor2', 'close')
# test_device('blow_sensor2', 'close')
# while True:
# if relay_controller.is_valid_sensor_status_1('sensor2'):
# test_device('conveyor2', 'close')
@ -112,8 +129,10 @@ if __name__ == "__main__":
# time.sleep(0.1)
# relay_controller._running=True
# relay_controller.handle_emergency_pressed()
time.sleep(100)
print('aaaaa')

View File

@ -47,7 +47,7 @@ photo_v5 = 0.0
photo_w5 = 1.0
linecount = 2
remain_linename = 1
remain_count = 0
remain_count = 3
maduo_count = 30
io_take_addr = 8
io_zip_addr = 11

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 888 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 866 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 KiB

148
main.py
View File

@ -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()
@ -92,6 +95,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def init_IOPanel(self):
self.dirt_io_points = {}
self.dirt_io_points.setdefault('y1', self.widget_y1)
@ -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)
result=msg_box_finish.exec()
if error_code==1:
msg_box_finish.setText("是否打开滚筒让料带滚出?")
msg_box_finish.addButton("取消", QMessageBox.RejectRole)
ok_button.setStyleSheet("QPushButton { color: #fff; background-color: red;margin-right: 80px;padding:15px }")
result=msg_box_finish.exec()
if result == QMessageBox.AcceptRole:
self.relay_controller.open(conveyor2=True)
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())

View File

@ -235,9 +235,9 @@ class Ui_MainWindow(object):
sizePolicy1.setHeightForWidth(self.pushButton_exit.sizePolicy().hasHeightForWidth())
self.pushButton_exit.setSizePolicy(sizePolicy1)
self.pushButton_exit.setStyleSheet(u"*{\n"
"color:#838992;\n"
"color:#fff;\n"
"background-color: #1B1F34;\n"
"font: 9pt \"Microsoft YaHei UI\";\n"
"font: 30pt \"Microsoft YaHei UI\";\n"
"border: 1px solid #282B40;\n"
"}\n"
"*:pressed\n"
@ -3455,7 +3455,7 @@ class Ui_MainWindow(object):
self.pushButton_numkeybord.setSizePolicy(sizePolicy1)
self.pushButton_numkeybord.setStyleSheet(u"\n"
"*{background-color: #101F3F;\n"
"font: 20pt \"\u6977\u4f53\";\n"
"font: 30pt \"\u6977\u4f53\";\n"
"color:#ffffff\n"
"}\n"
"*:hover {\n"
@ -3475,7 +3475,7 @@ class Ui_MainWindow(object):
self.pushButton_num_confirm.setSizePolicy(sizePolicy1)
self.pushButton_num_confirm.setStyleSheet(u"\n"
"*{background-color: #101F3F;\n"
"font: 20pt \"\u6977\u4f53\";\n"
"font: 30pt \"\u6977\u4f53\";\n"
"color:#ffffff\n"
"}\n"
"*:hover {\n"
@ -3545,7 +3545,7 @@ class Ui_MainWindow(object):
self.pushButton_reset.setSizePolicy(sizePolicy5)
self.pushButton_reset.setStyleSheet(u"*{\n"
"background-color: #FFFFBF;\n"
"font: 20pt \"\u6977\u4f53\";\n"
"font: 30pt \"\u6977\u4f53\";\n"
"border-radius: 10px;\n"
"}\n"
"*:pressed\n"
@ -3584,7 +3584,7 @@ class Ui_MainWindow(object):
self.pushButton_stopFeed.setSizePolicy(sizePolicy5)
self.pushButton_stopFeed.setStyleSheet(u"*{\n"
"background-color: #FF0000;\n"
"font: 20pt \"\u6977\u4f53\";\n"
"font: 30pt \"\u6977\u4f53\";\n"
"border-radius: 10px;\n"
"}\n"
"*:pressed\n"
@ -3603,7 +3603,7 @@ class Ui_MainWindow(object):
self.pushButton_pauseFeed.setSizePolicy(sizePolicy5)
self.pushButton_pauseFeed.setStyleSheet(u"*{\n"
"background-color: #2196F3;\n"
"font: 20pt \"\u6977\u4f53\";\n"
"font: 30pt \"\u6977\u4f53\";\n"
"border-radius: 10px;\n"
"}\n"
"*:pressed\n"
@ -3622,7 +3622,7 @@ class Ui_MainWindow(object):
self.pushButton_startFeed.setSizePolicy(sizePolicy5)
self.pushButton_startFeed.setStyleSheet(u"*{\n"
"background-color: #499C54;\n"
"font: 20pt \"\u6977\u4f53\";\n"
"font: 30pt \"\u6977\u4f53\";\n"
"\n"
"border-radius: 10px;\n"
"}\n"
@ -3642,7 +3642,7 @@ class Ui_MainWindow(object):
self.pushButton_clearAlarm.setSizePolicy(sizePolicy5)
self.pushButton_clearAlarm.setStyleSheet(u"*{\n"
"background-color: #1CB2B1;\n"
"font: 20pt \"\u6977\u4f53\";\n"
"font: 30pt \"\u6977\u4f53\";\n"
"border-radius: 10px;\n"
"}\n"
"*:pressed\n"
@ -3813,7 +3813,7 @@ class Ui_MainWindow(object):
self.label_remain_num = QLabel(self.frame_24)
self.label_remain_num.setObjectName(u"label_remain_num")
self.label_remain_num.setStyleSheet(u"color: rgb(0, 255, 0);\n"
"font: 36pt \"Microsoft YaHei UI\";")
"font: 66pt \"Microsoft YaHei UI\";")
self.label_remain_num.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.horizontalLayout_12.addWidget(self.label_remain_num)
@ -4043,7 +4043,7 @@ class Ui_MainWindow(object):
# self.pushButton_num4.setText(QCoreApplication.translate("MainWindow", u"40", None))
# self.pushButton_num5.setText(QCoreApplication.translate("MainWindow", u"50", None))
# self.pushButton_num6.setText(QCoreApplication.translate("MainWindow", u"60", None))
self.lineEdit_num.setPlaceholderText(QCoreApplication.translate("MainWindow", u"\u4ece\u7b2c\u51e0\u5305\u5f00\u59cb\u7801\u579b\u002c\u8f93\u5165\u540e\u70b9\u51fb\u786e\u5b9a", None))
self.lineEdit_num.setPlaceholderText(QCoreApplication.translate("MainWindow", u"已码垛数量", None))
self.pushButton_numkeybord.setText(QCoreApplication.translate("MainWindow", u"\u952e\u76d8", None))
self.pushButton_num_confirm.setText(QCoreApplication.translate("MainWindow", u"\u786e\u5b9a", None))
# self.pushButton_AddNum.setText(QCoreApplication.translate("MainWindow", u"\u8865\u4e00\u888b", None))