Browse Source

fix bug,添加天车逻辑,添加发送参数

oldwine 4 months ago
parent
commit
b61c398c3a
3 changed files with 79 additions and 26 deletions
  1. 5 2
      models/billet_trace_pusher.py
  2. 22 6
      models/data_sender.py
  3. 52 18
      models/overhead_crane.py

+ 5 - 2
models/billet_trace_pusher.py

@@ -213,10 +213,12 @@ class Trace_pusher:
 
 
     def billet_to_bed(self, billets, direc):
     def billet_to_bed(self, billets, direc):
         if direc == 'left':
         if direc == 'left':
-            self.billet_to_bed_impl(billets, self.bed_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':
         elif direc == 'right':
-            self.billet_to_bed_impl(billets, self.bed_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])}根")
 
 
 
 
@@ -225,6 +227,7 @@ class Trace_pusher:
         count = 0
         count = 0
         while i < len(dst) and dst[i]:
         while i < len(dst) and dst[i]:
             count += 1
             count += 1
+            i += 1
 
 
         if count == 0:
         if count == 0:
             dst[0].extend(billets)
             dst[0].extend(billets)

+ 22 - 6
models/data_sender.py

@@ -82,7 +82,12 @@ class Sender:
             "billetHotsendTypeConfigId": "",
             "billetHotsendTypeConfigId": "",
             "vehicleNumber": "",
             "vehicleNumber": "",
             "liftingTime": "",
             "liftingTime": "",
-            "location": ""
+            "location": "",
+            "destination":"",
+            "positionNum":"",
+            "plateOrStack":"",
+            "layer":"",
+            "address":""
         }
         }
 
 
         self.car_add_temp = {
         self.car_add_temp = {
@@ -99,7 +104,12 @@ class Sender:
             "licensePlate": "",
             "licensePlate": "",
             "vehicleNumber": "",
             "vehicleNumber": "",
             "liftingTime": "",
             "liftingTime": "",
-            "location": ""
+            "location": "",
+            "destination":"",
+            "positionNum":"",
+            "plateOrStack":"",
+            "layer":"",
+            "address":""
         }
         }
 
 
         self.car_go_temp = {
         self.car_go_temp = {
@@ -270,7 +280,7 @@ class Sender:
         #此处应存储进数据库
         #此处应存储进数据库
         self.send('billet_union', tmp)
         self.send('billet_union', tmp)
 
 
-    def host_send(self, ccmNo, billetNos, dst_str, craneNo = ""):
+    def host_send(self, ccmNo, billetNos, dst_str, craneNo = "", fromaddr = ""):
         tmp = self.host_send_temp.copy()
         tmp = self.host_send_temp.copy()
         
         
         tmp['ccmNo'] = ccmNo
         tmp['ccmNo'] = ccmNo
@@ -278,7 +288,8 @@ class Sender:
         tmp['billetHotsendTypeConfigId'] = "1" if dst_str == "棒一" else "15"
         tmp['billetHotsendTypeConfigId'] = "1" if dst_str == "棒一" else "15"
         tmp['liftingTime'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
         tmp['liftingTime'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
         tmp['vehicleNumber'] = craneNo
         tmp['vehicleNumber'] = craneNo
-        tmp['location'] = "6#热送辊道" if dst_str == "高线" else ""
+        tmp['location'] = fromaddr
+        tmp['destination'] = dst_str
 
 
         #此处应存储进数据库
         #此处应存储进数据库
         self.send('host_send', tmp)
         self.send('host_send', tmp)
@@ -294,7 +305,7 @@ class Sender:
         #此处应存储进数据库
         #此处应存储进数据库
         self.send('car_add', tmp)
         self.send('car_add', tmp)
 
 
-    def car_save(self, ccmNo, billetNos, plate, craneNo, Ltime):
+    def car_save(self, ccmNo, billetNos, plate, craneNo, Ltime, fromaddr, toaddr, layer=0, address=0):
         tmp = self.car_save_temp.copy()
         tmp = self.car_save_temp.copy()
         
         
         tmp['ccmNo'] = ccmNo
         tmp['ccmNo'] = ccmNo
@@ -303,7 +314,12 @@ class Sender:
         tmp['licensePlate'] = plate
         tmp['licensePlate'] = plate
         tmp['vehicleNumber'] = craneNo
         tmp['vehicleNumber'] = craneNo
         tmp['liftingTime'] = Ltime
         tmp['liftingTime'] = Ltime
-        tmp['location'] = '装车'
+        tmp['location'] = fromaddr
+        tmp['destination'] = toaddr
+        tmp['positionNum'] = toaddr[-1] if len(toaddr) else ""
+        tmp['plateOrStack'] = plate
+        tmp['layer'] = str(layer)
+        tmp['address'] = str(address)
 
 
         #此处应存储进数据库
         #此处应存储进数据库
         self.send('car_save', tmp)
         self.send('car_save', tmp)

+ 52 - 18
models/overhead_crane.py

@@ -26,18 +26,26 @@ class Crane:
             "A3": ""
             "A3": ""
         }
         }
 
 
+        self.billets_from = {
+            "A1": "",
+            "A2": "",
+            "A3": ""
+        }
+
         self.areas = {
         self.areas = {
-            "6#coolbed1": [35000, 38500],
-            "6#coolbed2": [22000, 24000],
-            "car3": [2000, 4000],
-            "highline": [60300, 62300]
+            "6#小冷床(左)": [35000, 38500],
+            "6#小冷床(右)": [22000, 24000],
+            "车位3": [2000, 4000],
+            "高线辊道": [60300, 62300],
+            "601堆垛": [10000, 14000]
         }
         }
 
 
         self.threads_poor = [
         self.threads_poor = [
-            threading.Thread(target=self.area_producer, args=("6#coolbed1",)),
-            threading.Thread(target=self.area_producer, args=("6#coolbed2",)),
-            threading.Thread(target=self.area_consumer, args=("car3",)),
-            threading.Thread(target=self.area_consumer, args=("highline",))
+            threading.Thread(target=self.area_producer, args=("6#小冷床(左)",)),
+            threading.Thread(target=self.area_producer, args=("6#小冷床(右)",)),
+            threading.Thread(target=self.area_consumer, args=("车位3",)),
+            threading.Thread(target=self.area_consumer, args=("高线辊道",)),
+            threading.Thread(target=self.area_consumer, args=("601堆垛",))
         ]
         ]
 
 
         for i in self.threads_poor:
         for i in self.threads_poor:
@@ -55,24 +63,36 @@ class Crane:
     def crane_leave(self, craneNo, areaNo):
     def crane_leave(self, craneNo, areaNo):
         start = self.areas[areaNo][0]
         start = self.areas[areaNo][0]
         end = self.areas[areaNo][1]
         end = self.areas[areaNo][1]
+        wait_time = 0
         while True:
         while True:
             if self.cranes[craneNo].data < start or self.cranes[craneNo].data > end:
             if self.cranes[craneNo].data < start or self.cranes[craneNo].data > end:
                 return True
                 return True
+            if wait_time >= 10:
+                return False
             time.sleep(0.5)
             time.sleep(0.5)
+            wait_time += 0.5
             
             
     def area_producer(self, areaNo):
     def area_producer(self, areaNo):
         while True:
         while True:
             craneNo = self.scan_crane(areaNo)
             craneNo = self.scan_crane(areaNo)
             self.logger.debug(f"天车{craneNo}进入区域{areaNo}")
             self.logger.debug(f"天车{craneNo}进入区域{areaNo}")
 
 
+            if self.crane_leave(craneNo, areaNo):
+                self.logger.debug(f"天车{craneNo}离开区域{areaNo}")
+                continue
+
             if self.billetsNo[craneNo] == "":
             if self.billetsNo[craneNo] == "":
                 self.logger.debug(f"天车{craneNo}正在等待或尝试夹起钢坯")
                 self.logger.debug(f"天车{craneNo}正在等待或尝试夹起钢坯")
-                self.get_billet(craneNo, areaNo)
-                self.logger.debug(f"天车{craneNo}获取到钢坯")
+                if self.get_billet(craneNo, areaNo):
+                    self.logger.debug(f"天车{craneNo}获取到钢坯")
+                else:
+                    self.logger.debug(f"天车{craneNo}未获取到钢坯直接离开")
             else:
             else:
                 self.logger.debug(f"天车{craneNo}有未卸下的钢坯")
                 self.logger.debug(f"天车{craneNo}有未卸下的钢坯")
 
 
-            self.crane_leave(craneNo, areaNo)
+            while not self.crane_leave(craneNo, areaNo):
+                pass
+
             self.logger.debug(f"天车{craneNo}离开区域{areaNo}")
             self.logger.debug(f"天车{craneNo}离开区域{areaNo}")
             time.sleep(1)
             time.sleep(1)
 
 
@@ -81,35 +101,49 @@ class Crane:
             craneNo = self.scan_crane(areaNo)
             craneNo = self.scan_crane(areaNo)
             self.logger.debug(f"天车{craneNo}进入区域{areaNo}")
             self.logger.debug(f"天车{craneNo}进入区域{areaNo}")
 
 
+            if self.crane_leave(craneNo, areaNo):
+                self.logger.debug(f"天车{craneNo}离开区域{areaNo}")
+                continue
+
             if self.billetsNo[craneNo] == "":
             if self.billetsNo[craneNo] == "":
                 self.logger.debug(f"天车{craneNo}未携带钢坯")
                 self.logger.debug(f"天车{craneNo}未携带钢坯")
             else:
             else:
                 self.logger.debug(f"天车{craneNo}正在等待或尝试卸下钢坯")
                 self.logger.debug(f"天车{craneNo}正在等待或尝试卸下钢坯")
                 self.unload_billet(craneNo, areaNo)
                 self.unload_billet(craneNo, areaNo)
 
 
-            self.crane_leave(craneNo, areaNo)
+            while not self.crane_leave(craneNo, areaNo):
+                pass
+            
             self.logger.debug(f"天车{craneNo}离开区域{areaNo}")
             self.logger.debug(f"天车{craneNo}离开区域{areaNo}")
             time.sleep(1)
             time.sleep(1)
 
 
     def get_billet(self, craneNo, areaNo):
     def get_billet(self, craneNo, areaNo):
         # 阻塞获取
         # 阻塞获取
+        start = self.areas[areaNo][0]
+        end = self.areas[areaNo][1]
         tmp = []
         tmp = []
         while not bool(tmp):
         while not bool(tmp):
-            if areaNo == "6#coolbed1":
+            if self.cranes[craneNo].data < start or self.cranes[craneNo].data > end:
+                return False
+            if areaNo == "6#小冷床(左)":
                 tmp = self.tracer_6.get_billet("left")
                 tmp = self.tracer_6.get_billet("left")
-            elif areaNo == "6#coolbed2":
+            elif areaNo == "6#小冷床(右)":
                 tmp = self.tracer_6.get_billet("right")
                 tmp = self.tracer_6.get_billet("right")
         
         
         self.billetsNo[craneNo] = ','.join(tmp)
         self.billetsNo[craneNo] = ','.join(tmp)
+        self.billets_from[craneNo] = areaNo
         return tmp
         return tmp
 
 
     def unload_billet(self, craneNo, areaNo):
     def unload_billet(self, craneNo, areaNo):
         # 直接放下
         # 直接放下
         tmp = self.billetsNo[craneNo]
         tmp = self.billetsNo[craneNo]
         self.billetsNo[craneNo] = ""
         self.billetsNo[craneNo] = ""
-        if areaNo == "car3":
+        self.billets_from[craneNo] = ""
+        if areaNo == "车位3":
             self.logger.info(f"有一夹子钢坯放置进了车位3")
             self.logger.info(f"有一夹子钢坯放置进了车位3")
-            self.sender.car_save(self.parking.ccmNo_list[2], tmp, self.parking.current_car[2], craneNo, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
-        elif areaNo == "highline":
+            self.sender.car_save(self.parking.ccmNo_list[2], tmp, self.parking.current_car[2], craneNo, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), self.billets_from[craneNo], areaNo)
+        elif areaNo == "高线辊道":
             self.logger.info(f"有一夹子钢坯放置进了高线辊道")
             self.logger.info(f"有一夹子钢坯放置进了高线辊道")
-            self.sender.host_send("6", tmp, "高线", craneNo)
+            self.sender.host_send("6", tmp, "高线", craneNo, self.billets_from[craneNo])
+        elif areaNo == "601堆垛":
+            self.logger.info(f"有一夹子钢坯放置进了601堆垛")