mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-04 05:15:10 +00:00
Merge pull request #134 from sun7151887/fix/yb3-material-names-and-model
feat: 添加扣电工作站 setup() 方法并修复显示问题
This commit is contained in:
@@ -396,6 +396,8 @@ class ClipMagazine(Resource):
|
|||||||
size_x: float,
|
size_x: float,
|
||||||
size_y: float,
|
size_y: float,
|
||||||
size_z: float,
|
size_z: float,
|
||||||
|
hole_diameter: float = 20.0,
|
||||||
|
hole_depth: float = 50.0,
|
||||||
hole_spacing: float = 25.0,
|
hole_spacing: float = 25.0,
|
||||||
max_sheets_per_hole: int = 100,
|
max_sheets_per_hole: int = 100,
|
||||||
category: str = "clip_magazine",
|
category: str = "clip_magazine",
|
||||||
@@ -425,8 +427,8 @@ class ClipMagazine(Resource):
|
|||||||
dz=size_z - 0,
|
dz=size_z - 0,
|
||||||
item_dx=hole_spacing,
|
item_dx=hole_spacing,
|
||||||
item_dy=hole_spacing,
|
item_dy=hole_spacing,
|
||||||
diameter=0,
|
diameter=hole_diameter,
|
||||||
depth=0,
|
depth=hole_depth,
|
||||||
)
|
)
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@@ -872,21 +874,23 @@ class CoincellDeck(Deck):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name: str = "coin_cell_deck",
|
name: str = "coin_cell_deck",
|
||||||
size_x: float = 1620.0, # 3.66m
|
size_x: float = 1000.0, # 1m
|
||||||
size_y: float = 1270.0, # 1.23m
|
size_y: float = 1000.0, # 1m
|
||||||
size_z: float = 500.0,
|
size_z: float = 900.0, # 0.9m
|
||||||
origin: Coordinate = Coordinate(0, 0, 0),
|
origin: Coordinate = Coordinate(0, 0, 0),
|
||||||
category: str = "coin_cell_deck",
|
category: str = "coin_cell_deck",
|
||||||
|
setup: bool = False, # 是否自动执行 setup
|
||||||
):
|
):
|
||||||
"""初始化纽扣电池组装工作站台面
|
"""初始化纽扣电池组装工作站台面
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name: 台面名称
|
name: 台面名称
|
||||||
size_x: 长度 (mm) - 3.66m
|
size_x: 长度 (mm) - 1m
|
||||||
size_y: 宽度 (mm) - 1.23m
|
size_y: 宽度 (mm) - 1m
|
||||||
size_z: 高度 (mm)
|
size_z: 高度 (mm) - 0.9m
|
||||||
origin: 原点坐标
|
origin: 原点坐标
|
||||||
category: 类别
|
category: 类别
|
||||||
|
setup: 是否自动执行 setup 配置标准布局
|
||||||
"""
|
"""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name=name,
|
name=name,
|
||||||
@@ -896,111 +900,77 @@ class CoincellDeck(Deck):
|
|||||||
origin=origin,
|
origin=origin,
|
||||||
category=category,
|
category=category,
|
||||||
)
|
)
|
||||||
|
if setup:
|
||||||
|
self.setup()
|
||||||
|
|
||||||
#if __name__ == "__main__":
|
def setup(self) -> None:
|
||||||
# # 转移极片的测试代码
|
"""设置工作站的标准布局 - 包含3个料盘"""
|
||||||
# deck = CoincellDeck("coin_cell_deck")
|
# 步骤 1: 创建所有料盘
|
||||||
# ban_cao_wei = PlateSlot("ban_cao_wei", max_plates=8)
|
self.plates = {
|
||||||
# deck.assign_child_resource(ban_cao_wei, Coordinate(x=0, y=0, z=0))
|
"liaopan1": MaterialPlate(
|
||||||
#
|
name="liaopan1",
|
||||||
# plate_1 = MaterialPlate("plate_1", 1,1,1, fill=True)
|
size_x=120.8,
|
||||||
# for i, hole in enumerate(plate_1.children):
|
size_y=120.5,
|
||||||
# sheet = ElectrodeSheet(f"hole_{i}_sheet_1")
|
size_z=10.0,
|
||||||
# sheet._unilabos_state = {
|
fill=True
|
||||||
# "diameter": 14,
|
),
|
||||||
# "info": "NMC",
|
"liaopan2": MaterialPlate(
|
||||||
# "mass": 5.0,
|
name="liaopan2",
|
||||||
# "material_type": "positive_electrode",
|
size_x=120.8,
|
||||||
# "thickness": 0.1
|
size_y=120.5,
|
||||||
# }
|
size_z=10.0,
|
||||||
# hole._unilabos_state = {
|
fill=True
|
||||||
# "depth": 1.0,
|
),
|
||||||
# "diameter": 14,
|
"电池料盘": MaterialPlate(
|
||||||
# "info": "",
|
name="电池料盘",
|
||||||
# "max_sheets": 1
|
size_x=120.8,
|
||||||
# }
|
size_y=160.5,
|
||||||
# hole.assign_child_resource(sheet, Coordinate.zero())
|
size_z=10.0,
|
||||||
# plate_1._unilabos_state = {
|
fill=True
|
||||||
# "hole_spacing_x": 20.0,
|
),
|
||||||
# "hole_spacing_y": 20.0,
|
}
|
||||||
# "hole_diameter": 5,
|
|
||||||
# "info": "这是第一块料板"
|
# 步骤 2: 定义料盘在 deck 上的位置
|
||||||
# }
|
# Deck 尺寸: 1000×1000mm,料盘尺寸: 120.8×120.5mm 或 120.8×160.5mm
|
||||||
# plate_1.update_locations()
|
self.plate_locations = {
|
||||||
# ban_cao_wei.assign_child_resource(plate_1, Coordinate.zero())
|
"liaopan1": Coordinate(x=50, y=50, z=0), # 左上角,留 50mm 边距
|
||||||
# # zi_dan_jia = ClipMagazine("zi_dan_jia", 1, 1, 1)
|
"liaopan2": Coordinate(x=250, y=50, z=0), # 中间,liaopan1 右侧
|
||||||
# # deck.assign_child_resource(ban_cao_wei, Coordinate(x=200, y=200, z=0))
|
"电池料盘": Coordinate(x=450, y=50, z=0), # 右侧
|
||||||
#
|
}
|
||||||
# from unilabos.resources.graphio import *
|
|
||||||
# A = tree_to_list([resource_plr_to_ulab(deck)])
|
# 步骤 3: 将料盘分配到 deck 上
|
||||||
# with open("test.json", "w") as f:
|
for plate_name, plate in self.plates.items():
|
||||||
# json.dump(A, f)
|
self.assign_child_resource(
|
||||||
#
|
plate,
|
||||||
#
|
location=self.plate_locations[plate_name]
|
||||||
#def get_plate_with_14mm_hole(name=""):
|
)
|
||||||
# plate = MaterialPlate(name=name)
|
|
||||||
# for i in range(4):
|
# 步骤 4: 为 liaopan1 添加初始极片
|
||||||
# for j in range(4):
|
for i in range(16):
|
||||||
# hole = MaterialHole(f"{i+1}x{j+1}")
|
jipian = ElectrodeSheet(
|
||||||
# hole._unilabos_state["diameter"] = 14
|
name=f"jipian1_{i}",
|
||||||
# hole._unilabos_state["max_sheets"] = 1
|
size_x=12,
|
||||||
# plate.assign_child_resource(hole)
|
size_y=12,
|
||||||
# return plate
|
size_z=0.1
|
||||||
|
)
|
||||||
import json
|
self.plates["liaopan1"].children[i].assign_child_resource(
|
||||||
|
jipian,
|
||||||
if __name__ == "__main__":
|
location=None
|
||||||
#electrode1 = BatteryPressSlot()
|
)
|
||||||
#print(electrode1.get_size_x())
|
|
||||||
#print(electrode1.get_size_y())
|
|
||||||
#print(electrode1.get_size_z())
|
|
||||||
#jipian = ElectrodeSheet()
|
|
||||||
#jipian._unilabos_state["diameter"] = 18
|
|
||||||
#print(jipian.serialize())
|
|
||||||
#print(jipian.serialize_state())
|
|
||||||
|
|
||||||
deck = CoincellDeck(size_x=1000,
|
|
||||||
size_y=1000,
|
|
||||||
size_z=900)
|
|
||||||
|
|
||||||
#liaopan = TipBox64(name="liaopan")
|
|
||||||
|
|
||||||
#创建一个4*4的物料板
|
|
||||||
liaopan1 = MaterialPlate(name="liaopan1", size_x=120.8, size_y=120.5, size_z=10.0, fill=True)
|
|
||||||
#把物料板放到桌子上
|
|
||||||
deck.assign_child_resource(liaopan1, Coordinate(x=0, y=0, z=0))
|
|
||||||
#创建一个极片
|
|
||||||
for i in range(16):
|
|
||||||
jipian = ElectrodeSheet(name=f"jipian1_{i}", size_x= 12, size_y=12, size_z=0.1)
|
|
||||||
liaopan1.children[i].assign_child_resource(jipian, location=None)
|
|
||||||
#
|
|
||||||
#创建一个4*4的物料板
|
|
||||||
liaopan2 = MaterialPlate(name="liaopan2", size_x=120.8, size_y=120.5, size_z=10.0, fill=True)
|
|
||||||
#把物料板放到桌子上
|
|
||||||
deck.assign_child_resource(liaopan2, Coordinate(x=500, y=0, z=0))
|
|
||||||
|
|
||||||
#创建一个4*4的物料板
|
|
||||||
liaopan3 = MaterialPlate(name="电池料盘", size_x=120.8, size_y=160.5, size_z=10.0, fill=True)
|
|
||||||
#把物料板放到桌子上
|
|
||||||
deck.assign_child_resource(liaopan3, Coordinate(x=100, y=100, z=0))
|
|
||||||
|
|
||||||
|
|
||||||
|
def create_coin_cell_deck(name: str = "coin_cell_deck", size_x: float = 1000.0, size_y: float = 1000.0, size_z: float = 900.0) -> CoincellDeck:
|
||||||
#liaopan.children[3].assign_child_resource(jipian, location=None)
|
"""创建并配置标准的纽扣电池组装工作站台面
|
||||||
print(deck)
|
|
||||||
|
Args:
|
||||||
|
name: 台面名称
|
||||||
from unilabos.resources.graphio import convert_resources_from_type
|
size_x: 长度 (mm)
|
||||||
from unilabos.config.config import BasicConfig
|
size_y: 宽度 (mm)
|
||||||
BasicConfig.ak = "4d5ce6ae-7234-4639-834e-93899b9caf94"
|
size_z: 高度 (mm)
|
||||||
BasicConfig.sk = "505d3b0a-620e-459a-9905-1efcffce382a"
|
|
||||||
from unilabos.app.web.client import http_client
|
Returns:
|
||||||
|
已配置好的 CoincellDeck 对象
|
||||||
resources = convert_resources_from_type([deck], [Resource])
|
"""
|
||||||
json.dump({"nodes": resources, "links": []}, open("button_battery_station_resources_unilab.json", "w"), indent=2)
|
deck = CoincellDeck(name=name, size_x=size_x, size_y=size_y, size_z=size_z)
|
||||||
|
deck.setup()
|
||||||
|
return deck
|
||||||
#print(resources)
|
|
||||||
http_client.remote_addr = "https://uni-lab.test.bohrium.com/api/v1"
|
|
||||||
|
|
||||||
http_client.resource_add(resources)
|
|
||||||
|
|||||||
@@ -136,27 +136,16 @@ class CoinCellAssemblyWorkstation(WorkstationBase):
|
|||||||
)
|
)
|
||||||
self.debug_mode = debug_mode
|
self.debug_mode = debug_mode
|
||||||
|
|
||||||
self.deck = None
|
# 如果没有传入 deck,则创建标准配置的 deck
|
||||||
|
|
||||||
if self.deck is None:
|
if self.deck is None:
|
||||||
self.deck = CoincellDeck(size_x=1000, size_y=1000, size_z=900)
|
self.deck = CoincellDeck(size_x=1000, size_y=1000, size_z=900, setup=True)
|
||||||
# 创建料盘1并添加极片
|
|
||||||
liaopan1 = MaterialPlate(name="liaopan1", size_x=120.8, size_y=120.5, size_z=10.0, fill=True)
|
|
||||||
self.deck.assign_child_resource(liaopan1, Coordinate(x=0, y=0, z=0))
|
|
||||||
for i in range(16):
|
|
||||||
jipian = ElectrodeSheet(name=f"jipian1_{i}", size_x=12, size_y=12, size_z=0.1)
|
|
||||||
liaopan1.children[i].assign_child_resource(jipian, location=None)
|
|
||||||
# 创建料盘2
|
|
||||||
liaopan2 = MaterialPlate(name="liaopan2", size_x=120.8, size_y=120.5, size_z=10.0, fill=True)
|
|
||||||
self.deck.assign_child_resource(liaopan2, Coordinate(x=500, y=0, z=0))
|
|
||||||
# 创建电池料盘
|
|
||||||
liaopan3 = MaterialPlate(name="电池料盘", size_x=120.8, size_y=160.5, size_z=10.0, fill=True)
|
|
||||||
self.deck.assign_child_resource(liaopan3, Coordinate(x=100, y=100, z=0))
|
|
||||||
else:
|
else:
|
||||||
if self.deck is None:
|
# 如果传入了 deck 但还没有 setup,可以选择是否 setup
|
||||||
self.deck = self.deck
|
if self.deck is not None and len(self.deck.children) == 0:
|
||||||
elif self.deck is not self.deck:
|
# deck 为空,执行 setup
|
||||||
self.deck = self.deck
|
self.deck.setup()
|
||||||
|
# 否则使用传入的 deck(可能已经配置好了)
|
||||||
|
self.deck = self.deck
|
||||||
|
|
||||||
""" 连接初始化 """
|
""" 连接初始化 """
|
||||||
modbus_client = TCPClient(addr=address, port=port)
|
modbus_client = TCPClient(addr=address, port=port)
|
||||||
@@ -1229,84 +1218,7 @@ class CoinCellAssemblyWorkstation(WorkstationBase):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# modbus_client = TCPClient(addr="172.21.32.20", port="502")
|
# 简单测试
|
||||||
# # modbus_client.client.connect()
|
workstation = CoinCellAssemblyWorkstation()
|
||||||
# nodes = BaseClient.load_csv(os.path.join(os.path.dirname(__file__), 'coin_cell_assembly_a.csv'))
|
print(f"工作站创建成功: {workstation.deck.name}")
|
||||||
# client = modbus_client.register_node_list(nodes)
|
print(f"料盘数量: {len(workstation.deck.children)}")
|
||||||
# # print("modbus_client", modbus_client)
|
|
||||||
# while True:
|
|
||||||
# time.sleep(1)
|
|
||||||
# cmd_feedback, read_err = modbus_client.use_node('COIL_SYS_AUTO_CMD').read(1)
|
|
||||||
# print("modbus_client", cmd_feedback)
|
|
||||||
Coin_Cell = CoinCellAssemblyWorkstation()
|
|
||||||
print(Coin_Cell.deck)
|
|
||||||
#Coin_Cell.func_pack_device_init()
|
|
||||||
#Coin_Cell.func_pack_device_auto()
|
|
||||||
#Coin_Cell.func_pack_device_start()
|
|
||||||
#Coin_Cell.func_pack_send_bottle_num(2)
|
|
||||||
#Coin_Cell.func_pack_send_msg_cmd(2)
|
|
||||||
#Coin_Cell.func_pack_get_msg_cmd()
|
|
||||||
#Coin_Cell.func_pack_get_msg_cmd()
|
|
||||||
#Coin_Cell.func_pack_send_finished_cmd()
|
|
||||||
#
|
|
||||||
#Coin_Cell.func_allpack_cmd(3, 2)
|
|
||||||
#print(Coin_Cell.data_stack_vision_code)
|
|
||||||
#print("success")
|
|
||||||
#创建一个物料台面
|
|
||||||
|
|
||||||
# deck = create_a_coin_cell_deck()
|
|
||||||
#deck = create_a_full_coin_cell_deck()
|
|
||||||
|
|
||||||
|
|
||||||
##在台面上找到料盘和极片
|
|
||||||
#liaopan1 = deck.get_resource("liaopan1")
|
|
||||||
#liaopan2 = deck.get_resource("liaopan2")
|
|
||||||
#jipian1 = liaopan1.children[1].children[0]
|
|
||||||
##
|
|
||||||
#print(jipian1)
|
|
||||||
##把物料解绑后放到另一盘上
|
|
||||||
#jipian1.parent.unassign_child_resource(jipian1)
|
|
||||||
#liaopan2.children[1].assign_child_resource(jipian1, location=None)
|
|
||||||
##print(jipian2.parent)
|
|
||||||
|
|
||||||
# 使用 Coin_Cell 对象的 deck 属性
|
|
||||||
deck = Coin_Cell.deck
|
|
||||||
|
|
||||||
liaopan1 = Coin_Cell.deck.get_resource("liaopan1")
|
|
||||||
liaopan2 = Coin_Cell.deck.get_resource("liaopan2")
|
|
||||||
for i in range(16):
|
|
||||||
#找到liaopan1上每一个jipian
|
|
||||||
jipian_linshi = liaopan1.children[i].children[0]
|
|
||||||
#把物料解绑后放到另一盘上
|
|
||||||
print("极片:", jipian_linshi)
|
|
||||||
jipian_linshi.parent.unassign_child_resource(jipian_linshi)
|
|
||||||
liaopan2.children[i].assign_child_resource(jipian_linshi, location=None)
|
|
||||||
|
|
||||||
|
|
||||||
from unilabos.resources.graphio import resource_ulab_to_plr, convert_resources_to_type
|
|
||||||
#with open("./button_battery_decks_unilab.json", "r", encoding="utf-8") as f:
|
|
||||||
# bioyond_resources_unilab = json.load(f)
|
|
||||||
#print(f"成功读取 JSON 文件,包含 {len(bioyond_resources_unilab)} 个资源")
|
|
||||||
#ulab_resources = convert_resources_to_type(bioyond_resources_unilab, List[PLRResource])
|
|
||||||
#print(f"转换结果类型: {type(ulab_resources)}")
|
|
||||||
#print(ulab_resources)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from unilabos.resources.graphio import convert_resources_from_type
|
|
||||||
from unilabos.config.config import BasicConfig
|
|
||||||
BasicConfig.ak = "beb0c15f-2279-46a1-aba5-00eaf89aef55"
|
|
||||||
BasicConfig.sk = "15d4f25e-3512-4f9c-9bfb-43ab85e7b561"
|
|
||||||
from unilabos.app.web.client import http_client
|
|
||||||
|
|
||||||
resources = convert_resources_from_type([Coin_Cell.deck], [Resource])
|
|
||||||
json.dump({"nodes": resources, "links": []}, open("button_battery_decks_unilab.json", "w"), indent=2)
|
|
||||||
|
|
||||||
#print(resources)
|
|
||||||
http_client.remote_addr = "https://uni-lab.test.bohrium.com/api/v1"
|
|
||||||
|
|
||||||
http_client.resource_add(resources)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user