|
|
@@ -4,10 +4,11 @@ from utils.s7data import *
|
|
|
from models.data_sender import *
|
|
|
|
|
|
class Trace_pusher:
|
|
|
- def __init__(self, data_s7: S7data, logger: logging.Logger, sender: Sender, strand_position: list, hostsend_flag=False, hostmove_flag=False):
|
|
|
+ def __init__(self, data_s7: S7data, logger: logging.Logger, sender: Sender, strand_position: list, manual_change_heat_sig: Statepoint, hostsend_flag=False, hostmove_flag=False):
|
|
|
self.data_s7 = data_s7
|
|
|
self.logger = logger
|
|
|
self.sender = sender
|
|
|
+ self.manual_change_heat_sig = manual_change_heat_sig
|
|
|
self.strands_cutting = [[], [], [], [], [], [], [], []]
|
|
|
self.strands_buffer = [[], [], [], [], [], [], [], []]
|
|
|
self.locks = [threading.Lock() for i in range(8)]
|
|
|
@@ -39,6 +40,8 @@ class Trace_pusher:
|
|
|
self.pusher_left.hmd_add(0)
|
|
|
self.pusher_right.hmd_add(0)
|
|
|
|
|
|
+ self.manual_change_heat_sig.set_excite_action(self.manual_change_heat)
|
|
|
+
|
|
|
self.pusher_left.set_convertor(lambda data: data < min(self.strand_position))
|
|
|
self.pusher_right.set_convertor(lambda data: data > max(self.strand_position))
|
|
|
self.pusher_left.set_excite_action(lambda: self.arrive_cooling_bed('left'))
|
|
|
@@ -59,6 +62,7 @@ class Trace_pusher:
|
|
|
self.integration_total = [0] * 8
|
|
|
self.integration_lock = threading.Lock()
|
|
|
self.billet_out_sig = [self.data_s7.make_point(f"L{i+1}拉速", Integration_speed_mpmin) for i in range(8)]
|
|
|
+ self.speed_to_zero_sig = [self.data_s7.make_point(f"L{i+1}拉速") for i in range(8)]
|
|
|
self.billet_position = [
|
|
|
self.data_s7.make_point('L1切割信号[1]'),
|
|
|
self.data_s7.make_point('L2切割信号[1]'),
|
|
|
@@ -96,18 +100,21 @@ class Trace_pusher:
|
|
|
]
|
|
|
|
|
|
if self.hostmove_flag:
|
|
|
- self.hostmove_sig = data_s7.make_point('推钢机激光')
|
|
|
- self.hostmove_sig.hmd_add(0)
|
|
|
- self.hostmove_sig.set_convertor(lambda data: data > 19000)
|
|
|
+ self.hostmove_sig = data_s7.make_point('热送辊道状态[1]')
|
|
|
self.hostmove_sig.set_excite_action(lambda: self.billet_to_stack("步进冷床", self.get_billet('right')))
|
|
|
|
|
|
for i in range(8):
|
|
|
self.billet_position[i].allow_update(False)
|
|
|
self.billet_position[i].set_state(False)
|
|
|
+ self.billet_out_sig[i].allow_update(False)
|
|
|
+ self.billet_out_sig[i].set_state(False)
|
|
|
# 6号机 + 5号机
|
|
|
# 拉速补充钢坯
|
|
|
self.billet_out_sig[i].set_convertor(lambda data, i=i: round(data*1000) >= self.integration_total[i] + self.length_cutting[i].data)
|
|
|
self.billet_out_sig[i].set_excite_action(lambda i=i: self.billet_out_action(i))
|
|
|
+ # 拉速为0时表示此时拉速补偿已经不可用
|
|
|
+ self.speed_to_zero_sig[i].set_convertor(lambda data: data == 0)
|
|
|
+ self.speed_to_zero_sig[i].set_excite_action(lambda i=i: self.billet_out_sig[i].allow_update(False))
|
|
|
# 正常情况进入跟踪
|
|
|
self.billet_position[i].set_excite_action(lambda i=i: self.billet_in_buffer_action(i))
|
|
|
self.billet_position[i].allow_update()
|
|
|
@@ -127,15 +134,21 @@ class Trace_pusher:
|
|
|
self.hostsend_barrier[i].set_reset_action(lambda i=i: self.logger.debug(f"{i+1}流热送挡板关闭"))
|
|
|
self.hostsend_barrier[i].allow_update()
|
|
|
|
|
|
+ def integration_start(self, i):
|
|
|
+ if self.speed_to_zero_sig[i].data == 0:
|
|
|
+ return None
|
|
|
+ self.billet_out_sig[i].data = 0
|
|
|
+ self.billet_out_sig[i].state = False
|
|
|
+ self.integration_total[i] = 0
|
|
|
+ self.billet_out_sig[i].allow_update()
|
|
|
+
|
|
|
def billet_out_action(self, i):
|
|
|
billetNo = self.current_heatNo + '0' + str(i+1) + '99'
|
|
|
sizing = self.length_cutting[i].data
|
|
|
speed = self.drawing_speed[i].data
|
|
|
- # 积分的钢坯长度的累计
|
|
|
- with self.integration_lock:
|
|
|
- if self.strands_cutting[i]:
|
|
|
- return None
|
|
|
- self.integration_total[i] += sizing
|
|
|
+
|
|
|
+ if self.strands_cutting[i]:
|
|
|
+ return None
|
|
|
|
|
|
# [坯号, 炉次信息, 定尺, 拉速, 开切时间, 停切时间]
|
|
|
self.billet_out[i] = [billetNo, self.current_heatData, sizing, speed, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), '']
|
|
|
@@ -146,6 +159,10 @@ class Trace_pusher:
|
|
|
if self.strands_cutting[i]:
|
|
|
return None
|
|
|
time.sleep(0.5)
|
|
|
+
|
|
|
+ # 漏钢时,积分数据不会被清零,需要累加
|
|
|
+ with self.integration_lock:
|
|
|
+ self.integration_total[i] += sizing
|
|
|
self.billet_in_buffer_action(i)
|
|
|
|
|
|
def billet_in_buffer_action(self, i):
|
|
|
@@ -170,14 +187,14 @@ class Trace_pusher:
|
|
|
with self.locks[i]:
|
|
|
if self.strands_buffer[i]:
|
|
|
self.barrier_checker[i] = True
|
|
|
- time.sleep(12)
|
|
|
+ time.sleep(10)
|
|
|
billetData = self.strands_buffer[i]
|
|
|
self.strands_buffer[i] = []
|
|
|
if self.strand_position[i] <= self.pusher_left.data:
|
|
|
- self.logger.info(f"[TRACE]{i+1}流钢坯通过挡板进入推钢区域,在推钢机左侧")
|
|
|
+ self.logger.info(f"[TRACE]{i+1}流钢坯通过挡板进入推钢区域,在推钢机北侧")
|
|
|
self.pusher_left_list.append(billetData)
|
|
|
else:
|
|
|
- self.logger.info(f"[TRACE]{i+1}流钢坯通过挡板进入推钢区域,在推钢机右侧")
|
|
|
+ self.logger.info(f"[TRACE]{i+1}流钢坯通过挡板进入推钢区域,在推钢机南侧")
|
|
|
self.pusher_right_list.append(billetData)
|
|
|
|
|
|
if self.hostsend_flag and self.hostsend_barrier[i].state:
|
|
|
@@ -202,7 +219,7 @@ class Trace_pusher:
|
|
|
break
|
|
|
if index == -1:
|
|
|
pass
|
|
|
- #self.logger.warning(f"[TRACE]推钢机左侧未找到{i+1}流的热送钢坯")
|
|
|
+ #self.logger.warning(f"[TRACE]推钢机北侧未找到{i+1}流的热送钢坯")
|
|
|
else:
|
|
|
gp_tmp = self.pusher_left_list[index]
|
|
|
self.pusher_left_list = self.pusher_left_list[:index] + self.pusher_left_list[index+1:]
|
|
|
@@ -214,16 +231,16 @@ class Trace_pusher:
|
|
|
break
|
|
|
if index == -1:
|
|
|
pass
|
|
|
- #self.logger.warning(f"[TRACE]推钢机右侧未找到{i+1}流的热送钢坯")
|
|
|
+ #self.logger.warning(f"[TRACE]推钢机南侧未找到{i+1}流的热送钢坯")
|
|
|
else:
|
|
|
gp_tmp = self.pusher_right_list[index]
|
|
|
self.pusher_right_list = self.pusher_right_list[:index] + self.pusher_right_list[index+1:]
|
|
|
|
|
|
if gp_tmp:
|
|
|
- self.logger.info(f"[TRACE]{i+1}流钢坯热送")
|
|
|
- if gp_tmp[0][:8] not in self.heat_filter:
|
|
|
+ # self.logger.info(f"[TRACE]{i+1}流钢坯热送")
|
|
|
+ if not gp_tmp[0].startswith('0') and gp_tmp[0][:8] not in self.heat_filter:
|
|
|
self.change_heat(gp_tmp)
|
|
|
- if not gp_tmp[0].startswith('0'):
|
|
|
+ if not self.current_heatNo.startswith('0'):
|
|
|
self.hostsend(gp_tmp)
|
|
|
|
|
|
def change_heat(self, data):
|
|
|
@@ -238,20 +255,33 @@ class Trace_pusher:
|
|
|
self.total = 0
|
|
|
self.strand = [0, 0, 0, 0, 0, 0, 0, 0]
|
|
|
|
|
|
+ def manual_change_heat(self):
|
|
|
+ with self.count_lock:
|
|
|
+ tmp = self.manual_change_heat_sig.data
|
|
|
+ if tmp['heatNo'] == self.current_heatNo:
|
|
|
+ return None
|
|
|
+
|
|
|
+ self.logger.info(f"手动换炉触发:{self.current_heatNo}->{tmp['heatNo']}")
|
|
|
+
|
|
|
+ tmp['sendTime'] = tmp['startPourTime']
|
|
|
+ self.sender.begin_pour(tmp, max(self.data_s7.get_value('大包重量1'), self.data_s7.get_value('大包重量2')))
|
|
|
+
|
|
|
+ self.change_heat([tmp['heatNo'], tmp])
|
|
|
+
|
|
|
def arrive_cooling_bed(self, direc):
|
|
|
with self.count_lock:
|
|
|
if direc == 'left':
|
|
|
- self.logger.debug(f"左侧冷床上推入{len(self.pusher_left_list)}根钢坯")
|
|
|
+ self.logger.debug(f"北侧冷床上推入{len(self.pusher_left_list)}根钢坯")
|
|
|
tmp = self.pusher_left_list
|
|
|
self.pusher_left_list = []
|
|
|
|
|
|
elif direc == 'right':
|
|
|
- self.logger.debug(f"右侧冷床上推入{len(self.pusher_right_list)}根钢坯")
|
|
|
+ self.logger.debug(f"南侧冷床上推入{len(self.pusher_right_list)}根钢坯")
|
|
|
tmp = self.pusher_right_list
|
|
|
self.pusher_right_list = []
|
|
|
|
|
|
for i in tmp:
|
|
|
- if not (i[0].startswith(self.current_heatNo) or i[0].startswith(self.old_heatNo)):
|
|
|
+ if not i[0].startswith('0') and i[0][:8] not in self.heat_filter:
|
|
|
self.change_heat(i)
|
|
|
break
|
|
|
|
|
|
@@ -261,11 +291,11 @@ class Trace_pusher:
|
|
|
if direc == 'left':
|
|
|
if len(billets):
|
|
|
self.billet_to_bed_impl(billets, self.bed_left)
|
|
|
- self.logger.debug(f"左侧冷床目前情况:{len(self.bed_left[0])}根|{len(self.bed_left[1])}根|{len(self.bed_left[2])}根")
|
|
|
+ self.logger.debug(f"北侧冷床目前情况:{len(self.bed_left[0])}根|{len(self.bed_left[1])}根|{len(self.bed_left[2])}根")
|
|
|
elif direc == 'right':
|
|
|
if len(billets):
|
|
|
self.billet_to_bed_impl(billets, self.bed_right)
|
|
|
- self.logger.debug(f"右侧冷床目前情况:{len(self.bed_right[2])}根|{len(self.bed_right[1])}根|{len(self.bed_right[0])}根")
|
|
|
+ self.logger.debug(f"南侧冷床目前情况:{len(self.bed_right[2])}根|{len(self.bed_right[1])}根|{len(self.bed_right[0])}根")
|
|
|
|
|
|
|
|
|
def billet_to_bed_impl(self, billets: list, dst: list):
|
|
|
@@ -279,6 +309,12 @@ class Trace_pusher:
|
|
|
dst[0].extend(billets)
|
|
|
elif count == 3 and (len(billets) >= 4 or len(dst[count-1]) >= 4 or len(dst[count-1]) + len(billets) > 4):
|
|
|
self.logger.error(f"组坯异常!")
|
|
|
+
|
|
|
+ # test 把无法组坯的不正常钢坯 直接上传服务器
|
|
|
+ tmp = dst[0]
|
|
|
+ if len(tmp) < 4:
|
|
|
+ self.billet_union(tmp)
|
|
|
+
|
|
|
dst.remove(dst[0])
|
|
|
dst.append(billets)
|
|
|
count -= 1
|
|
|
@@ -293,18 +329,36 @@ class Trace_pusher:
|
|
|
|
|
|
|
|
|
def billet_union(self, billets):
|
|
|
+ ccmNo = self.current_heatData['ccmNo'] if self.current_heatData else '0'
|
|
|
+
|
|
|
+ if len(billets) < 4:
|
|
|
+ for i in billets:
|
|
|
+ strandNo = i[0][9]
|
|
|
+ billetNo = self.current_heatNo + ccmNo + strandNo + '{:0>2}'.format(99)
|
|
|
+ i[0] = billetNo
|
|
|
+ i[1] = self.current_heatData
|
|
|
+ if self.current_heatData:
|
|
|
+ self.sender.billet_upload(self.current_heatData, billetNo, self.total, i[2], i[3], i[4], i[5], '', error=True)
|
|
|
+ self.logger.warning(f"{self.current_heatNo}炉发送异常钢坯{len(billets)}根")
|
|
|
+ return None
|
|
|
+
|
|
|
if self.sizing_count_heatNo != self.current_heatNo:
|
|
|
self.sizing_count_heatNo = self.current_heatNo
|
|
|
self.sizing_count = {}
|
|
|
|
|
|
- if billets[0][2] not in self.sizing_count:
|
|
|
- self.sizing_count[billets[0][2]] = 0
|
|
|
+ # 组坯时,定尺为此组内定尺最小值
|
|
|
+ sizing = billets[0][2]
|
|
|
+ for i in billets:
|
|
|
+ if i[2] < sizing:
|
|
|
+ sizing = i[2]
|
|
|
+
|
|
|
+ if sizing not in self.sizing_count:
|
|
|
+ self.sizing_count[sizing] = 0
|
|
|
|
|
|
- self.sizing_count[billets[0][2]] += 1
|
|
|
- billet_unionNo = self.current_heatNo + '{:0>5}'.format(int(billets[0][2])) + '{:0>2}'.format(self.sizing_count[billets[0][2]])
|
|
|
+ self.sizing_count[sizing] += 1
|
|
|
+ billet_unionNo = self.current_heatNo + '{:0>5}'.format(int(sizing)) + '{:0>2}'.format(self.sizing_count[sizing])
|
|
|
|
|
|
billetsNo = []
|
|
|
- ccmNo = self.current_heatData['ccmNo'] if self.current_heatData else '0'
|
|
|
for i in billets:
|
|
|
strandNo = i[0][9]
|
|
|
self.total += 1
|
|
|
@@ -313,11 +367,12 @@ class Trace_pusher:
|
|
|
billetsNo.append(billetNo)
|
|
|
i[0] = billetNo
|
|
|
i[1] = self.current_heatData
|
|
|
+ i[2] = sizing
|
|
|
if self.current_heatData:
|
|
|
self.sender.billet_upload(self.current_heatData, billetNo, self.total, i[2], i[3], i[4], i[5], billet_unionNo)
|
|
|
|
|
|
if self.current_heatData:
|
|
|
- self.sender.billet_union(self.current_heatData, billet_unionNo, billetsNo, int(billets[0][2]))
|
|
|
+ self.sender.billet_union(self.current_heatData, billet_unionNo, billetsNo, sizing)
|
|
|
|
|
|
self.logger.info(f"{self.current_heatNo}炉组号{billet_unionNo}钢坯{len(billets)}根:\n {'、'.join(billetsNo)}")
|
|
|
|
|
|
@@ -336,17 +391,25 @@ class Trace_pusher:
|
|
|
|
|
|
else:
|
|
|
with self.integration_lock:
|
|
|
- self.billet_out_sig[i].data = 0
|
|
|
- self.integration_total[i] = 0
|
|
|
+ # 验证现在拉速积分是否有效
|
|
|
+ if self.billet_out_sig[i].permitted_update:
|
|
|
+ # 有效:检测并把所有短尺的钢坯定尺都改为定尺软件给的
|
|
|
+ if round(self.billet_out_sig[i].data * 1000) - self.integration_total[i] < 10000:
|
|
|
+ data[2] = self.data_s7.get_value(f"L{i+1}短尺")
|
|
|
+
|
|
|
+ # 对拉速积分进行切割信号校准
|
|
|
+ self.billet_out_sig[i].data = 0
|
|
|
+ self.integration_total[i] = 0
|
|
|
+ else:
|
|
|
+ # 无效:开启拉速积分
|
|
|
+ self.integration_start(i)
|
|
|
|
|
|
if self.strands_cutting[i]:
|
|
|
self.logger.warning(f"{i+1}流有钢坯开切冲突")
|
|
|
self.strands_cutting[i] = data
|
|
|
- self.strands_cutting[i].append('')
|
|
|
else:
|
|
|
self.logger.info(f"{i+1}流钢坯开切")
|
|
|
self.strands_cutting[i] = data
|
|
|
- self.strands_cutting[i].append('')
|
|
|
|
|
|
def hostsend(self, i):
|
|
|
ccmNo = self.current_heatData['ccmNo']
|
|
|
@@ -358,9 +421,13 @@ class Trace_pusher:
|
|
|
i[1] = self.current_heatData
|
|
|
self.sender.billet_upload(self.current_heatData, billetNo, self.total, i[2], i[3], i[4], i[5], '')
|
|
|
|
|
|
- self.logger.info(f"{self.current_heatNo}炉钢坯热送:{billetNo}")
|
|
|
+ self.logger.info(f"{self.current_heatNo}炉{strandNo}流钢坯热送:{billetNo}")
|
|
|
self.sender.host_send(ccmNo, billetNo, "棒一")
|
|
|
|
|
|
+ def show_coolbed(self):
|
|
|
+ print(f"北侧冷床目前情况:{len(self.bed_left[0])}根|{len(self.bed_left[1])}根|{len(self.bed_left[2])}根")
|
|
|
+ print(f"南侧冷床目前情况:{len(self.bed_right[2])}根|{len(self.bed_right[1])}根|{len(self.bed_right[0])}根")
|
|
|
+
|
|
|
def clean_status(self):
|
|
|
self.logger.debug(f"[TRACE]小冷床状态清空")
|
|
|
with self.count_lock:
|
|
|
@@ -369,6 +436,21 @@ class Trace_pusher:
|
|
|
self.bed_left = [[], [], []]
|
|
|
self.bed_right = [[], [], []]
|
|
|
|
|
|
+ def init_coolbed(self):
|
|
|
+ left_count = input(f"输入北侧冷床钢坯根数序列(由外到内):")
|
|
|
+ right_count = input(f"输入南侧冷床钢坯根数序列(由外到内):")
|
|
|
+ if not (left_count.isdigit() and len(left_count) == 3 and right_count.isdigit() and len(right_count) == 3):
|
|
|
+ warnings.warn("冷床格式化错误,请输入正确格式")
|
|
|
+ return None
|
|
|
+
|
|
|
+ left_count = [int(i) for i in left_count]
|
|
|
+ right_count = [int(i) for i in right_count]
|
|
|
+ temp = ['000000000000', {}, 0, 0, '', '']
|
|
|
+ with self.count_lock:
|
|
|
+ self.bed_left = [[temp.copy() for i in range(left_count[j])] for j in range(3)]
|
|
|
+ self.bed_right = [[temp.copy() for i in range(right_count[j])] for j in range(3)]
|
|
|
+
|
|
|
+
|
|
|
def get_billet(self, direc):
|
|
|
with self.count_lock:
|
|
|
if direc == "left":
|
|
|
@@ -390,6 +472,6 @@ class Trace_pusher:
|
|
|
def billet_to_stack(self, stackNo, billets):
|
|
|
if billets:
|
|
|
self.logger.info(f"有钢坯放入{stackNo}堆垛")
|
|
|
- self.sender.stack_add('6', billets, "", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), "6#小冷床(右)", '501堆垛')
|
|
|
+ self.sender.stack_add('6', billets, "", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), "6#小冷床(南)", '步进冷床堆垛')
|
|
|
|
|
|
# [坯号, 炉次信息, 定尺, 拉速, 开切时间, 停切时间]
|