0313界面对接
This commit is contained in:
@ -3,6 +3,7 @@ from pickle import FALSE
|
||||
from re import S
|
||||
from cv2.gapi import ov
|
||||
from config.settings import app_set_config
|
||||
from core.relay_feed import RelayFeedController
|
||||
from hardware.relay import RelayController
|
||||
from hardware.transmitter import TransmitterController
|
||||
import time
|
||||
@ -16,7 +17,7 @@ from vision.camera_picture import save_camera_picture
|
||||
from busisness.blls import ArtifactBll,PDRecordBll
|
||||
from busisness.models import ArtifactInfoModel,PDRecordModel
|
||||
from service.mould_service import app_web_service
|
||||
from core.system_state import SystemState,FeedStatus
|
||||
from core.system_state import SystemState,FeedStatus,Upper_Door_Position
|
||||
from dataclasses import asdict
|
||||
import json
|
||||
import math
|
||||
@ -44,6 +45,8 @@ class VisualCallback:
|
||||
|
||||
self.relay_controller = relay_controller
|
||||
self.transmitter_controller = transmitter_controller
|
||||
self.relay_feed=RelayFeedController(relay_controller,state)
|
||||
|
||||
self.pd_record_bll=PDRecordBll()
|
||||
self.state=state
|
||||
|
||||
@ -67,6 +70,8 @@ class VisualCallback:
|
||||
self._current_controlling_thread = None
|
||||
#是否启动后的第一个模具
|
||||
self._is_first_module=True
|
||||
#上一次派单方量
|
||||
self.prev_pd_volume=0.0
|
||||
|
||||
self.init_val()
|
||||
# self._setup_logging_2()
|
||||
@ -88,6 +93,8 @@ class VisualCallback:
|
||||
self._time_mould_end=''
|
||||
#记录当前模具信息model
|
||||
self._cur_mould_model=None
|
||||
self.plc_valid_data=[5,37]
|
||||
self.plc_valid_data_jbl=[66,98]
|
||||
# self.db_queue=queue.Queue()
|
||||
|
||||
# 获取视觉数据线程(angle_visual_callback推送的数据),并进行处理,注意处理视觉进行夹角控制
|
||||
@ -308,7 +315,7 @@ class VisualCallback:
|
||||
(current_time - self._last_arch_time) >= 2:
|
||||
self._last_arch_time = current_time
|
||||
print('---------------------第一阶段振动5秒(小于200KG)-----------------')
|
||||
self.relay_controller.control_arch_lower_open_sync(5)
|
||||
self.relay_feed.control_arch_lower_open_sync(5)
|
||||
self._last_arch_one_weight = _arch_weight
|
||||
continue
|
||||
self._last_arch_one_weight = _arch_weight
|
||||
@ -322,8 +329,8 @@ class VisualCallback:
|
||||
if (_weight_changed < 100) and \
|
||||
(current_time - self._last_arch_time) >= 2:
|
||||
self._last_arch_time = current_time
|
||||
print('---------------------第二阶段振动3秒-----------------')
|
||||
self.relay_controller.control_arch_upper_open_sync(3)
|
||||
#print('---------------------第二阶段振动3秒-----------------')
|
||||
# self.relay_feed.control_arch_upper_open_sync(3)
|
||||
self._last_arch_two_weight = _arch_weight
|
||||
continue
|
||||
self._last_arch_two_weight = _arch_weight
|
||||
@ -339,7 +346,7 @@ class VisualCallback:
|
||||
(current_time - self._last_arch_time) >= 2:
|
||||
self._last_arch_time = current_time
|
||||
print('---------------------第三阶段振动5秒(小于100KG)-----------------')
|
||||
self.relay_controller.control_arch_lower_open_sync(5)
|
||||
self.relay_feed.control_arch_lower_open_sync(5)
|
||||
self._last_arch_three_weight = _arch_weight
|
||||
continue
|
||||
self._last_arch_three_weight = _arch_weight
|
||||
@ -355,7 +362,7 @@ class VisualCallback:
|
||||
self._last_arch_time = current_time
|
||||
print('---------------------第四阶段振动5秒-----------------')
|
||||
#重量不准,暂时不振动
|
||||
# self.relay_controller.control_arch_upper_open_sync(5)
|
||||
# self.relay_feed.control_arch_upper_open_sync(5)
|
||||
self._last_arch_four_weight = _arch_weight
|
||||
continue
|
||||
self._last_arch_four_weight = _arch_weight
|
||||
@ -372,7 +379,7 @@ class VisualCallback:
|
||||
(current_time - self._last_arch_time) >= 2:
|
||||
self._last_arch_time = current_time
|
||||
print(f'---------------------第五阶段振动3秒(小于{_min_arch_weight}kg))-----------------')
|
||||
self.relay_controller.control_arch_lower_open_sync(3)
|
||||
self.relay_feed.control_arch_lower_open_sync(3)
|
||||
self._last_arch_five_weight = _arch_weight
|
||||
continue
|
||||
self._last_arch_five_weight = _arch_weight
|
||||
@ -486,6 +493,13 @@ class VisualCallback:
|
||||
print('------------启动程序后,进入第一块-------------')
|
||||
self._is_first_module=False
|
||||
self._mould_before_aligned=True
|
||||
if self._cur_mould_model:
|
||||
self.state._db_mould_status={
|
||||
'mould_code':self._cur_mould_model.MouldCode,
|
||||
'status':2,
|
||||
'weight':0,
|
||||
}
|
||||
|
||||
_current_weight=self.transmitter_controller.read_data(2)
|
||||
if _current_weight:
|
||||
self._init_lower_weight=_current_weight
|
||||
@ -575,6 +589,14 @@ class VisualCallback:
|
||||
print(f'--------进入关闭(浇筑满)-----------')
|
||||
self.safe_control_lower_close(3)
|
||||
print(f'--------浇筑完成-----------')
|
||||
|
||||
if self._cur_mould_model:
|
||||
self.state._db_mould_status={
|
||||
'mould_code':self._cur_mould_model.MouldCode,
|
||||
'status':3,
|
||||
'weight':self.state._mould_finish_weight,
|
||||
}
|
||||
|
||||
# try:
|
||||
# self.db_queue.put_nowait({
|
||||
# "f":self._is_small_f,
|
||||
@ -633,7 +655,6 @@ class VisualCallback:
|
||||
"""第一阶段下料:下料斗向模具车下料(低速)"""
|
||||
print("--------------------开始下料(F块)--------------------")
|
||||
self._time_mould_begin=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
# loc_relay=self.relay_controller
|
||||
loc_mitter=self.transmitter_controller
|
||||
max_weight_none=5
|
||||
cur_weight_none=0
|
||||
@ -664,6 +685,8 @@ class VisualCallback:
|
||||
cur_weight_none=0
|
||||
first_finish_weight=initial_lower_weight-current_weight
|
||||
self._is_finish_ratio=(first_finish_weight)/need_total_weight
|
||||
self.state._mould_finish_weight=first_finish_weight
|
||||
self.state._mould_finish_ratio=self._is_finish_ratio
|
||||
print(f'------------已下料比例: {self._is_finish_ratio}-------------')
|
||||
# if self._is_finish_ratio>=1:
|
||||
#关5秒
|
||||
@ -683,7 +706,7 @@ class VisualCallback:
|
||||
"""第一阶段下料:下料斗向模具车下料(低速)"""
|
||||
print("--------------------开始下料(普通块)--------------------")
|
||||
self._time_mould_begin=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
loc_relay=self.relay_controller
|
||||
loc_relay=self.relay_feed
|
||||
loc_mitter=self.transmitter_controller
|
||||
max_weight_none=5
|
||||
cur_weight_none=0
|
||||
@ -710,12 +733,15 @@ class VisualCallback:
|
||||
return
|
||||
continue
|
||||
cur_weight_none=0
|
||||
self._is_finish_ratio=(initial_lower_weight-current_weight)/need_total_weight
|
||||
self.state._mould_finish_weight=initial_lower_weight-current_weight
|
||||
self._is_finish_ratio= self.state._mould_finish_weight/need_total_weight
|
||||
self.state._mould_finish_ratio=self._is_finish_ratio
|
||||
|
||||
print(f'------------已下料比例: {self._is_finish_ratio}-------------')
|
||||
if current_weight<250 and current_weight>0:
|
||||
# if current_weight>100:
|
||||
#100,上面粘贴的,振动一下
|
||||
# self.relay_controller.control_arch_lower_open_async(5)
|
||||
# loc_relay.control_arch_lower_open_async(5)
|
||||
self.close_lower_door_visual()
|
||||
break
|
||||
time.sleep(1)
|
||||
@ -729,12 +755,12 @@ class VisualCallback:
|
||||
print(f'------------已下料(第一次): {first_finish_weight}kg-------------')
|
||||
self._is_feed_stage=0
|
||||
|
||||
while self.plc_data not in [5,37]:
|
||||
while self.plc_data not in self.plc_valid_data:
|
||||
#print('------------上料斗未就位----------------')
|
||||
# print('------------上料斗未就位----------------')
|
||||
time.sleep(1)
|
||||
|
||||
if self.plc_data==5 or self.plc_data==37:
|
||||
if self.plc_data in self.plc_valid_data:
|
||||
print(f'------------上料斗就位(上料斗往下料斗阶段)-------------')
|
||||
#打开上料斗出砼门,开5就,开三分之一下
|
||||
|
||||
@ -742,7 +768,7 @@ class VisualCallback:
|
||||
self._is_feed_stage=2
|
||||
loc_time_count=1
|
||||
upper_open_time=time.time()
|
||||
|
||||
self.state._upper_door_closed=1
|
||||
while not self._is_finish:
|
||||
current_upper_weight = loc_mitter.read_data(1)
|
||||
if current_upper_weight is None:
|
||||
@ -751,7 +777,8 @@ class VisualCallback:
|
||||
#如果重量连续5次为None,认为上料斗未就位,跳出循环
|
||||
print('------------第一次上到下,上料斗重量异常----------------')
|
||||
print('------------第一次上到下,上料斗重量异常----------------')
|
||||
loc_relay.control_upper_close_sync(5+loc_time_count)
|
||||
self.state._upper_door_closed=0
|
||||
loc_relay.control_upper_close_sync(5+loc_time_count)
|
||||
return
|
||||
continue
|
||||
cur_weight_none=0
|
||||
@ -760,6 +787,7 @@ class VisualCallback:
|
||||
_two_lower_weight=0
|
||||
if (current_upper_weight<3200 and current_upper_weight>0) or _two_lower_weight>3200:
|
||||
#关5秒,loc_time_count多关一秒
|
||||
self.state._upper_door_closed=0
|
||||
loc_relay.control_upper_close_sync(5+loc_time_count)
|
||||
break
|
||||
else:
|
||||
@ -772,7 +800,7 @@ class VisualCallback:
|
||||
time.sleep(0.5)
|
||||
else:
|
||||
loc_relay.control_upper_close_sync(6+loc_time_count)
|
||||
|
||||
self.state._upper_door_closed=0
|
||||
self.is_start_visual=True
|
||||
initial_lower_weight=loc_mitter.read_data(2)
|
||||
if initial_lower_weight is None:
|
||||
@ -789,11 +817,13 @@ class VisualCallback:
|
||||
return
|
||||
continue
|
||||
cur_weight_none=0
|
||||
self._is_finish_ratio=(first_finish_weight+initial_lower_weight-current_weight)/need_total_weight
|
||||
self.state._mould_finish_weight=first_finish_weight+initial_lower_weight-current_weight
|
||||
self._is_finish_ratio=self.state._mould_finish_weight/need_total_weight
|
||||
self.state._mould_finish_ratio=self._is_finish_ratio
|
||||
if current_weight<250:
|
||||
# if current_weight>100:
|
||||
#100,上面粘贴的,振动一下
|
||||
# self.relay_controller.control_arch_lower_open_async(5)
|
||||
# loc_relay.control_arch_lower_open_async(5)
|
||||
self.close_lower_door_visual()
|
||||
break
|
||||
# print(f'------------已下料: {first_finish_weight+second_finish_weight}kg-------------')
|
||||
@ -807,7 +837,8 @@ class VisualCallback:
|
||||
print(f'------------已下料(第二次): {first_finish_weight}kg-------------')
|
||||
|
||||
self._is_feed_stage=0
|
||||
if self.plc_data==5 or self.plc_data==37:
|
||||
if self.plc_data in self.plc_valid_data:
|
||||
self.state._upper_door_closed=2
|
||||
#第二次上料斗向下料斗转移
|
||||
loc_relay.control_upper_open_sync(12)
|
||||
loc_time_count=1
|
||||
@ -818,6 +849,7 @@ class VisualCallback:
|
||||
#initial_upper_weight=loc_mitter.read_data(1)
|
||||
#start_time=None
|
||||
self._is_feed_stage=4
|
||||
|
||||
while not self._is_finish:
|
||||
# print(f'------------上料斗向下料斗转移22222-------------')
|
||||
current_upper_weight = loc_mitter.read_data(1)
|
||||
@ -827,8 +859,9 @@ class VisualCallback:
|
||||
#如果重量连续5次为None,认为上料斗未就位,跳出循环
|
||||
print('------------第二次上到下,上料斗重量异常----------------')
|
||||
print('------------第二次上到下,上料斗重量异常----------------')
|
||||
self.state._upper_door_closed=0
|
||||
loc_relay.control_upper_close_sync(15)
|
||||
break
|
||||
return
|
||||
continue
|
||||
cur_weight_none=0
|
||||
if (current_upper_weight<600 and current_upper_weight>0) or upper_open_time_2 is not None:
|
||||
@ -838,6 +871,7 @@ class VisualCallback:
|
||||
loc_relay.control_arch_upper_open_async(5)
|
||||
# loc_relay.control_arch_upper_open()
|
||||
loc_relay.control_upper_open_sync(5)
|
||||
self.state._upper_door_closed=2
|
||||
# start_time=None
|
||||
#5秒后关闭
|
||||
loc_relay.control_upper_close_after()#control_upper_close_sync(8+loc_time_count)
|
||||
@ -853,6 +887,8 @@ class VisualCallback:
|
||||
time.sleep(0.5)
|
||||
else:
|
||||
loc_relay.control_upper_close_sync(15)
|
||||
|
||||
self.state._upper_door_closed=0
|
||||
# time.sleep(0.4)
|
||||
|
||||
#第三次下料斗转移到模具车
|
||||
@ -877,7 +913,9 @@ class VisualCallback:
|
||||
continue
|
||||
cur_weight_none=0
|
||||
second_finish_weight=initial_lower_weight-current_weight
|
||||
self._is_finish_ratio=(second_finish_weight+first_finish_weight)/need_total_weight
|
||||
self.state._mould_finish_weight=second_finish_weight+first_finish_weight
|
||||
self._is_finish_ratio=self.state._mould_finish_weight/need_total_weight
|
||||
self.state._mould_finish_ratio=self._is_finish_ratio
|
||||
print(f'------------已下料比例: {self._is_finish_ratio}-------------')
|
||||
# if self._is_finish_ratio>=1:
|
||||
#关5秒
|
||||
@ -1340,6 +1378,15 @@ class VisualCallback:
|
||||
#4即将振捣室5振捣室 64即将搅拌楼 66到达搅拌楼
|
||||
# print(f"[数据回调] 数值: 0x{data:02X} | 十进制: {data:3d} | 二进制: {binary}")
|
||||
self.plc_data=data
|
||||
if self.plc_data in self.plc_valid_data:
|
||||
if self.state._upper_door_position!=Upper_Door_Position.ZDS:
|
||||
self.state._upper_door_position=Upper_Door_Position.ZDS
|
||||
elif self.plc_data in self.plc_valid_data_jbl:
|
||||
if self.state._upper_door_position!=Upper_Door_Position.JBL:
|
||||
self.state._upper_door_position=Upper_Door_Position.JBL
|
||||
else:
|
||||
if self.state._upper_door_position!=Upper_Door_Position.Returning:
|
||||
self.state._upper_door_position=Upper_Door_Position.Returning
|
||||
|
||||
# @classmethod
|
||||
# def instance_exists(cls):
|
||||
@ -1360,82 +1407,12 @@ class VisualCallback:
|
||||
# self.safe_control_lower_close()
|
||||
|
||||
# 等待线程结束
|
||||
if self.callback_thread.is_alive():
|
||||
if self.callback_thread and self.callback_thread.is_alive():
|
||||
self.callback_thread.join(timeout=1.0)
|
||||
if self.diff_thread:
|
||||
if self.diff_thread and self.diff_thread.is_alive():
|
||||
self.diff_thread.join(timeout=1.0)
|
||||
|
||||
# self.relay_controller._close_lower_5s
|
||||
|
||||
def send_pd_data(self):
|
||||
"""
|
||||
发送PD数据到OPC队列
|
||||
"""
|
||||
# 构建PD数据
|
||||
_cur_mould=self._cur_mould_model
|
||||
if _cur_mould is not None:
|
||||
if _cur_mould.MouldCode:
|
||||
_pdrecords = self.pd_record_bll.get_last_pds(_cur_mould.MouldCode)
|
||||
if _pdrecords:
|
||||
_pdrecord=_pdrecords[0]
|
||||
if _pdrecord.TaskID:
|
||||
if _pdrecord.BlockNumber=='F':
|
||||
print(f'{_pdrecord.MouldCode} F块,不发送派单数据')
|
||||
print(f'{_pdrecord.MouldCode} F块,不发送派单数据')
|
||||
print(f'{_pdrecord.MouldCode} F块,不发送派单数据')
|
||||
return True
|
||||
_fact_volumn=self.get_fact_volumn(_pdrecord.MouldCode,_pdrecord.BlockNumber)
|
||||
if _fact_volumn>0:
|
||||
_pdrecord.FBetonVolume=_fact_volumn
|
||||
print(f'{_pdrecord.MouldCode}-{_pdrecord.BlockNumber} 实际派单方量:{_fact_volumn},{_fact_volumn},{_fact_volumn}')
|
||||
print(f'{_pdrecord.MouldCode}-{_pdrecord.BlockNumber} 实际派单方量:{_fact_volumn},{_fact_volumn},{_fact_volumn}')
|
||||
print(f'{_pdrecord.MouldCode}-{_pdrecord.BlockNumber} 实际派单方量:{_fact_volumn},{_fact_volumn},{_fact_volumn}')
|
||||
self.state._pd_data=_pdrecord
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
print(f'{_pdrecord.MouldCode} 未获取到数据-(等待扫码)')
|
||||
return False
|
||||
else:
|
||||
print(f'接口数据异常')
|
||||
return False
|
||||
else:
|
||||
return None
|
||||
def get_fact_volumn(self,mould_code:str,block_number:str='') -> float:
|
||||
"""获取实际派单发量"""
|
||||
_now_volumn=0
|
||||
_pd_volumn=0
|
||||
print(f'get_fact_volumn当前重量:{self._init_lower_weight}')
|
||||
_now_volumn=self._init_lower_weight/2500
|
||||
if not block_number and '-' in mould_code:
|
||||
block_number = mould_code.split('-')[0][-2:]
|
||||
if block_number in ['B1','B2','B3']:
|
||||
_pd_volumn=1.9
|
||||
elif block_number=='L1':
|
||||
_pd_volumn=2.0
|
||||
if _now_volumn>0.5:
|
||||
#保证至少0.5方
|
||||
_pd_volumn=1.9-_now_volumn+0.5
|
||||
_pd_volumn=math.ceil(_pd_volumn*10)/10
|
||||
|
||||
if _pd_volumn<0.8:
|
||||
_pd_volumn=0.8
|
||||
#调整
|
||||
elif block_number=='L2':
|
||||
#2.4方,大约L2和F的量
|
||||
_pd_volumn=2.4
|
||||
# if _weight>1300:
|
||||
#留0.15 math.floor(_now_volumn*10)/10 保留一位小数,丢掉其他的
|
||||
_pd_volumn=_pd_volumn-math.floor(_now_volumn*10)/10+0.1
|
||||
_pd_volumn=math.ceil(_pd_volumn*10)/10
|
||||
if _pd_volumn>2.1:
|
||||
_pd_volumn=2.1
|
||||
elif _pd_volumn<0.8:
|
||||
_pd_volumn=0.8
|
||||
|
||||
return _pd_volumn
|
||||
|
||||
|
||||
def get_current_mould(self):
|
||||
"""获取当前要浇筑的管片"""
|
||||
_not_poured=app_web_service.get_not_pour_artifacts()
|
||||
@ -1443,6 +1420,7 @@ class VisualCallback:
|
||||
_cur_poured_model=_not_poured[-1]
|
||||
if _cur_poured_model.MouldCode:
|
||||
self._cur_mould_model=_cur_poured_model
|
||||
self.state.current_mould=_cur_poured_model
|
||||
print(f'当前要浇筑的管片 {json.dumps(asdict(_cur_poured_model), ensure_ascii=False)}')
|
||||
else:
|
||||
print('当前没有未浇筑的管片')
|
||||
|
||||
Reference in New Issue
Block a user