重量记录0104

This commit is contained in:
2026-01-04 11:48:12 +08:00
parent cddb7531ab
commit d0d71b9efe
5 changed files with 59 additions and 13 deletions

View File

@ -69,7 +69,7 @@ class ArtifactBll:
"BlockNumber": model["BlockNumber"], "BlockNumber": model["BlockNumber"],
"BetonVolume": model["BetonVolume"], "BetonVolume": model["BetonVolume"],
"PStatus":1, "PStatus":1,
"Status": 2, "Status": 1,
"Source": 2, "Source": 2,
"OptTime": datetime.now(), "OptTime": datetime.now(),
}) })

Binary file not shown.

View File

@ -242,7 +242,7 @@ class RelayController:
time.sleep(1) time.sleep(1)
self.control(self.DOOR_UPPER_CLOSE, 'close') 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_sync(5)
self.control_arch_upper_open_async(8) self.control_arch_upper_open_async(8)
self.control(self.DOOR_UPPER_CLOSE, 'open') self.control(self.DOOR_UPPER_CLOSE, 'open')
time.sleep(20) time.sleep(20)

View File

@ -66,7 +66,7 @@ class OmronFinsPollingService:
old_status = self._status old_status = self._status
if old_status != new_status: if old_status != new_status:
self._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: for callback in self._status_callbacks:
try: try:

View File

@ -8,6 +8,7 @@ import time
import threading import threading
from datetime import datetime from datetime import datetime
import logging import logging
import queue
from hardware.upper_plc import OmronFinsPollingService from hardware.upper_plc import OmronFinsPollingService
from vision.muju_cls.muju_utils import run_stable_classification_loop from vision.muju_cls.muju_utils import run_stable_classification_loop
@ -49,6 +50,9 @@ class VisualCallback:
self._max_f_angle_ratio=0.7 self._max_f_angle_ratio=0.7
#完成多少,调整角度比例 多于0.8就没记录了(注意) #完成多少,调整角度比例 多于0.8就没记录了(注意)
self._max_angle_radio=0.8 self._max_angle_radio=0.8
#重量大于95%停留时间2秒其他的1秒
self._weight_ratio_955=0.955
#完成多少,忽略未浇筑满 #完成多少,忽略未浇筑满
self._max_ignore_radio=0.5 self._max_ignore_radio=0.5
@ -59,6 +63,8 @@ class VisualCallback:
#模具结束浇筑时间 #模具结束浇筑时间
self._time_mould_end='' self._time_mould_end=''
# self.db_queue=queue.Queue()
# self.plc_data=5 # self.plc_data=5
self.plc_service = OmronFinsPollingService("192.168.250.233") self.plc_service = OmronFinsPollingService("192.168.250.233")
self.plc_service.register_data_callback(self.on_plc_update) self.plc_service.register_data_callback(self.on_plc_update)
@ -86,6 +92,16 @@ class VisualCallback:
) )
self.monitor_thread.start() 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): def init_val(self):
#初始化值 #初始化值
"""初始化视觉回调处理器""" """初始化视觉回调处理器"""
@ -123,8 +139,11 @@ class VisualCallback:
#采集数据用,下料重量=之前下的重量+最后一阶段(下-->模具车)重量差 #采集数据用,下料重量=之前下的重量+最后一阶段(下-->模具车)重量差
#记录最后一次下料斗到模具车前的重量 #记录最后一次下料斗到模具车前的重量
self._finish_weight=0 self._finish_weight=0
#记录最后一次下料斗到车初始重量 #记录最后一次下料斗到车初始重量
self._inital_finish_lweight=0 self._inital_finish_lweight=0
#记录视觉停止下料时的重量(计算后面加了多少)
self._last_lower_weight=0
# 初始化控制间隔和堆料状态跟踪属性 # 初始化控制间隔和堆料状态跟踪属性
self._last_overflow_state = False self._last_overflow_state = False
@ -341,6 +360,7 @@ class VisualCallback:
#未对齐,检测对齐 #未对齐,检测对齐
_is_not_aligned=self._aligned_get_times(2) _is_not_aligned=self._aligned_get_times(2)
if _is_not_aligned: if _is_not_aligned:
#标志位
self._mould_before_aligned=False self._mould_before_aligned=False
print('------------连续盖板未对齐-------------') print('------------连续盖板未对齐-------------')
else: else:
@ -350,6 +370,11 @@ class VisualCallback:
self._mould_before_aligned=True self._mould_before_aligned=True
print('-----------进入连续块111111-----------') print('-----------进入连续块111111-----------')
# self.is_start_visual=True # 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.init_val()
self.run_feed_all() self.run_feed_all()
@ -392,9 +417,17 @@ class VisualCallback:
print(f'--------进入关闭(浇筑满)-----------') print(f'--------进入关闭(浇筑满)-----------')
self.safe_control_lower_close(3) self.safe_control_lower_close(3)
print(f'--------关闭完成-----------') 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) _current_weight=self.transmitter_controller.read_data(2)
if _current_weight is not None: if _current_weight is not None:
self._last_lower_weight=_current_weight
self._finish_weight= self._finish_weight+(self._inital_finish_lweight-_current_weight) self._finish_weight= self._finish_weight+(self._inital_finish_lweight-_current_weight)
with open('weight.txt', 'a') as f: with open('weight.txt', 'a') as f:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
@ -552,7 +585,10 @@ class VisualCallback:
return return
continue continue
cur_weight_none=0 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多关一秒 #关5秒,loc_time_count多关一秒
loc_relay.control_upper_close_sync(5+loc_time_count) loc_relay.control_upper_close_sync(5+loc_time_count)
break break
@ -670,7 +706,7 @@ class VisualCallback:
second_finish_weight=initial_lower_weight-current_weight second_finish_weight=initial_lower_weight-current_weight
self._is_finish_ratio=(second_finish_weight+first_finish_weight)/need_total_weight self._is_finish_ratio=(second_finish_weight+first_finish_weight)/need_total_weight
print(f'------------已下料比例: {self._is_finish_ratio}-------------') print(f'------------已下料比例: {self._is_finish_ratio}-------------')
if self._is_finish_ratio>self._max_angle_radio: if self._is_finish_ratio>=1:
#关5秒 #关5秒
# print(f'------------已下料比例: {self._is_finish_ratio}-------------') # print(f'------------已下料比例: {self._is_finish_ratio}-------------')
break break
@ -725,17 +761,23 @@ class VisualCallback:
self._pulse_control('open',0.3) self._pulse_control('open',0.3)
time.sleep(0.3) time.sleep(0.3)
self._pulse_control('close',0.4) self._pulse_control('close',0.4)
print(f'--------比例:{self._is_finish_ratio}-----------')
if self._is_finish_ratio>= self._weight_ratio_955:
time.sleep(2)
else:
time.sleep(1) time.sleep(1)
self._is_before_finish=True self._is_before_finish=True
else: else:
# self._pulse_control('open',0.5) # self._pulse_control('open',0.5)
# time.sleep(0.3) # 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) self._pulse_control('open',0.6)
time.sleep(0.3) time.sleep(0.3)
self._pulse_control('close',0.7) self._pulse_control('close',0.7)
if self._is_finish_ratio>= self._weight_ratio_955:
time.sleep(2)
else:
time.sleep(1) time.sleep(1)
self._is_before_finish=True self._is_before_finish=True
if self._is_finish_ratio<=self._max_ignore_radio: if self._is_finish_ratio<=self._max_ignore_radio:
@ -972,7 +1014,7 @@ class VisualCallback:
def on_plc_update(self,data: int, binary: str): def on_plc_update(self,data: int, binary: str):
#4即将振捣室5振捣室 64即将搅拌楼 66到达搅拌楼 #4即将振捣室5振捣室 64即将搅拌楼 66到达搅拌楼
print(f"[数据回调] 数值: 0x{data:02X} | 十进制: {data:3d} | 二进制: {binary}") # print(f"[数据回调] 数值: 0x{data:02X} | 十进制: {data:3d} | 二进制: {binary}")
self.plc_data=data self.plc_data=data
@classmethod @classmethod
@ -989,7 +1031,9 @@ class VisualCallback:
self._is_running=False self._is_running=False
self._is_finish=True self._is_finish=True
self.is_start_visual=False
# #关闭下料斗
# self.safe_control_lower_close()
if self.plc_service: if self.plc_service:
self.plc_service.stop_polling() self.plc_service.stop_polling()
# 等待线程结束 # 等待线程结束
@ -1002,6 +1046,8 @@ class VisualCallback:
if self.monitor_thread.is_alive(): if self.monitor_thread.is_alive():
self.monitor_thread.join(timeout=1.0) self.monitor_thread.join(timeout=1.0)
# self.relay_controller._close_lower_5s
def __del__(self): def __del__(self):
"""析构函数,确保线程安全关闭""" """析构函数,确保线程安全关闭"""
self.shutdown() self.shutdown()