| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- from utils.s7data import S7data
- import time
- class Billet_stack:
- def __init__(self, name, ccmNo, data_s7: S7data, height_init_offset = 0):
- self.name = name
- self.ccmNo = ccmNo
- self.height_init_offset = height_init_offset
- self.height = data_s7.make_point(f"{name}堆垛高度")
- self.toptotal = data_s7.make_point(f"{name}堆垛组数")
- self.fangx = data_s7.make_point(f"{name}堆垛方向")
- self.last_toptotal = self.toptotal.data
- self.changed_time = time.time()
- self.changed_count = 0
- self.jinwei = 0
- # self.groups = []
- # self.vertical = data_s7.make_point(f"{name}堆垛摆放方式")
- # self.crane = data_s7.make_point(f"{name}堆垛行车")
- # self.update_sig = data_s7.make_point(f"{name}堆垛更新信号")
- # for i in range(12):
- # self.groups.append(data_s7.make_point(f"{name}堆垛第{i+1}组"))
- self.height.set_convertor(self.layerNum_cal)
- self.toptotal.set_convertor(self.do_update)
- self.fangx.set_convertor(self.height.allow_update)
- def layerNum_cal(self, data):
- res = (data + self.height_init_offset) // 170
- if self.fangx.data == 1:
- if res % 2 == 0:
- res += 1
- elif self.fangx.data == 2:
- if res % 2:
- res += 1
- return res
- def do_update(self, data):
- if data != self.last_toptotal:
- self.jinwei = 0
- self.changed_count = data - self.last_toptotal
- self.last_toptotal = data
- self.changed_time = time.time()
- if self.changed_count > 2:
- self.changed_count = -1
- self.jinwei = -1
- elif self.changed_count < -2:
- self.changed_count = 1
- self.jinwei = 1
- def get_changed(self):
- if time.time() - self.changed_time <= 20:
- return self.changed_count
- return 0
- class Stack_manager:
- def __init__(self):
- self.stacks = {}
- def add_stack(self, name, ccmNo, data_s7: S7data, height_init_offset = 0):
- self.stacks[name] = Billet_stack(name, ccmNo, data_s7, height_init_offset)
- def wait_signal(self, name):
- stack = self.stacks[name]
- count = 4
- while count:
- time.sleep(5)
- count -= 1
- changed = stack.get_changed()
- if changed > 0:
- return [changed, stack.height.state, stack.toptotal.data]
- elif changed < 0:
- return [changed, stack.height.state-stack.jinwei, 1 if stack.jinwei else stack.toptotal.data+1]
- else:
- continue
- return [0, 0, 0]
|