2025-11-01 17:33:26 +08:00
|
|
|
|
from enum import IntEnum
|
|
|
|
|
|
from core.state import FeedStatus
|
|
|
|
|
|
from service.mould_service import MouldService
|
|
|
|
|
|
from busisness.blls import ArtifactBll
|
2025-12-12 18:00:14 +08:00
|
|
|
|
from busisness.models import ArtifactInfoModel,ArtifactInfo
|
2025-11-17 00:05:40 +08:00
|
|
|
|
import time
|
|
|
|
|
|
from datetime import datetime
|
2025-12-12 18:00:14 +08:00
|
|
|
|
from hardware.RFID.rfid_service import rfid_service
|
2025-11-21 14:55:52 +08:00
|
|
|
|
from config.settings import app_set_config
|
2025-11-01 17:33:26 +08:00
|
|
|
|
|
2025-09-26 13:32:34 +08:00
|
|
|
|
class FeedingProcess:
|
|
|
|
|
|
def __init__(self, relay_controller, inverter_controller,
|
|
|
|
|
|
transmitter_controller, vision_detector,
|
2025-11-21 14:55:52 +08:00
|
|
|
|
camera_controller, state):
|
2025-09-26 13:32:34 +08:00
|
|
|
|
self.relay_controller = relay_controller
|
2025-11-01 17:33:26 +08:00
|
|
|
|
self.artifact_bll = ArtifactBll()
|
2025-11-17 00:05:40 +08:00
|
|
|
|
self.mould_service = MouldService()
|
2025-09-26 13:32:34 +08:00
|
|
|
|
self.inverter_controller = inverter_controller
|
|
|
|
|
|
self.transmitter_controller = transmitter_controller
|
|
|
|
|
|
self.vision_detector = vision_detector
|
|
|
|
|
|
self.camera_controller = camera_controller
|
|
|
|
|
|
self.state = state
|
2025-12-12 18:00:14 +08:00
|
|
|
|
self.state._feed_status = FeedStatus.FNone
|
2025-11-12 09:22:21 +08:00
|
|
|
|
|
2025-11-17 00:05:40 +08:00
|
|
|
|
#标志位用,是否是第一次运行
|
|
|
|
|
|
self.is_first_flag=True
|
2025-09-26 13:32:34 +08:00
|
|
|
|
|
|
|
|
|
|
def start_feeding(self):
|
2025-11-12 09:22:21 +08:00
|
|
|
|
loc_state=self.state
|
2025-11-21 14:55:52 +08:00
|
|
|
|
loc_state._upper_weight=self.transmitter_controller.read_data(1)
|
|
|
|
|
|
loc_state._lower_weight=self.transmitter_controller.read_data(2)
|
2025-12-12 18:00:14 +08:00
|
|
|
|
# loc_state._upper_volume=round(loc_state._upper_weight/self.state.density,1)
|
2025-11-01 17:33:26 +08:00
|
|
|
|
"""开始生产管片"""
|
2025-11-21 14:55:52 +08:00
|
|
|
|
if loc_state._feed_status == FeedStatus.FNone:
|
2025-11-01 17:33:26 +08:00
|
|
|
|
return
|
2025-11-21 14:55:52 +08:00
|
|
|
|
elif loc_state._feed_status == FeedStatus.FCheckM:
|
2025-12-12 18:00:14 +08:00
|
|
|
|
print("---------------初始化数据------------------")
|
|
|
|
|
|
loc_state._mould_need_weight= 1200
|
|
|
|
|
|
loc_state._feed_status = FeedStatus.FFeed
|
2025-11-01 17:33:26 +08:00
|
|
|
|
return
|
2025-12-12 18:00:14 +08:00
|
|
|
|
elif loc_state._feed_status == FeedStatus.FFeed:
|
|
|
|
|
|
print("----------------下料------------------")
|
|
|
|
|
|
loc_state.mould_vibrate_time=time.time()
|
|
|
|
|
|
loc_state._mould_frequency=app_set_config.frequencies[0]
|
|
|
|
|
|
loc_state._mould_vibrate_status=1
|
2025-11-12 09:22:21 +08:00
|
|
|
|
#上料斗重量
|
2025-11-21 14:55:52 +08:00
|
|
|
|
loc_state.initial_upper_weight=loc_state._upper_weight
|
2025-11-12 09:22:21 +08:00
|
|
|
|
#下料斗重量
|
2025-12-12 18:00:14 +08:00
|
|
|
|
loc_state.initial_lower_weight=loc_state._lower_weight
|
|
|
|
|
|
self.feeding_stage(loc_state)
|
|
|
|
|
|
# if loc_state._mould_need_weight>loc_state.initial_lower_weight:
|
|
|
|
|
|
# self.transfer_material_from_upper_to_lower(loc_state,loc_state.initial_upper_weight,loc_state.initial_lower_weight)
|
|
|
|
|
|
# loc_state._feed_status = FeedStatus.FFeed1
|
|
|
|
|
|
# else:
|
|
|
|
|
|
# loc_state._feed_status = FeedStatus.FFeed1
|
2025-11-01 17:33:26 +08:00
|
|
|
|
return
|
2025-11-21 14:55:52 +08:00
|
|
|
|
elif loc_state._feed_status == FeedStatus.FFinished:
|
2025-11-17 00:05:40 +08:00
|
|
|
|
"""完成当前批次下料"""
|
2025-12-12 18:00:14 +08:00
|
|
|
|
print("振捣完成")
|
|
|
|
|
|
print("关闭所有网络继电器")
|
|
|
|
|
|
self.relay_controller.close_all()
|
2025-11-17 00:05:40 +08:00
|
|
|
|
return
|
2025-11-01 17:33:26 +08:00
|
|
|
|
|
|
|
|
|
|
def _start_feeding_stage(self):
|
|
|
|
|
|
"""启动指定下料阶段"""
|
2025-09-26 13:32:34 +08:00
|
|
|
|
"""开始分步下料"""
|
|
|
|
|
|
print("开始分步下料过程")
|
|
|
|
|
|
self.transfer_material_from_upper_to_lower()
|
|
|
|
|
|
|
2025-11-21 14:55:52 +08:00
|
|
|
|
def transfer_material_from_upper_to_lower(self,loc_state,initial_upper_weight,initial_lower_weight):
|
2025-11-01 17:33:26 +08:00
|
|
|
|
|
2025-11-12 09:22:21 +08:00
|
|
|
|
"""target_upper_weight:转移后剩下的上料斗重量"""
|
|
|
|
|
|
# 如果低于单次,全部卸掉
|
2025-12-12 18:00:14 +08:00
|
|
|
|
_max_lower_weight=app_set_config.max_lower_volume*loc_state.density
|
2025-11-21 14:55:52 +08:00
|
|
|
|
# if (initial_lower_weight+feed_weight>_max_lower_weight):
|
|
|
|
|
|
feed_weight=_max_lower_weight-initial_lower_weight
|
2025-11-12 09:22:21 +08:00
|
|
|
|
|
|
|
|
|
|
target_upper_weight=initial_upper_weight-feed_weight
|
|
|
|
|
|
target_upper_weight = max(target_upper_weight, 0)
|
2025-12-12 18:00:14 +08:00
|
|
|
|
# 确保下料斗出砼门关闭,同步关5秒
|
|
|
|
|
|
self.relay_controller.control_lower_close()
|
2025-09-26 13:32:34 +08:00
|
|
|
|
# 打开上料斗出砼门
|
2025-12-12 18:00:14 +08:00
|
|
|
|
# self.relay_controller.control_upper_open()
|
|
|
|
|
|
#一直打开3秒
|
2025-11-21 14:55:52 +08:00
|
|
|
|
self.relay_controller.control(self.relay_controller.DOOR_UPPER_OPEN, 'open')
|
2025-12-12 18:00:14 +08:00
|
|
|
|
time.sleep(3)
|
|
|
|
|
|
loc_state._upper_door_closed=False
|
2025-09-26 13:32:34 +08:00
|
|
|
|
# 等待物料流入下料斗,基于上料斗重量变化控制
|
2025-12-12 18:00:14 +08:00
|
|
|
|
|
2025-09-26 13:32:34 +08:00
|
|
|
|
start_time = time.time()
|
2025-11-12 09:22:21 +08:00
|
|
|
|
# timeout = 30 # 30秒超时
|
2025-09-26 13:32:34 +08:00
|
|
|
|
|
2025-11-21 14:55:52 +08:00
|
|
|
|
while loc_state.running:
|
2025-12-12 18:00:14 +08:00
|
|
|
|
# self.relay_controller.control_upper_open_sync()
|
|
|
|
|
|
self.relay_controller.control(self.relay_controller.DOOR_UPPER_OPEN, 'close')
|
2025-09-26 13:32:34 +08:00
|
|
|
|
current_upper_weight = self.transmitter_controller.read_data(1)
|
|
|
|
|
|
# 如果无法读取重量,继续尝试
|
|
|
|
|
|
if current_upper_weight is None:
|
|
|
|
|
|
print("无法读取上料斗重量,继续尝试...")
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
continue
|
2025-12-12 18:00:14 +08:00
|
|
|
|
|
2025-11-21 14:55:52 +08:00
|
|
|
|
loc_state._upper_weight=current_upper_weight
|
2025-12-12 18:00:14 +08:00
|
|
|
|
loc_state._upper_volume=round(loc_state._upper_weight/self.state.density,1)
|
2025-09-26 13:32:34 +08:00
|
|
|
|
print(f"上料斗当前重量: {current_upper_weight:.2f}kg")
|
|
|
|
|
|
|
|
|
|
|
|
# 如果达到目标重量,则关闭上料斗出砼门
|
|
|
|
|
|
if current_upper_weight <= target_upper_weight + 50: # 允许50kg的误差范围
|
|
|
|
|
|
print(f"达到目标重量,当前重量: {current_upper_weight:.2f}kg")
|
2025-11-12 09:22:21 +08:00
|
|
|
|
print(f"花费时间 {time.time() - start_time:.2f}秒")
|
2025-09-26 13:32:34 +08:00
|
|
|
|
break
|
2025-12-12 18:00:14 +08:00
|
|
|
|
# time.sleep(1)
|
|
|
|
|
|
# self.relay_controller.control(self.relay_controller.DOOR_UPPER_OPEN, 'open')
|
|
|
|
|
|
# time.sleep(0.2)
|
|
|
|
|
|
|
|
|
|
|
|
loc_state._upper_door_closed=True
|
|
|
|
|
|
# 关闭上料斗出砼门d
|
2025-11-21 14:55:52 +08:00
|
|
|
|
self.relay_controller.control_upper_close()
|
|
|
|
|
|
|
|
|
|
|
|
#测试用
|
2025-09-26 13:32:34 +08:00
|
|
|
|
print("上料斗下料完成")
|
|
|
|
|
|
|
2025-12-12 18:00:14 +08:00
|
|
|
|
def feeding_stage(self,loc_state):
|
2025-09-26 13:32:34 +08:00
|
|
|
|
"""第一阶段下料:下料斗向模具车下料(低速)"""
|
2025-12-12 18:00:14 +08:00
|
|
|
|
print("开始下料")
|
|
|
|
|
|
# self.relay_controller.control
|
|
|
|
|
|
first_finish_weight=0
|
|
|
|
|
|
while True:
|
|
|
|
|
|
current_weight = loc_state._lower_weight
|
|
|
|
|
|
loc_state._mould_finish_weight=loc_state.initial_lower_weight-current_weight
|
|
|
|
|
|
first_finish_weight=loc_state._mould_finish_weight
|
|
|
|
|
|
if current_weight<100:
|
|
|
|
|
|
#关5秒
|
|
|
|
|
|
self.relay_controller.control_lower_close()
|
|
|
|
|
|
break
|
2025-09-26 13:32:34 +08:00
|
|
|
|
|
2025-12-12 18:00:14 +08:00
|
|
|
|
time.sleep(1)
|
2025-09-26 13:32:34 +08:00
|
|
|
|
|
2025-12-12 18:00:14 +08:00
|
|
|
|
#打开上料斗出砼门
|
|
|
|
|
|
self.relay_controller.control_upper_open_sync(5)
|
|
|
|
|
|
while True:
|
2025-11-21 14:55:52 +08:00
|
|
|
|
|
2025-12-12 18:00:14 +08:00
|
|
|
|
if loc_state._upper_weight<3000:
|
|
|
|
|
|
#关5秒
|
|
|
|
|
|
self.relay_controller.control_upper_close()
|
|
|
|
|
|
break
|
|
|
|
|
|
loc_state.initial_lower_weight=loc_state.lower_weight
|
|
|
|
|
|
while True:
|
|
|
|
|
|
current_weight = loc_state._lower_weight
|
|
|
|
|
|
loc_state._mould_finish_weight=first_finish_weight+loc_state.initial_lower_weight-current_weight
|
|
|
|
|
|
if current_weight<100:
|
|
|
|
|
|
#关5秒
|
|
|
|
|
|
self.relay_controller.control_lower_close()
|
|
|
|
|
|
break
|
2025-09-26 13:32:34 +08:00
|
|
|
|
|
2025-12-12 18:00:14 +08:00
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
2025-09-26 13:32:34 +08:00
|
|
|
|
|
2025-12-12 18:00:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-09-26 13:32:34 +08:00
|
|
|
|
|
2025-12-12 18:00:14 +08:00
|
|
|
|
|
2025-09-26 13:32:34 +08:00
|
|
|
|
def return_upper_door_to_default(self):
|
|
|
|
|
|
"""上料斗回到默认位置(搅拌楼下接料位置)"""
|
|
|
|
|
|
print("上料斗回到默认位置")
|
2025-12-12 18:00:14 +08:00
|
|
|
|
# self.relay_controller.control(self.relay_controller.UPPER_TO_JBL, 'open')
|
2025-11-01 17:33:26 +08:00
|
|
|
|
self.state._upper_door_position = 'default'
|