Merge branch 'feature/main_ui' of http://www.xj-robot.com:3000/xiongyi/Feeding_control_system into feature/main_ui

This commit is contained in:
2025-11-13 09:40:58 +08:00
8 changed files with 89 additions and 65 deletions

View File

@ -56,5 +56,10 @@ class Settings:
#是否在线生产
self.is_online_control = True # 是否API在线
#最后一块进行尾数控制
# self.block_numbers=['B1','B2','B3','L1','L2','F']
#需核实上下位漏斗容量
self.max_upper_volume = 2.4 # 上料斗容量(方)
self.max_lower_volume = 2.4 # 下料斗容量(方)

View File

@ -21,6 +21,9 @@ class SystemState(QObject):
self.last_upper_weight = 0
self.last_lower_weight = 0
self.last_weight_time = 0
self.need_total_weight=0
self.initial_upper_weight=0
self.initial_lower_weight=0
# 错误计数
self.upper_weight_error_count = 0
@ -40,6 +43,9 @@ class SystemState(QObject):
self.current_artifact=None
#当前生产状态
self.feed_status=FeedStatus.FNone
#每方重量
self.density=2500
# 记录需要监听的属性名(筛选掉不需要发信号的内部变量)
#是否破拱
@ -64,14 +70,16 @@ class FeedStatus(IntEnum):
#RFID检测或匹配
FRFID=2,
# 开始(管片待生产任务)
FStart = 3
FApiCheck = 3
# 检查盖板(盖板到位)
FCheckGB = 4
# 上料到下料(上料斗到下料斗)
FUpperToLower=5
#下料1
FFeed1 = 5
FFeed1 = 6
# 下料2
FFeed2 = 6
FFeed2 = 7
# 下料3
FFeed3 = 7
FFeed3 = 8
#完成(管片生产完成)
FFinished = 11

View File

@ -164,6 +164,7 @@ class FeedingControlSystem:
"""启动下料流程"""
self.lower_feeding_thread = threading.Thread(
target=self._start_lower_feeding,
name="Feeding",
daemon=True
)
self.lower_feeding_thread.start()

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -62,6 +62,7 @@ class FeedingController:
print("发送要料请求至搅拌楼...")
# self.settings.
self.process.return_upper_door_to_default()
# 这里需要与同事对接具体的通信方式
# 可能是Modbus写寄存器、TCP通信、HTTP请求等

View File

@ -16,20 +16,22 @@ class FeedingProcess:
self.camera_controller = camera_controller
self.state = state
self.state.feed_status = FeedStatus.FNone
self.settings = settings
def start_feeding(self):
loc_state=self.state
"""开始生产管片"""
if self.state.feed_status == FeedStatus.FNone:
self.state.feed_status = FeedStatus.FCheckM
if loc_state.feed_status == FeedStatus.FNone:
loc_state.feed_status = FeedStatus.FCheckM
return
elif self.state.feed_status == FeedStatus.FCheckM:
self.state._lower_feeding_stage = 4
elif loc_state.feed_status == FeedStatus.FCheckM:
loc_state._lower_feeding_stage = 4
self.wait_for_vehicle_alignment()
self.state.feed_status = FeedStatus.FStart
loc_state.feed_status = FeedStatus.FStart
print("生产已检查模车")
return
elif self.state.feed_status == FeedStatus.FStart:
elif loc_state.feed_status == FeedStatus.FApiCheck:
print("生产已开始")
time.sleep(2)
loc_modules = MouldService.get_not_pour_artifacts()
@ -41,7 +43,7 @@ class FeedingProcess:
#未读取到AIP接口数据.
self.state.current_artifact = None
return
elif self.state.feed_status == FeedStatus.FRFID:
elif loc_state.feed_status == FeedStatus.FRFID:
print("生产已检查RFID")
#RFID格式模具编号,分块号,尺寸规格,方量
rfid_info =''
@ -64,14 +66,55 @@ class FeedingProcess:
#确认是否保存到数据库
self.state.feed_status = FeedStatus.FCheckGB
return
elif self.state.feed_status == FeedStatus.FCheckGB:
print("生产已检查盖板")
elif loc_state.feed_status == FeedStatus.FCheckGB:
print("检查盖板对齐,")
time.sleep(10)
self.state.feed_status = FeedStatus.FFeed
loc_state.feed_status = FeedStatus.FUpperToLower
#计算本次生产需要的总重量
print(f"本次生产需要的总重量:{self.state.need_total_weight}")
return
elif self.state.feed_status == FeedStatus.FFeed:
self._start_feeding_stage()
print("生产已下料")
elif loc_state.feed_status == FeedStatus.FUpperToLower:
print("上料斗向下料斗转移")
#上料斗重量
loc_state.initial_upper_weight=self.transmitter_controller.read_data(1)
#下料斗重量
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:
# 等待上料斗重量增加(多久不够报警可能出现F块不足的情况)
print('重量不够,需要增加')
return
if loc_state.need_total_weight>loc_state.initial_lower_weight:
if self.state._upper_door_position != 'over_lower':
#是否需要等待上料斗下料,如果下料斗够重量,则不需要等待
return
else:
# 需要等待上料斗下料
# 最后一块进行尾数控制
# 最后一块F块前面多要0.25,0.3F块直接下料先多下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
# time.sleep(10)
return
elif self.state.feed_status == FeedStatus.FFeed1:
#下料
# self._start_feeding_stage()
print("下料1")
return
elif self.state.feed_status == FeedStatus.FFeed2:
#上料
# self._start_feeding_stage()
print("下料2")
return
elif self.state.feed_status == FeedStatus.FFeed3:
#下料
# self._start_feeding_stage()
print("下料3")
return
elif self.state.feed_status == FeedStatus.FFinished:
print("生产已完成")
@ -81,42 +124,19 @@ class FeedingProcess:
def _start_feeding_stage(self):
"""启动指定下料阶段"""
"""开始分步下料"""
if self.state._lower_feeding_stage != 0:
print("下料已在进行中")
return
print("开始分步下料过程")
# 重置计数器
#下料斗下料循环次数
self.state.lower_feeding_cycle = 0
#上料斗已下料次数
self.state.upper_feeding_count = 0
#上料斗最大下料次数
self.state.upper_feeding_max = 2
# 第一次上料
self.transfer_material_from_upper_to_lower()
# 等待模具车对齐并开始第一轮下料
# self.state._lower_feeding_stage = 4
# self.wait_for_vehicle_alignment()
def transfer_material_from_upper_to_lower(self):
"""上料斗向下料斗下料"""
print(f"上料斗向下料斗下料 (第 {self.state.upper_feeding_count + 1} 次)")
# 记录下料前的重量
initial_upper_weight = self.transmitter_controller.read_data(1)
# 如果无法读取重量,直接报错
if initial_upper_weight is None:
raise Exception("无法读取上料斗重量传感器数据,下料操作终止")
# 单次下料重量(kg),self.settings.single_batch_weight
target_upper_weight = initial_upper_weight - self.settings.single_batch_weight
target_upper_weight = max(target_upper_weight, 0) # 确保不低于0
print(f"上料斗初始重量: {initial_upper_weight:.2f}kg, 目标重量: {target_upper_weight:.2f}kg")
def transfer_material_from_upper_to_lower(self,initial_upper_weight,initial_lower_weight,feed_weight):
"""target_upper_weight转移后剩下的上料斗重量"""
# 如果低于单次,全部卸掉
_max_lower_weight=self.settings.max_lower_volume*self.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)
# 确保下料斗出砼门关闭
self.relay_controller.control(self.relay_controller.DOOR_LOWER_2, 'close')
# 打开上料斗出砼门
@ -125,11 +145,10 @@ class FeedingProcess:
# 等待物料流入下料斗,基于上料斗重量变化控制
import time
start_time = time.time()
timeout = 30 # 30秒超时
# timeout = 30 # 30秒超时
while time.time() - start_time < timeout:
while self.state.running:
current_upper_weight = self.transmitter_controller.read_data(1)
# 如果无法读取重量,继续尝试
if current_upper_weight is None:
print("无法读取上料斗重量,继续尝试...")
@ -141,26 +160,16 @@ class FeedingProcess:
# 如果达到目标重量,则关闭上料斗出砼门
if current_upper_weight <= target_upper_weight + 50: # 允许50kg的误差范围
print(f"达到目标重量,当前重量: {current_upper_weight:.2f}kg")
print(f"花费时间 {time.time() - start_time:.2f}")
break
elif time.time() - start_time > 25: # 如果25秒后重量变化过小
weight_change = initial_upper_weight - current_upper_weight
if weight_change < 100: # 如果重量变化小于100kg
print("重量变化过小,可能存在堵塞,交由监控系统处理...")
break
#需要增加报警处理
print("重量变化过小,可能存在堵塞")
time.sleep(1)
# 关闭上料斗出砼门
self.relay_controller.control(self.relay_controller.DOOR_LOWER_1, 'close')
# 验证下料结果
final_upper_weight = self.transmitter_controller.read_data(1)
if final_upper_weight is not None:
actual_transferred = initial_upper_weight - final_upper_weight
print(f"实际下料重量: {actual_transferred:.2f}kg")
# 增加上料计数
self.state.upper_feeding_count += 1
print("上料斗下料完成")
def wait_for_vehicle_alignment(self):