diff --git a/busisness/blls.py b/busisness/blls.py index 3ebd9f7..8111cc7 100644 --- a/busisness/blls.py +++ b/busisness/blls.py @@ -69,7 +69,7 @@ class ArtifactBll: "BlockNumber": model["BlockNumber"], "BetonVolume": model["BetonVolume"], "PStatus":1, - "Status": 2, + "Status": 1, "Source": 2, "OptTime": datetime.now(), }) diff --git a/doc/table表设计.doc b/doc/table表设计.doc index 9d8a23d..f19a6bb 100644 Binary files a/doc/table表设计.doc and b/doc/table表设计.doc differ diff --git a/hardware/relay.py b/hardware/relay.py index d364768..4ce7b71 100644 --- a/hardware/relay.py +++ b/hardware/relay.py @@ -242,7 +242,7 @@ class RelayController: time.sleep(1) self.control(self.DOOR_UPPER_CLOSE, 'close') self.control_arch_upper_open_sync(5) - self.control_arch_upper_open_sync(5) + # self.control_arch_upper_open_sync(5) self.control_arch_upper_open_async(8) self.control(self.DOOR_UPPER_CLOSE, 'open') time.sleep(20) diff --git a/hardware/upper_plc.py b/hardware/upper_plc.py index 370f188..632a5bc 100644 --- a/hardware/upper_plc.py +++ b/hardware/upper_plc.py @@ -66,7 +66,7 @@ class OmronFinsPollingService: old_status = self._status if old_status != new_status: self._status = new_status - self.logger.info(f"状态变更: {old_status.value} -> {new_status.value} {message}") + # self.logger.info(f"状态变更: {old_status.value} -> {new_status.value} {message}") for callback in self._status_callbacks: try: diff --git a/vision/visual_callback_dq.py b/vision/visual_callback_dq.py index 906d2f9..32d7276 100644 --- a/vision/visual_callback_dq.py +++ b/vision/visual_callback_dq.py @@ -8,6 +8,7 @@ import time import threading from datetime import datetime import logging +import queue from hardware.upper_plc import OmronFinsPollingService from vision.muju_cls.muju_utils import run_stable_classification_loop @@ -49,6 +50,9 @@ class VisualCallback: self._max_f_angle_ratio=0.7 #完成多少,调整角度比例 ,多于0.8就没记录了(注意) self._max_angle_radio=0.8 + + #重量大于95%,停留时间2秒,其他的1秒 + self._weight_ratio_955=0.955 #完成多少,忽略未浇筑满 self._max_ignore_radio=0.5 @@ -58,6 +62,8 @@ class VisualCallback: self._time_mould_begin='' #模具结束浇筑时间 self._time_mould_end='' + + # self.db_queue=queue.Queue() # self.plc_data=5 self.plc_service = OmronFinsPollingService("192.168.250.233") @@ -85,6 +91,16 @@ class VisualCallback: name='monitor' ) self.monitor_thread.start() + + """启动数据库监控""" + # self.db_thread = threading.Thread( + # target=self._monitor_db_loop, + # daemon=True, + # name='db_monitor' + # ) + # self.db_thread.start() + + def init_val(self): #初始化值 @@ -123,8 +139,11 @@ class VisualCallback: #采集数据用,下料重量=之前下的重量+最后一阶段(下-->模具车)重量差 #记录最后一次下料斗到模具车前的重量 self._finish_weight=0 + #记录最后一次下料斗到车初始重量 self._inital_finish_lweight=0 + #记录视觉停止下料时的重量(计算后面加了多少) + self._last_lower_weight=0 # 初始化控制间隔和堆料状态跟踪属性 self._last_overflow_state = False @@ -150,7 +169,7 @@ class VisualCallback: # 更新参数 if overflow_detected is not None: - #print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 收到溢料:{overflow_detected}") + # print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 收到溢料:{overflow_detected}") self._overflow_detected = overflow_detected if current_angle is not None: #print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 收到角度:{current_angle}") @@ -341,6 +360,7 @@ class VisualCallback: #未对齐,检测对齐 _is_not_aligned=self._aligned_get_times(2) if _is_not_aligned: + #标志位 self._mould_before_aligned=False print('------------连续盖板未对齐-------------') else: @@ -350,6 +370,11 @@ class VisualCallback: self._mould_before_aligned=True print('-----------进入连续块111111-----------') # self.is_start_visual=True + if self._last_lower_weight>0: + _current_weight=self.transmitter_controller.read_data(2) + if _current_weight is not None: + with open('weight.txt', 'a') as f: + f.write(f"{self._last_lower_weight-_current_weight}\n") self.init_val() self.run_feed_all() @@ -392,9 +417,17 @@ class VisualCallback: print(f'--------进入关闭(浇筑满)-----------') self.safe_control_lower_close(3) print(f'--------关闭完成-----------') + # try: + # self.db_queue.put_nowait({ + # "f":self._is_small_f, + # "Status": 3 + # }) + # except queue.Full: + # print("数据库队列已满,无法添加数据") #记录重量 _current_weight=self.transmitter_controller.read_data(2) if _current_weight is not None: + self._last_lower_weight=_current_weight self._finish_weight= self._finish_weight+(self._inital_finish_lweight-_current_weight) with open('weight.txt', 'a') as f: timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") @@ -552,7 +585,10 @@ class VisualCallback: return continue cur_weight_none=0 - if current_upper_weight<3000 and current_upper_weight>0: + _two_lower_weight=loc_mitter.read_data(2) + if _two_lower_weight is None: + _two_lower_weight=0 + if (current_upper_weight<3000 and current_upper_weight>0) or _two_lower_weight>3200: #关5秒,loc_time_count多关一秒 loc_relay.control_upper_close_sync(5+loc_time_count) break @@ -670,7 +706,7 @@ class VisualCallback: second_finish_weight=initial_lower_weight-current_weight self._is_finish_ratio=(second_finish_weight+first_finish_weight)/need_total_weight print(f'------------已下料比例: {self._is_finish_ratio}-------------') - if self._is_finish_ratio>self._max_angle_radio: + if self._is_finish_ratio>=1: #关5秒 # print(f'------------已下料比例: {self._is_finish_ratio}-------------') break @@ -725,18 +761,24 @@ class VisualCallback: self._pulse_control('open',0.3) time.sleep(0.3) self._pulse_control('close',0.4) - - time.sleep(1) + print(f'--------比例:{self._is_finish_ratio}-----------') + if self._is_finish_ratio>= self._weight_ratio_955: + time.sleep(2) + else: + time.sleep(1) self._is_before_finish=True else: # self._pulse_control('open',0.5) # time.sleep(0.3) - # self._pulse_control('close',0.6) + # self._pulse_control('close',0.6) + # print(f'--------比例:{self._is_finish_ratio}-----------') self._pulse_control('open',0.6) time.sleep(0.3) self._pulse_control('close',0.7) - - time.sleep(1) + if self._is_finish_ratio>= self._weight_ratio_955: + time.sleep(2) + else: + time.sleep(1) self._is_before_finish=True if self._is_finish_ratio<=self._max_ignore_radio: #如果重量未达到最大忽略角度,需要跳出 @@ -972,7 +1014,7 @@ class VisualCallback: def on_plc_update(self,data: int, binary: str): #4即将振捣室5振捣室 64即将搅拌楼 66到达搅拌楼 - print(f"[数据回调] 数值: 0x{data:02X} | 十进制: {data:3d} | 二进制: {binary}") + # print(f"[数据回调] 数值: 0x{data:02X} | 十进制: {data:3d} | 二进制: {binary}") self.plc_data=data @classmethod @@ -989,7 +1031,9 @@ class VisualCallback: self._is_running=False self._is_finish=True - + self.is_start_visual=False + # #关闭下料斗 + # self.safe_control_lower_close() if self.plc_service: self.plc_service.stop_polling() # 等待线程结束 @@ -1001,6 +1045,8 @@ class VisualCallback: if self.monitor_thread.is_alive(): self.monitor_thread.join(timeout=1.0) + + # self.relay_controller._close_lower_5s def __del__(self): """析构函数,确保线程安全关闭"""