Ver código fonte

添加了延时等待、加入了拉速验证机制,添加了车到站离站

oldwine 2 meses atrás
pai
commit
78c90ddb23

+ 4 - 0
conf/5#nodes.csv

@@ -80,3 +80,7 @@ L8
 集群限位L7_2,boollist,105,35,0,1,TRUE,FALSE,500,5
 集群限位L8_1,boollist,105,36,0,1,TRUE,FALSE,500,5
 集群限位L8_2,boollist,105,37,0,1,TRUE,FALSE,500,5
+车1存在,int,306,2,0,2,TRUE,FALSE,500,5
+车2存在,int,307,2,0,2,TRUE,FALSE,500,5
+车3存在,int,308,2,0,2,TRUE,FALSE,500,5
+车4存在,int,309,2,0,2,TRUE,FALSE,500,5

+ 1 - 1
models/billet_counter.py

@@ -259,7 +259,7 @@ class Counter:
                 pass
                 # self.sender.heat_first(heatData)
         else:
-            pass
+            self.send_dst.data_from_casting(sno-1, [f'000000000{sno}00', {}, sizing, speed, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())])
             # self.logger.info(f"[Counter]{sno}流:未知炉第{heatIndex}根,本炉无法计入系统,下一炉开始正常")
 
 

+ 40 - 55
models/billet_trace_pusher.py

@@ -52,27 +52,12 @@ class Trace_pusher:
         for i in range(8):
             self.drawing_speed.append(self.data_s7.make_point(f'L{i+1}拉速'))
 
+        # 5号机
         if self.hostsend_flag:
-            # self.billet_position = [
-            #     Through_state_continues3(data_s7.make_point('集群限位L1_1[3]'), data_s7.make_point('集群限位L1_1[4]'), data_s7.make_point('集群限位L1_1[5]')),
-            #     Through_state_continues3(data_s7.make_point('集群限位L2_1[3]'), data_s7.make_point('集群限位L2_1[4]'), data_s7.make_point('集群限位L2_1[5]')),
-            #     Through_state_continues3(data_s7.make_point('集群限位L3_1[3]'), data_s7.make_point('集群限位L3_1[4]'), data_s7.make_point('集群限位L3_1[5]')),
-            #     Through_state_continues3(data_s7.make_point('集群限位L4_1[3]'), data_s7.make_point('集群限位L4_1[4]'), data_s7.make_point('集群限位L4_1[5]')),
-            #     Through_state_continues3(data_s7.make_point('集群限位L5_1[3]'), data_s7.make_point('集群限位L5_1[4]'), data_s7.make_point('集群限位L5_1[5]')),
-            #     Through_state_continues3(data_s7.make_point('集群限位L6_1[3]'), data_s7.make_point('集群限位L6_1[4]'), data_s7.make_point('集群限位L6_1[5]')),
-            #     Through_state_separation2(data_s7.make_point('集群限位L7_1[4]'), data_s7.make_point('集群限位L7_1[5]')),
-            #     Through_state_continues3(data_s7.make_point('集群限位L8_1[3]'), data_s7.make_point('集群限位L8_1[4]'), data_s7.make_point('集群限位L8_1[5]'))
-            # ]
-            # self.billet_out_sig = [
-            #     data_s7.make_point('集群限位L1_2[1]'),
-            #     data_s7.make_point('集群限位L2_2[1]'),
-            #     data_s7.make_point('集群限位L3_2[1]'),
-            #     data_s7.make_point('集群限位L4_2[1]'),
-            #     data_s7.make_point('集群限位L5_2[1]'),
-            #     data_s7.make_point('集群限位L6_2[1]'),
-            #     data_s7.make_point('集群限位L7_2[1]'),
-            #     data_s7.make_point('集群限位L8_2[1]')
-            # ]
+            # 拉速积分得到长度
+            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.billet_position = [
                 self.data_s7.make_point('L1切割信号[1]'),
                 self.data_s7.make_point('L2切割信号[1]'),
@@ -83,16 +68,7 @@ class Trace_pusher:
                 self.data_s7.make_point('L7切割信号[1]'),
                 self.data_s7.make_point('L8切割信号[1]')
             ]
-            self.billet_out_sig = [
-                self.data_s7.make_point('L1切割信号[0]'),
-                self.data_s7.make_point('L2切割信号[0]'),
-                self.data_s7.make_point('L3切割信号[0]'),
-                self.data_s7.make_point('L4切割信号[0]'),
-                self.data_s7.make_point('L5切割信号[0]'),
-                self.data_s7.make_point('L6切割信号[0]'),
-                self.data_s7.make_point('L7切割信号[0]'),
-                self.data_s7.make_point('L8切割信号[0]')
-            ]
+        # 6号机
         else:
             self.billet_position = [
                 self.data_s7.make_point('L1坯头位置'),
@@ -127,7 +103,7 @@ class Trace_pusher:
                 self.data_s7.make_point('热送挡板[4]'),
                 self.data_s7.make_point('热送挡板[5]'),
                 self.data_s7.make_point('热送挡板[6]'),
-                self.data_s7.make_point('热送挡板[7]'),
+                self.data_s7.make_point('热送挡板[7]')
             ]
 
         if self.hostmove_flag:
@@ -137,16 +113,21 @@ class Trace_pusher:
             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)
+            # 6号机
             if not self.hostsend_flag:
+                # 正常情况进入跟踪
                 self.billet_position[i].set_convertor(lambda data: 12000 < data < 20000)
                 self.billet_position[i].set_excite_action(lambda i=i: self.billet_out_action(i))
                 self.billet_position[i].set_reset_action(lambda i=i: self.billet_in_buffer_action(i))
+            # 5号机
             else:
-                self.billet_position[i].set_excite_action(lambda i=i: self.billet_in_buffer_action(i))
+                # 拉速补充钢坯
+                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))
+                # 正常情况进入跟踪
+                self.billet_position[i].set_excite_action(lambda i=i: self.billet_in_buffer_action(i))
             self.billet_position[i].allow_update()
             # 挡板抬起
             self.barrier[i].allow_update(False)
@@ -155,7 +136,7 @@ class Trace_pusher:
             self.barrier[i].set_excite_action(lambda i=i: self.barrier_up_action(i))
             self.barrier[i].set_reset_action(lambda i=i: self.barrier_down_action(i))
             self.barrier[i].allow_update()
-            # 直轧挡板抬起
+            # 5号机直轧挡板抬起
             if self.hostsend_flag:
                 self.hostsend_barrier[i].allow_update(False)
                 self.hostsend_barrier[i].set_state(False)
@@ -165,23 +146,39 @@ class Trace_pusher:
                 self.hostsend_barrier[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
+        
+        # [坯号, 炉次信息, 定尺, 拉速, 开切时间, 停切时间]
         self.billet_out[i] = [billetNo, self.current_heatData, sizing, speed, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), '']
 
+        # 等待20s,若无开切信号,即为漏坯
+        start_time = time.time()
+        while time.time() - start_time < 20:
+            if self.strands_cutting[i]:
+                return None
+            time.sleep(0.5)
+        self.billet_in_buffer_action(i)
+
     def billet_in_buffer_action(self, i):
+        time.sleep(1)
         with self.locks[i]:
             if self.strands_cutting[i]:
+                time.sleep(10)
                 self.logger.info(f"[TRACE]{i+1}流新增钢坯存储")
                 self.strands_buffer[i] = self.strands_cutting[i]
                 self.strands_cutting[i] = []
             elif self.billet_out[i]:
-                self.logger.info(f"[TRACE]{i+1}流开切漏钢,算法补入")
+                self.logger.info(f"[TRACE]{i+1}流无已经开切的钢坯,算法补入")
                 self.strands_buffer[i] = self.billet_out[i]
             else:
-                self.logger.info(f"[TRACE]{i+1}流开切漏钢,但未检测到可补入钢坯的信息")
+                self.logger.info(f"[TRACE]{i+1}流无已经开切的钢坯,但未检测到可补入的钢坯信息")
             self.billet_out[i] = []
 
         if self.barrier[i].state and self.barrier_checker[i] == False:
@@ -296,24 +293,6 @@ class Trace_pusher:
 
         if count == 0:
             dst[0].extend(billets)
-        # elif count == 3 and (len(billets) >= 4 or len(dst[count-1]) >= 4):
-        #     self.logger.error(f"组坯异常!")
-        #     flag = False
-        #     for j in dst:
-        #         if len(j) < 4:
-        #             flag = True
-        #             dst.remove(j)
-        #             break
-        #     if flag:
-        #         dst.append(billets)
-        #     else:
-        #         dst.remove(dst[0])
-        #         dst.append(billets)
-        #     count -= 1
-        # elif count == 3 and len(dst[count-1]) + len(billets) > 4:
-        #     self.logger.error(f"组坯异常!")
-        #     dst[count-1].extend(billets)
-        #     count -= 1
         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"组坯异常!")
             dst.remove(dst[0])
@@ -372,6 +351,10 @@ class Trace_pusher:
                     self.logger.warning(f"{i+1}流对已经离开的钢坯补充停切时间,无效")
 
             else:
+                with self.integration_lock:
+                    self.billet_out_sig[i].data = 0
+                    self.integration_total[i] = 0
+
                 if self.strands_cutting[i]:
                     self.logger.warning(f"{i+1}流有钢坯开切冲突")
                     self.strands_cutting[i] = data
@@ -414,6 +397,8 @@ class Trace_pusher:
             if len(src[i]) >= 4:
                 tmp = [j[0] for j in src.pop(i)]
                 src.append([])
+                if tmp[0].startswith('0'):
+                    return []
                 return tmp
         
         return []

+ 2 - 1
models/data_sender.py

@@ -340,10 +340,11 @@ class Sender:
         #此处应存储进数据库
         self.send('car_save', tmp)
 
-    def car_go(self, ccmNo, plate):
+    def car_go(self, ccmNo, carNo, plate = ''):
         tmp = self.car_go_temp.copy()
         
         tmp['ccmNo'] = ccmNo
+        tmp['positionNum'] = carNo
         tmp['licensePlate'] = plate
 
         #此处应存储进数据库

+ 20 - 3
models/parking.py

@@ -1,4 +1,4 @@
-import threading
+import threading, time
 from utils.s7data import S7data
 from models.data_sender import Sender
 
@@ -15,6 +15,9 @@ class Parking:
 
         self.lock = threading.Lock()
         self.current_car = ["", "", "", ""]
+        self.car_time = [0, 0, 0, 0]
+
+        self.car_be = []
 
         self.plate_set = {'厂内00664', '厂内00415', '厂内00687', '厂内00701', '厂内00700', '厂内00901', '厂内00699', '厂内00695', '厂内00694', '厂内00693', '厂内00692', '厂内00902', '厂内00690', '厂内00689', '陕E08582D', '陕E08515D', '陕E08000D', '陕E00298D'}
 
@@ -30,6 +33,10 @@ class Parking:
             self.value_a.append(data_s7.make_point(f"车{name+1}自动触发结果"))
             self.value_m.append(data_s7.make_point(f"车{name+1}手动触发结果"))
 
+            tmp = data_s7.make_point(f"车{name+1}存在")
+            tmp.set_excite_action(lambda i=name: self.car_in(i))
+            tmp.set_reset_action(lambda i=name: self.car_out(i))
+            self.car_be.append(tmp)
 
     def signal_on(self, i, manual_flag):
         if manual_flag:
@@ -40,5 +47,15 @@ class Parking:
         with self.lock:
             if self.current_car[i] != valuedata.data:
                 self.current_car[i] = valuedata.data
-                self.sender.car_add(self.ccmNo_list[i], str(i+1), self.current_car[i])
-            
+                self.car_time[i] = time.time()
+                # self.sender.car_add(self.ccmNo_list[i], str(i+1), self.current_car[i])
+            
+    def car_in(self, i):
+        plate = ''
+        if time.time() - self.car_time[i] <= 10:
+            plate = self.current_car[i]
+
+        self.sender.car_add(self.ccmNo_list[i], str(i+1), plate)
+
+    def car_out(self, i):
+        self.sender.car_go(self.ccmNo_list[i], str(i+1))

+ 2 - 2
utils/s7data.py

@@ -206,7 +206,7 @@ class S7data:
         for i in self.threads:
             i.join()
 
-    def make_point(self, name):
+    def make_point(self, name, point_type = Statepoint):
         index = -1
         solvedname = name
         if len(name) > 3 and name[-3] == '[' and name[-1] == ']' and name[-2].isdigit() and 0 <= int(name[-2]) < 8:
@@ -222,7 +222,7 @@ class S7data:
             else:
                 self.target_from_name[solvedname] = [[],[],[],[],[],[],[],[]]
                 
-        res = Statepoint()
+        res = point_type()
         if index == -1:
             self.target_from_name[solvedname].append(res)
         else:

+ 22 - 1
utils/statepoint.py

@@ -1,4 +1,4 @@
-import threading
+import threading, time
 
 class Statepoint:
     def __init__(self, initvalue = False, initstate = False):
@@ -176,3 +176,24 @@ class Through_state_separation2(Statepoint):
             self.point1.state = False
             self.point2.state = False
             self.permitted_update = True
+
+class Integration_speed_mpmin(Statepoint):
+    def __init__(self, *args):
+        super().__init__(*args)
+        self.last_inject_time = time.time()
+        self.last_data = 0
+        self.last_data_time = self.last_inject_time
+
+    def inject(self, data):
+        current_inject_time = time.time()
+        current_data = data
+        current_data_time = self.last_inject_time + (current_inject_time - self.last_inject_time) / 2
+
+        data = self.data + (current_data_time - self.last_data_time) * (self.last_data + current_data) / 120
+
+        self.last_inject_time = current_inject_time
+        self.last_data = current_data
+        self.last_data_time = current_data_time
+
+        return super().inject(data)
+