feeding
This commit is contained in:
@ -3,6 +3,8 @@ from core.state import FeedStatus
|
||||
from service.mould_service import MouldService
|
||||
from busisness.blls import ArtifactBll
|
||||
from busisness.models import ArtifactInfoModel
|
||||
import time
|
||||
from datetime import datetime
|
||||
|
||||
class FeedingProcess:
|
||||
def __init__(self, relay_controller, inverter_controller,
|
||||
@ -10,6 +12,7 @@ class FeedingProcess:
|
||||
camera_controller, state, settings):
|
||||
self.relay_controller = relay_controller
|
||||
self.artifact_bll = ArtifactBll()
|
||||
self.mould_service = MouldService()
|
||||
self.inverter_controller = inverter_controller
|
||||
self.transmitter_controller = transmitter_controller
|
||||
self.vision_detector = vision_detector
|
||||
@ -17,6 +20,8 @@ class FeedingProcess:
|
||||
self.state = state
|
||||
self.state.feed_status = FeedStatus.FNone
|
||||
|
||||
#标志位用,是否是第一次运行
|
||||
self.is_first_flag=True
|
||||
self.settings = settings
|
||||
|
||||
def start_feeding(self):
|
||||
@ -26,19 +31,32 @@ class FeedingProcess:
|
||||
loc_state.feed_status = FeedStatus.FCheckM
|
||||
return
|
||||
elif loc_state.feed_status == FeedStatus.FCheckM:
|
||||
"""开始生产管片"""
|
||||
loc_state._lower_feeding_stage = 4
|
||||
self.wait_for_vehicle_alignment()
|
||||
loc_state.feed_status = FeedStatus.FStart
|
||||
print("生产已检查模车")
|
||||
|
||||
if self.settings.debug_feeding:
|
||||
loc_state.feed_status = FeedStatus.FApiCheck
|
||||
if self.state.vehicle_aligned:
|
||||
loc_state.feed_status = FeedStatus.FCheckGB
|
||||
print("检查模车")
|
||||
return
|
||||
elif loc_state.feed_status == FeedStatus.FApiCheck:
|
||||
print("生产已开始")
|
||||
time.sleep(2)
|
||||
loc_modules = MouldService.get_not_pour_artifacts()
|
||||
loc_modules = self.mould_service.get_not_pour_artifacts()
|
||||
if loc_modules:
|
||||
# 取第一个未浇筑的管片
|
||||
#后续放入队列处理
|
||||
loc_module = loc_modules[0]
|
||||
#API
|
||||
loc_module.Source = 1
|
||||
loc_module.BeginTime=datetime.now()
|
||||
|
||||
self.artifact_bll.insert_artifact_task(loc_module)
|
||||
self.state.current_artifact = loc_module
|
||||
|
||||
# self.artifact_bll.finish_artifact_task(loc_state.current_artifact.ArtifactID,1.92)
|
||||
self.state.feed_status = FeedStatus.FCheckGB
|
||||
else:
|
||||
#未读取到AIP接口数据.
|
||||
self.state.current_artifact = None
|
||||
@ -71,7 +89,7 @@ class FeedingProcess:
|
||||
time.sleep(10)
|
||||
loc_state.feed_status = FeedStatus.FUpperToLower
|
||||
#计算本次生产需要的总重量
|
||||
print(f"本次生产需要的总重量:{self.state.need_total_weight}")
|
||||
print(f"本次生产需要的总重量:{self.state._mould_need_weight}")
|
||||
return
|
||||
elif loc_state.feed_status == FeedStatus.FUpperToLower:
|
||||
print("上料斗向下料斗转移")
|
||||
@ -80,13 +98,13 @@ class FeedingProcess:
|
||||
#下料斗重量
|
||||
loc_state.initial_lower_weight=self.transmitter_controller.read_data(2)
|
||||
#需要的总重量
|
||||
loc_state.need_total_weight=loc_state.current_artifact.BetonVolume*loc_state.density
|
||||
if loc_state.need_total_weight > loc_state.initial_upper_weight + loc_state.initial_lower_weight:
|
||||
loc_state._mould_need_weight=loc_state.current_artifact.BetonVolume*loc_state.density
|
||||
if loc_state._mould_need_weight > loc_state.initial_upper_weight + loc_state.initial_lower_weight:
|
||||
# 等待上料斗重量增加(多久不够报警,可能出现F块不足的情况)
|
||||
print('重量不够,需要增加')
|
||||
return
|
||||
|
||||
if loc_state.need_total_weight>loc_state.initial_lower_weight:
|
||||
if loc_state._mould_need_weight>loc_state.initial_lower_weight:
|
||||
if self.state._upper_door_position != 'over_lower':
|
||||
#是否需要等待上料斗下料,如果下料斗够重量,则不需要等待
|
||||
return
|
||||
@ -94,32 +112,43 @@ class FeedingProcess:
|
||||
# 需要等待上料斗下料
|
||||
# 最后一块进行尾数控制
|
||||
# 最后一块F块,前面多要0.25,0.3,F块直接下料(先多下0.3后续)
|
||||
loc_FWeight=0.3*loc_state.density
|
||||
loc_feed_weight=loc_state.need_total_weight-loc_state.initial_lower_weight-loc_FWeight
|
||||
self.transfer_material_from_upper_to_lower(loc_state.initial_upper_weight,loc_state.initial_lower_weight,loc_feed_weight)
|
||||
|
||||
self.state.feed_status = FeedStatus.FFeed1
|
||||
# loc_FWeight=0.3*loc_state.density
|
||||
# loc_feed_weight=loc_state.need_total_weight-loc_state.initial_lower_weight-loc_FWeight
|
||||
self.transfer_material_from_upper_to_lower(loc_state.initial_upper_weight,loc_state.initial_lower_weight)
|
||||
#完成了上料斗重量转移才进入下料斗
|
||||
loc_state.feed_status = FeedStatus.FFeed1
|
||||
# time.sleep(10)
|
||||
return
|
||||
elif self.state.feed_status == FeedStatus.FFeed1:
|
||||
elif loc_state.feed_status == FeedStatus.FFeed1:
|
||||
#下料
|
||||
# self._start_feeding_stage()
|
||||
self.feeding_stage_one(loc_state)
|
||||
print("下料1")
|
||||
return
|
||||
elif self.state.feed_status == FeedStatus.FFeed2:
|
||||
elif loc_state.feed_status == FeedStatus.FFeed2:
|
||||
#上料
|
||||
# self._start_feeding_stage()
|
||||
self.feeding_stage_two(loc_state)
|
||||
print("下料2")
|
||||
return
|
||||
elif self.state.feed_status == FeedStatus.FFeed3:
|
||||
elif loc_state.feed_status == FeedStatus.FFeed3:
|
||||
#下料
|
||||
# self._start_feeding_stage()
|
||||
self.feeding_stage_three(loc_state)
|
||||
print("下料3")
|
||||
return
|
||||
elif self.state.feed_status == FeedStatus.FFinished:
|
||||
print("生产已完成")
|
||||
self.state.feed_status = FeedStatus.FCheckM
|
||||
return
|
||||
elif loc_state.feed_status == FeedStatus.FFinished:
|
||||
"""完成当前批次下料"""
|
||||
print("当前批次下料完成,关闭出砼门")
|
||||
|
||||
if loc_state.overflow_detected=="浇筑满":
|
||||
self.inverter_controller.control('stop')
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_1, 'close')
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_2, 'close')
|
||||
#更新数据库状态
|
||||
self.artifact_bll.finish_artifact_task(loc_state.current_artifact.ArtifactID,loc_state._mould_finish_weight/loc_state.density)
|
||||
loc_state.feed_status = FeedStatus.FCheckM
|
||||
return
|
||||
|
||||
def _start_feeding_stage(self):
|
||||
"""启动指定下料阶段"""
|
||||
@ -127,7 +156,7 @@ class FeedingProcess:
|
||||
print("开始分步下料过程")
|
||||
self.transfer_material_from_upper_to_lower()
|
||||
|
||||
def transfer_material_from_upper_to_lower(self,initial_upper_weight,initial_lower_weight,feed_weight):
|
||||
def transfer_material_from_upper_to_lower(self,initial_upper_weight,initial_lower_weight):
|
||||
|
||||
"""target_upper_weight:转移后剩下的上料斗重量"""
|
||||
# 如果低于单次,全部卸掉
|
||||
@ -186,118 +215,110 @@ class FeedingProcess:
|
||||
break
|
||||
time.sleep(self.settings.alignment_check_interval)
|
||||
|
||||
def feeding_stage_one(self):
|
||||
def feeding_stage_one(self,loc_state):
|
||||
"""第一阶段下料:下料斗向模具车下料(低速)"""
|
||||
print("开始第一阶段下料:下料斗低速下料")
|
||||
self.inverter_controller.set_frequency(self.settings.frequencies[0])
|
||||
self.inverter_controller.control('start')
|
||||
if self.is_first_flag:
|
||||
self.inverter_controller.set_frequency(self.settings.frequencies[0])
|
||||
self.inverter_controller.control('start')
|
||||
|
||||
# 确保上料斗出砼门关闭
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_1, 'close')
|
||||
# 打开下料斗出砼门
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_2, 'open')
|
||||
# 确保上料斗出砼门关闭
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_1, 'close')
|
||||
# 打开下料斗出砼门
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_2, 'open')
|
||||
loc_cur_weight = self.transmitter_controller.read_data(2)
|
||||
if loc_cur_weight is None:
|
||||
#报警处理
|
||||
print("无法获取初始重量,取消下料")
|
||||
# self.finish_feeding_process()
|
||||
return
|
||||
loc_state.initial_lower_weight=loc_cur_weight
|
||||
self.is_first_flag=False
|
||||
|
||||
import time
|
||||
|
||||
start_time = time.time()
|
||||
initial_weight = self.transmitter_controller.read_data(2)
|
||||
if initial_weight is None:
|
||||
print("无法获取初始重量,取消下料")
|
||||
self.finish_feeding_process()
|
||||
|
||||
current_weight = self.transmitter_controller.read_data(2)
|
||||
if current_weight is None:
|
||||
#报警处理
|
||||
print("无法获取当前重量,取消下料")
|
||||
# self.finish_feeding_process()
|
||||
return
|
||||
loc_state._mould_finish_weight=loc_state.initial_lower_weight-current_weight
|
||||
target_weight = loc_state._mould_need_weight/3
|
||||
|
||||
target_weight = initial_weight + self.settings.single_batch_weight
|
||||
|
||||
while self.state._lower_feeding_stage == 1:
|
||||
current_weight = self.transmitter_controller.read_data(2)
|
||||
if current_weight is None:
|
||||
self.state.lower_weight_error_count += 1
|
||||
if self.state.lower_weight_error_count >= self.settings.max_error_count:
|
||||
print("下料斗传感器连续读取失败,停止下料")
|
||||
self.finish_feeding_process()
|
||||
return
|
||||
else:
|
||||
self.state.lower_weight_error_count = 0
|
||||
|
||||
if (current_weight is not None and current_weight >= target_weight) or (time.time() - start_time) > 30:
|
||||
self.state._lower_feeding_stage = 2
|
||||
self.feeding_stage_two()
|
||||
break
|
||||
time.sleep(2)
|
||||
if (current_weight is not None and loc_state._mould_finish_weight >= target_weight) or (time.time() - start_time) > 30:
|
||||
loc_state.feed_status = FeedStatus.FFeed2
|
||||
loc_state._lower_feeding_stage = 2
|
||||
self.is_first_flag=True
|
||||
return
|
||||
else:
|
||||
time.sleep(1)
|
||||
|
||||
def feeding_stage_two(self):
|
||||
"""第二阶段下料:下料斗向模具车下料(中速)"""
|
||||
print("开始第二阶段下料:下料斗中速下料")
|
||||
self.inverter_controller.set_frequency(self.settings.frequencies[1])
|
||||
if self.is_first_flag:
|
||||
print("开始第二阶段下料:下料斗中速下料")
|
||||
self.inverter_controller.set_frequency(self.settings.frequencies[1])
|
||||
|
||||
# 保持下料斗出砼门打开
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_2, 'open')
|
||||
# 确保上料斗出砼门关闭
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_1, 'close')
|
||||
# 保持下料斗出砼门打开
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_2, 'open')
|
||||
# 确保上料斗出砼门关闭
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_1, 'close')
|
||||
# loc_cur_weight = self.transmitter_controller.read_data(2)
|
||||
# if loc_cur_weight is None:
|
||||
# #报警处理
|
||||
# print("无法获取初始重量,取消下料")
|
||||
# # self.finish_feeding_process()
|
||||
# return
|
||||
# loc_state.initial_lower_weight=loc_cur_weight
|
||||
self.is_first_flag=False
|
||||
|
||||
import time
|
||||
start_time = time.time()
|
||||
initial_weight = self.transmitter_controller.read_data(2)
|
||||
if initial_weight is None:
|
||||
print("无法获取初始重量,取消下料")
|
||||
self.finish_feeding_process()
|
||||
current_weight = self.transmitter_controller.read_data(2)
|
||||
if current_weight is None:
|
||||
#报警处理
|
||||
print("无法获取当前重量,取消下料")
|
||||
# self.finish_feeding_process()
|
||||
return
|
||||
|
||||
target_weight = initial_weight + self.settings.single_batch_weight
|
||||
|
||||
while self.state._lower_feeding_stage == 2:
|
||||
current_weight = self.transmitter_controller.read_data(2)
|
||||
if current_weight is None:
|
||||
self.state.lower_weight_error_count += 1
|
||||
if self.state.lower_weight_error_count >= self.settings.max_error_count:
|
||||
print("下料斗传感器连续读取失败,停止下料")
|
||||
self.finish_feeding_process()
|
||||
return
|
||||
else:
|
||||
self.state.lower_weight_error_count = 0
|
||||
|
||||
if (current_weight is not None and current_weight >= target_weight) or (time.time() - start_time) > 30:
|
||||
self.state._lower_feeding_stage = 3
|
||||
self.feeding_stage_three()
|
||||
break
|
||||
time.sleep(2)
|
||||
|
||||
loc_state._mould_finish_weight=loc_state.initial_lower_weight-current_weight
|
||||
target_weight = (loc_state._mould_need_weight/3)*2
|
||||
|
||||
if (current_weight is not None and loc_state._mould_finish_weight >= target_weight) or (time.time() - start_time) > 30:
|
||||
loc_state.feed_status = FeedStatus.FFeed3
|
||||
loc_state._lower_feeding_stage = 3
|
||||
self.is_first_flag=True
|
||||
return
|
||||
else:
|
||||
time.sleep(1)
|
||||
def feeding_stage_three(self):
|
||||
"""第三阶段下料:下料斗向模具车下料(高速)"""
|
||||
print("开始第三阶段下料:下料斗高速下料")
|
||||
self.inverter_controller.set_frequency(self.settings.frequencies[2])
|
||||
|
||||
# 保持下料斗出砼门打开
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_2, 'open')
|
||||
# 确保上料斗出砼门关闭
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_1, 'close')
|
||||
|
||||
import time
|
||||
start_time = time.time()
|
||||
initial_weight = self.transmitter_controller.read_data(2)
|
||||
if initial_weight is None:
|
||||
print("无法获取初始重量,取消下料")
|
||||
self.finish_feeding_process()
|
||||
if self.is_first_flag:
|
||||
print("开始第三阶段下料:下料斗高速下料")
|
||||
self.inverter_controller.set_frequency(self.settings.frequencies[2])
|
||||
# 保持下料斗出砼门打开
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_2, 'open')
|
||||
# 确保上料斗出砼门关闭
|
||||
self.relay_controller.control(self.relay_controller.DOOR_LOWER_1, 'close')
|
||||
self.is_first_flag=False
|
||||
|
||||
current_weight = self.transmitter_controller.read_data(2)
|
||||
if current_weight is None:
|
||||
#报警处理
|
||||
print("无法获取当前重量,取消下料")
|
||||
# self.finish_feeding_process()
|
||||
return
|
||||
|
||||
target_weight = initial_weight + self.settings.single_batch_weight
|
||||
|
||||
while self.state._lower_feeding_stage == 3:
|
||||
current_weight = self.transmitter_controller.read_data(2)
|
||||
if current_weight is None:
|
||||
self.state.lower_weight_error_count += 1
|
||||
if self.state.lower_weight_error_count >= self.settings.max_error_count:
|
||||
print("下料斗传感器连续读取失败,停止下料")
|
||||
self.finish_feeding_process()
|
||||
return
|
||||
else:
|
||||
self.state.lower_weight_error_count = 0
|
||||
|
||||
if (current_weight is not None and current_weight >= target_weight) or (time.time() - start_time) > 30:
|
||||
self.state._lower_feeding_stage = 4
|
||||
self.finish_current_batch()
|
||||
break
|
||||
time.sleep(2)
|
||||
|
||||
loc_state._mould_finish_weight=loc_state.initial_lower_weight-current_weight
|
||||
target_weight = loc_state._mould_need_weight
|
||||
|
||||
if (current_weight is not None and loc_state._mould_finish_weight >= target_weight):
|
||||
loc_state.feed_status = FeedStatus.FFinished
|
||||
loc_state._lower_feeding_stage = 5
|
||||
self.is_first_flag=True
|
||||
return
|
||||
else:
|
||||
time.sleep(1)
|
||||
|
||||
def finish_current_batch(self):
|
||||
"""完成当前批次下料"""
|
||||
print("当前批次下料完成,关闭出砼门")
|
||||
@ -341,5 +362,5 @@ class FeedingProcess:
|
||||
def return_upper_door_to_default(self):
|
||||
"""上料斗回到默认位置(搅拌楼下接料位置)"""
|
||||
print("上料斗回到默认位置")
|
||||
self.relay_controller.control(self.relay_controller.DOOR_UPPER, 'close')
|
||||
self.relay_controller.control(self.relay_controller.UPPER_TO_JBL, 'open')
|
||||
self.state._upper_door_position = 'default'
|
||||
|
||||
Reference in New Issue
Block a user