fix: 修复 BioyondCellWorkstation 和 CoinCellAssembly 工作流程

- 修复 run 方法的函数参数语法错误(冒号改为等号)
- 将 BioyondCellWorkstation 的 run 函数移入类内部
- 添加 run_bioyond_cell_workflow 方法支持可选的 1to2 步骤
- 更新相关 YAML 配置文件
This commit is contained in:
dijkstra402
2025-11-25 15:39:07 +08:00
parent fa9b2a08f2
commit 4d4bbcbae8
10 changed files with 629 additions and 359 deletions

View File

@@ -257,7 +257,7 @@ class BioyondCellWorkstation(BioyondWorkstation):
def auto_feeding4to3(
self,
# ★ 修改点:默认模板路径
xlsx_path: Optional[str] = "/Users/calvincao/Desktop/work/uni-lab-all/Uni-Lab-OS/unilabos/devices/workstation/bioyond_studio/bioyond_cell/material_template.xlsx",
xlsx_path: Optional[str] = "/Users/sml/work/Unilab/Uni-Lab-OS/unilabos/devices/workstation/bioyond_studio/bioyond_cell/material_template.xlsx",
# ---------------- WH4 - 加样头面 (Z=1, 12个点位) ----------------
WH4_x1_y1_z1_1_materialName: str = "", WH4_x1_y1_z1_1_quantity: float = 0.0,
WH4_x2_y1_z1_2_materialName: str = "", WH4_x2_y1_z1_2_quantity: float = 0.0,
@@ -477,7 +477,7 @@ class BioyondCellWorkstation(BioyondWorkstation):
- totalMass 自动计算为所有物料质量之和
- createTime 缺失或为空时自动填充为当前日期YYYY/M/D
"""
default_path = Path("/Users/calvincao/Desktop/work/uni-lab-all/Uni-Lab-OS/unilabos/devices/workstation/bioyond_studio/bioyond_cell/2025092701.xlsx")
default_path = Path("/Users/sml/work/Unilab/Uni-Lab-OS/unilabos/devices/workstation/bioyond_studio/bioyond_cell/2025092701.xlsx")
path = Path(xlsx_path) if xlsx_path else default_path
print(f"[create_orders] 使用 Excel 路径: {path}")
if path != default_path:
@@ -1165,137 +1165,39 @@ class BioyondCellWorkstation(BioyondWorkstation):
})
return final_result
def run_bioyond_cell_workflow(config: Dict[str, Any]) -> BioyondCellWorkstation:
"""按照统一配置执行奔曜配液与转运工作流。
Args:
config: 统一的工作流配置。字段示例:
{
"lab_registry": {"setup": True},
"deck": {"setup": True},
"workstation": {"config": {...}},
"update_push_ip": True,
"samples": [
{"name": "...", "board_type": "...", "bottle_type": "...", "location_code": "...", "warehouse_name": "..."}
],
"scheduler": {"start": True, "log": True},
"operations": {
"auto_feeding4to3": {"enabled": True},
"create_orders": {"excel_path": "...", "log": True},
"transfer_3_to_2_to_1": {"enabled": True, "log": True},
"transfer_1_to_2": {"enabled": True, "log": True}
},
"keep_alive": False,
"keep_alive_interval": 1
}
Returns:
执行完毕的 `BioyondCellWorkstation` 实例。
"""
if config.get("lab_registry", {}).get("setup", True):
lab_registry.setup()
deck_config = config.get("deck")
if isinstance(deck_config, dict):
deck = BIOYOND_YB_Deck(**deck_config)
elif deck_config is None:
deck = BIOYOND_YB_Deck(setup=True)
else:
deck = deck_config
workstation_kwargs = dict(config.get("workstation", {}))
if "deck" not in workstation_kwargs:
workstation_kwargs["deck"] = deck
ws = BioyondCellWorkstation(**workstation_kwargs)
if config.get("update_push_ip", True):
ws.update_push_ip()
for sample_cfg in config.get("samples", []):
ws.create_sample(**sample_cfg)
scheduler_cfg = config.get("scheduler", {})
if scheduler_cfg.get("start", True):
result = ws.scheduler_start()
if scheduler_cfg.get("log", True):
logger.info(result)
operations_cfg = config.get("operations", {})
auto_feeding_cfg = operations_cfg.get("auto_feeding4to3", {})
if auto_feeding_cfg.get("enabled", True):
result = ws.auto_feeding4to3()
if auto_feeding_cfg.get("log", True):
logger.info(result)
create_orders_cfg = operations_cfg.get("create_orders")
if create_orders_cfg:
excel_path = create_orders_cfg.get("excel_path")
if not excel_path:
raise ValueError("create_orders 需要提供 excel_path。")
result = ws.create_orders(Path(excel_path))
if create_orders_cfg.get("log", True):
logger.info(result)
transfer_321_cfg = operations_cfg.get("transfer_3_to_2_to_1", {})
if transfer_321_cfg.get("enabled", True):
result = ws.transfer_3_to_2_to_1()
if transfer_321_cfg.get("log", True):
logger.info(result)
transfer_12_cfg = operations_cfg.get("transfer_1_to_2", {})
if transfer_12_cfg.get("enabled", True):
result = ws.transfer_1_to_2()
if transfer_12_cfg.get("log", True):
logger.info(result)
if config.get("keep_alive", False):
interval = config.get("keep_alive_interval", 1)
while True:
time.sleep(interval)
return ws
def run_bioyond_cell_workflow(self):
self.create_sample(
board_type="配液瓶(小)板",
bottle_type="配液瓶(小)",
location_code="B01",
name="配液瓶",
warehouse_name="手动堆栈"
)
self.create_sample(
board_type="5ml分液瓶板",
bottle_type="5ml分液瓶",
location_code="B02",
name="分液瓶",
warehouse_name="手动堆栈"
)
self.scheduler_start()
self.auto_feeding4to3(
xlsx_path="/Users/sml/work/Unilab/Uni-Lab-OS/unilabos/devices/workstation/bioyond_studio/bioyond_cell/material_template.xlsx"
)
self.create_orders(
xlsx_path="/Users/sml/work/Unilab/Uni-Lab-OS/unilabos/devices/workstation/bioyond_studio/bioyond_cell/2025092701.xlsx"
)
self.transfer_3_to_2_to_1(
source_wh_id="3a19debc-84b4-0359-e2d4-b3beea49348b",
source_x=1,
source_y=1,
source_z=1,
)
return self
if __name__ == "__main__":
workflow_config = {
"deck": {"setup": True},
"update_push_ip": True,
"samples": [
{
"name": "配液瓶",
"board_type": "配液瓶(小)板",
"bottle_type": "配液瓶(小)",
"location_code": "E01",
},
{
"name": "分液瓶",
"board_type": "5ml分液瓶板",
"bottle_type": "5ml分液瓶",
"location_code": "D01",
},
],
"operations": {
"auto_feeding4to3": {"enabled": True, "log": True},
"create_orders": {
"excel_path": "/Users/calvincao/Desktop/work/uni-lab-all/Uni-Lab-OS/unilabos/devices/workstation/bioyond_studio/bioyond_cell/2025092701.xlsx",
"log": True,
},
"transfer_3_to_2_to_1": {"enabled": True, "log": True},
"transfer_1_to_2": {"enabled": True, "log": True},
},
"keep_alive": True,
}
run_bioyond_cell_workflow(workflow_config)
# 1. location code
# 2. 实验文件
# 3. material template file
deck = BIOYOND_YB_Deck(setup=True)
w = BioyondCellWorkstation(deck=deck, address="172.16.28.102", port="502", debug_mode=False)
w.run_bioyond_cell_workflow()
while True:
time.sleep(1)
# re=ws.scheduler_stop()

View File

@@ -8,8 +8,8 @@ import os
# BioyondCellWorkstation 默认配置(包含所有必需参数)
API_CONFIG = {
# API 连接配置
"api_host": os.getenv("BIOYOND_API_HOST", "http://172.16.1.143:44389"),#实机
# "api_host": os.getenv("BIOYOND_API_HOST", "http://172.16.7.149:44388"),# 仿真机
# "api_host": os.getenv("BIOYOND_API_HOST", "http://172.16.1.143:44389"),#实机
"api_host": os.getenv("BIOYOND_API_HOST", "http://172.16.11.219:44388"),# 仿真机
"api_key": os.getenv("BIOYOND_API_KEY", "8A819E5C"),
"timeout": int(os.getenv("BIOYOND_TIMEOUT", "30")),
@@ -17,7 +17,7 @@ API_CONFIG = {
"report_token": os.getenv("BIOYOND_REPORT_TOKEN", "CHANGE_ME_TOKEN"),
# HTTP 服务配置
"HTTP_host": os.getenv("BIOYOND_HTTP_HOST", "172.16.2.140"), # HTTP服务监听地址监听计算机飞连ip地址
"HTTP_host": os.getenv("BIOYOND_HTTP_HOST", "172.16.11.2"), # HTTP服务监听地址监听计算机飞连ip地址
"HTTP_port": int(os.getenv("BIOYOND_HTTP_PORT", "8080")),
"debug_mode": False,# 调试模式
}

View File

@@ -1,4 +1,3 @@
import csv
import inspect
import json
@@ -139,12 +138,11 @@ class CoinCellAssemblyWorkstation(WorkstationBase):
time.sleep(2)
if not modbus_client.client.is_socket_open():
raise ValueError('modbus tcp connection failed')
self.nodes = BaseClient.load_csv(os.path.join(os.path.dirname(__file__), 'coin_cell_assembly_a.csv'))
self.nodes = BaseClient.load_csv(os.path.join(os.path.dirname(__file__), 'coin_cell_assembly_1105.csv'))
self.client = modbus_client.register_node_list(self.nodes)
else:
print("测试模式,跳过连接")
self.nodes, self.client = None, None
""" 工站的配置 """
self.success = False
@@ -986,6 +984,31 @@ class CoinCellAssemblyWorkstation(WorkstationBase):
#self.success = True
#return self.success
def run_packaging_workflow(self, workflow_config: Dict[str, Any]) -> "CoinCellAssemblyWorkstation":
config = workflow_config or {}
qiming_params = config.get("qiming") or {}
if qiming_params:
self.qiming_coin_cell_code(**qiming_params)
if config.get("init", True):
self.func_pack_device_init()
if config.get("auto", True):
self.func_pack_device_auto()
if config.get("start", True):
self.func_pack_device_start()
packaging_config = config.get("packaging") or {}
bottle_num = packaging_config.get("bottle_num")
if bottle_num is not None:
self.func_pack_send_bottle_num(bottle_num)
allpack_params = packaging_config.get("command") or {}
if allpack_params:
self.func_allpack_cmd(**allpack_params)
return self
def fun_wuliao_test(self) -> bool:
#找到data_init中构建的2个物料盘
liaopan3 = self.deck.get_resource("\u7535\u6c60\u6599\u76d8")
@@ -1199,96 +1222,34 @@ class CoinCellAssemblyWorkstation(WorkstationBase):
"""移液枪头库存 (数量, INT16)"""
inventory, read_err = self.client.register_node_list(self.nodes).use_node('REG_DATA_TIPS_INVENTORY').read(1)
return inventory
'''
def run_coin_cell_packaging_workflow(config: Dict[str, Any]) -> CoinCellAssemblyWorkstation:
"""根据统一配置顺序执行扣电池装配工作流。
Args:
config: 统一的工作流配置。字段示例:
{
"deck": {"setup": True, "name": "coin_cell_deck"},
"workstation": {"address": "...", "port": "...", "debug_mode": False},
"qiming": {...},
"init": True,
"auto": True,
"start": True,
"packaging": {
"bottle_num": 16,
"command": {...}
}
}
Returns:
执行完毕的 `CoinCellAssemblyWorkstation` 实例。
"""
deck_config = config.get("deck")
if isinstance(deck_config, Deck):
deck = deck_config
elif isinstance(deck_config, dict):
deck = CoincellDeck(**deck_config)
elif deck_config is None:
deck = CoincellDeck(setup=True, name="coin_cell_deck")
else:
raise ValueError("deck 配置需为 Deck 实例或 dict。")
workstation_config = dict(config.get("workstation", {}))
workstation_config.setdefault("deck", deck)
workstation = CoinCellAssemblyWorkstation(**workstation_config)
qiming_params = config.get("qiming", {})
if qiming_params:
workstation.qiming_coin_cell_code(**qiming_params)
if config.get("init", True):
workstation.func_pack_device_init()
if config.get("auto", True):
workstation.func_pack_device_auto()
if config.get("start", True):
workstation.func_pack_device_start()
packaging_config = config.get("packaging", {})
bottle_num = packaging_config.get("bottle_num")
if bottle_num is not None:
workstation.func_pack_send_bottle_num(bottle_num)
allpack_params = packaging_config.get("command", {})
if allpack_params:
workstation.func_allpack_cmd(**allpack_params)
return workstation
def run_coin_cell_assembly_workflow(self):
self.qiming_coin_cell_code(
fujipian_panshu=1,
fujipian_juzhendianwei=0,
gemopanshu=0,
gemo_juzhendianwei=0,
lvbodian=True,
battery_pressure_mode=True,
battery_pressure=4200,
battery_clean_ignore=False,
)
self.func_pack_device_init()
self.func_pack_device_auto()
self.func_pack_device_start()
self.func_pack_send_bottle_num(1)
self.func_allpack_cmd(elec_num = 1, elec_use_num = 1, elec_vol=50, assembly_type=7, assembly_pressure=4200, file_path="/Users/sml/work")
self.func_pack_send_finished_cmd()
self.func_pack_device_stop()
# 物料转换
return self
if __name__ == "__main__":
workflow_config = {
"deck": {"setup": True, "name": "coin_cell_deck"},
"workstation": {
"address": "172.16.28.102",
"port": "502",
"debug_mode": False,
},
"qiming": {
"fujipian_panshu": 1,
"fujipian_juzhendianwei": 2,
"gemopanshu": 3,
"gemo_juzhendianwei": 4,
"lvbodian": False,
"battery_pressure_mode": False,
"battery_pressure": 4200,
"battery_clean_ignore": False,
},
"packaging": {
"bottle_num": 16,
"command": {
"elec_num": 16,
"elec_use_num": 16,
"elec_vol": 50,
"assembly_type": 7,
"assembly_pressure": 4200,
"file_path": "/Users/calvincao/Desktop/work/Uni-Lab-OS-hhm",
},
},
}
run_coin_cell_packaging_workflow(workflow_config)
deck = CoincellDeck(setup=True, name="coin_cell_deck")
w = CoinCellAssemblyWorkstation(deck=deck, address="172.16.28.102", port="502", debug_mode=False)
w.run_coin_cell_assembly_workflow()