Files
Feeding_control_system/feeding/process.py
2025-12-12 18:00:14 +08:00

168 lines
7.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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