mirror of
https://github.com/deepmodeling/Uni-Lab-OS
synced 2026-04-24 09:39:58 +00:00
Compare commits
32 Commits
prcix9320
...
workstatio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99ee27bfc2 | ||
|
|
e8f54d50f9 | ||
|
|
201b1064d7 | ||
|
|
2ebe35e70e | ||
|
|
717f236332 | ||
|
|
79c0815b70 | ||
|
|
f431d61d85 | ||
|
|
3af86a07f2 | ||
|
|
d1713fcca1 | ||
|
|
52b460466d | ||
|
|
7efccbc688 | ||
|
|
dc1de44b19 | ||
|
|
4581ee1eeb | ||
|
|
620cb8435f | ||
|
|
83565038cb | ||
|
|
01d281189a | ||
|
|
db22156d77 | ||
|
|
20342c6484 | ||
|
|
008c355754 | ||
|
|
0895252bc1 | ||
|
|
3e43359460 | ||
|
|
73add2dc06 | ||
|
|
dd21d93151 | ||
|
|
e11c3533c7 | ||
|
|
ed952e8a44 | ||
|
|
467f0b1115 | ||
|
|
91928a87ac | ||
|
|
d7850b050b | ||
|
|
dff70bd72b | ||
|
|
03e3719b18 | ||
|
|
41a018febc | ||
|
|
7505e024f3 |
@@ -1,9 +0,0 @@
|
|||||||
@echo off
|
|
||||||
setlocal enabledelayedexpansion
|
|
||||||
|
|
||||||
REM upgrade pip
|
|
||||||
"%PREFIX%\python.exe" -m pip install --upgrade pip
|
|
||||||
|
|
||||||
REM install extra deps
|
|
||||||
"%PREFIX%\python.exe" -m pip install paho-mqtt opentrons_shared_data
|
|
||||||
"%PREFIX%\python.exe" -m pip install git+https://github.com/Xuwznln/pylabrobot.git
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -euxo pipefail
|
|
||||||
|
|
||||||
# make sure pip is available
|
|
||||||
"$PREFIX/bin/python" -m pip install --upgrade pip
|
|
||||||
|
|
||||||
# install extra deps
|
|
||||||
"$PREFIX/bin/python" -m pip install paho-mqtt opentrons_shared_data
|
|
||||||
"$PREFIX/bin/python" -m pip install git+https://github.com/Xuwznln/pylabrobot.git
|
|
||||||
@@ -27,14 +27,15 @@ python -c "import base64,sys; print('Authorization: Lab ' + base64.b64encode(f'{
|
|||||||
|
|
||||||
### 2. --addr → BASE URL
|
### 2. --addr → BASE URL
|
||||||
|
|
||||||
| `--addr` 值 | BASE |
|
| `--addr` 值 | BASE |
|
||||||
|-------------|------|
|
| ------------ | ----------------------------------- |
|
||||||
| `test` | `https://uni-lab.test.bohrium.com` |
|
| `test` | `https://leap-lab.test.bohrium.com` |
|
||||||
| `uat` | `https://uni-lab.uat.bohrium.com` |
|
| `uat` | `https://leap-lab.uat.bohrium.com` |
|
||||||
| `local` | `http://127.0.0.1:48197` |
|
| `local` | `http://127.0.0.1:48197` |
|
||||||
| 不传(默认) | `https://uni-lab.bohrium.com` |
|
| 不传(默认) | `https://leap-lab.bohrium.com` |
|
||||||
|
|
||||||
确认后设置:
|
确认后设置:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
BASE="<根据 addr 确定的 URL>"
|
BASE="<根据 addr 确定的 URL>"
|
||||||
AUTH="Authorization: Lab <gen_auth.py 输出的 token>"
|
AUTH="Authorization: Lab <gen_auth.py 输出的 token>"
|
||||||
@@ -65,7 +66,7 @@ curl -s -X GET "$BASE/api/v1/edge/lab/info" -H "$AUTH"
|
|||||||
返回:
|
返回:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"code": 0, "data": {"uuid": "xxx", "name": "实验室名称"}}
|
{ "code": 0, "data": { "uuid": "xxx", "name": "实验室名称" } }
|
||||||
```
|
```
|
||||||
|
|
||||||
记住 `data.uuid` 为 `lab_uuid`。
|
记住 `data.uuid` 为 `lab_uuid`。
|
||||||
@@ -90,6 +91,7 @@ curl -s -X POST "$BASE/api/v1/lab/reagent" \
|
|||||||
```
|
```
|
||||||
|
|
||||||
返回成功时包含试剂 UUID:
|
返回成功时包含试剂 UUID:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"code": 0, "data": {"uuid": "xxx", ...}}
|
{"code": 0, "data": {"uuid": "xxx", ...}}
|
||||||
```
|
```
|
||||||
@@ -98,28 +100,28 @@ curl -s -X POST "$BASE/api/v1/lab/reagent" \
|
|||||||
|
|
||||||
## 试剂字段说明
|
## 试剂字段说明
|
||||||
|
|
||||||
| 字段 | 类型 | 必填 | 说明 | 示例 |
|
| 字段 | 类型 | 必填 | 说明 | 示例 |
|
||||||
|------|------|------|------|------|
|
| ------------------- | ------ | ---- | ----------------------------- | ------------------------ |
|
||||||
| `lab_uuid` | string | 是 | 实验室 UUID(从 API #1 获取) | `"8511c672-..."` |
|
| `lab_uuid` | string | 是 | 实验室 UUID(从 API #1 获取) | `"8511c672-..."` |
|
||||||
| `cas` | string | 是 | CAS 注册号 | `"7732-18-3"` |
|
| `cas` | string | 是 | CAS 注册号 | `"7732-18-3"` |
|
||||||
| `name` | string | 是 | 试剂中文/英文名称 | `"水"` |
|
| `name` | string | 是 | 试剂中文/英文名称 | `"水"` |
|
||||||
| `molecular_formula` | string | 是 | 分子式 | `"H2O"` |
|
| `molecular_formula` | string | 是 | 分子式 | `"H2O"` |
|
||||||
| `smiles` | string | 是 | SMILES 表示 | `"O"` |
|
| `smiles` | string | 是 | SMILES 表示 | `"O"` |
|
||||||
| `stock_in_quantity` | number | 是 | 入库数量 | `10` |
|
| `stock_in_quantity` | number | 是 | 入库数量 | `10` |
|
||||||
| `unit` | string | 是 | 单位(字符串,见下表) | `"mL"` |
|
| `unit` | string | 是 | 单位(字符串,见下表) | `"mL"` |
|
||||||
| `supplier` | string | 否 | 供应商名称 | `"国药集团"` |
|
| `supplier` | string | 否 | 供应商名称 | `"国药集团"` |
|
||||||
| `production_date` | string | 否 | 生产日期(ISO 8601) | `"2025-11-18T00:00:00Z"` |
|
| `production_date` | string | 否 | 生产日期(ISO 8601) | `"2025-11-18T00:00:00Z"` |
|
||||||
| `expiry_date` | string | 否 | 过期日期(ISO 8601) | `"2026-11-18T00:00:00Z"` |
|
| `expiry_date` | string | 否 | 过期日期(ISO 8601) | `"2026-11-18T00:00:00Z"` |
|
||||||
|
|
||||||
### unit 单位值
|
### unit 单位值
|
||||||
|
|
||||||
| 值 | 单位 |
|
| 值 | 单位 |
|
||||||
|------|------|
|
| ------ | ---- |
|
||||||
| `"mL"` | 毫升 |
|
| `"mL"` | 毫升 |
|
||||||
| `"L"` | 升 |
|
| `"L"` | 升 |
|
||||||
| `"g"` | 克 |
|
| `"g"` | 克 |
|
||||||
| `"kg"` | 千克 |
|
| `"kg"` | 千克 |
|
||||||
| `"瓶"` | 瓶 |
|
| `"瓶"` | 瓶 |
|
||||||
|
|
||||||
> 根据试剂状态选择:液体用 `"mL"` / `"L"`,固体用 `"g"` / `"kg"`。
|
> 根据试剂状态选择:液体用 `"mL"` / `"L"`,固体用 `"g"` / `"kg"`。
|
||||||
|
|
||||||
@@ -133,8 +135,22 @@ curl -s -X POST "$BASE/api/v1/lab/reagent" \
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
[
|
[
|
||||||
{"cas": "7732-18-3", "name": "水", "molecular_formula": "H2O", "smiles": "O", "stock_in_quantity": 10, "unit": "mL"},
|
{
|
||||||
{"cas": "64-17-5", "name": "乙醇", "molecular_formula": "C2H6O", "smiles": "CCO", "stock_in_quantity": 5, "unit": "L"}
|
"cas": "7732-18-3",
|
||||||
|
"name": "水",
|
||||||
|
"molecular_formula": "H2O",
|
||||||
|
"smiles": "O",
|
||||||
|
"stock_in_quantity": 10,
|
||||||
|
"unit": "mL"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cas": "64-17-5",
|
||||||
|
"name": "乙醇",
|
||||||
|
"molecular_formula": "C2H6O",
|
||||||
|
"smiles": "CCO",
|
||||||
|
"stock_in_quantity": 5,
|
||||||
|
"unit": "L"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -160,9 +176,20 @@ cas,name,molecular_formula,smiles,stock_in_quantity,unit,supplier,production_dat
|
|||||||
7732-18-3,水,H2O,O,10,mL,农夫山泉,2025-11-18T00:00:00Z,2026-11-18T00:00:00Z
|
7732-18-3,水,H2O,O,10,mL,农夫山泉,2025-11-18T00:00:00Z,2026-11-18T00:00:00Z
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 日期格式规则(重要)
|
||||||
|
|
||||||
|
所有日期字段(`production_date`、`expiry_date`)**必须**使用 ISO 8601 完整格式:`YYYY-MM-DDTHH:MM:SSZ`。
|
||||||
|
|
||||||
|
- 用户输入 `2025-03-01` → 转换为 `"2025-03-01T00:00:00Z"`
|
||||||
|
- 用户输入 `2025/9/1` → 转换为 `"2025-09-01T00:00:00Z"`
|
||||||
|
- 用户未提供日期 → 使用当天日期 + `T00:00:00Z`,有效期默认 +1 年
|
||||||
|
|
||||||
|
**禁止**发送不带时间部分的日期字符串(如 `"2025-03-01"`),API 会拒绝。
|
||||||
|
|
||||||
### 执行与汇报
|
### 执行与汇报
|
||||||
|
|
||||||
每次 API 调用后:
|
每次 API 调用后:
|
||||||
|
|
||||||
1. 检查返回 `code`(0 = 成功)
|
1. 检查返回 `code`(0 = 成功)
|
||||||
2. 记录成功/失败数量
|
2. 记录成功/失败数量
|
||||||
3. 全部完成后汇总:「共录入 N 条试剂,成功 X 条,失败 Y 条」
|
3. 全部完成后汇总:「共录入 N 条试剂,成功 X 条,失败 Y 条」
|
||||||
@@ -172,28 +199,29 @@ cas,name,molecular_formula,smiles,stock_in_quantity,unit,supplier,production_dat
|
|||||||
|
|
||||||
## 常见试剂速查表
|
## 常见试剂速查表
|
||||||
|
|
||||||
| 名称 | CAS | 分子式 | SMILES |
|
| 名称 | CAS | 分子式 | SMILES |
|
||||||
|------|-----|--------|--------|
|
| --------------------- | --------- | ---------- | ------------------------------------ |
|
||||||
| 水 | 7732-18-3 | H2O | O |
|
| 水 | 7732-18-3 | H2O | O |
|
||||||
| 乙醇 | 64-17-5 | C2H6O | CCO |
|
| 乙醇 | 64-17-5 | C2H6O | CCO |
|
||||||
| 甲醇 | 67-56-1 | CH4O | CO |
|
| 乙酸 | 64-19-7 | C2H4O2 | CC(O)=O |
|
||||||
| 丙酮 | 67-64-1 | C3H6O | CC(C)=O |
|
| 甲醇 | 67-56-1 | CH4O | CO |
|
||||||
| 二甲基亚砜(DMSO) | 67-68-5 | C2H6OS | CS(C)=O |
|
| 丙酮 | 67-64-1 | C3H6O | CC(C)=O |
|
||||||
| 乙酸乙酯 | 141-78-6 | C4H8O2 | CCOC(C)=O |
|
| 二甲基亚砜(DMSO) | 67-68-5 | C2H6OS | CS(C)=O |
|
||||||
| 二氯甲烷 | 75-09-2 | CH2Cl2 | ClCCl |
|
| 乙酸乙酯 | 141-78-6 | C4H8O2 | CCOC(C)=O |
|
||||||
| 四氢呋喃(THF) | 109-99-9 | C4H8O | C1CCOC1 |
|
| 二氯甲烷 | 75-09-2 | CH2Cl2 | ClCCl |
|
||||||
| N,N-二甲基甲酰胺(DMF) | 68-12-2 | C3H7NO | CN(C)C=O |
|
| 四氢呋喃(THF) | 109-99-9 | C4H8O | C1CCOC1 |
|
||||||
| 氯仿 | 67-66-3 | CHCl3 | ClC(Cl)Cl |
|
| N,N-二甲基甲酰胺(DMF) | 68-12-2 | C3H7NO | CN(C)C=O |
|
||||||
| 乙腈 | 75-05-8 | C2H3N | CC#N |
|
| 氯仿 | 67-66-3 | CHCl3 | ClC(Cl)Cl |
|
||||||
| 甲苯 | 108-88-3 | C7H8 | Cc1ccccc1 |
|
| 乙腈 | 75-05-8 | C2H3N | CC#N |
|
||||||
| 正己烷 | 110-54-3 | C6H14 | CCCCCC |
|
| 甲苯 | 108-88-3 | C7H8 | Cc1ccccc1 |
|
||||||
| 异丙醇 | 67-63-0 | C3H8O | CC(C)O |
|
| 正己烷 | 110-54-3 | C6H14 | CCCCCC |
|
||||||
| 盐酸 | 7647-01-0 | HCl | Cl |
|
| 异丙醇 | 67-63-0 | C3H8O | CC(C)O |
|
||||||
| 硫酸 | 7664-93-9 | H2SO4 | OS(O)(=O)=O |
|
| 盐酸 | 7647-01-0 | HCl | Cl |
|
||||||
| 氢氧化钠 | 1310-73-2 | NaOH | [Na]O |
|
| 硫酸 | 7664-93-9 | H2SO4 | OS(O)(=O)=O |
|
||||||
| 碳酸钠 | 497-19-8 | Na2CO3 | [Na]OC([O-])=O.[Na+] |
|
| 氢氧化钠 | 1310-73-2 | NaOH | [Na]O |
|
||||||
| 氯化钠 | 7647-14-5 | NaCl | [Na]Cl |
|
| 碳酸钠 | 497-19-8 | Na2CO3 | [Na]OC([O-])=O.[Na+] |
|
||||||
| 乙二胺四乙酸(EDTA) | 60-00-4 | C10H16N2O8 | OC(=O)CN(CCN(CC(O)=O)CC(O)=O)CC(O)=O |
|
| 氯化钠 | 7647-14-5 | NaCl | [Na]Cl |
|
||||||
|
| 乙二胺四乙酸(EDTA) | 60-00-4 | C10H16N2O8 | OC(=O)CN(CCN(CC(O)=O)CC(O)=O)CC(O)=O |
|
||||||
|
|
||||||
> 此表仅供快速参考。对于不在表中的试剂,agent 应根据化学知识推断或提示用户补充。
|
> 此表仅供快速参考。对于不在表中的试剂,agent 应根据化学知识推断或提示用户补充。
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
---
|
---
|
||||||
name: batch-submit-experiment
|
name: batch-submit-experiment
|
||||||
description: Batch submit experiments (notebooks) to Uni-Lab platform — list workflows, generate node_params from registry schemas, submit multiple rounds, check notebook status. Use when the user wants to submit experiments, create notebooks, batch run workflows, check experiment status, or mentions 提交实验/批量实验/notebook/实验轮次/实验状态.
|
description: Batch submit experiments (notebooks) to the Uni-Lab cloud platform (leap-lab) — list workflows, generate node_params from registry schemas, submit multiple rounds, check notebook status. Use when the user wants to submit experiments, create notebooks, batch run workflows, check experiment status, or mentions 提交实验/批量实验/notebook/实验轮次/实验状态.
|
||||||
---
|
---
|
||||||
|
|
||||||
# 批量提交实验指南
|
# Uni-Lab 批量提交实验指南
|
||||||
|
|
||||||
通过云端 API 批量提交实验(notebook),支持多轮实验参数配置。根据 workflow 模板详情和本地设备注册表自动生成 `node_params` 模板。
|
通过 Uni-Lab 云端 API 批量提交实验(notebook),支持多轮实验参数配置。根据 workflow 模板详情和本地设备注册表自动生成 `node_params` 模板。
|
||||||
|
|
||||||
|
> **重要**:本指南中的 `Authorization: Lab <token>` 是 **Uni-Lab 平台专用的认证方式**,`Lab` 是 Uni-Lab 的 auth scheme 关键字,**不是** HTTP Basic 认证。请勿将其替换为 `Basic`。
|
||||||
|
|
||||||
## 前置条件(缺一不可)
|
## 前置条件(缺一不可)
|
||||||
|
|
||||||
@@ -18,25 +20,28 @@ description: Batch submit experiments (notebooks) to Uni-Lab platform — list w
|
|||||||
生成 AUTH token(任选一种方式):
|
生成 AUTH token(任选一种方式):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 方式一:Python 一行生成
|
# 方式一:Python 一行生成(注意:scheme 是 "Lab" 不是 "Basic")
|
||||||
python -c "import base64,sys; print('Authorization: Lab ' + base64.b64encode(f'{sys.argv[1]}:{sys.argv[2]}'.encode()).decode())" <ak> <sk>
|
python -c "import base64,sys; print('Authorization: Lab ' + base64.b64encode(f'{sys.argv[1]}:{sys.argv[2]}'.encode()).decode())" <ak> <sk>
|
||||||
|
|
||||||
# 方式二:手动计算
|
# 方式二:手动计算
|
||||||
# base64(ak:sk) → Authorization: Lab <token>
|
# base64(ak:sk) → Authorization: Lab <token>
|
||||||
|
# ⚠️ 这里的 "Lab" 是 Uni-Lab 平台的 auth scheme,绝对不能用 "Basic" 替代
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. --addr → BASE URL
|
### 2. --addr → BASE URL
|
||||||
|
|
||||||
| `--addr` 值 | BASE |
|
| `--addr` 值 | BASE |
|
||||||
|-------------|------|
|
| ------------ | ----------------------------------- |
|
||||||
| `test` | `https://uni-lab.test.bohrium.com` |
|
| `test` | `https://leap-lab.test.bohrium.com` |
|
||||||
| `uat` | `https://uni-lab.uat.bohrium.com` |
|
| `uat` | `https://leap-lab.uat.bohrium.com` |
|
||||||
| `local` | `http://127.0.0.1:48197` |
|
| `local` | `http://127.0.0.1:48197` |
|
||||||
| 不传(默认) | `https://uni-lab.bohrium.com` |
|
| 不传(默认) | `https://leap-lab.bohrium.com` |
|
||||||
|
|
||||||
确认后设置:
|
确认后设置:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
BASE="<根据 addr 确定的 URL>"
|
BASE="<根据 addr 确定的 URL>"
|
||||||
|
# ⚠️ Auth scheme 必须是 "Lab"(Uni-Lab 专用),不是 "Basic"
|
||||||
AUTH="Authorization: Lab <上面命令输出的 token>"
|
AUTH="Authorization: Lab <上面命令输出的 token>"
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -44,18 +49,19 @@ AUTH="Authorization: Lab <上面命令输出的 token>"
|
|||||||
|
|
||||||
**批量提交实验时需要本地注册表来解析 workflow 节点的参数 schema。**
|
**批量提交实验时需要本地注册表来解析 workflow 节点的参数 schema。**
|
||||||
|
|
||||||
按优先级搜索:
|
**必须先用 Glob 工具搜索文件**,不要直接猜测路径:
|
||||||
|
|
||||||
```
|
```
|
||||||
<workspace 根目录>/unilabos_data/req_device_registry_upload.json
|
Glob: **/req_device_registry_upload.json
|
||||||
<workspace 根目录>/req_device_registry_upload.json
|
|
||||||
```
|
```
|
||||||
|
|
||||||
也可直接 Glob 搜索:`**/req_device_registry_upload.json`
|
常见位置(仅供参考,以 Glob 实际结果为准):
|
||||||
|
- `<workspace>/unilabos_data/req_device_registry_upload.json`
|
||||||
|
- `<workspace>/req_device_registry_upload.json`
|
||||||
|
|
||||||
找到后**检查文件修改时间**并告知用户。超过 1 天提醒用户是否需要重新启动 `unilab`。
|
找到后**检查文件修改时间**并告知用户。超过 1 天提醒用户是否需要重新启动 `unilab`。
|
||||||
|
|
||||||
**如果文件不存在** → 告知用户先运行 `unilab` 启动命令,等注册表生成后再执行。可跳过此步,但将无法自动生成参数模板,需要用户手动填写 `param`。
|
**如果 Glob 搜索无结果** → 告知用户先运行 `unilab` 启动命令,等注册表生成后再执行。可跳过此步,但将无法自动生成参数模板,需要用户手动填写 `param`。
|
||||||
|
|
||||||
### 4. workflow_uuid(目标工作流)
|
### 4. workflow_uuid(目标工作流)
|
||||||
|
|
||||||
@@ -93,7 +99,7 @@ curl -s -X GET "$BASE/api/v1/edge/lab/info" -H "$AUTH"
|
|||||||
返回:
|
返回:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"code": 0, "data": {"uuid": "xxx", "name": "实验室名称"}}
|
{ "code": 0, "data": { "uuid": "xxx", "name": "实验室名称" } }
|
||||||
```
|
```
|
||||||
|
|
||||||
记住 `data.uuid` 为 `lab_uuid`。
|
记住 `data.uuid` 为 `lab_uuid`。
|
||||||
@@ -104,9 +110,33 @@ curl -s -X GET "$BASE/api/v1/edge/lab/info" -H "$AUTH"
|
|||||||
curl -s -X GET "$BASE/api/v1/lab/project/list?lab_uuid=$lab_uuid" -H "$AUTH"
|
curl -s -X GET "$BASE/api/v1/lab/project/list?lab_uuid=$lab_uuid" -H "$AUTH"
|
||||||
```
|
```
|
||||||
|
|
||||||
返回项目列表,展示给用户选择。列出每个项目的 `uuid` 和 `name`。
|
返回:
|
||||||
|
|
||||||
用户**必须**选择一个项目,记住 `project_uuid`,后续创建 notebook 时需要提供。
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"data": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"uuid": "1b3f249a-...",
|
||||||
|
"name": "bt",
|
||||||
|
"description": null,
|
||||||
|
"status": "active",
|
||||||
|
"created_at": "2026-04-09T14:31:28+08:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uuid": "b6366243-...",
|
||||||
|
"name": "default",
|
||||||
|
"description": "默认项目",
|
||||||
|
"status": "active",
|
||||||
|
"created_at": "2026-03-26T11:13:36+08:00"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
展示 `data.items[]` 中每个项目的 `name` 和 `uuid`,让用户选择。用户**必须**选择一个项目,记住 `project_uuid`(即选中项目的 `uuid`),后续创建 notebook 时需要提供。
|
||||||
|
|
||||||
### 3. 列出可用 workflow
|
### 3. 列出可用 workflow
|
||||||
|
|
||||||
@@ -123,6 +153,7 @@ curl -s -X GET "$BASE/api/v1/lab/workflow/template/detail/$workflow_uuid" -H "$A
|
|||||||
```
|
```
|
||||||
|
|
||||||
返回 workflow 的完整结构,包含所有 action 节点信息。需要从响应中提取:
|
返回 workflow 的完整结构,包含所有 action 节点信息。需要从响应中提取:
|
||||||
|
|
||||||
- 每个 action 节点的 `node_uuid`
|
- 每个 action 节点的 `node_uuid`
|
||||||
- 每个节点对应的设备 ID(`resource_template_name`)
|
- 每个节点对应的设备 ID(`resource_template_name`)
|
||||||
- 每个节点的动作名(`node_template_name`)
|
- 每个节点的动作名(`node_template_name`)
|
||||||
@@ -142,30 +173,30 @@ curl -s -X POST "$BASE/api/v1/lab/notebook" \
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"lab_uuid": "<lab_uuid>",
|
"lab_uuid": "<lab_uuid>",
|
||||||
"project_uuid": "<project_uuid>",
|
"project_uuid": "<project_uuid>",
|
||||||
"workflow_uuid": "<workflow_uuid>",
|
"workflow_uuid": "<workflow_uuid>",
|
||||||
"name": "<实验名称>",
|
"name": "<实验名称>",
|
||||||
"node_params": [
|
"node_params": [
|
||||||
|
{
|
||||||
|
"sample_uuids": ["<样品UUID1>", "<样品UUID2>"],
|
||||||
|
"datas": [
|
||||||
{
|
{
|
||||||
"sample_uuids": ["<样品UUID1>", "<样品UUID2>"],
|
"node_uuid": "<workflow中的节点UUID>",
|
||||||
"datas": [
|
"param": {},
|
||||||
{
|
"sample_params": [
|
||||||
"node_uuid": "<workflow中的节点UUID>",
|
{
|
||||||
"param": {},
|
"container_uuid": "<容器UUID>",
|
||||||
"sample_params": [
|
"sample_value": {
|
||||||
{
|
"liquid_names": "<液体名称>",
|
||||||
"container_uuid": "<容器UUID>",
|
"volumes": 1000
|
||||||
"sample_value": {
|
}
|
||||||
"liquid_names": "<液体名称>",
|
}
|
||||||
"volumes": 1000
|
]
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -194,25 +225,25 @@ curl -s -X GET "$BASE/api/v1/lab/notebook/status?uuid=$notebook_uuid" -H "$AUTH"
|
|||||||
|
|
||||||
### 每轮的字段
|
### 每轮的字段
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
|------|------|------|
|
| -------------- | ------------- | ----------------------------------------- |
|
||||||
| `sample_uuids` | array\<uuid\> | 该轮实验的样品 UUID 数组,无样品时传 `[]` |
|
| `sample_uuids` | array\<uuid\> | 该轮实验的样品 UUID 数组,无样品时传 `[]` |
|
||||||
| `datas` | array | 该轮中每个 workflow 节点的参数配置 |
|
| `datas` | array | 该轮中每个 workflow 节点的参数配置 |
|
||||||
|
|
||||||
### datas 中每个节点
|
### datas 中每个节点
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
|------|------|------|
|
| --------------- | ------ | -------------------------------------------- |
|
||||||
| `node_uuid` | string | workflow 模板中的节点 UUID(从 API #4 获取) |
|
| `node_uuid` | string | workflow 模板中的节点 UUID(从 API #4 获取) |
|
||||||
| `param` | object | 动作参数(根据本地注册表 schema 填写) |
|
| `param` | object | 动作参数(根据本地注册表 schema 填写) |
|
||||||
| `sample_params` | array | 样品相关参数(液体名、体积等) |
|
| `sample_params` | array | 样品相关参数(液体名、体积等) |
|
||||||
|
|
||||||
### sample_params 中每条
|
### sample_params 中每条
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
|------|------|------|
|
| ---------------- | ------ | ---------------------------------------------------- |
|
||||||
| `container_uuid` | string | 容器 UUID |
|
| `container_uuid` | string | 容器 UUID |
|
||||||
| `sample_value` | object | 样品值,如 `{"liquid_names": "水", "volumes": 1000}` |
|
| `sample_value` | object | 样品值,如 `{"liquid_names": "水", "volumes": 1000}` |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -233,6 +264,7 @@ python scripts/gen_notebook_params.py \
|
|||||||
> 脚本位于本文档同级目录下的 `scripts/gen_notebook_params.py`。
|
> 脚本位于本文档同级目录下的 `scripts/gen_notebook_params.py`。
|
||||||
|
|
||||||
脚本会:
|
脚本会:
|
||||||
|
|
||||||
1. 调用 workflow detail API 获取所有 action 节点
|
1. 调用 workflow detail API 获取所有 action 节点
|
||||||
2. 读取本地注册表,为每个节点查找对应的 action schema
|
2. 读取本地注册表,为每个节点查找对应的 action schema
|
||||||
3. 生成 `notebook_template.json`,包含:
|
3. 生成 `notebook_template.json`,包含:
|
||||||
@@ -270,8 +302,11 @@ python scripts/gen_notebook_params.py \
|
|||||||
"properties": {
|
"properties": {
|
||||||
"goal": {
|
"goal": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"asp_vols": {"type": "array", "items": {"type": "number"}},
|
"asp_vols": {
|
||||||
"sources": {"type": "array"}
|
"type": "array",
|
||||||
|
"items": { "type": "number" }
|
||||||
|
},
|
||||||
|
"sources": { "type": "array" }
|
||||||
},
|
},
|
||||||
"required": ["asp_vols", "sources"]
|
"required": ["asp_vols", "sources"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
选项:
|
选项:
|
||||||
--auth <token> Lab token(base64(ak:sk) 的结果,不含 "Lab " 前缀)
|
--auth <token> Lab token(base64(ak:sk) 的结果,不含 "Lab " 前缀)
|
||||||
--base <url> API 基础 URL(如 https://uni-lab.test.bohrium.com)
|
--base <url> API 基础 URL(如 https://leap-lab.test.bohrium.com)
|
||||||
--workflow-uuid <uuid> 目标 workflow 的 UUID
|
--workflow-uuid <uuid> 目标 workflow 的 UUID
|
||||||
--registry <path> 本地注册表文件路径(默认自动搜索)
|
--registry <path> 本地注册表文件路径(默认自动搜索)
|
||||||
--rounds <n> 实验轮次数(默认 1)
|
--rounds <n> 实验轮次数(默认 1)
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
示例:
|
示例:
|
||||||
python gen_notebook_params.py \\
|
python gen_notebook_params.py \\
|
||||||
--auth YTFmZDlkNGUtxxxx \\
|
--auth YTFmZDlkNGUtxxxx \\
|
||||||
--base https://uni-lab.test.bohrium.com \\
|
--base https://leap-lab.test.bohrium.com \\
|
||||||
--workflow-uuid abc-123-def \\
|
--workflow-uuid abc-123-def \\
|
||||||
--rounds 2
|
--rounds 2
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ python ./scripts/gen_auth.py --config <config.py>
|
|||||||
|
|
||||||
决定 API 请求发往哪个服务器。从启动命令的 `--addr` 参数获取:
|
决定 API 请求发往哪个服务器。从启动命令的 `--addr` 参数获取:
|
||||||
|
|
||||||
| `--addr` 值 | BASE URL |
|
| `--addr` 值 | BASE URL |
|
||||||
|-------------|----------|
|
| -------------- | ----------------------------------- |
|
||||||
| `test` | `https://uni-lab.test.bohrium.com` |
|
| `test` | `https://leap-lab.test.bohrium.com` |
|
||||||
| `uat` | `https://uni-lab.uat.bohrium.com` |
|
| `uat` | `https://leap-lab.uat.bohrium.com` |
|
||||||
| `local` | `http://127.0.0.1:48197` |
|
| `local` | `http://127.0.0.1:48197` |
|
||||||
| 不传(默认) | `https://uni-lab.bohrium.com` |
|
| 不传(默认) | `https://leap-lab.bohrium.com` |
|
||||||
| 其他自定义 URL | 直接使用该 URL |
|
| 其他自定义 URL | 直接使用该 URL |
|
||||||
|
|
||||||
#### 必备项 ③:req_device_registry_upload.json(设备注册表)
|
#### 必备项 ③:req_device_registry_upload.json(设备注册表)
|
||||||
|
|
||||||
@@ -54,11 +54,11 @@ python ./scripts/gen_auth.py --config <config.py>
|
|||||||
|
|
||||||
**推断 working_dir**(即 `unilabos_data` 所在目录):
|
**推断 working_dir**(即 `unilabos_data` 所在目录):
|
||||||
|
|
||||||
| 条件 | working_dir 取值 |
|
| 条件 | working_dir 取值 |
|
||||||
|------|------------------|
|
| -------------------- | -------------------------------------------------------- |
|
||||||
| 传了 `--working_dir` | `<working_dir>/unilabos_data/`(若子目录已存在则直接用) |
|
| 传了 `--working_dir` | `<working_dir>/unilabos_data/`(若子目录已存在则直接用) |
|
||||||
| 仅传了 `--config` | `<config 文件所在目录>/unilabos_data/` |
|
| 仅传了 `--config` | `<config 文件所在目录>/unilabos_data/` |
|
||||||
| 都没传 | `<当前工作目录>/unilabos_data/` |
|
| 都没传 | `<当前工作目录>/unilabos_data/` |
|
||||||
|
|
||||||
**按优先级搜索文件**:
|
**按优先级搜索文件**:
|
||||||
|
|
||||||
@@ -84,24 +84,6 @@ python ./scripts/gen_auth.py --config <config.py>
|
|||||||
python ./scripts/extract_device_actions.py --registry <找到的文件路径>
|
python ./scripts/extract_device_actions.py --registry <找到的文件路径>
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 完整示例
|
|
||||||
|
|
||||||
用户提供:
|
|
||||||
|
|
||||||
```
|
|
||||||
--ak a1fd9d4e-xxxx-xxxx-xxxx-d9a69c09f0fd
|
|
||||||
--sk 136ff5c6-xxxx-xxxx-xxxx-a03e301f827b
|
|
||||||
--addr test
|
|
||||||
--port 8003
|
|
||||||
--disable_browser
|
|
||||||
```
|
|
||||||
|
|
||||||
从中提取:
|
|
||||||
- ✅ ak/sk → 运行 `gen_auth.py` 得到 `AUTH="Authorization: Lab YTFmZDlk..."`
|
|
||||||
- ✅ addr=test → `BASE=https://uni-lab.test.bohrium.com`
|
|
||||||
- ✅ 搜索 `unilabos_data/req_device_registry_upload.json` → 找到并确认时间
|
|
||||||
- ✅ 用户指明目标设备 → 如 `liquid_handler.prcxi`
|
|
||||||
|
|
||||||
**四项全部就绪后才进入 Step 1。**
|
**四项全部就绪后才进入 Step 1。**
|
||||||
|
|
||||||
### Step 1 — 列出可用设备
|
### Step 1 — 列出可用设备
|
||||||
@@ -129,6 +111,7 @@ python ./scripts/extract_device_actions.py [--registry <path>] <device_id> ./ski
|
|||||||
脚本会显示设备的 Python 源码路径和类名,方便阅读源码了解参数含义。
|
脚本会显示设备的 Python 源码路径和类名,方便阅读源码了解参数含义。
|
||||||
|
|
||||||
每个 action 生成一个 JSON 文件,包含:
|
每个 action 生成一个 JSON 文件,包含:
|
||||||
|
|
||||||
- `type` — 作为 API 调用的 `action_type`
|
- `type` — 作为 API 调用的 `action_type`
|
||||||
- `schema` — 完整 JSON Schema(含 `properties.goal.properties` 参数定义)
|
- `schema` — 完整 JSON Schema(含 `properties.goal.properties` 参数定义)
|
||||||
- `goal` — goal 字段映射(含占位符 `$placeholder`)
|
- `goal` — goal 字段映射(含占位符 `$placeholder`)
|
||||||
@@ -136,13 +119,14 @@ python ./scripts/extract_device_actions.py [--registry <path>] <device_id> ./ski
|
|||||||
|
|
||||||
### Step 3 — 写 action-index.md
|
### Step 3 — 写 action-index.md
|
||||||
|
|
||||||
按模板为每个 action 写条目:
|
按模板为每个 action 写条目(**必须包含 `action_type`**):
|
||||||
|
|
||||||
```markdown
|
```markdown
|
||||||
### `<action_name>`
|
### `<action_name>`
|
||||||
|
|
||||||
<用途描述(一句话)>
|
<用途描述(一句话)>
|
||||||
|
|
||||||
|
- **action_type**: `<从 actions/<name>.json 的 type 字段获取>`
|
||||||
- **Schema**: [`actions/<filename>.json`](actions/<filename>.json)
|
- **Schema**: [`actions/<filename>.json`](actions/<filename>.json)
|
||||||
- **核心参数**: `param1`, `param2`(从 schema.required 获取)
|
- **核心参数**: `param1`, `param2`(从 schema.required 获取)
|
||||||
- **可选参数**: `param3`, `param4`
|
- **可选参数**: `param3`, `param4`
|
||||||
@@ -150,6 +134,8 @@ python ./scripts/extract_device_actions.py [--registry <path>] <device_id> ./ski
|
|||||||
```
|
```
|
||||||
|
|
||||||
描述规则:
|
描述规则:
|
||||||
|
|
||||||
|
- **每个 action 必须标注 `action_type`**(从 JSON 的 `type` 字段读取),这是 API #9 调用时的必填参数,传错会导致任务永远卡住
|
||||||
- 从 `schema.properties` 读参数列表(schema 已提升为 goal 内容)
|
- 从 `schema.properties` 读参数列表(schema 已提升为 goal 内容)
|
||||||
- 从 `schema.required` 区分核心/可选参数
|
- 从 `schema.required` 区分核心/可选参数
|
||||||
- 按功能分类(移液、枪头、外设等)
|
- 按功能分类(移液、枪头、外设等)
|
||||||
@@ -165,6 +151,7 @@ python ./scripts/extract_device_actions.py [--registry <path>] <device_id> ./ski
|
|||||||
### Step 4 — 写 SKILL.md
|
### Step 4 — 写 SKILL.md
|
||||||
|
|
||||||
直接复用 `unilab-device-api` 的 API 模板,修改:
|
直接复用 `unilab-device-api` 的 API 模板,修改:
|
||||||
|
|
||||||
- 设备名称
|
- 设备名称
|
||||||
- Action 数量
|
- Action 数量
|
||||||
- 目录列表
|
- 目录列表
|
||||||
@@ -172,42 +159,77 @@ python ./scripts/extract_device_actions.py [--registry <path>] <device_id> ./ski
|
|||||||
- **AUTH 头** — 使用 Step 0 中 `gen_auth.py` 生成的 `Authorization: Lab <token>`(不要硬编码 `Api` 类型的 key)
|
- **AUTH 头** — 使用 Step 0 中 `gen_auth.py` 生成的 `Authorization: Lab <token>`(不要硬编码 `Api` 类型的 key)
|
||||||
- **Python 源码路径** — 在 SKILL.md 开头注明设备对应的源码文件,方便参考参数含义
|
- **Python 源码路径** — 在 SKILL.md 开头注明设备对应的源码文件,方便参考参数含义
|
||||||
- **Slot 字段表** — 列出本设备哪些 action 的哪些字段需要填入 Slot(物料/设备/节点/类名)
|
- **Slot 字段表** — 列出本设备哪些 action 的哪些字段需要填入 Slot(物料/设备/节点/类名)
|
||||||
|
- **action_type 速查表** — 在 API #9 说明后面紧跟一个表格,列出每个 action 对应的 `action_type` 值(从 JSON `type` 字段提取),方便 agent 快速查找而无需打开 JSON 文件
|
||||||
|
|
||||||
API 模板结构:
|
API 模板结构:
|
||||||
|
|
||||||
```markdown
|
```markdown
|
||||||
## 设备信息
|
## 设备信息
|
||||||
|
|
||||||
- device_id, Python 源码路径, 设备类名
|
- device_id, Python 源码路径, 设备类名
|
||||||
|
|
||||||
## 前置条件(缺一不可)
|
## 前置条件(缺一不可)
|
||||||
|
|
||||||
- ak/sk → AUTH, --addr → BASE URL
|
- ak/sk → AUTH, --addr → BASE URL
|
||||||
|
|
||||||
## 请求约定
|
## 请求约定
|
||||||
|
|
||||||
- Windows 平台必须用 curl.exe(非 PowerShell 的 curl 别名)
|
- Windows 平台必须用 curl.exe(非 PowerShell 的 curl 别名)
|
||||||
|
|
||||||
## Session State
|
## Session State
|
||||||
|
|
||||||
- lab_uuid(通过 GET /edge/lab/info 直接获取,不要问用户), device_name
|
- lab_uuid(通过 GET /edge/lab/info 直接获取,不要问用户), device_name
|
||||||
|
|
||||||
## API Endpoints
|
## API Endpoints
|
||||||
# - #1 GET /edge/lab/info → 直接拿到 lab_uuid
|
|
||||||
# - #2 创建工作流 POST /lab/workflow/owner → 拼 URL 告知用户
|
# - #1 GET /edge/lab/info → 直接拿到 lab_uuid
|
||||||
# - #3 创建节点 POST /edge/workflow/node
|
|
||||||
# body: {workflow_uuid, resource_template_name: "<device_id>", node_template_name: "<action_name>"}
|
# - #2 创建工作流 POST /lab/workflow/owner → 拼 URL 告知用户
|
||||||
# - #4 删除节点 DELETE /lab/workflow/nodes
|
|
||||||
# - #5 更新节点参数 PATCH /lab/workflow/node
|
# - #3 创建节点 POST /edge/workflow/node
|
||||||
# - #6 查询节点 handles POST /lab/workflow/node-handles
|
|
||||||
# body: {node_uuids: ["uuid1","uuid2"]} → 返回各节点的 handle_uuid
|
# body: {workflow_uuid, resource_template_name: "<device_id>", node_template_name: "<action_name>"}
|
||||||
# - #7 批量创建边 POST /lab/workflow/edges
|
|
||||||
# body: {edges: [{source_node_uuid, target_node_uuid, source_handle_uuid, target_handle_uuid}]}
|
# - #4 删除节点 DELETE /lab/workflow/nodes
|
||||||
# - #8 启动工作流 POST /lab/workflow/{uuid}/run
|
|
||||||
# - #9 运行设备单动作 POST /lab/mcp/run/action
|
# - #5 更新节点参数 PATCH /lab/workflow/node
|
||||||
|
|
||||||
|
# - #6 查询节点 handles POST /lab/workflow/node-handles
|
||||||
|
|
||||||
|
# body: {node_uuids: ["uuid1","uuid2"]} → 返回各节点的 handle_uuid
|
||||||
|
|
||||||
|
# - #7 批量创建边 POST /lab/workflow/edges
|
||||||
|
|
||||||
|
# body: {edges: [{source_node_uuid, target_node_uuid, source_handle_uuid, target_handle_uuid}]}
|
||||||
|
|
||||||
|
# - #8 启动工作流 POST /lab/workflow/{uuid}/run
|
||||||
|
|
||||||
|
# - #9 运行设备单动作 POST /lab/mcp/run/action(⚠️ action_type 必须从 action-index.md 或 actions/<name>.json 的 type 字段获取,传错会导致任务永远卡住)
|
||||||
|
|
||||||
# - #10 查询任务状态 GET /lab/mcp/task/{task_uuid}
|
# - #10 查询任务状态 GET /lab/mcp/task/{task_uuid}
|
||||||
|
|
||||||
# - #11 运行工作流单节点 POST /lab/mcp/run/workflow/action
|
# - #11 运行工作流单节点 POST /lab/mcp/run/workflow/action
|
||||||
|
|
||||||
# - #12 获取资源树 GET /lab/material/download/{lab_uuid}
|
# - #12 获取资源树 GET /lab/material/download/{lab_uuid}
|
||||||
|
|
||||||
# - #13 获取工作流模板详情 GET /lab/workflow/template/detail/{workflow_uuid}
|
# - #13 获取工作流模板详情 GET /lab/workflow/template/detail/{workflow_uuid}
|
||||||
# 返回 workflow 完整结构:data.nodes[] 含每个节点的 uuid、name、param、device_name、handles
|
|
||||||
|
# 返回 workflow 完整结构:data.nodes[] 含每个节点的 uuid、name、param、device_name、handles
|
||||||
|
|
||||||
|
# - #14 按名称查询物料模板 GET /lab/material/template/by-name?lab_uuid=&name=
|
||||||
|
|
||||||
|
# 返回 res_template_uuid,用于 #15 创建物料时的必填字段
|
||||||
|
|
||||||
|
# - #15 创建物料节点 POST /edge/material/node
|
||||||
|
|
||||||
|
# body: {res_template_uuid(从#14获取), name(自定义), display_name, parent_uuid?(从#12获取), ...}
|
||||||
|
|
||||||
|
# - #16 更新物料节点 PUT /edge/material/node
|
||||||
|
|
||||||
|
# body: {uuid(从#12获取), display_name?, description?, init_param_data?, data?, ...}
|
||||||
|
|
||||||
## Placeholder Slot 填写规则
|
## Placeholder Slot 填写规则
|
||||||
|
|
||||||
- unilabos_resources → ResourceSlot → {"id":"/path/name","name":"name","uuid":"xxx"}
|
- unilabos_resources → ResourceSlot → {"id":"/path/name","name":"name","uuid":"xxx"}
|
||||||
- unilabos_devices → DeviceSlot → "/parent/device" 路径字符串
|
- unilabos_devices → DeviceSlot → "/parent/device" 路径字符串
|
||||||
- unilabos_nodes → NodeSlot → "/parent/node" 路径字符串
|
- unilabos_nodes → NodeSlot → "/parent/node" 路径字符串
|
||||||
@@ -217,13 +239,15 @@ API 模板结构:
|
|||||||
- 列出本设备所有 Slot 字段、类型及含义
|
- 列出本设备所有 Slot 字段、类型及含义
|
||||||
|
|
||||||
## 渐进加载策略
|
## 渐进加载策略
|
||||||
|
|
||||||
## 完整工作流 Checklist
|
## 完整工作流 Checklist
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 5 — 验证
|
### Step 5 — 验证
|
||||||
|
|
||||||
检查文件完整性:
|
检查文件完整性:
|
||||||
- [ ] `SKILL.md` 包含 API endpoint(#1 获取 lab_uuid、#2-#7 工作流/节点/边、#8-#11 运行/查询、#12 资源树、#13 工作流模板详情)
|
|
||||||
|
- [ ] `SKILL.md` 包含 API endpoint(#1 获取 lab_uuid、#2-#7 工作流/节点/边、#8-#11 运行/查询、#12 资源树、#13 工作流模板详情、#14-#16 物料管理)
|
||||||
- [ ] `SKILL.md` 包含 Placeholder Slot 填写规则(ResourceSlot / DeviceSlot / NodeSlot / ClassSlot / FormulationSlot + create_resource 特例)和本设备的 Slot 字段表
|
- [ ] `SKILL.md` 包含 Placeholder Slot 填写规则(ResourceSlot / DeviceSlot / NodeSlot / ClassSlot / FormulationSlot + create_resource 特例)和本设备的 Slot 字段表
|
||||||
- [ ] `action-index.md` 列出所有 action 并有描述
|
- [ ] `action-index.md` 列出所有 action 并有描述
|
||||||
- [ ] `actions/` 目录中每个 action 有对应 JSON 文件
|
- [ ] `actions/` 目录中每个 action 有对应 JSON 文件
|
||||||
@@ -272,92 +296,48 @@ API 模板结构:
|
|||||||
|
|
||||||
`placeholder_keys` / `_unilabos_placeholder_info` 中有 5 种值,对应不同的填写方式:
|
`placeholder_keys` / `_unilabos_placeholder_info` 中有 5 种值,对应不同的填写方式:
|
||||||
|
|
||||||
| placeholder 值 | Slot 类型 | 填写格式 | 选取范围 |
|
| placeholder 值 | Slot 类型 | 填写格式 | 选取范围 |
|
||||||
|---------------|-----------|---------|---------|
|
| ---------------------- | --------------- | ----------------------------------------------------- | ----------------------------------------- |
|
||||||
| `unilabos_resources` | ResourceSlot | `{"id": "/path/name", "name": "name", "uuid": "xxx"}` | 仅**物料**节点(不含设备) |
|
| `unilabos_resources` | ResourceSlot | `{"id": "/path/name", "name": "name", "uuid": "xxx"}` | 仅**物料**节点(不含设备) |
|
||||||
| `unilabos_devices` | DeviceSlot | `"/parent/device_name"` | 仅**设备**节点(type=device),路径字符串 |
|
| `unilabos_devices` | DeviceSlot | `"/parent/device_name"` | 仅**设备**节点(type=device),路径字符串 |
|
||||||
| `unilabos_nodes` | NodeSlot | `"/parent/node_name"` | **设备 + 物料**,即所有节点,路径字符串 |
|
| `unilabos_nodes` | NodeSlot | `"/parent/node_name"` | **设备 + 物料**,即所有节点,路径字符串 |
|
||||||
| `unilabos_class` | ClassSlot | `"class_name"` | 注册表中已上报的资源类 name |
|
| `unilabos_class` | ClassSlot | `"class_name"` | 注册表中已上报的资源类 name |
|
||||||
| `unilabos_formulation` | FormulationSlot | `[{well_name, liquids: [{name, volume}]}]` | 资源树中物料节点的 **name**,配合液体配方 |
|
| `unilabos_formulation` | FormulationSlot | `[{well_name, liquids: [{name, volume}]}]` | 资源树中物料节点的 **name**,配合液体配方 |
|
||||||
|
|
||||||
### ResourceSlot(`unilabos_resources`)
|
### ResourceSlot(`unilabos_resources`)
|
||||||
|
|
||||||
最常见的类型。从资源树中选取**物料**节点(孔板、枪头盒、试剂槽等):
|
最常见的类型。从资源树中选取**物料**节点(孔板、枪头盒、试剂槽等):
|
||||||
|
|
||||||
```json
|
- 单个:`{"id": "/workstation/container1", "name": "container1", "uuid": "ff149a9a-..."}`
|
||||||
{"id": "/workstation/container1", "name": "container1", "uuid": "ff149a9a-2cb8-419d-8db5-d3ba056fb3c2"}
|
- 数组:`[{"id": "/path/a", "name": "a", "uuid": "xxx"}, ...]`
|
||||||
```
|
- `id` 从 parent 计算的路径格式,根据 action 语义选择正确的物料
|
||||||
|
|
||||||
- 单个(schema type=object):`{"id": "/path/name", "name": "name", "uuid": "xxx"}`
|
> **特例**:`create_resource` 的 `res_id`,目标物料可能尚不存在,直接填期望路径,不需要 uuid。
|
||||||
- 数组(schema type=array):`[{"id": "/path/a", "name": "a", "uuid": "xxx"}, ...]`
|
|
||||||
- `id` 本身是从 parent 计算的路径格式
|
|
||||||
- 根据 action 语义选择正确的物料(如 `sources` = 液体来源,`targets` = 目标位置)
|
|
||||||
|
|
||||||
> **特例**:`create_resource` 的 `res_id` 字段,目标物料可能**尚不存在**,此时直接填写期望的路径(如 `"/workstation/container1"`),不需要 uuid。
|
### DeviceSlot / NodeSlot / ClassSlot
|
||||||
|
|
||||||
### DeviceSlot(`unilabos_devices`)
|
- **DeviceSlot**(`unilabos_devices`):路径字符串如 `"/host_node"`,仅 type=device 的节点
|
||||||
|
- **NodeSlot**(`unilabos_nodes`):路径字符串如 `"/PRCXI/PRCXI_Deck"`,设备 + 物料均可选
|
||||||
填写**设备路径字符串**。从资源树中筛选 type=device 的节点,从 parent 计算路径:
|
- **ClassSlot**(`unilabos_class`):类名字符串如 `"container"`,从 `req_resource_registry_upload.json` 查找
|
||||||
|
|
||||||
```
|
|
||||||
"/host_node"
|
|
||||||
"/bioyond_cell/reaction_station"
|
|
||||||
```
|
|
||||||
|
|
||||||
- 只填路径字符串,不需要 `{id, uuid}` 对象
|
|
||||||
- 根据 action 语义选择正确的设备(如 `target_device_id` = 目标设备)
|
|
||||||
|
|
||||||
### NodeSlot(`unilabos_nodes`)
|
|
||||||
|
|
||||||
范围 = 设备 + 物料。即资源树中**所有节点**都可以选,填写**路径字符串**:
|
|
||||||
|
|
||||||
```
|
|
||||||
"/PRCXI/PRCXI_Deck"
|
|
||||||
```
|
|
||||||
|
|
||||||
- 使用场景:当参数既可能指向物料也可能指向设备时(如 `PumpTransferProtocol` 的 `from_vessel`/`to_vessel`,`create_resource` 的 `parent`)
|
|
||||||
|
|
||||||
### ClassSlot(`unilabos_class`)
|
|
||||||
|
|
||||||
填写注册表中已上报的**资源类 name**。从本地 `req_resource_registry_upload.json` 中查找:
|
|
||||||
|
|
||||||
```
|
|
||||||
"container"
|
|
||||||
```
|
|
||||||
|
|
||||||
### FormulationSlot(`unilabos_formulation`)
|
### FormulationSlot(`unilabos_formulation`)
|
||||||
|
|
||||||
描述**液体配方**:向哪些物料容器中加入哪些液体及体积。填写为**对象数组**:
|
描述**液体配方**:向哪些容器中加入哪些液体及体积。
|
||||||
|
|
||||||
```json
|
```json
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"sample_uuid": "",
|
"sample_uuid": "",
|
||||||
"well_name": "YB_PrepBottle_15mL_Carrier_bottle_A1",
|
"well_name": "bottle_A1",
|
||||||
"liquids": [
|
"liquids": [{ "name": "LiPF6", "volume": 0.6 }]
|
||||||
{ "name": "LiPF6", "volume": 0.6 },
|
|
||||||
{ "name": "DMC", "volume": 1.2 }
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 字段说明
|
- `well_name` — 目标物料的 **name**(从资源树取,不是 `id` 路径)
|
||||||
|
- `liquids[]` — 液体列表,每条含 `name`(试剂名)和 `volume`(体积,单位由上下文决定;pylabrobot 内部统一 uL)
|
||||||
| 字段 | 类型 | 说明 |
|
- `sample_uuid` — 样品 UUID,无样品传 `""`
|
||||||
|------|------|------|
|
- 与 ResourceSlot 的区别:ResourceSlot 指向物料本身,FormulationSlot 引用物料名并附带配方信息
|
||||||
| `sample_uuid` | string | 样品 UUID,无样品时传空字符串 `""` |
|
|
||||||
| `well_name` | string | 目标物料容器的 **name**(从资源树中取物料节点的 `name` 字段,如瓶子、孔位名称) |
|
|
||||||
| `liquids` | array | 要加入的液体列表 |
|
|
||||||
| `liquids[].name` | string | 液体名称(如试剂名、溶剂名) |
|
|
||||||
| `liquids[].volume` | number | 液体体积(单位由设备决定,通常为 mL) |
|
|
||||||
|
|
||||||
#### 填写规则
|
|
||||||
|
|
||||||
- `well_name` 必须是资源树中已存在的物料节点 `name`(不是 `id` 路径),通过 API #12 获取资源树后筛选
|
|
||||||
- 每个数组元素代表一个目标容器的配方
|
|
||||||
- 一个容器可以加入多种液体(`liquids` 数组多条记录)
|
|
||||||
- 与 ResourceSlot 的区别:ResourceSlot 填 `{id, name, uuid}` 指向物料本身;FormulationSlot 用 `well_name` 引用物料,并附带液体配方信息
|
|
||||||
|
|
||||||
### 通过 API #12 获取资源树
|
### 通过 API #12 获取资源树
|
||||||
|
|
||||||
@@ -365,7 +345,147 @@ API 模板结构:
|
|||||||
curl -s -X GET "$BASE/api/v1/lab/material/download/$lab_uuid" -H "$AUTH"
|
curl -s -X GET "$BASE/api/v1/lab/material/download/$lab_uuid" -H "$AUTH"
|
||||||
```
|
```
|
||||||
|
|
||||||
注意 `lab_uuid` 在路径中(不是查询参数)。资源树返回所有节点,每个节点包含 `id`(路径格式)、`name`、`uuid`、`type`、`parent` 等字段。填写 Slot 时需根据 placeholder 类型筛选正确的节点。
|
注意 `lab_uuid` 在路径中(不是查询参数)。返回结构:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 0,
|
||||||
|
"data": {
|
||||||
|
"nodes": [
|
||||||
|
{"name": "host_node", "uuid": "c3ec1e68-...", "type": "device", "parent": ""},
|
||||||
|
{"name": "PRCXI", "uuid": "e249c9a6-...", "type": "device", "parent": ""},
|
||||||
|
{"name": "PRCXI_Deck", "uuid": "fb6a8b71-...", "type": "deck", "parent": "PRCXI"}
|
||||||
|
],
|
||||||
|
"edges": [...]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- `data.nodes[]` — 所有节点(设备 + 物料),每个节点含 `name`、`uuid`、`type`、`parent`
|
||||||
|
- `type` 区分设备(`device`)和物料(`deck`、`container`、`resource` 等)
|
||||||
|
- `parent` 为父节点名称(空字符串表示顶级)
|
||||||
|
- 填写 Slot 时根据 placeholder 类型筛选:ResourceSlot 取非 device 节点,DeviceSlot 取 device 节点
|
||||||
|
- 创建/更新物料时:`parent_uuid` 取父节点的 `uuid`,更新目标的 `uuid` 取节点自身的 `uuid`
|
||||||
|
|
||||||
|
## 物料管理 API
|
||||||
|
|
||||||
|
设备 Skill 除了设备动作外,还需支持物料节点的创建和参数设定,用于在资源树中动态管理物料。
|
||||||
|
|
||||||
|
典型流程:先通过 **#14 按名称查询模板** 获取 `res_template_uuid` → 再通过 **#15 创建物料** → 之后可通过 **#16 更新物料** 修改属性。更新时需要的 `uuid` 和 `parent_uuid` 均从 **#12 资源树下载** 获取。
|
||||||
|
|
||||||
|
### API #14 — 按名称查询物料模板
|
||||||
|
|
||||||
|
创建物料前,需要先获取物料模板的 UUID。通过模板名称查询:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/material/template/by-name?lab_uuid=$lab_uuid&name=<template_name>" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
| 参数 | 必填 | 说明 |
|
||||||
|
| ---------- | ------ | -------------------------------- |
|
||||||
|
| `lab_uuid` | **是** | 实验室 UUID(从 API #1 获取) |
|
||||||
|
| `name` | **是** | 物料模板名称(如 `"container"`) |
|
||||||
|
|
||||||
|
返回 `code: 0` 时,**`data.uuid`** 即为 `res_template_uuid`,用于 API #15 创建物料。返回还包含 `name`、`resource_type`、`handles`、`config_infos` 等模板元信息。
|
||||||
|
|
||||||
|
模板不存在时返回 `code: 10002`,`data` 为空对象。模板名称来自资源注册表中已注册的资源类型。
|
||||||
|
|
||||||
|
### API #15 — 创建物料节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/edge/material/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '<request_body>'
|
||||||
|
```
|
||||||
|
|
||||||
|
请求体:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"res_template_uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
||||||
|
"name": "my_custom_bottle",
|
||||||
|
"display_name": "自定义瓶子",
|
||||||
|
"parent_uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
||||||
|
"type": "",
|
||||||
|
"init_param_data": {},
|
||||||
|
"schema": {},
|
||||||
|
"data": {
|
||||||
|
"liquids": [["water", 1000, "uL"]],
|
||||||
|
"max_volume": 50000
|
||||||
|
},
|
||||||
|
"plate_well_datas": {},
|
||||||
|
"plate_reagent_datas": {},
|
||||||
|
"pose": {},
|
||||||
|
"model": {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
| 字段 | 必填 | 类型 | 数据来源 | 说明 |
|
||||||
|
| --------------------- | ------ | ------------- | ----------------------------------- | -------------------------------------- |
|
||||||
|
| `res_template_uuid` | **是** | string (UUID) | **API #14** 按名称查询获取 | 物料模板 UUID |
|
||||||
|
| `name` | 否 | string | **用户自定义** | 节点名称(标识符),可自由命名 |
|
||||||
|
| `display_name` | 否 | string | 用户自定义 | 显示名称(UI 展示用) |
|
||||||
|
| `parent_uuid` | 否 | string (UUID) | **API #12** 资源树中父节点的 `uuid` | 父节点,为空则创建顶级节点 |
|
||||||
|
| `type` | 否 | string | 从模板继承 | 节点类型 |
|
||||||
|
| `init_param_data` | 否 | object | 用户指定 | 初始化参数,覆盖模板默认值 |
|
||||||
|
| `data` | 否 | object | 用户指定 | 节点数据,container 见下方 data 格式 |
|
||||||
|
| `plate_well_datas` | 否 | object | 用户指定 | 孔板子节点数据(创建带孔位的板时使用) |
|
||||||
|
| `plate_reagent_datas` | 否 | object | 用户指定 | 试剂关联数据 |
|
||||||
|
| `schema` | 否 | object | 从模板继承 | 自定义 schema,不传则从模板继承 |
|
||||||
|
| `pose` | 否 | object | 用户指定 | 位姿信息 |
|
||||||
|
| `model` | 否 | object | 用户指定 | 3D 模型信息 |
|
||||||
|
|
||||||
|
#### container 的 `data` 格式
|
||||||
|
|
||||||
|
> **体积单位统一为 uL(微升)**。pylabrobot 体系中所有体积值(`max_volume`、`liquids` 中的 volume)均为 uL。外部如果是 mL 需乘 1000 转换。
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"liquids": [["water", 1000, "uL"], ["ethanol", 500, "uL"]],
|
||||||
|
"max_volume": 50000
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- `liquids` — 液体列表,每条为 `[液体名称, 体积(uL), 单位字符串]`
|
||||||
|
- `max_volume` — 容器最大容量(uL),如 50 mL = 50000 uL
|
||||||
|
|
||||||
|
### API #16 — 更新物料节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X PUT "$BASE/api/v1/edge/material/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '<request_body>'
|
||||||
|
```
|
||||||
|
|
||||||
|
请求体:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
||||||
|
"parent_uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
|
||||||
|
"display_name": "新显示名称",
|
||||||
|
"description": "新描述",
|
||||||
|
"init_param_data": {},
|
||||||
|
"data": {},
|
||||||
|
"pose": {},
|
||||||
|
"schema": {},
|
||||||
|
"extra": {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
| 字段 | 必填 | 类型 | 数据来源 | 说明 |
|
||||||
|
| ----------------- | ------ | ------------- | ------------------------------------- | ---------------- |
|
||||||
|
| `uuid` | **是** | string (UUID) | **API #12** 资源树中目标节点的 `uuid` | 要更新的物料节点 |
|
||||||
|
| `parent_uuid` | 否 | string (UUID) | API #12 资源树 | 移动到新父节点 |
|
||||||
|
| `display_name` | 否 | string | 用户指定 | 更新显示名称 |
|
||||||
|
| `description` | 否 | string | 用户指定 | 更新描述 |
|
||||||
|
| `init_param_data` | 否 | object | 用户指定 | 更新初始化参数 |
|
||||||
|
| `data` | 否 | object | 用户指定 | 更新节点数据 |
|
||||||
|
| `pose` | 否 | object | 用户指定 | 更新位姿 |
|
||||||
|
| `schema` | 否 | object | 用户指定 | 更新 schema |
|
||||||
|
| `extra` | 否 | object | 用户指定 | 更新扩展数据 |
|
||||||
|
|
||||||
|
> 只传需要更新的字段,未传的字段保持不变。
|
||||||
|
|
||||||
## 最终目录结构
|
## 最终目录结构
|
||||||
|
|
||||||
|
|||||||
251
.cursor/skills/host-node/SKILL.md
Normal file
251
.cursor/skills/host-node/SKILL.md
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
---
|
||||||
|
name: host-node
|
||||||
|
description: Operate Uni-Lab host node via REST API — create resources, test latency, test resource tree, manual confirm. Use when the user mentions host_node, creating resources, resource management, testing latency, or any host node operation.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Host Node API Skill
|
||||||
|
|
||||||
|
## 设备信息
|
||||||
|
|
||||||
|
- **device_id**: `host_node`
|
||||||
|
- **Python 源码**: `unilabos/ros/nodes/presets/host_node.py`
|
||||||
|
- **设备类**: `HostNode`
|
||||||
|
- **动作数**: 4(`create_resource`, `test_latency`, `auto-test_resource`, `manual_confirm`)
|
||||||
|
|
||||||
|
## 前置条件(缺一不可)
|
||||||
|
|
||||||
|
使用本 skill 前,**必须**先确认以下信息。如果缺少任何一项,**立即向用户询问并终止**,等补齐后再继续。
|
||||||
|
|
||||||
|
### 1. ak / sk → AUTH
|
||||||
|
|
||||||
|
从启动参数 `--ak` `--sk` 或 config.py 中获取,生成 token:`base64(ak:sk)` → `Authorization: Lab <token>`
|
||||||
|
|
||||||
|
### 2. --addr → BASE URL
|
||||||
|
|
||||||
|
| `--addr` 值 | BASE |
|
||||||
|
| ------------ | ----------------------------------- |
|
||||||
|
| `test` | `https://leap-lab.test.bohrium.com` |
|
||||||
|
| `uat` | `https://leap-lab.uat.bohrium.com` |
|
||||||
|
| `local` | `http://127.0.0.1:48197` |
|
||||||
|
| 不传(默认) | `https://leap-lab.bohrium.com` |
|
||||||
|
|
||||||
|
确认后设置:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
BASE="<根据 addr 确定的 URL>"
|
||||||
|
AUTH="Authorization: Lab <token>"
|
||||||
|
```
|
||||||
|
|
||||||
|
**两项全部就绪后才可发起 API 请求。**
|
||||||
|
|
||||||
|
## Session State
|
||||||
|
|
||||||
|
在整个对话过程中,agent 需要记住以下状态,避免重复询问用户:
|
||||||
|
|
||||||
|
- `lab_uuid` — 实验室 UUID(首次通过 API #1 自动获取,**不需要问用户**)
|
||||||
|
- `device_name` — `host_node`
|
||||||
|
|
||||||
|
## 请求约定
|
||||||
|
|
||||||
|
所有请求使用 `curl -s`,POST/PATCH/DELETE 需加 `Content-Type: application/json`。
|
||||||
|
|
||||||
|
> **Windows 平台**必须使用 `curl.exe`(而非 PowerShell 的 `curl` 别名)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## API Endpoints
|
||||||
|
|
||||||
|
### 1. 获取实验室信息(自动获取 lab_uuid)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/edge/lab/info" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `lab_uuid`,`data.name` 为 `lab_name`。
|
||||||
|
|
||||||
|
### 2. 创建工作流
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/owner" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"name":"<名称>","lab_uuid":"<lab_uuid>","description":"<描述>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `workflow_uuid`。创建成功后告知用户链接:`$BASE/laboratory/$lab_uuid/workflow/$workflow_uuid`
|
||||||
|
|
||||||
|
### 3. 创建节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/edge/workflow/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"workflow_uuid":"<workflow_uuid>","resource_template_name":"host_node","node_template_name":"<action_name>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
- `resource_template_name` 固定为 `host_node`
|
||||||
|
- `node_template_name` — action 名称(如 `create_resource`, `test_latency`)
|
||||||
|
|
||||||
|
### 4. 删除节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X DELETE "$BASE/api/v1/lab/workflow/nodes" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuids":["<uuid1>"],"workflow_uuid":"<workflow_uuid>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. 更新节点参数
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X PATCH "$BASE/api/v1/lab/workflow/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"workflow_uuid":"<wf_uuid>","uuid":"<node_uuid>","param":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
`param` 直接使用创建节点返回的 `data.param` 结构,修改需要填入的字段值。参考 [action-index.md](action-index.md) 确定哪些字段是 Slot。
|
||||||
|
|
||||||
|
### 6. 查询节点 handles
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/node-handles" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuids":["<node_uuid_1>","<node_uuid_2>"]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7. 批量创建边
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/edges" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"edges":[{"source_node_uuid":"<uuid>","target_node_uuid":"<uuid>","source_handle_uuid":"<uuid>","target_handle_uuid":"<uuid>"}]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8. 启动工作流
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/<workflow_uuid>/run" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 9. 运行设备单动作
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/mcp/run/action" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"lab_uuid":"<lab_uuid>","device_id":"host_node","action":"<action_name>","action_type":"<type>","param":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
`param` 直接放 goal 里的属性,**不要**再包一层 `{"goal": {...}}`。
|
||||||
|
|
||||||
|
> **WARNING: `action_type` 必须正确,传错会导致任务永远卡住无法完成。** 从下表或 `actions/<name>.json` 的 `type` 字段获取。
|
||||||
|
|
||||||
|
#### action_type 速查表
|
||||||
|
|
||||||
|
| action | action_type |
|
||||||
|
|--------|-------------|
|
||||||
|
| `test_latency` | `UniLabJsonCommand` |
|
||||||
|
| `create_resource` | `ResourceCreateFromOuterEasy` |
|
||||||
|
| `auto-test_resource` | `UniLabJsonCommand` |
|
||||||
|
| `manual_confirm` | `UniLabJsonCommand` |
|
||||||
|
|
||||||
|
### 10. 查询任务状态
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/mcp/task/<task_uuid>" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 11. 运行工作流单节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/mcp/run/workflow/action" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuid":"<node_uuid>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 12. 获取资源树(物料信息)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/material/download/$lab_uuid" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
注意 `lab_uuid` 在路径中。返回 `data.nodes[]` 含所有节点(设备 + 物料),每个节点含 `name`、`uuid`、`type`、`parent`。
|
||||||
|
|
||||||
|
### 13. 获取工作流模板详情
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/workflow/template/detail/$workflow_uuid" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
> 必须使用 `/lab/workflow/template/detail/{uuid}`,其他路径会返回 404。
|
||||||
|
|
||||||
|
### 14. 按名称查询物料模板
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/material/template/by-name?lab_uuid=$lab_uuid&name=<template_name>" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `res_template_uuid`,用于 API #15。
|
||||||
|
|
||||||
|
### 15. 创建物料节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/edge/material/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"res_template_uuid":"<uuid>","name":"<名称>","display_name":"<显示名>","parent_uuid":"<父节点uuid>","data":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 16. 更新物料节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X PUT "$BASE/api/v1/edge/material/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"uuid":"<节点uuid>","display_name":"<新名称>","data":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Placeholder Slot 填写规则
|
||||||
|
|
||||||
|
| `placeholder_keys` 值 | Slot 类型 | 填写格式 | 选取范围 |
|
||||||
|
| --------------------- | ------------ | ----------------------------------------------------- | ---------------------- |
|
||||||
|
| `unilabos_resources` | ResourceSlot | `{"id": "/path/name", "name": "name", "uuid": "xxx"}` | 仅物料节点(非设备) |
|
||||||
|
| `unilabos_devices` | DeviceSlot | `"/parent/device_name"` | 仅设备节点(type=device) |
|
||||||
|
| `unilabos_nodes` | NodeSlot | `"/parent/node_name"` | 所有节点(设备 + 物料) |
|
||||||
|
| `unilabos_class` | ClassSlot | `"class_name"` | 注册表中已注册的资源类 |
|
||||||
|
|
||||||
|
### host_node 设备的 Slot 字段表
|
||||||
|
|
||||||
|
| Action | 字段 | Slot 类型 | 说明 |
|
||||||
|
| ----------------- | ----------- | ------------ | ------------------------------ |
|
||||||
|
| `create_resource` | `res_id` | ResourceSlot | 新资源路径(可填不存在的路径) |
|
||||||
|
| `create_resource` | `device_id` | DeviceSlot | 归属设备 |
|
||||||
|
| `create_resource` | `parent` | NodeSlot | 父节点路径 |
|
||||||
|
| `create_resource` | `class_name`| ClassSlot | 资源类名如 `"container"` |
|
||||||
|
| `auto-test_resource` | `resource` | ResourceSlot | 单个测试物料 |
|
||||||
|
| `auto-test_resource` | `resources` | ResourceSlot | 测试物料数组 |
|
||||||
|
| `auto-test_resource` | `device` | DeviceSlot | 测试设备 |
|
||||||
|
| `auto-test_resource` | `devices` | DeviceSlot | 测试设备 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 渐进加载策略
|
||||||
|
|
||||||
|
1. **SKILL.md**(本文件)— API 端点 + session state 管理
|
||||||
|
2. **[action-index.md](action-index.md)** — 按分类浏览 4 个动作的描述和核心参数
|
||||||
|
3. **[actions/\<name\>.json](actions/)** — 仅在需要构建具体请求时,加载对应 action 的完整 JSON Schema
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 完整工作流 Checklist
|
||||||
|
|
||||||
|
```
|
||||||
|
Task Progress:
|
||||||
|
- [ ] Step 1: GET /edge/lab/info 获取 lab_uuid
|
||||||
|
- [ ] Step 2: 获取资源树 (GET #12) → 记住可用物料
|
||||||
|
- [ ] Step 3: 读 action-index.md 确定要用的 action 名
|
||||||
|
- [ ] Step 4: 创建工作流 (POST #2) → 记住 workflow_uuid,告知用户链接
|
||||||
|
- [ ] Step 5: 创建节点 (POST #3, resource_template_name=host_node) → 记住 node_uuid + data.param
|
||||||
|
- [ ] Step 6: 根据 _unilabos_placeholder_info 和资源树,填写 data.param 中的 Slot 字段
|
||||||
|
- [ ] Step 7: 更新节点参数 (PATCH #5)
|
||||||
|
- [ ] Step 8: 查询节点 handles (POST #6) → 获取各节点的 handle_uuid
|
||||||
|
- [ ] Step 9: 批量创建边 (POST #7) → 用 handle_uuid 连接节点
|
||||||
|
- [ ] Step 10: 启动工作流 (POST #8) 或运行单节点 (POST #11)
|
||||||
|
- [ ] Step 11: 查询任务状态 (GET #10) 确认完成
|
||||||
|
```
|
||||||
58
.cursor/skills/host-node/action-index.md
Normal file
58
.cursor/skills/host-node/action-index.md
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# Action Index — host_node
|
||||||
|
|
||||||
|
4 个动作,按功能分类。每个动作的完整 JSON Schema 在 `actions/<name>.json`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 资源管理
|
||||||
|
|
||||||
|
### `create_resource`
|
||||||
|
|
||||||
|
在资源树中创建新资源(容器、物料等),支持指定位置、类型和初始液体
|
||||||
|
|
||||||
|
- **action_type**: `ResourceCreateFromOuterEasy`
|
||||||
|
- **Schema**: [`actions/create_resource.json`](actions/create_resource.json)
|
||||||
|
- **可选参数**: `res_id`, `device_id`, `class_name`, `parent`, `bind_locations`, `liquid_input_slot`, `liquid_type`, `liquid_volume`, `slot_on_deck`
|
||||||
|
- **占位符字段**:
|
||||||
|
- `res_id` — **ResourceSlot**(特例:目标物料可能尚不存在,直接填期望路径)
|
||||||
|
- `device_id` — **DeviceSlot**,填路径字符串如 `"/host_node"`
|
||||||
|
- `parent` — **NodeSlot**,填路径字符串如 `"/workstation/deck"`
|
||||||
|
- `class_name` — **ClassSlot**,填类名如 `"container"`
|
||||||
|
|
||||||
|
### `auto-test_resource`
|
||||||
|
|
||||||
|
测试资源系统,返回当前资源树和设备列表
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/test_resource.json`](actions/test_resource.json)
|
||||||
|
- **可选参数**: `resource`, `resources`, `device`, `devices`
|
||||||
|
- **占位符字段**:
|
||||||
|
- `resource` — **ResourceSlot**,单个物料节点 `{id, name, uuid}`
|
||||||
|
- `resources` — **ResourceSlot**,物料节点数组 `[{id, name, uuid}, ...]`
|
||||||
|
- `device` — **DeviceSlot**,设备路径字符串
|
||||||
|
- `devices` — **DeviceSlot**,设备路径字符串
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 系统工具
|
||||||
|
|
||||||
|
### `test_latency`
|
||||||
|
|
||||||
|
测试设备通信延迟,返回 RTT、时间差、任务延迟等指标
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/test_latency.json`](actions/test_latency.json)
|
||||||
|
- **参数**: 无(零参数调用)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 人工确认
|
||||||
|
|
||||||
|
### `manual_confirm`
|
||||||
|
|
||||||
|
创建人工确认节点,等待用户手动确认后继续
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/manual_confirm.json`](actions/manual_confirm.json)
|
||||||
|
- **核心参数**: `timeout_seconds`(超时时间,秒), `assignee_user_ids`(指派用户 ID 列表)
|
||||||
|
- **占位符字段**: `assignee_user_ids` — `unilabos_manual_confirm` 类型
|
||||||
93
.cursor/skills/host-node/actions/create_resource.json
Normal file
93
.cursor/skills/host-node/actions/create_resource.json
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
{
|
||||||
|
"type": "ResourceCreateFromOuterEasy",
|
||||||
|
"goal": {
|
||||||
|
"res_id": "res_id",
|
||||||
|
"class_name": "class_name",
|
||||||
|
"parent": "parent",
|
||||||
|
"device_id": "device_id",
|
||||||
|
"bind_locations": "bind_locations",
|
||||||
|
"liquid_input_slot": "liquid_input_slot[]",
|
||||||
|
"liquid_type": "liquid_type[]",
|
||||||
|
"liquid_volume": "liquid_volume[]",
|
||||||
|
"slot_on_deck": "slot_on_deck"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"res_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"device_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"class_name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"bind_locations": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "bind_locations",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"liquid_input_slot": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"liquid_type": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"liquid_volume": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"slot_on_deck": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [],
|
||||||
|
"_unilabos_placeholder_info": {
|
||||||
|
"res_id": "unilabos_resources",
|
||||||
|
"device_id": "unilabos_devices",
|
||||||
|
"parent": "unilabos_nodes",
|
||||||
|
"class_name": "unilabos_class"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {
|
||||||
|
"res_id": "unilabos_resources",
|
||||||
|
"device_id": "unilabos_devices",
|
||||||
|
"parent": "unilabos_nodes",
|
||||||
|
"class_name": "unilabos_class"
|
||||||
|
}
|
||||||
|
}
|
||||||
32
.cursor/skills/host-node/actions/manual_confirm.json
Normal file
32
.cursor/skills/host-node/actions/manual_confirm.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"timeout_seconds": "timeout_seconds",
|
||||||
|
"assignee_user_ids": "assignee_user_ids"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"timeout_seconds": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"assignee_user_ids": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"timeout_seconds",
|
||||||
|
"assignee_user_ids"
|
||||||
|
],
|
||||||
|
"_unilabos_placeholder_info": {
|
||||||
|
"assignee_user_ids": "unilabos_manual_confirm"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {
|
||||||
|
"assignee_user_ids": "unilabos_manual_confirm"
|
||||||
|
}
|
||||||
|
}
|
||||||
11
.cursor/skills/host-node/actions/test_latency.json
Normal file
11
.cursor/skills/host-node/actions/test_latency.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {},
|
||||||
|
"required": []
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {}
|
||||||
|
}
|
||||||
255
.cursor/skills/host-node/actions/test_resource.json
Normal file
255
.cursor/skills/host-node/actions/test_resource.json
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"resource": "resource",
|
||||||
|
"resources": "resources",
|
||||||
|
"device": "device",
|
||||||
|
"devices": "devices"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"resource": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "resource"
|
||||||
|
},
|
||||||
|
"resources": {
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "resources"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"device": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "device reference"
|
||||||
|
},
|
||||||
|
"devices": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "device reference"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [],
|
||||||
|
"_unilabos_placeholder_info": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"resources": "unilabos_resources",
|
||||||
|
"device": "unilabos_devices",
|
||||||
|
"devices": "unilabos_devices"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"resources": "unilabos_resources",
|
||||||
|
"device": "unilabos_devices",
|
||||||
|
"devices": "unilabos_devices"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
---
|
---
|
||||||
name: submit-agent-result
|
name: submit-agent-result
|
||||||
description: Submit historical experiment results (agent_result) to Uni-Lab notebook — read data files, assemble JSON payload, PUT to cloud API. Use when the user wants to submit experiment results, upload agent results, report experiment data, or mentions agent_result/实验结果/历史记录/notebook结果.
|
description: Submit historical experiment results (agent_result) to Uni-Lab cloud platform (leap-lab) notebook — read data files, assemble JSON payload, PUT to cloud API. Use when the user wants to submit experiment results, upload agent results, report experiment data, or mentions agent_result/实验结果/历史记录/notebook结果.
|
||||||
---
|
---
|
||||||
|
|
||||||
# 提交历史实验记录指南
|
# Uni-Lab 提交历史实验记录指南
|
||||||
|
|
||||||
通过云端 API 向已创建的 notebook 提交实验结果数据(agent_result)。支持从 JSON / CSV 文件读取数据,整合后提交。
|
通过 Uni-Lab 云端 API 向已创建的 notebook 提交实验结果数据(agent_result)。支持从 JSON / CSV 文件读取数据,整合后提交。
|
||||||
|
|
||||||
|
> **重要**:本指南中的 `Authorization: Lab <token>` 是 **Uni-Lab 平台专用的认证方式**,`Lab` 是 Uni-Lab 的 auth scheme 关键字,**不是** HTTP Basic 认证。请勿将其替换为 `Basic`。
|
||||||
|
|
||||||
## 前置条件(缺一不可)
|
## 前置条件(缺一不可)
|
||||||
|
|
||||||
@@ -18,23 +20,26 @@ description: Submit historical experiment results (agent_result) to Uni-Lab note
|
|||||||
生成 AUTH token:
|
生成 AUTH token:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# ⚠️ 注意:scheme 是 "Lab"(Uni-Lab 专用),不是 "Basic"
|
||||||
python -c "import base64,sys; print(base64.b64encode(f'{sys.argv[1]}:{sys.argv[2]}'.encode()).decode())" <ak> <sk>
|
python -c "import base64,sys; print(base64.b64encode(f'{sys.argv[1]}:{sys.argv[2]}'.encode()).decode())" <ak> <sk>
|
||||||
```
|
```
|
||||||
|
|
||||||
输出即为 token 值,拼接为 `Authorization: Lab <token>`。
|
输出即为 token 值,拼接为 `Authorization: Lab <token>`(`Lab` 是 Uni-Lab 平台 auth scheme,不可替换为 `Basic`)。
|
||||||
|
|
||||||
### 2. --addr → BASE URL
|
### 2. --addr → BASE URL
|
||||||
|
|
||||||
| `--addr` 值 | BASE |
|
| `--addr` 值 | BASE |
|
||||||
|-------------|------|
|
| ------------ | ----------------------------------- |
|
||||||
| `test` | `https://uni-lab.test.bohrium.com` |
|
| `test` | `https://leap-lab.test.bohrium.com` |
|
||||||
| `uat` | `https://uni-lab.uat.bohrium.com` |
|
| `uat` | `https://leap-lab.uat.bohrium.com` |
|
||||||
| `local` | `http://127.0.0.1:48197` |
|
| `local` | `http://127.0.0.1:48197` |
|
||||||
| 不传(默认) | `https://uni-lab.bohrium.com` |
|
| 不传(默认) | `https://leap-lab.bohrium.com` |
|
||||||
|
|
||||||
确认后设置:
|
确认后设置:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
BASE="<根据 addr 确定的 URL>"
|
BASE="<根据 addr 确定的 URL>"
|
||||||
|
# ⚠️ Auth scheme 必须是 "Lab"(Uni-Lab 专用),不是 "Basic"
|
||||||
AUTH="Authorization: Lab <上面命令输出的 token>"
|
AUTH="Authorization: Lab <上面命令输出的 token>"
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -45,6 +50,7 @@ AUTH="Authorization: Lab <上面命令输出的 token>"
|
|||||||
notebook_uuid 来自之前通过「批量提交实验」创建的实验批次,即 `POST /api/v1/lab/notebook` 返回的 `data.uuid`。
|
notebook_uuid 来自之前通过「批量提交实验」创建的实验批次,即 `POST /api/v1/lab/notebook` 返回的 `data.uuid`。
|
||||||
|
|
||||||
如果用户不记得,可提示:
|
如果用户不记得,可提示:
|
||||||
|
|
||||||
- 查看之前的对话记录中创建 notebook 时返回的 UUID
|
- 查看之前的对话记录中创建 notebook 时返回的 UUID
|
||||||
- 或通过平台页面查找对应的 notebook
|
- 或通过平台页面查找对应的 notebook
|
||||||
|
|
||||||
@@ -54,11 +60,11 @@ notebook_uuid 来自之前通过「批量提交实验」创建的实验批次,
|
|||||||
|
|
||||||
用户需要提供实验结果数据,支持以下方式:
|
用户需要提供实验结果数据,支持以下方式:
|
||||||
|
|
||||||
| 方式 | 说明 |
|
| 方式 | 说明 |
|
||||||
|------|------|
|
| --------- | ----------------------------------------------- |
|
||||||
| JSON 文件 | 直接作为 `agent_result` 的内容合并 |
|
| JSON 文件 | 直接作为 `agent_result` 的内容合并 |
|
||||||
| CSV 文件 | 转为 `{"文件名": [行数据...]}` 格式 |
|
| CSV 文件 | 转为 `{"文件名": [行数据...]}` 格式 |
|
||||||
| 手动指定 | 用户直接告知 key-value 数据,由 agent 构建 JSON |
|
| 手动指定 | 用户直接告知 key-value 数据,由 agent 构建 JSON |
|
||||||
|
|
||||||
**四项全部就绪后才可开始。**
|
**四项全部就绪后才可开始。**
|
||||||
|
|
||||||
@@ -90,7 +96,7 @@ curl -s -X GET "$BASE/api/v1/edge/lab/info" -H "$AUTH"
|
|||||||
返回:
|
返回:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"code": 0, "data": {"uuid": "xxx", "name": "实验室名称"}}
|
{ "code": 0, "data": { "uuid": "xxx", "name": "实验室名称" } }
|
||||||
```
|
```
|
||||||
|
|
||||||
记住 `data.uuid` 为 `lab_uuid`。
|
记住 `data.uuid` 为 `lab_uuid`。
|
||||||
@@ -121,42 +127,45 @@ curl -s -X PUT "$BASE/api/v1/lab/notebook/agent-result" \
|
|||||||
|
|
||||||
#### 必要字段
|
#### 必要字段
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
|------|------|------|
|
| --------------- | ------------- | ------------------------------------------- |
|
||||||
| `notebook_uuid` | string (UUID) | 目标 notebook 的 UUID,从批量提交实验时获取 |
|
| `notebook_uuid` | string (UUID) | 目标 notebook 的 UUID,从批量提交实验时获取 |
|
||||||
| `agent_result` | object | 实验结果数据,任意 JSON 对象 |
|
| `agent_result` | object | 实验结果数据,任意 JSON 对象 |
|
||||||
|
|
||||||
#### agent_result 内容格式
|
#### agent_result 内容格式
|
||||||
|
|
||||||
`agent_result` 接受**任意 JSON 对象**,常见格式:
|
`agent_result` 接受**任意 JSON 对象**,常见格式:
|
||||||
|
|
||||||
**简单键值对**:
|
**简单键值对**:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"avg_rtt_ms": 12.5,
|
"avg_rtt_ms": 12.5,
|
||||||
"status": "success",
|
"status": "success",
|
||||||
"test_count": 5
|
"test_count": 5
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**包含嵌套结构**:
|
**包含嵌套结构**:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"summary": {"total": 100, "passed": 98, "failed": 2},
|
"summary": { "total": 100, "passed": 98, "failed": 2 },
|
||||||
"measurements": [
|
"measurements": [
|
||||||
{"sample_id": "S001", "value": 3.14, "unit": "mg/mL"},
|
{ "sample_id": "S001", "value": 3.14, "unit": "mg/mL" },
|
||||||
{"sample_id": "S002", "value": 2.71, "unit": "mg/mL"}
|
{ "sample_id": "S002", "value": 2.71, "unit": "mg/mL" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**从 CSV 文件导入**(脚本自动转换):
|
**从 CSV 文件导入**(脚本自动转换):
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"experiment_data": [
|
"experiment_data": [
|
||||||
{"温度": 25, "压力": 101.3, "产率": 0.85},
|
{ "温度": 25, "压力": 101.3, "产率": 0.85 },
|
||||||
{"温度": 30, "压力": 101.3, "产率": 0.91}
|
{ "温度": 30, "压力": 101.3, "产率": 0.91 }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -178,22 +187,22 @@ python scripts/prepare_agent_result.py \
|
|||||||
[--output <output.json>]
|
[--output <output.json>]
|
||||||
```
|
```
|
||||||
|
|
||||||
| 参数 | 必选 | 说明 |
|
| 参数 | 必选 | 说明 |
|
||||||
|------|------|------|
|
| ----------------- | ---------- | ----------------------------------------------- |
|
||||||
| `--notebook-uuid` | 是 | 目标 notebook UUID |
|
| `--notebook-uuid` | 是 | 目标 notebook UUID |
|
||||||
| `--files` | 是 | 输入文件路径(支持多个,JSON / CSV) |
|
| `--files` | 是 | 输入文件路径(支持多个,JSON / CSV) |
|
||||||
| `--auth` | 提交时必选 | Lab token(base64(ak:sk)) |
|
| `--auth` | 提交时必选 | Lab token(base64(ak:sk)) |
|
||||||
| `--base` | 提交时必选 | API base URL |
|
| `--base` | 提交时必选 | API base URL |
|
||||||
| `--submit` | 否 | 加上此标志则直接提交到云端 |
|
| `--submit` | 否 | 加上此标志则直接提交到云端 |
|
||||||
| `--output` | 否 | 输出 JSON 路径(默认 `agent_result_body.json`) |
|
| `--output` | 否 | 输出 JSON 路径(默认 `agent_result_body.json`) |
|
||||||
|
|
||||||
### 文件合并规则
|
### 文件合并规则
|
||||||
|
|
||||||
| 文件类型 | 合并方式 |
|
| 文件类型 | 合并方式 |
|
||||||
|----------|----------|
|
| --------------------- | -------------------------------------------- |
|
||||||
| `.json`(dict) | 字段直接合并到 `agent_result` 顶层 |
|
| `.json`(dict) | 字段直接合并到 `agent_result` 顶层 |
|
||||||
| `.json`(list/other) | 以文件名为 key 放入 `agent_result` |
|
| `.json`(list/other) | 以文件名为 key 放入 `agent_result` |
|
||||||
| `.csv` | 以文件名(不含扩展名)为 key,值为行对象数组 |
|
| `.csv` | 以文件名(不含扩展名)为 key,值为行对象数组 |
|
||||||
|
|
||||||
多个文件的字段会合并。JSON dict 中的重复 key 后者覆盖前者。
|
多个文件的字段会合并。JSON dict 中的重复 key 后者覆盖前者。
|
||||||
|
|
||||||
@@ -210,7 +219,7 @@ python scripts/prepare_agent_result.py \
|
|||||||
--notebook-uuid 73c67dca-c8cc-4936-85a0-329106aa7cca \
|
--notebook-uuid 73c67dca-c8cc-4936-85a0-329106aa7cca \
|
||||||
--files results.json \
|
--files results.json \
|
||||||
--auth YTFmZDlkNGUt... \
|
--auth YTFmZDlkNGUt... \
|
||||||
--base https://uni-lab.test.bohrium.com \
|
--base https://leap-lab.test.bohrium.com \
|
||||||
--submit
|
--submit
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -272,4 +281,4 @@ Task Progress:
|
|||||||
|
|
||||||
### Q: 认证方式是 Lab 还是 Api?
|
### Q: 认证方式是 Lab 还是 Api?
|
||||||
|
|
||||||
本指南统一使用 `Authorization: Lab <base64(ak:sk)>` 方式。如果用户有独立的 API Key,也可用 `Authorization: Api <key>` 替代。
|
本指南统一使用 `Authorization: Lab <base64(ak:sk)>` 方式(`Lab` 是 Uni-Lab 平台的 auth scheme,**绝不能用 `Basic` 替代**)。如果用户有独立的 API Key,也可用 `Authorization: Api <key>` 替代。
|
||||||
|
|||||||
272
.cursor/skills/virtual-workbench/SKILL.md
Normal file
272
.cursor/skills/virtual-workbench/SKILL.md
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
---
|
||||||
|
name: virtual-workbench
|
||||||
|
description: Operate Virtual Workbench via REST API — prepare materials, move to heating stations, start heating, move to output, transfer resources. Use when the user mentions virtual workbench, virtual_workbench, 虚拟工作台, heating stations, material processing, or workbench operations.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Virtual Workbench API Skill
|
||||||
|
|
||||||
|
## 设备信息
|
||||||
|
|
||||||
|
- **device_id**: `virtual_workbench`
|
||||||
|
- **Python 源码**: `unilabos/devices/virtual/workbench.py`
|
||||||
|
- **设备类**: `VirtualWorkbench`
|
||||||
|
- **动作数**: 6(`auto-prepare_materials`, `auto-move_to_heating_station`, `auto-start_heating`, `auto-move_to_output`, `transfer`, `manual_confirm`)
|
||||||
|
- **设备描述**: 模拟工作台,包含 1 个机械臂(每次操作 2s,独占锁)和 3 个加热台(每次加热 60s,可并行)
|
||||||
|
|
||||||
|
### 典型工作流程
|
||||||
|
|
||||||
|
1. `prepare_materials` — 生成 A1-A5 物料(5 个 output handle)
|
||||||
|
2. `move_to_heating_station` — 物料并发竞争机械臂,移动到空闲加热台
|
||||||
|
3. `start_heating` — 启动加热(3 个加热台可并行)
|
||||||
|
4. `move_to_output` — 加热完成后移到输出位置 Cn
|
||||||
|
|
||||||
|
## 前置条件(缺一不可)
|
||||||
|
|
||||||
|
使用本 skill 前,**必须**先确认以下信息。如果缺少任何一项,**立即向用户询问并终止**,等补齐后再继续。
|
||||||
|
|
||||||
|
### 1. ak / sk → AUTH
|
||||||
|
|
||||||
|
从启动参数 `--ak` `--sk` 或 config.py 中获取,生成 token:`base64(ak:sk)` → `Authorization: Lab <token>`
|
||||||
|
|
||||||
|
### 2. --addr → BASE URL
|
||||||
|
|
||||||
|
| `--addr` 值 | BASE |
|
||||||
|
| ------------ | ----------------------------------- |
|
||||||
|
| `test` | `https://leap-lab.test.bohrium.com` |
|
||||||
|
| `uat` | `https://leap-lab.uat.bohrium.com` |
|
||||||
|
| `local` | `http://127.0.0.1:48197` |
|
||||||
|
| 不传(默认) | `https://leap-lab.bohrium.com` |
|
||||||
|
|
||||||
|
确认后设置:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
BASE="<根据 addr 确定的 URL>"
|
||||||
|
AUTH="Authorization: Lab <token>"
|
||||||
|
```
|
||||||
|
|
||||||
|
**两项全部就绪后才可发起 API 请求。**
|
||||||
|
|
||||||
|
## Session State
|
||||||
|
|
||||||
|
- `lab_uuid` — 实验室 UUID(首次通过 API #1 自动获取,**不需要问用户**)
|
||||||
|
- `device_name` — `virtual_workbench`
|
||||||
|
|
||||||
|
## 请求约定
|
||||||
|
|
||||||
|
所有请求使用 `curl -s`,POST/PATCH/DELETE 需加 `Content-Type: application/json`。
|
||||||
|
|
||||||
|
> **Windows 平台**必须使用 `curl.exe`(而非 PowerShell 的 `curl` 别名)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## API Endpoints
|
||||||
|
|
||||||
|
### 1. 获取实验室信息(自动获取 lab_uuid)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/edge/lab/info" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `lab_uuid`,`data.name` 为 `lab_name`。
|
||||||
|
|
||||||
|
### 2. 创建工作流
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/owner" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"name":"<名称>","lab_uuid":"<lab_uuid>","description":"<描述>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `workflow_uuid`。创建成功后告知用户链接:`$BASE/laboratory/$lab_uuid/workflow/$workflow_uuid`
|
||||||
|
|
||||||
|
### 3. 创建节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/edge/workflow/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"workflow_uuid":"<workflow_uuid>","resource_template_name":"virtual_workbench","node_template_name":"<action_name>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
- `resource_template_name` 固定为 `virtual_workbench`
|
||||||
|
- `node_template_name` — action 名称(如 `auto-prepare_materials`, `auto-move_to_heating_station`)
|
||||||
|
|
||||||
|
### 4. 删除节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X DELETE "$BASE/api/v1/lab/workflow/nodes" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuids":["<uuid1>"],"workflow_uuid":"<workflow_uuid>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. 更新节点参数
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X PATCH "$BASE/api/v1/lab/workflow/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"workflow_uuid":"<wf_uuid>","uuid":"<node_uuid>","param":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
参考 [action-index.md](action-index.md) 确定哪些字段是 Slot。
|
||||||
|
|
||||||
|
### 6. 查询节点 handles
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/node-handles" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuids":["<node_uuid_1>","<node_uuid_2>"]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 7. 批量创建边
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/edges" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"edges":[{"source_node_uuid":"<uuid>","target_node_uuid":"<uuid>","source_handle_uuid":"<uuid>","target_handle_uuid":"<uuid>"}]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8. 启动工作流
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/workflow/<workflow_uuid>/run" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 9. 运行设备单动作
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/mcp/run/action" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"lab_uuid":"<lab_uuid>","device_id":"virtual_workbench","action":"<action_name>","action_type":"<type>","param":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
`param` 直接放 goal 里的属性,**不要**再包一层 `{"goal": {...}}`。
|
||||||
|
|
||||||
|
> **WARNING: `action_type` 必须正确,传错会导致任务永远卡住无法完成。** 从下表或 `actions/<name>.json` 的 `type` 字段获取。
|
||||||
|
|
||||||
|
#### action_type 速查表
|
||||||
|
|
||||||
|
| action | action_type |
|
||||||
|
|--------|-------------|
|
||||||
|
| `auto-prepare_materials` | `UniLabJsonCommand` |
|
||||||
|
| `auto-move_to_heating_station` | `UniLabJsonCommand` |
|
||||||
|
| `auto-start_heating` | `UniLabJsonCommand` |
|
||||||
|
| `auto-move_to_output` | `UniLabJsonCommand` |
|
||||||
|
| `transfer` | `UniLabJsonCommandAsync` |
|
||||||
|
| `manual_confirm` | `UniLabJsonCommand` |
|
||||||
|
|
||||||
|
### 10. 查询任务状态
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/mcp/task/<task_uuid>" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 11. 运行工作流单节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/lab/mcp/run/workflow/action" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"node_uuid":"<node_uuid>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 12. 获取资源树(物料信息)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/material/download/$lab_uuid" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
注意 `lab_uuid` 在路径中。返回 `data.nodes[]` 含所有节点(设备 + 物料),每个节点含 `name`、`uuid`、`type`、`parent`。
|
||||||
|
|
||||||
|
### 13. 获取工作流模板详情
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/workflow/template/detail/$workflow_uuid" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
> 必须使用 `/lab/workflow/template/detail/{uuid}`,其他路径会返回 404。
|
||||||
|
|
||||||
|
### 14. 按名称查询物料模板
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X GET "$BASE/api/v1/lab/material/template/by-name?lab_uuid=$lab_uuid&name=<template_name>" -H "$AUTH"
|
||||||
|
```
|
||||||
|
|
||||||
|
返回 `data.uuid` 为 `res_template_uuid`,用于 API #15。
|
||||||
|
|
||||||
|
### 15. 创建物料节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X POST "$BASE/api/v1/edge/material/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"res_template_uuid":"<uuid>","name":"<名称>","display_name":"<显示名>","parent_uuid":"<父节点uuid>","data":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 16. 更新物料节点
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -X PUT "$BASE/api/v1/edge/material/node" \
|
||||||
|
-H "$AUTH" -H "Content-Type: application/json" \
|
||||||
|
-d '{"uuid":"<节点uuid>","display_name":"<新名称>","data":{...}}'
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Placeholder Slot 填写规则
|
||||||
|
|
||||||
|
| `placeholder_keys` 值 | Slot 类型 | 填写格式 | 选取范围 |
|
||||||
|
| --------------------- | ------------ | ----------------------------------------------------- | ---------------------- |
|
||||||
|
| `unilabos_resources` | ResourceSlot | `{"id": "/path/name", "name": "name", "uuid": "xxx"}` | 仅物料节点(非设备) |
|
||||||
|
| `unilabos_devices` | DeviceSlot | `"/parent/device_name"` | 仅设备节点(type=device) |
|
||||||
|
| `unilabos_nodes` | NodeSlot | `"/parent/node_name"` | 所有节点(设备 + 物料) |
|
||||||
|
| `unilabos_class` | ClassSlot | `"class_name"` | 注册表中已注册的资源类 |
|
||||||
|
|
||||||
|
### virtual_workbench 设备的 Slot 字段表
|
||||||
|
|
||||||
|
| Action | 字段 | Slot 类型 | 说明 |
|
||||||
|
| ----------------- | ---------------- | ------------ | -------------------- |
|
||||||
|
| `transfer` | `resource` | ResourceSlot | 待转移物料数组 |
|
||||||
|
| `transfer` | `target_device` | DeviceSlot | 目标设备路径 |
|
||||||
|
| `transfer` | `mount_resource` | ResourceSlot | 目标孔位数组 |
|
||||||
|
| `manual_confirm` | `resource` | ResourceSlot | 确认用物料数组 |
|
||||||
|
| `manual_confirm` | `target_device` | DeviceSlot | 确认用目标设备 |
|
||||||
|
| `manual_confirm` | `mount_resource` | ResourceSlot | 确认用目标孔位数组 |
|
||||||
|
|
||||||
|
> `prepare_materials`、`move_to_heating_station`、`start_heating`、`move_to_output` 这 4 个动作**无 Slot 字段**,参数为纯数值/整数。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 渐进加载策略
|
||||||
|
|
||||||
|
1. **SKILL.md**(本文件)— API 端点 + session state 管理 + 设备工作流概览
|
||||||
|
2. **[action-index.md](action-index.md)** — 按分类浏览 6 个动作的描述和核心参数
|
||||||
|
3. **[actions/\<name\>.json](actions/)** — 仅在需要构建具体请求时,加载对应 action 的完整 JSON Schema
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 完整工作流 Checklist
|
||||||
|
|
||||||
|
```
|
||||||
|
Task Progress:
|
||||||
|
- [ ] Step 1: GET /edge/lab/info 获取 lab_uuid
|
||||||
|
- [ ] Step 2: 获取资源树 (GET #12) → 记住可用物料
|
||||||
|
- [ ] Step 3: 读 action-index.md 确定要用的 action 名
|
||||||
|
- [ ] Step 4: 创建工作流 (POST #2) → 记住 workflow_uuid,告知用户链接
|
||||||
|
- [ ] Step 5: 创建节点 (POST #3, resource_template_name=virtual_workbench) → 记住 node_uuid + data.param
|
||||||
|
- [ ] Step 6: 根据 _unilabos_placeholder_info 和资源树,填写 data.param 中的 Slot 字段
|
||||||
|
- [ ] Step 7: 更新节点参数 (PATCH #5)
|
||||||
|
- [ ] Step 8: 查询节点 handles (POST #6) → 获取各节点的 handle_uuid
|
||||||
|
- [ ] Step 9: 批量创建边 (POST #7) → 用 handle_uuid 连接节点
|
||||||
|
- [ ] Step 10: 启动工作流 (POST #8) 或运行单节点 (POST #11)
|
||||||
|
- [ ] Step 11: 查询任务状态 (GET #10) 确认完成
|
||||||
|
```
|
||||||
|
|
||||||
|
### 典型 5 物料并发加热工作流示例
|
||||||
|
|
||||||
|
```
|
||||||
|
prepare_materials (count=5)
|
||||||
|
├─ channel_1 → move_to_heating_station (material_number=1) → start_heating → move_to_output
|
||||||
|
├─ channel_2 → move_to_heating_station (material_number=2) → start_heating → move_to_output
|
||||||
|
├─ channel_3 → move_to_heating_station (material_number=3) → start_heating → move_to_output
|
||||||
|
├─ channel_4 → move_to_heating_station (material_number=4) → start_heating → move_to_output
|
||||||
|
└─ channel_5 → move_to_heating_station (material_number=5) → start_heating → move_to_output
|
||||||
|
```
|
||||||
|
|
||||||
|
创建节点时,`prepare_materials` 的 5 个 output handle(`channel_1` ~ `channel_5`)分别连接到 5 个 `move_to_heating_station` 节点的 `material_input` handle。每个 `move_to_heating_station` 的 `heating_station_output` 和 `material_number_output` 连接到对应 `start_heating` 的 `station_id_input` 和 `material_number_input`。
|
||||||
76
.cursor/skills/virtual-workbench/action-index.md
Normal file
76
.cursor/skills/virtual-workbench/action-index.md
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# Action Index — virtual_workbench
|
||||||
|
|
||||||
|
6 个动作,按功能分类。每个动作的完整 JSON Schema 在 `actions/<name>.json`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 物料准备
|
||||||
|
|
||||||
|
### `auto-prepare_materials`
|
||||||
|
|
||||||
|
批量准备物料(虚拟起始节点),生成 A1-A5 物料编号,输出 5 个 handle 供后续节点使用
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/prepare_materials.json`](actions/prepare_materials.json)
|
||||||
|
- **可选参数**: `count`(物料数量,默认 5)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 机械臂 & 加热台操作
|
||||||
|
|
||||||
|
### `auto-move_to_heating_station`
|
||||||
|
|
||||||
|
将物料从 An 位置移动到空闲加热台(竞争机械臂,自动查找空闲加热台)
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/move_to_heating_station.json`](actions/move_to_heating_station.json)
|
||||||
|
- **核心参数**: `material_number`(物料编号,integer)
|
||||||
|
|
||||||
|
### `auto-start_heating`
|
||||||
|
|
||||||
|
启动指定加热台的加热程序(可并行,3 个加热台同时工作)
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/start_heating.json`](actions/start_heating.json)
|
||||||
|
- **核心参数**: `station_id`(加热台 ID),`material_number`(物料编号)
|
||||||
|
|
||||||
|
### `auto-move_to_output`
|
||||||
|
|
||||||
|
将加热完成的物料从加热台移动到输出位置 Cn
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/move_to_output.json`](actions/move_to_output.json)
|
||||||
|
- **核心参数**: `station_id`(加热台 ID),`material_number`(物料编号)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 物料转移
|
||||||
|
|
||||||
|
### `transfer`
|
||||||
|
|
||||||
|
异步转移物料到目标设备(通过 ROS 资源转移)
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommandAsync`
|
||||||
|
- **Schema**: [`actions/transfer.json`](actions/transfer.json)
|
||||||
|
- **核心参数**: `resource`, `target_device`, `mount_resource`
|
||||||
|
- **占位符字段**:
|
||||||
|
- `resource` — **ResourceSlot**,待转移的物料数组 `[{id, name, uuid}, ...]`
|
||||||
|
- `target_device` — **DeviceSlot**,目标设备路径字符串
|
||||||
|
- `mount_resource` — **ResourceSlot**,目标孔位数组 `[{id, name, uuid}, ...]`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 人工确认
|
||||||
|
|
||||||
|
### `manual_confirm`
|
||||||
|
|
||||||
|
创建人工确认节点,等待用户手动确认后继续(含物料转移上下文)
|
||||||
|
|
||||||
|
- **action_type**: `UniLabJsonCommand`
|
||||||
|
- **Schema**: [`actions/manual_confirm.json`](actions/manual_confirm.json)
|
||||||
|
- **核心参数**: `resource`, `target_device`, `mount_resource`, `timeout_seconds`, `assignee_user_ids`
|
||||||
|
- **占位符字段**:
|
||||||
|
- `resource` — **ResourceSlot**,物料数组
|
||||||
|
- `target_device` — **DeviceSlot**,目标设备路径
|
||||||
|
- `mount_resource` — **ResourceSlot**,目标孔位数组
|
||||||
|
- `assignee_user_ids` — `unilabos_manual_confirm` 类型
|
||||||
270
.cursor/skills/virtual-workbench/actions/manual_confirm.json
Normal file
270
.cursor/skills/virtual-workbench/actions/manual_confirm.json
Normal file
@@ -0,0 +1,270 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"resource": "resource",
|
||||||
|
"target_device": "target_device",
|
||||||
|
"mount_resource": "mount_resource",
|
||||||
|
"timeout_seconds": "timeout_seconds",
|
||||||
|
"assignee_user_ids": "assignee_user_ids"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"resource": {
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "resource"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"target_device": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "device reference"
|
||||||
|
},
|
||||||
|
"mount_resource": {
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "mount_resource"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"timeout_seconds": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"assignee_user_ids": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"resource",
|
||||||
|
"target_device",
|
||||||
|
"mount_resource",
|
||||||
|
"timeout_seconds",
|
||||||
|
"assignee_user_ids"
|
||||||
|
],
|
||||||
|
"_unilabos_placeholder_info": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"target_device": "unilabos_devices",
|
||||||
|
"mount_resource": "unilabos_resources",
|
||||||
|
"assignee_user_ids": "unilabos_manual_confirm"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"target_device": "unilabos_devices",
|
||||||
|
"mount_resource": "unilabos_resources",
|
||||||
|
"assignee_user_ids": "unilabos_manual_confirm"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"material_number": "material_number"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"material_number": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"material_number"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {}
|
||||||
|
}
|
||||||
24
.cursor/skills/virtual-workbench/actions/move_to_output.json
Normal file
24
.cursor/skills/virtual-workbench/actions/move_to_output.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"station_id": "station_id",
|
||||||
|
"material_number": "material_number"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"station_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"material_number": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"station_id",
|
||||||
|
"material_number"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"count": "count"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"count": {
|
||||||
|
"type": "integer",
|
||||||
|
"default": 5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": []
|
||||||
|
},
|
||||||
|
"goal_default": {
|
||||||
|
"count": 5
|
||||||
|
},
|
||||||
|
"placeholder_keys": {}
|
||||||
|
}
|
||||||
24
.cursor/skills/virtual-workbench/actions/start_heating.json
Normal file
24
.cursor/skills/virtual-workbench/actions/start_heating.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommand",
|
||||||
|
"goal": {
|
||||||
|
"station_id": "station_id",
|
||||||
|
"material_number": "material_number"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"station_id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"material_number": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"station_id",
|
||||||
|
"material_number"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {}
|
||||||
|
}
|
||||||
255
.cursor/skills/virtual-workbench/actions/transfer.json
Normal file
255
.cursor/skills/virtual-workbench/actions/transfer.json
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
{
|
||||||
|
"type": "UniLabJsonCommandAsync",
|
||||||
|
"goal": {
|
||||||
|
"resource": "resource",
|
||||||
|
"target_device": "target_device",
|
||||||
|
"mount_resource": "mount_resource"
|
||||||
|
},
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"resource": {
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "resource"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"target_device": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "device reference"
|
||||||
|
},
|
||||||
|
"mount_resource": {
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sample_id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parent": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"category": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"pose": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"position": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z"
|
||||||
|
],
|
||||||
|
"title": "position",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"orientation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"x": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"y": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"z": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"type": "number",
|
||||||
|
"minimum": -1.7976931348623157e+308,
|
||||||
|
"maximum": 1.7976931348623157e+308
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"x",
|
||||||
|
"y",
|
||||||
|
"z",
|
||||||
|
"w"
|
||||||
|
],
|
||||||
|
"title": "orientation",
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"position",
|
||||||
|
"orientation"
|
||||||
|
],
|
||||||
|
"title": "pose",
|
||||||
|
"additionalProperties": false
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title": "mount_resource"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"resource",
|
||||||
|
"target_device",
|
||||||
|
"mount_resource"
|
||||||
|
],
|
||||||
|
"_unilabos_placeholder_info": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"target_device": "unilabos_devices",
|
||||||
|
"mount_resource": "unilabos_resources"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"goal_default": {},
|
||||||
|
"placeholder_keys": {
|
||||||
|
"resource": "unilabos_resources",
|
||||||
|
"target_device": "unilabos_devices",
|
||||||
|
"mount_resource": "unilabos_resources"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
.conda
|
|
||||||
# .github
|
|
||||||
.idea
|
|
||||||
# .vscode
|
|
||||||
output
|
|
||||||
pylabrobot_repo
|
|
||||||
recipes
|
|
||||||
scripts
|
|
||||||
service
|
|
||||||
temp
|
|
||||||
# unilabos/test
|
|
||||||
# unilabos/app/web
|
|
||||||
unilabos/device_mesh
|
|
||||||
unilabos_data
|
|
||||||
unilabos_msgs
|
|
||||||
unilabos.egg-info
|
|
||||||
CONTRIBUTORS
|
|
||||||
# LICENSE
|
|
||||||
MANIFEST.in
|
|
||||||
pyrightconfig.json
|
|
||||||
# README.md
|
|
||||||
# README_zh.md
|
|
||||||
setup.py
|
|
||||||
setup.cfg
|
|
||||||
.gitattrubutes
|
|
||||||
**/__pycache__
|
|
||||||
19
.github/dependabot.yml
vendored
Normal file
19
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
# GitHub Actions
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
target-branch: "dev"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
day: "monday"
|
||||||
|
time: "06:00"
|
||||||
|
open-pull-requests-limit: 5
|
||||||
|
reviewers:
|
||||||
|
- "msgcenterpy-team"
|
||||||
|
labels:
|
||||||
|
- "dependencies"
|
||||||
|
- "github-actions"
|
||||||
|
commit-message:
|
||||||
|
prefix: "ci"
|
||||||
|
include: "scope"
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -251,6 +251,7 @@ ros-humble-unilabos-msgs-0.9.13-h6403a04_5.tar.bz2
|
|||||||
*.bz2
|
*.bz2
|
||||||
test_config.py
|
test_config.py
|
||||||
|
|
||||||
|
# Local config files with secrets
|
||||||
/.claude
|
yibin_coin_cell_only_config.json
|
||||||
/.cursor
|
yibin_electrolyte_config.json
|
||||||
|
yibin_electrolyte_only_config.json
|
||||||
|
|||||||
72
260415csv_export_walkthrough.md
Normal file
72
260415csv_export_walkthrough.md
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
# CSV 导出功能变更概要
|
||||||
|
|
||||||
|
## 修改的文件
|
||||||
|
|
||||||
|
### 1. [bioyond_cell_workstation.py](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/devices/workstation/bioyond_studio/bioyond_cell/bioyond_cell_workstation.py)
|
||||||
|
|
||||||
|
#### 新增导入
|
||||||
|
- `import csv` 和 `import os`(L14-15)
|
||||||
|
|
||||||
|
#### 新增方法
|
||||||
|
|
||||||
|
| 方法 | 功能 |
|
||||||
|
|------|------|
|
||||||
|
| `_extract_prep_bottle_from_report` | 从 order_finish 报文提取**配液瓶**信息(每订单最多1个) |
|
||||||
|
| `_extract_vial_bottles_from_report` | 从 order_finish 报文提取**分液瓶**信息(每订单可多个,返回数组) |
|
||||||
|
| `_export_order_csv` | 汇总所有信息写入 CSV 文件 |
|
||||||
|
|
||||||
|
#### 配液瓶筛选逻辑 (`_extract_prep_bottle_from_report`)
|
||||||
|
- `typemode="1"`, `realQuantity=1`, `usedQuantity=1`
|
||||||
|
- `locationId` 以 `3a19deae-2c7a-` 开头(手动传递窗)
|
||||||
|
- LIMS API 二次确认:`typeName` 含"配液瓶(小)"或"配液瓶(大)"
|
||||||
|
|
||||||
|
#### 分液瓶筛选逻辑 (`_extract_vial_bottles_from_report`)
|
||||||
|
- `typemode="1"`, `realQuantity=1`, `usedQuantity=1`
|
||||||
|
- `locationId` 以 `3a19debc-84b5-` 或 `3a19debe-5200` 开头(自动堆栈-左/右)
|
||||||
|
- LIMS API 二次确认:`typeName` 为"5ml分液瓶"或"20ml分液瓶"
|
||||||
|
- **返回数组**,支持 1×5ml + n×20ml 的组合
|
||||||
|
|
||||||
|
#### 修改的方法
|
||||||
|
|
||||||
|
| 方法 | 变更 |
|
||||||
|
|------|------|
|
||||||
|
| `_submit_and_wait_orders` | 新增配液瓶+分液瓶提取步骤,将 `prep_bottles` 和 `vial_bottles` 存入 `final_result` |
|
||||||
|
| `create_orders` | 添加 `csv_export_path` 参数,末尾调用 `_export_order_csv` |
|
||||||
|
| `create_orders_formulation` | 添加 `csv_export_path` 参数,末尾调用 `_export_order_csv` |
|
||||||
|
|
||||||
|
#### CSV 输出格式
|
||||||
|
```
|
||||||
|
orderCode, orderName, 配液瓶类型, 配液瓶二维码, 分液瓶类型, 分液瓶二维码, 目标配液质量比, 真实配液质量比, 时间
|
||||||
|
```
|
||||||
|
- 单个分液瓶时直接写值;多个分液瓶时类型和二维码用 JSON 数组表示
|
||||||
|
- CSV 编码使用 `utf-8-sig`(兼容 Excel 打开)
|
||||||
|
- `csv_export_path` 默认为空字符串,不传则不导出(向后兼容)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2. [bioyond_cell.yaml](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/registry/devices/bioyond_cell.yaml)
|
||||||
|
|
||||||
|
为两个 action 注册了 `csv_export_path` 参数:
|
||||||
|
|
||||||
|
- `auto-create_orders`: `goal_default` + `schema.properties.goal.properties` 中添加 `csv_export_path`
|
||||||
|
- `auto-create_orders_formulation`: 同上
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3. [coin_cell_assembly.py](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/devices/workstation/coin_cell_assembly/coin_cell_assembly.py) 的 CSV 改动与全流程追溯
|
||||||
|
|
||||||
|
在 `bioyond_cell_workstation.py` 的 `_submit_and_wait_orders` 最后阶段,提取 `prep_bottles`(配液瓶)和 `vial_bottles`(分液瓶)的条码并随 `mass_ratios` 数组一起下发给各下游工站(例如扣电组装站),实现跨站的全流程配方追溯。
|
||||||
|
|
||||||
|
并在扣电站生成的 `date_xxx.csv` 中,**替换并新增**了以下列:
|
||||||
|
- 移除了原有的 `formulation_order_code` 与合并的 `formulation_ratio` 列。
|
||||||
|
- 新增 `orderName` 导出
|
||||||
|
- 新增 `prep_bottle_barcode`(奔曜传递的配液瓶二维码)
|
||||||
|
- 新增 `vial_bottle_barcodes`(奔曜传递的分液瓶二维码,多瓶时存 JSON 数组)
|
||||||
|
- 新增 `target_mass_ratio` 理论目标质量比
|
||||||
|
- 新增 `real_mass_ratio` 实际称量真实质量比
|
||||||
|
|
||||||
|
*注意:这与操作人员在手套箱内扫码传入扣电站的 `electrolyte_code` 是单独记录的,方便做数据核对。*
|
||||||
|
|
||||||
|
## 向后兼容性
|
||||||
|
- `csv_export_path` 默认值为 `""`(空字符串),现有调用不受影响
|
||||||
|
- 新增的 `prep_bottles` 和 `vial_bottles` 字段为 `final_result` 和 `mass_ratios` 内部的新增附属字段,不破坏现有数据结构。
|
||||||
168
CHANGES_2026_03_24.md
Normal file
168
CHANGES_2026_03_24.md
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
# 变更说明 2026-03-24
|
||||||
|
|
||||||
|
## 问题背景
|
||||||
|
|
||||||
|
`BioyondElectrolyteDeck`(原 `BIOYOND_YB_Deck`)迁移后,前端物料未能正常上传/同步。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 修复内容
|
||||||
|
|
||||||
|
### 1. `unilabos/resources/bioyond/decks.py`
|
||||||
|
|
||||||
|
- 补回 `setup: bool = False` 参数及 `if setup: self.setup()` 逻辑,与旧版 `BIOYOND_YB_Deck` 保持一致
|
||||||
|
- 工厂函数 `bioyond_electrolyte_deck` 保留显式调用 `deck.setup()`,避免重复初始化
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 修复前(缺少 setup 参数,无法通过 setup=True 触发初始化)
|
||||||
|
def __init__(self, name, size_x, size_y, size_z, category):
|
||||||
|
super().__init__(...)
|
||||||
|
|
||||||
|
# 修复后
|
||||||
|
def __init__(self, name, size_x, size_y, size_z, category, setup: bool = False):
|
||||||
|
super().__init__(...)
|
||||||
|
if setup:
|
||||||
|
self.setup()
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2. `unilabos/resources/graphio.py`
|
||||||
|
|
||||||
|
- 修复 `resource_bioyond_to_plr` 中两处 `bottle.tracker.liquids` 直接赋值导致的崩溃
|
||||||
|
- `ResourceHolder`(如枪头盒的 TipSpot 槽位)没有 `tracker` 属性,直接访问会抛出 `AttributeError`,阻断整个 Bioyond 同步流程
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 修复前
|
||||||
|
bottle.tracker.liquids = [...]
|
||||||
|
|
||||||
|
# 修复后
|
||||||
|
if hasattr(bottle, 'tracker') and bottle.tracker is not None:
|
||||||
|
bottle.tracker.liquids = [...]
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3. `unilabos/app/main.py`
|
||||||
|
|
||||||
|
- 保留 `file_path is not None` 条件不变(已还原),并补充注释说明原因
|
||||||
|
- 该逻辑只在**本地文件模式**下有意义:本地 graph 文件只含设备结构,远端有已保存物料,merge 才能将两者合并
|
||||||
|
- 远端模式(`file_path=None`)下,`resource_tree_set` 和 `request_startup_json` 来自同一份数据,merge 为空操作,条件是否加 `file_path is not None` 对结果没有影响
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. `unilabos/devices/workstation/bioyond_studio/station.py` ⭐ 核心修复
|
||||||
|
|
||||||
|
- 当 deck 通过反序列化创建时,不会自动调用 `setup()`,导致 `deck.children` 为空,`warehouses` 始终是 `{}`
|
||||||
|
- 增加兜底逻辑:仓库扫描后仍为空,则主动调用 `deck.setup()` 初始化仓库
|
||||||
|
- 这是导致所有物料放置失败(`warehouse '...' 在deck中不存在。可用warehouses: []`)的根本原因
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 新增兜底
|
||||||
|
if not self.deck.warehouses and hasattr(self.deck, "setup") and callable(self.deck.setup):
|
||||||
|
logger.info("Deck 无仓库子节点,调用 setup() 初始化仓库")
|
||||||
|
self.deck.setup()
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 补充修复 2026-03-25:依华扣电组装工站子物料未上传
|
||||||
|
|
||||||
|
### 问题
|
||||||
|
|
||||||
|
`CoinCellAssemblyWorkstation.post_init` 直接上传空 deck,未调用 `deck.setup()`,导致:
|
||||||
|
- 前端子物料(成品弹夹、料盘、瓶架等)不显示
|
||||||
|
- 运行时 `self.deck.get_resource("成品弹夹")` 抛出 `ResourceNotFoundError`
|
||||||
|
|
||||||
|
### 修复文件
|
||||||
|
|
||||||
|
**`unilabos/devices/workstation/coin_cell_assembly/YB_YH_materials.py`**
|
||||||
|
- `YihuaCoinCellDeck.__init__` 补回 `setup: bool = False` 参数及 `if setup: self.setup()` 逻辑
|
||||||
|
|
||||||
|
**`unilabos/devices/workstation/coin_cell_assembly/coin_cell_assembly.py`**
|
||||||
|
- `post_init` 中增加与 Bioyond 工站相同的兜底逻辑:deck 无子节点时调用 `deck.setup()` 初始化
|
||||||
|
|
||||||
|
```python
|
||||||
|
# post_init 中新增
|
||||||
|
if self.deck and not self.deck.children and hasattr(self.deck, "setup") and callable(self.deck.setup):
|
||||||
|
logger.info("YihuaCoinCellDeck 无子节点,调用 setup() 初始化")
|
||||||
|
self.deck.setup()
|
||||||
|
```
|
||||||
|
|
||||||
|
### 联动 Bug:`MaterialPlate.create_with_holes` 构造顺序错误
|
||||||
|
|
||||||
|
**现象**:`deck.setup()` 被调用后,启动时抛出:
|
||||||
|
```
|
||||||
|
设备后初始化失败: Must specify either `ordered_items` or `ordering`.
|
||||||
|
```
|
||||||
|
|
||||||
|
**根因**:`create_with_holes` 原来的逻辑是先构造空的 `MaterialPlate` 实例,再 assign 洞位:
|
||||||
|
```python
|
||||||
|
# 旧(错误):cls(...) 时 ordered_items=None → ItemizedResource.__init__ 立即报错
|
||||||
|
plate = cls(name=name, ...) # ← 这里就崩了
|
||||||
|
holes = create_ordered_items_2d(...) # ← 根本没走到这里
|
||||||
|
for hole_name, hole in holes.items():
|
||||||
|
plate.assign_child_resource(...)
|
||||||
|
```
|
||||||
|
pylabrobot 的 `ItemizedResource.__init__` 强制要求 `ordered_items` 和 `ordering` 必须有一个不为 `None`,空构造直接失败。
|
||||||
|
|
||||||
|
**修复**:先建洞位,再作为 `ordered_items` 传给构造函数:
|
||||||
|
```python
|
||||||
|
# 新(正确):先建洞位,再一次性传入构造函数
|
||||||
|
holes = create_ordered_items_2d(klass=MaterialHole, num_items_x=4, ...)
|
||||||
|
return cls(name=name, ..., ordered_items=holes)
|
||||||
|
```
|
||||||
|
|
||||||
|
> 此 bug 此前未被触发,是因为 `deck.setup()` 从未被调用到——正是上面 `post_init` 兜底修复引出的联动问题。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 补充修复 2026-03-25:3→2→1 转运资源同步失败
|
||||||
|
|
||||||
|
### 问题
|
||||||
|
|
||||||
|
配液工站(Bioyond)完成分液后,调用 `transfer_3_to_2_to_1_auto` 将分液瓶板转运到扣电工站(BatteryStation)。物理 LIMS 转运成功,但数字孪生资源树同步始终失败:
|
||||||
|
```
|
||||||
|
[资源同步] ❌ 失败: 目标设备 'BatteryStation' 中未找到资源 'bottle_rack_6x2'
|
||||||
|
```
|
||||||
|
|
||||||
|
### 根因
|
||||||
|
|
||||||
|
`_get_resource_from_device` 方法负责跨设备查找资源对象,有两个问题:
|
||||||
|
|
||||||
|
1. **原始路径完全失效**:尝试 `from unilabos.app.ros2_app import get_device_plr_resource_by_name`,但该模块不存在,`ImportError` 被 `except Exception: pass` 静默吞掉
|
||||||
|
2. **降级路径搜错地方**:遍历 `self._plr_resources`(Bioyond 自己的资源),不可能找到 BatteryStation 的 `bottle_rack_6x2`
|
||||||
|
|
||||||
|
### 修复文件
|
||||||
|
|
||||||
|
**`unilabos/devices/workstation/bioyond_studio/bioyond_cell/bioyond_cell_workstation.py`**
|
||||||
|
|
||||||
|
改用全局设备注册表 `registered_devices` 跨设备访问目标 deck:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 修复前(失效)
|
||||||
|
from unilabos.app.ros2_app import get_device_plr_resource_by_name # 模块不存在
|
||||||
|
return get_device_plr_resource_by_name(device_id, resource_name)
|
||||||
|
|
||||||
|
# 修复后
|
||||||
|
from unilabos.ros.nodes.base_device_node import registered_devices
|
||||||
|
device_info = registered_devices.get(device_id)
|
||||||
|
if device_info is not None:
|
||||||
|
driver = device_info.get("driver_instance") # TypedDict 是 dict,必须用 .get()
|
||||||
|
if driver is not None:
|
||||||
|
deck = getattr(driver, "deck", None)
|
||||||
|
if deck is not None:
|
||||||
|
res = deck.get_resource(resource_name)
|
||||||
|
```
|
||||||
|
|
||||||
|
关键细节:`DeviceInfoType` 是 `TypedDict`(即普通 `dict`),必须用 `device_info.get("driver_instance")` 而非 `getattr(device_info, "driver_instance", None)`——后者对字典永远返回 `None`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 根本原因分析
|
||||||
|
|
||||||
|
旧版以**本地文件模式**启动(有 `graph` 文件),deck 在启动前已通过 `merge_remote_resources` 获得仓库子节点,反序列化时能正确恢复 warehouses。
|
||||||
|
|
||||||
|
新版以**远端模式**启动(`file_path=None`),deck 反序列化时没有仓库子节点,`station.py` 扫描为空,所有物料的 warehouse 匹配失败,Bioyond 同步的 16 个资源全部无法放置到对应仓库位,前端不显示。
|
||||||
@@ -12,7 +12,7 @@ Uni-Lab 使用 Python 格式的配置文件(`.py`),默认为 `unilabos_dat
|
|||||||
|
|
||||||
**获取方式:**
|
**获取方式:**
|
||||||
|
|
||||||
进入 [Uni-Lab 实验室](https://uni-lab.bohrium.com),点击左下角的头像,在实验室详情中获取所在实验室的 ak 和 sk:
|
进入 [Uni-Lab 实验室](https://leap-lab.bohrium.com),点击左下角的头像,在实验室详情中获取所在实验室的 ak 和 sk:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ class WSConfig:
|
|||||||
|
|
||||||
# HTTP配置
|
# HTTP配置
|
||||||
class HTTPConfig:
|
class HTTPConfig:
|
||||||
remote_addr = "https://uni-lab.bohrium.com/api/v1" # 远程服务器地址
|
remote_addr = "https://leap-lab.bohrium.com/api/v1" # 远程服务器地址
|
||||||
|
|
||||||
# ROS配置
|
# ROS配置
|
||||||
class ROSConfig:
|
class ROSConfig:
|
||||||
@@ -209,8 +209,8 @@ unilab --ak "key" --sk "secret" --addr "test" --upload_registry --2d_vis -g grap
|
|||||||
|
|
||||||
`--addr` 参数支持以下预设值,会自动转换为对应的完整 URL:
|
`--addr` 参数支持以下预设值,会自动转换为对应的完整 URL:
|
||||||
|
|
||||||
- `test` → `https://uni-lab.test.bohrium.com/api/v1`
|
- `test` → `https://leap-lab.test.bohrium.com/api/v1`
|
||||||
- `uat` → `https://uni-lab.uat.bohrium.com/api/v1`
|
- `uat` → `https://leap-lab.uat.bohrium.com/api/v1`
|
||||||
- `local` → `http://127.0.0.1:48197/api/v1`
|
- `local` → `http://127.0.0.1:48197/api/v1`
|
||||||
- 其他值 → 直接使用作为完整 URL
|
- 其他值 → 直接使用作为完整 URL
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ unilab --ak "key" --sk "secret" --addr "test" --upload_registry --2d_vis -g grap
|
|||||||
|
|
||||||
`ak` 和 `sk` 是必需的认证参数:
|
`ak` 和 `sk` 是必需的认证参数:
|
||||||
|
|
||||||
1. **获取方式**:在 [Uni-Lab 官网](https://uni-lab.bohrium.com) 注册实验室后获得
|
1. **获取方式**:在 [Uni-Lab 官网](https://leap-lab.bohrium.com) 注册实验室后获得
|
||||||
2. **配置方式**:
|
2. **配置方式**:
|
||||||
- **命令行参数**:`--ak "your_key" --sk "your_secret"`(最高优先级,推荐)
|
- **命令行参数**:`--ak "your_key" --sk "your_secret"`(最高优先级,推荐)
|
||||||
- **环境变量**:`UNILABOS_BASICCONFIG_AK` 和 `UNILABOS_BASICCONFIG_SK`
|
- **环境变量**:`UNILABOS_BASICCONFIG_AK` 和 `UNILABOS_BASICCONFIG_SK`
|
||||||
@@ -275,15 +275,15 @@ WebSocket 是 Uni-Lab 的主要通信方式:
|
|||||||
|
|
||||||
HTTP 客户端配置用于与云端服务通信:
|
HTTP 客户端配置用于与云端服务通信:
|
||||||
|
|
||||||
| 参数 | 类型 | 默认值 | 说明 |
|
| 参数 | 类型 | 默认值 | 说明 |
|
||||||
| ------------- | ---- | -------------------------------------- | ------------ |
|
| ------------- | ---- | --------------------------------------- | ------------ |
|
||||||
| `remote_addr` | str | `"https://uni-lab.bohrium.com/api/v1"` | 远程服务地址 |
|
| `remote_addr` | str | `"https://leap-lab.bohrium.com/api/v1"` | 远程服务地址 |
|
||||||
|
|
||||||
**预设环境地址**:
|
**预设环境地址**:
|
||||||
|
|
||||||
- 生产环境:`https://uni-lab.bohrium.com/api/v1`(默认)
|
- 生产环境:`https://leap-lab.bohrium.com/api/v1`(默认)
|
||||||
- 测试环境:`https://uni-lab.test.bohrium.com/api/v1`
|
- 测试环境:`https://leap-lab.test.bohrium.com/api/v1`
|
||||||
- UAT 环境:`https://uni-lab.uat.bohrium.com/api/v1`
|
- UAT 环境:`https://leap-lab.uat.bohrium.com/api/v1`
|
||||||
- 本地环境:`http://127.0.0.1:48197/api/v1`
|
- 本地环境:`http://127.0.0.1:48197/api/v1`
|
||||||
|
|
||||||
### 4. ROSConfig - ROS 配置
|
### 4. ROSConfig - ROS 配置
|
||||||
@@ -401,7 +401,7 @@ export UNILABOS_WSCONFIG_RECONNECT_INTERVAL="10"
|
|||||||
export UNILABOS_WSCONFIG_MAX_RECONNECT_ATTEMPTS="500"
|
export UNILABOS_WSCONFIG_MAX_RECONNECT_ATTEMPTS="500"
|
||||||
|
|
||||||
# 设置HTTP配置
|
# 设置HTTP配置
|
||||||
export UNILABOS_HTTPCONFIG_REMOTE_ADDR="https://uni-lab.test.bohrium.com/api/v1"
|
export UNILABOS_HTTPCONFIG_REMOTE_ADDR="https://leap-lab.test.bohrium.com/api/v1"
|
||||||
```
|
```
|
||||||
|
|
||||||
## 配置文件使用方法
|
## 配置文件使用方法
|
||||||
@@ -484,13 +484,13 @@ export UNILABOS_WSCONFIG_MAX_RECONNECT_ATTEMPTS=100
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
class HTTPConfig:
|
class HTTPConfig:
|
||||||
remote_addr = "https://uni-lab.test.bohrium.com/api/v1"
|
remote_addr = "https://leap-lab.test.bohrium.com/api/v1"
|
||||||
```
|
```
|
||||||
|
|
||||||
**环境变量方式:**
|
**环境变量方式:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
export UNILABOS_HTTPCONFIG_REMOTE_ADDR=https://uni-lab.test.bohrium.com/api/v1
|
export UNILABOS_HTTPCONFIG_REMOTE_ADDR=https://leap-lab.test.bohrium.com/api/v1
|
||||||
```
|
```
|
||||||
|
|
||||||
**命令行方式(推荐):**
|
**命令行方式(推荐):**
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ Uni-Lab-OS 支持多种部署模式:
|
|||||||
```
|
```
|
||||||
┌──────────────────────────────────────────────┐
|
┌──────────────────────────────────────────────┐
|
||||||
│ Cloud Platform/Self-hosted Platform │
|
│ Cloud Platform/Self-hosted Platform │
|
||||||
│ uni-lab.bohrium.com │
|
│ leap-lab.bohrium.com │
|
||||||
│ (Resource Management, Task Scheduling, │
|
│ (Resource Management, Task Scheduling, │
|
||||||
│ Monitoring) │
|
│ Monitoring) │
|
||||||
└────────────────────┬─────────────────────────┘
|
└────────────────────┬─────────────────────────┘
|
||||||
@@ -444,7 +444,7 @@ ros2 daemon stop && ros2 daemon start
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 测试云端连接
|
# 测试云端连接
|
||||||
curl https://uni-lab.bohrium.com/api/v1/health
|
curl https://leap-lab.bohrium.com/api/v1/health
|
||||||
|
|
||||||
# 测试WebSocket
|
# 测试WebSocket
|
||||||
# 启动Uni-Lab后查看日志
|
# 启动Uni-Lab后查看日志
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -33,11 +33,11 @@
|
|||||||
|
|
||||||
**选择合适的安装包:**
|
**选择合适的安装包:**
|
||||||
|
|
||||||
| 安装包 | 适用场景 | 包含组件 |
|
| 安装包 | 适用场景 | 包含组件 |
|
||||||
|--------|----------|----------|
|
| --------------- | ---------------------------- | --------------------------------------------- |
|
||||||
| `unilabos` | **推荐大多数用户**,生产部署 | 完整安装包,开箱即用 |
|
| `unilabos` | **推荐大多数用户**,生产部署 | 完整安装包,开箱即用 |
|
||||||
| `unilabos-env` | 开发者(可编辑安装) | 仅环境依赖,通过 pip 安装 unilabos |
|
| `unilabos-env` | 开发者(可编辑安装) | 仅环境依赖,通过 pip 安装 unilabos |
|
||||||
| `unilabos-full` | 仿真/可视化 | unilabos + 完整 ROS2 桌面版 + Gazebo + MoveIt |
|
| `unilabos-full` | 仿真/可视化 | unilabos + 完整 ROS2 桌面版 + Gazebo + MoveIt |
|
||||||
|
|
||||||
**关键步骤:**
|
**关键步骤:**
|
||||||
|
|
||||||
@@ -66,6 +66,7 @@ mamba install uni-lab::unilabos-full -c robostack-staging -c conda-forge
|
|||||||
```
|
```
|
||||||
|
|
||||||
**选择建议:**
|
**选择建议:**
|
||||||
|
|
||||||
- **日常使用/生产部署**:使用 `unilabos`(推荐),完整功能,开箱即用
|
- **日常使用/生产部署**:使用 `unilabos`(推荐),完整功能,开箱即用
|
||||||
- **开发者**:使用 `unilabos-env` + `pip install -e .` + `uv pip install -r unilabos/utils/requirements.txt`,代码修改立即生效
|
- **开发者**:使用 `unilabos-env` + `pip install -e .` + `uv pip install -r unilabos/utils/requirements.txt`,代码修改立即生效
|
||||||
- **仿真/可视化**:使用 `unilabos-full`,含 Gazebo、rviz2、MoveIt
|
- **仿真/可视化**:使用 `unilabos-full`,含 Gazebo、rviz2、MoveIt
|
||||||
@@ -88,7 +89,7 @@ python -c "from unilabos_msgs.msg import Resource; print('ROS msgs OK')"
|
|||||||
|
|
||||||
#### 2.1 注册实验室账号
|
#### 2.1 注册实验室账号
|
||||||
|
|
||||||
1. 访问 [https://uni-lab.bohrium.com](https://uni-lab.bohrium.com)
|
1. 访问 [https://leap-lab.bohrium.com](https://leap-lab.bohrium.com)
|
||||||
2. 注册账号并登录
|
2. 注册账号并登录
|
||||||
3. 创建新实验室
|
3. 创建新实验室
|
||||||
|
|
||||||
@@ -297,7 +298,7 @@ unilab --ak your_ak --sk your_sk -g test/experiments/mock_devices/mock_all.json
|
|||||||
|
|
||||||
#### 5.2 访问 Web 界面
|
#### 5.2 访问 Web 界面
|
||||||
|
|
||||||
启动系统后,访问[https://uni-lab.bohrium.com](https://uni-lab.bohrium.com)
|
启动系统后,访问[https://leap-lab.bohrium.com](https://leap-lab.bohrium.com)
|
||||||
|
|
||||||
#### 5.3 添加设备和物料
|
#### 5.3 添加设备和物料
|
||||||
|
|
||||||
@@ -306,12 +307,10 @@ unilab --ak your_ak --sk your_sk -g test/experiments/mock_devices/mock_all.json
|
|||||||
**示例场景:** 创建一个简单的液体转移实验
|
**示例场景:** 创建一个简单的液体转移实验
|
||||||
|
|
||||||
1. **添加工作站(必需):**
|
1. **添加工作站(必需):**
|
||||||
|
|
||||||
- 在"仪器设备"中找到 `work_station`
|
- 在"仪器设备"中找到 `work_station`
|
||||||
- 添加 `workstation` x1
|
- 添加 `workstation` x1
|
||||||
|
|
||||||
2. **添加虚拟转移泵:**
|
2. **添加虚拟转移泵:**
|
||||||
|
|
||||||
- 在"仪器设备"中找到 `virtual_device`
|
- 在"仪器设备"中找到 `virtual_device`
|
||||||
- 添加 `virtual_transfer_pump` x1
|
- 添加 `virtual_transfer_pump` x1
|
||||||
|
|
||||||
@@ -818,6 +817,7 @@ uv pip install -r unilabos/utils/requirements.txt
|
|||||||
```
|
```
|
||||||
|
|
||||||
**为什么使用这种方式?**
|
**为什么使用这种方式?**
|
||||||
|
|
||||||
- `unilabos-env` 提供 ROS2 核心组件和 uv(通过 conda 安装,避免编译)
|
- `unilabos-env` 提供 ROS2 核心组件和 uv(通过 conda 安装,避免编译)
|
||||||
- `unilabos/utils/requirements.txt` 包含所有运行时需要的 pip 依赖
|
- `unilabos/utils/requirements.txt` 包含所有运行时需要的 pip 依赖
|
||||||
- `dev_install.py` 自动检测中文环境,中文系统自动使用清华镜像
|
- `dev_install.py` 自动检测中文环境,中文系统自动使用清华镜像
|
||||||
@@ -1796,32 +1796,27 @@ unilab --ak your_ak --sk your_sk -g graph.json \
|
|||||||
**详细步骤:**
|
**详细步骤:**
|
||||||
|
|
||||||
1. **需求分析**:
|
1. **需求分析**:
|
||||||
|
|
||||||
- 明确实验流程
|
- 明确实验流程
|
||||||
- 列出所需设备和物料
|
- 列出所需设备和物料
|
||||||
- 设计工作流程图
|
- 设计工作流程图
|
||||||
|
|
||||||
2. **环境搭建**:
|
2. **环境搭建**:
|
||||||
|
|
||||||
- 安装 Uni-Lab-OS
|
- 安装 Uni-Lab-OS
|
||||||
- 创建实验室账号
|
- 创建实验室账号
|
||||||
- 准备开发工具(IDE、Git)
|
- 准备开发工具(IDE、Git)
|
||||||
|
|
||||||
3. **原型验证**:
|
3. **原型验证**:
|
||||||
|
|
||||||
- 使用虚拟设备测试流程
|
- 使用虚拟设备测试流程
|
||||||
- 验证工作流逻辑
|
- 验证工作流逻辑
|
||||||
- 调整参数
|
- 调整参数
|
||||||
|
|
||||||
4. **迭代开发**:
|
4. **迭代开发**:
|
||||||
|
|
||||||
- 实现自定义设备驱动(同时撰写单点函数测试)
|
- 实现自定义设备驱动(同时撰写单点函数测试)
|
||||||
- 编写注册表
|
- 编写注册表
|
||||||
- 单元测试
|
- 单元测试
|
||||||
- 集成测试
|
- 集成测试
|
||||||
|
|
||||||
5. **测试部署**:
|
5. **测试部署**:
|
||||||
|
|
||||||
- 连接真实硬件
|
- 连接真实硬件
|
||||||
- 空跑测试
|
- 空跑测试
|
||||||
- 小规模试验
|
- 小规模试验
|
||||||
@@ -1871,7 +1866,7 @@ unilab --ak your_ak --sk your_sk -g graph.json \
|
|||||||
#### 14.5 社区支持
|
#### 14.5 社区支持
|
||||||
|
|
||||||
- **GitHub Issues**:[https://github.com/deepmodeling/Uni-Lab-OS/issues](https://github.com/deepmodeling/Uni-Lab-OS/issues)
|
- **GitHub Issues**:[https://github.com/deepmodeling/Uni-Lab-OS/issues](https://github.com/deepmodeling/Uni-Lab-OS/issues)
|
||||||
- **官方网站**:[https://uni-lab.bohrium.com](https://uni-lab.bohrium.com)
|
- **官方网站**:[https://leap-lab.bohrium.com](https://leap-lab.bohrium.com)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -626,7 +626,7 @@ unilab
|
|||||||
|
|
||||||
**云端图文件管理**:
|
**云端图文件管理**:
|
||||||
|
|
||||||
1. 登录 https://uni-lab.bohrium.com
|
1. 登录 https://leap-lab.bohrium.com
|
||||||
2. 进入"设备配置"
|
2. 进入"设备配置"
|
||||||
3. 创建或编辑配置
|
3. 创建或编辑配置
|
||||||
4. 保存到云端
|
4. 保存到云端
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ Uni-Lab 的启动过程分为以下几个阶段:
|
|||||||
您可以直接跟随 unilabos 的提示进行,无需查阅本节
|
您可以直接跟随 unilabos 的提示进行,无需查阅本节
|
||||||
|
|
||||||
- **工作目录设置**:
|
- **工作目录设置**:
|
||||||
|
|
||||||
- 如果当前目录以 `unilabos_data` 结尾,则使用当前目录
|
- 如果当前目录以 `unilabos_data` 结尾,则使用当前目录
|
||||||
- 否则使用 `当前目录/unilabos_data` 作为工作目录
|
- 否则使用 `当前目录/unilabos_data` 作为工作目录
|
||||||
- 可通过 `--working_dir` 指定自定义工作目录
|
- 可通过 `--working_dir` 指定自定义工作目录
|
||||||
@@ -68,8 +67,8 @@ Uni-Lab 的启动过程分为以下几个阶段:
|
|||||||
|
|
||||||
支持多种后端环境:
|
支持多种后端环境:
|
||||||
|
|
||||||
- `--addr test`:测试环境 (`https://uni-lab.test.bohrium.com/api/v1`)
|
- `--addr test`:测试环境 (`https://leap-lab.test.bohrium.com/api/v1`)
|
||||||
- `--addr uat`:UAT 环境 (`https://uni-lab.uat.bohrium.com/api/v1`)
|
- `--addr uat`:UAT 环境 (`https://leap-lab.uat.bohrium.com/api/v1`)
|
||||||
- `--addr local`:本地环境 (`http://127.0.0.1:48197/api/v1`)
|
- `--addr local`:本地环境 (`http://127.0.0.1:48197/api/v1`)
|
||||||
- 自定义地址:直接指定完整 URL
|
- 自定义地址:直接指定完整 URL
|
||||||
|
|
||||||
@@ -176,7 +175,7 @@ unilab --config path/to/your/config.py
|
|||||||
|
|
||||||
如果是首次使用,系统会:
|
如果是首次使用,系统会:
|
||||||
|
|
||||||
1. 提示前往 https://uni-lab.bohrium.com 注册实验室
|
1. 提示前往 https://leap-lab.bohrium.com 注册实验室
|
||||||
2. 引导创建配置文件
|
2. 引导创建配置文件
|
||||||
3. 设置工作目录
|
3. 设置工作目录
|
||||||
|
|
||||||
@@ -216,7 +215,7 @@ unilab --ak your_ak --sk your_sk --port 8080 --disable_browser
|
|||||||
|
|
||||||
如果提示 "后续运行必须拥有一个实验室",请确保:
|
如果提示 "后续运行必须拥有一个实验室",请确保:
|
||||||
|
|
||||||
- 已在 https://uni-lab.bohrium.com 注册实验室
|
- 已在 https://leap-lab.bohrium.com 注册实验室
|
||||||
- 正确设置了 `--ak` 和 `--sk` 参数
|
- 正确设置了 `--ak` 和 `--sk` 参数
|
||||||
- 配置文件中包含正确的认证信息
|
- 配置文件中包含正确的认证信息
|
||||||
|
|
||||||
|
|||||||
@@ -1,539 +0,0 @@
|
|||||||
import pytest
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import asyncio
|
|
||||||
import collections
|
|
||||||
from typing import List, Dict, Any
|
|
||||||
|
|
||||||
from pylabrobot.resources import Coordinate
|
|
||||||
from pylabrobot.resources.opentrons.tip_racks import opentrons_96_tiprack_300ul, opentrons_96_tiprack_10ul
|
|
||||||
from pylabrobot.resources.opentrons.plates import corning_96_wellplate_360ul_flat, nest_96_wellplate_2ml_deep
|
|
||||||
|
|
||||||
from unilabos.devices.liquid_handling.prcxi.prcxi import (
|
|
||||||
PRCXI9300Deck,
|
|
||||||
PRCXI9300Container,
|
|
||||||
PRCXI9300Trash,
|
|
||||||
PRCXI9300Handler,
|
|
||||||
PRCXI9300Backend,
|
|
||||||
DefaultLayout,
|
|
||||||
Material,
|
|
||||||
WorkTablets,
|
|
||||||
MatrixInfo
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def prcxi_materials() -> Dict[str, Any]:
|
|
||||||
"""加载 PRCXI 物料数据"""
|
|
||||||
print("加载 PRCXI 物料数据...")
|
|
||||||
material_path = os.path.join(os.path.dirname(__file__), "..", "..", "unilabos", "devices", "liquid_handling", "prcxi", "prcxi_material.json")
|
|
||||||
with open(material_path, "r", encoding="utf-8") as f:
|
|
||||||
data = json.load(f)
|
|
||||||
print(f"加载了 {len(data)} 条物料数据")
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def prcxi_9300_deck() -> PRCXI9300Deck:
|
|
||||||
"""创建 PRCXI 9300 工作台"""
|
|
||||||
return PRCXI9300Deck(name="PRCXI_Deck_9300", size_x=100, size_y=100, size_z=100, model="9300")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def prcxi_9320_deck() -> PRCXI9300Deck:
|
|
||||||
"""创建 PRCXI 9320 工作台"""
|
|
||||||
return PRCXI9300Deck(name="PRCXI_Deck_9320", size_x=100, size_y=100, size_z=100, model="9320")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def prcxi_9300_handler(prcxi_9300_deck) -> PRCXI9300Handler:
|
|
||||||
"""创建 PRCXI 9300 处理器(模拟模式)"""
|
|
||||||
return PRCXI9300Handler(
|
|
||||||
deck=prcxi_9300_deck,
|
|
||||||
host="192.168.1.201",
|
|
||||||
port=9999,
|
|
||||||
timeout=10.0,
|
|
||||||
channel_num=8,
|
|
||||||
axis="Left",
|
|
||||||
setup=False,
|
|
||||||
debug=True,
|
|
||||||
simulator=True,
|
|
||||||
matrix_id="test-matrix-9300"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def prcxi_9320_handler(prcxi_9320_deck) -> PRCXI9300Handler:
|
|
||||||
"""创建 PRCXI 9320 处理器(模拟模式)"""
|
|
||||||
return PRCXI9300Handler(
|
|
||||||
deck=prcxi_9320_deck,
|
|
||||||
host="192.168.1.201",
|
|
||||||
port=9999,
|
|
||||||
timeout=10.0,
|
|
||||||
channel_num=1,
|
|
||||||
axis="Right",
|
|
||||||
setup=False,
|
|
||||||
debug=True,
|
|
||||||
simulator=True,
|
|
||||||
matrix_id="test-matrix-9320",
|
|
||||||
is_9320=True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def tip_rack_300ul(prcxi_materials) -> PRCXI9300Container:
|
|
||||||
"""创建 300μL 枪头盒"""
|
|
||||||
tip_rack = PRCXI9300Container(
|
|
||||||
name="tip_rack_300ul",
|
|
||||||
size_x=50,
|
|
||||||
size_y=50,
|
|
||||||
size_z=10,
|
|
||||||
category="tip_rack",
|
|
||||||
ordering=collections.OrderedDict()
|
|
||||||
)
|
|
||||||
tip_rack.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["300μL Tip头"]["uuid"],
|
|
||||||
"Code": "ZX-001-300",
|
|
||||||
"Name": "300μL Tip头"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return tip_rack
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def tip_rack_10ul(prcxi_materials) -> PRCXI9300Container:
|
|
||||||
"""创建 10μL 枪头盒"""
|
|
||||||
tip_rack = PRCXI9300Container(
|
|
||||||
name="tip_rack_10ul",
|
|
||||||
size_x=50,
|
|
||||||
size_y=50,
|
|
||||||
size_z=10,
|
|
||||||
category="tip_rack",
|
|
||||||
ordering=collections.OrderedDict()
|
|
||||||
)
|
|
||||||
tip_rack.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["10μL加长 Tip头"]["uuid"],
|
|
||||||
"Code": "ZX-001-10+",
|
|
||||||
"Name": "10μL加长 Tip头"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return tip_rack
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def well_plate_96(prcxi_materials) -> PRCXI9300Container:
|
|
||||||
"""创建 96 孔板"""
|
|
||||||
plate = PRCXI9300Container(
|
|
||||||
name="well_plate_96",
|
|
||||||
size_x=50,
|
|
||||||
size_y=50,
|
|
||||||
size_z=10,
|
|
||||||
category="plate",
|
|
||||||
ordering=collections.OrderedDict()
|
|
||||||
)
|
|
||||||
plate.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["96深孔板"]["uuid"],
|
|
||||||
"Code": "ZX-019-2.2",
|
|
||||||
"Name": "96深孔板"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return plate
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def deep_well_plate(prcxi_materials) -> PRCXI9300Container:
|
|
||||||
"""创建深孔板"""
|
|
||||||
plate = PRCXI9300Container(
|
|
||||||
name="deep_well_plate",
|
|
||||||
size_x=50,
|
|
||||||
size_y=50,
|
|
||||||
size_z=10,
|
|
||||||
category="plate",
|
|
||||||
ordering=collections.OrderedDict()
|
|
||||||
)
|
|
||||||
plate.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["96深孔板"]["uuid"],
|
|
||||||
"Code": "ZX-019-2.2",
|
|
||||||
"Name": "96深孔板"
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return plate
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def trash_container(prcxi_materials) -> PRCXI9300Trash:
|
|
||||||
"""创建垃圾桶"""
|
|
||||||
trash = PRCXI9300Trash(name="trash", size_x=50, size_y=50, size_z=10, category="trash")
|
|
||||||
trash.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["废弃槽"]["uuid"]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return trash
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def default_layout_9300() -> DefaultLayout:
|
|
||||||
"""创建 PRCXI 9300 默认布局"""
|
|
||||||
return DefaultLayout("PRCXI9300")
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def default_layout_9320() -> DefaultLayout:
|
|
||||||
"""创建 PRCXI 9320 默认布局"""
|
|
||||||
return DefaultLayout("PRCXI9320")
|
|
||||||
|
|
||||||
|
|
||||||
class TestPRCXIDeckSetup:
|
|
||||||
"""测试 PRCXI 工作台设置功能"""
|
|
||||||
|
|
||||||
def test_prcxi_9300_deck_creation(self, prcxi_9300_deck):
|
|
||||||
"""测试 PRCXI 9300 工作台创建"""
|
|
||||||
assert prcxi_9300_deck.name == "PRCXI_Deck_9300"
|
|
||||||
assert len(prcxi_9300_deck.sites) == 6
|
|
||||||
assert prcxi_9300_deck._size_x == 100
|
|
||||||
assert prcxi_9300_deck._size_y == 100
|
|
||||||
assert prcxi_9300_deck._size_z == 100
|
|
||||||
|
|
||||||
def test_prcxi_9320_deck_creation(self, prcxi_9320_deck):
|
|
||||||
"""测试 PRCXI 9320 工作台创建"""
|
|
||||||
assert prcxi_9320_deck.name == "PRCXI_Deck_9320"
|
|
||||||
assert len(prcxi_9320_deck.sites) == 16
|
|
||||||
assert prcxi_9320_deck._size_x == 100
|
|
||||||
assert prcxi_9320_deck._size_y == 100
|
|
||||||
assert prcxi_9320_deck._size_z == 100
|
|
||||||
|
|
||||||
def test_container_assignment(self, prcxi_9300_deck, tip_rack_300ul, well_plate_96, trash_container):
|
|
||||||
"""测试容器分配到工作台"""
|
|
||||||
# 分配枪头盒
|
|
||||||
prcxi_9300_deck.assign_child_resource(tip_rack_300ul, location=Coordinate(0, 0, 0))
|
|
||||||
assert tip_rack_300ul in prcxi_9300_deck.children
|
|
||||||
|
|
||||||
# 分配孔板
|
|
||||||
prcxi_9300_deck.assign_child_resource(well_plate_96, location=Coordinate(0, 0, 0))
|
|
||||||
assert well_plate_96 in prcxi_9300_deck.children
|
|
||||||
|
|
||||||
# 分配垃圾桶
|
|
||||||
prcxi_9300_deck.assign_child_resource(trash_container, location=Coordinate(0, 0, 0))
|
|
||||||
assert trash_container in prcxi_9300_deck.children
|
|
||||||
|
|
||||||
def test_container_material_loading(self, tip_rack_300ul, well_plate_96, prcxi_materials):
|
|
||||||
"""测试容器物料信息加载"""
|
|
||||||
# 测试枪头盒物料信息
|
|
||||||
tip_material = tip_rack_300ul._unilabos_state["Material"]
|
|
||||||
assert tip_material["uuid"] == prcxi_materials["300μL Tip头"]["uuid"]
|
|
||||||
assert tip_material["Name"] == "300μL Tip头"
|
|
||||||
|
|
||||||
# 测试孔板物料信息
|
|
||||||
plate_material = well_plate_96._unilabos_state["Material"]
|
|
||||||
assert plate_material["uuid"] == prcxi_materials["96深孔板"]["uuid"]
|
|
||||||
assert plate_material["Name"] == "96深孔板"
|
|
||||||
|
|
||||||
|
|
||||||
class TestPRCXISingleStepOperations:
|
|
||||||
"""测试 PRCXI 单步操作功能"""
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_pick_up_tips_single_channel(self, prcxi_9320_handler, prcxi_9320_deck, tip_rack_10ul):
|
|
||||||
"""测试单通道拾取枪头"""
|
|
||||||
# 将枪头盒添加到工作台
|
|
||||||
prcxi_9320_deck.assign_child_resource(tip_rack_10ul, location=Coordinate(0, 0, 0))
|
|
||||||
|
|
||||||
# 初始化处理器
|
|
||||||
await prcxi_9320_handler.setup()
|
|
||||||
|
|
||||||
# 设置枪头盒
|
|
||||||
prcxi_9320_handler.set_tiprack([tip_rack_10ul])
|
|
||||||
|
|
||||||
# 创建模拟的枪头位置
|
|
||||||
from pylabrobot.resources import TipSpot, Tip
|
|
||||||
tip = Tip(has_filter=False, total_tip_length=10, maximal_volume=10, fitting_depth=5)
|
|
||||||
tip_spot = TipSpot("A1", size_x=1, size_y=1, size_z=1, make_tip=lambda: tip)
|
|
||||||
tip_rack_10ul.assign_child_resource(tip_spot, location=Coordinate(0, 0, 0))
|
|
||||||
|
|
||||||
# 直接测试后端方法
|
|
||||||
from pylabrobot.liquid_handling import Pickup
|
|
||||||
pickup = Pickup(resource=tip_spot, offset=None, tip=tip)
|
|
||||||
await prcxi_9320_handler._unilabos_backend.pick_up_tips([pickup], [0])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "Load"
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_pick_up_tips_multi_channel(self, prcxi_9300_handler, tip_rack_300ul):
|
|
||||||
"""测试多通道拾取枪头"""
|
|
||||||
# 设置枪头盒
|
|
||||||
prcxi_9300_handler.set_tiprack([tip_rack_300ul])
|
|
||||||
|
|
||||||
# 拾取8个枪头
|
|
||||||
tip_spots = tip_rack_300ul.children[:8]
|
|
||||||
await prcxi_9300_handler.pick_up_tips(tip_spots, [0, 1, 2, 3, 4, 5, 6, 7])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9300_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9300_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "Load"
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_aspirate_single_channel(self, prcxi_9320_handler, well_plate_96):
|
|
||||||
"""测试单通道吸取液体"""
|
|
||||||
# 设置液体
|
|
||||||
well = well_plate_96.get_item("A1")
|
|
||||||
prcxi_9320_handler.set_liquid([well], ["water"], [50])
|
|
||||||
|
|
||||||
# 吸取液体
|
|
||||||
await prcxi_9320_handler.aspirate([well], [50], [0])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "Imbibing"
|
|
||||||
assert step["DosageNum"] == 50
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_dispense_single_channel(self, prcxi_9320_handler, well_plate_96):
|
|
||||||
"""测试单通道分配液体"""
|
|
||||||
# 分配液体
|
|
||||||
well = well_plate_96.get_item("A1")
|
|
||||||
await prcxi_9320_handler.dispense([well], [25], [0])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "Tapping"
|
|
||||||
assert step["DosageNum"] == 25
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_mix_single_channel(self, prcxi_9320_handler, well_plate_96):
|
|
||||||
"""测试单通道混合液体"""
|
|
||||||
# 混合液体
|
|
||||||
well = well_plate_96.get_item("A1")
|
|
||||||
await prcxi_9320_handler.mix([well], mix_time=3, mix_vol=50)
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "Blending"
|
|
||||||
assert step["BlendingTimes"] == 3
|
|
||||||
assert step["DosageNum"] == 50
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_drop_tips_to_trash(self, prcxi_9320_handler, trash_container):
|
|
||||||
"""测试丢弃枪头到垃圾桶"""
|
|
||||||
# 丢弃枪头
|
|
||||||
await prcxi_9320_handler.drop_tips([trash_container], [0])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "UnLoad"
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_discard_tips(self, prcxi_9320_handler):
|
|
||||||
"""测试丢弃枪头"""
|
|
||||||
# 丢弃枪头
|
|
||||||
await prcxi_9320_handler.discard_tips([0])
|
|
||||||
|
|
||||||
# 验证步骤已添加到待办列表
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 1
|
|
||||||
step = prcxi_9320_handler._unilabos_backend.steps_todo_list[0]
|
|
||||||
assert step["Function"] == "UnLoad"
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_liquid_transfer_workflow(self, prcxi_9320_handler, tip_rack_10ul, well_plate_96):
|
|
||||||
"""测试完整的液体转移工作流程"""
|
|
||||||
# 设置枪头盒和液体
|
|
||||||
prcxi_9320_handler.set_tiprack([tip_rack_10ul])
|
|
||||||
source_well = well_plate_96.get_item("A1")
|
|
||||||
target_well = well_plate_96.get_item("B1")
|
|
||||||
prcxi_9320_handler.set_liquid([source_well], ["water"], [100])
|
|
||||||
|
|
||||||
# 创建协议
|
|
||||||
await prcxi_9320_handler.create_protocol(protocol_name="Test Transfer Protocol")
|
|
||||||
|
|
||||||
# 执行转移流程
|
|
||||||
tip_spot = tip_rack_10ul.get_item("A1")
|
|
||||||
await prcxi_9320_handler.pick_up_tips([tip_spot], [0])
|
|
||||||
await prcxi_9320_handler.aspirate([source_well], [50], [0])
|
|
||||||
await prcxi_9320_handler.dispense([target_well], [50], [0])
|
|
||||||
await prcxi_9320_handler.discard_tips([0])
|
|
||||||
|
|
||||||
# 验证所有步骤都已添加
|
|
||||||
assert len(prcxi_9320_handler._unilabos_backend.steps_todo_list) == 4
|
|
||||||
functions = [step["Function"] for step in prcxi_9320_handler._unilabos_backend.steps_todo_list]
|
|
||||||
assert functions == ["Load", "Imbibing", "Tapping", "UnLoad"]
|
|
||||||
|
|
||||||
|
|
||||||
class TestPRCXILayoutRecommendation:
|
|
||||||
"""测试 PRCXI 板位推荐功能"""
|
|
||||||
|
|
||||||
def test_9300_layout_creation(self, default_layout_9300):
|
|
||||||
"""测试 PRCXI 9300 布局创建"""
|
|
||||||
layout_info = default_layout_9300.get_layout()
|
|
||||||
assert layout_info["rows"] == 2
|
|
||||||
assert layout_info["columns"] == 3
|
|
||||||
assert len(layout_info["layout"]) == 6
|
|
||||||
assert layout_info["trash_slot"] == 6
|
|
||||||
assert "waste_liquid_slot" not in layout_info
|
|
||||||
|
|
||||||
def test_9320_layout_creation(self, default_layout_9320):
|
|
||||||
"""测试 PRCXI 9320 布局创建"""
|
|
||||||
layout_info = default_layout_9320.get_layout()
|
|
||||||
assert layout_info["rows"] == 4
|
|
||||||
assert layout_info["columns"] == 4
|
|
||||||
assert len(layout_info["layout"]) == 16
|
|
||||||
assert layout_info["trash_slot"] == 16
|
|
||||||
assert layout_info["waste_liquid_slot"] == 12
|
|
||||||
|
|
||||||
def test_layout_recommendation_9320(self, default_layout_9320, prcxi_materials):
|
|
||||||
"""测试 PRCXI 9320 板位推荐功能"""
|
|
||||||
# 添加物料信息
|
|
||||||
default_layout_9320.add_lab_resource(prcxi_materials)
|
|
||||||
|
|
||||||
# 推荐布局
|
|
||||||
needs = [
|
|
||||||
("reagent_1", "96 细胞培养皿", 3),
|
|
||||||
("reagent_2", "12道储液槽", 1),
|
|
||||||
("reagent_3", "200μL Tip头", 7),
|
|
||||||
("reagent_4", "10μL加长 Tip头", 1),
|
|
||||||
]
|
|
||||||
|
|
||||||
matrix_layout, layout_list = default_layout_9320.recommend_layout(needs)
|
|
||||||
|
|
||||||
# 验证返回结果
|
|
||||||
assert "MatrixId" in matrix_layout
|
|
||||||
assert "MatrixName" in matrix_layout
|
|
||||||
assert "MatrixCount" in matrix_layout
|
|
||||||
assert "WorkTablets" in matrix_layout
|
|
||||||
assert len(layout_list) == 12 # 3+1+7+1 = 12个位置
|
|
||||||
|
|
||||||
# 验证推荐的位置不包含预留位置
|
|
||||||
reserved_positions = {12, 16}
|
|
||||||
recommended_positions = [item["positions"] for item in layout_list]
|
|
||||||
for pos in recommended_positions:
|
|
||||||
assert pos not in reserved_positions
|
|
||||||
|
|
||||||
def test_layout_recommendation_insufficient_space(self, default_layout_9320, prcxi_materials):
|
|
||||||
"""测试板位推荐空间不足的情况"""
|
|
||||||
# 添加物料信息
|
|
||||||
default_layout_9320.add_lab_resource(prcxi_materials)
|
|
||||||
|
|
||||||
# 尝试推荐超过可用空间的布局
|
|
||||||
needs = [
|
|
||||||
("reagent_1", "96 细胞培养皿", 15), # 需要15个位置,但只有14个可用
|
|
||||||
]
|
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="需要 .* 个位置,但只有 .* 个可用位置"):
|
|
||||||
default_layout_9320.recommend_layout(needs)
|
|
||||||
|
|
||||||
def test_layout_recommendation_material_not_found(self, default_layout_9320, prcxi_materials):
|
|
||||||
"""测试板位推荐物料不存在的情况"""
|
|
||||||
# 添加物料信息
|
|
||||||
default_layout_9320.add_lab_resource(prcxi_materials)
|
|
||||||
|
|
||||||
# 尝试推荐不存在的物料
|
|
||||||
needs = [
|
|
||||||
("reagent_1", "不存在的物料", 1),
|
|
||||||
]
|
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="Material .* not found in lab resources"):
|
|
||||||
default_layout_9320.recommend_layout(needs)
|
|
||||||
|
|
||||||
|
|
||||||
class TestPRCXIBackendOperations:
|
|
||||||
"""测试 PRCXI 后端操作功能"""
|
|
||||||
|
|
||||||
def test_backend_initialization(self, prcxi_9300_handler):
|
|
||||||
"""测试后端初始化"""
|
|
||||||
backend = prcxi_9300_handler._unilabos_backend
|
|
||||||
assert isinstance(backend, PRCXI9300Backend)
|
|
||||||
assert backend._num_channels == 8
|
|
||||||
assert backend.debug is True
|
|
||||||
|
|
||||||
def test_protocol_creation(self, prcxi_9300_handler):
|
|
||||||
"""测试协议创建"""
|
|
||||||
backend = prcxi_9300_handler._unilabos_backend
|
|
||||||
backend.create_protocol("Test Protocol")
|
|
||||||
assert backend.protocol_name == "Test Protocol"
|
|
||||||
assert len(backend.steps_todo_list) == 0
|
|
||||||
|
|
||||||
def test_channel_validation(self):
|
|
||||||
"""测试通道验证"""
|
|
||||||
# 测试正确的8通道配置
|
|
||||||
valid_channels = [0, 1, 2, 3, 4, 5, 6, 7]
|
|
||||||
result = PRCXI9300Backend.check_channels(valid_channels)
|
|
||||||
assert result == valid_channels
|
|
||||||
|
|
||||||
# 测试错误的通道配置
|
|
||||||
invalid_channels = [0, 1, 2, 3]
|
|
||||||
result = PRCXI9300Backend.check_channels(invalid_channels)
|
|
||||||
assert result == [0, 1, 2, 3, 4, 5, 6, 7]
|
|
||||||
|
|
||||||
def test_matrix_info_creation(self, prcxi_9300_handler):
|
|
||||||
"""测试矩阵信息创建"""
|
|
||||||
backend = prcxi_9300_handler._unilabos_backend
|
|
||||||
backend.create_protocol("Test Protocol")
|
|
||||||
|
|
||||||
# 模拟运行协议时的矩阵信息创建
|
|
||||||
run_time = 1234567890
|
|
||||||
matrix_info = MatrixInfo(
|
|
||||||
MatrixId=f"{int(run_time)}",
|
|
||||||
MatrixName=f"protocol_{run_time}",
|
|
||||||
MatrixCount=len(backend.tablets_info),
|
|
||||||
WorkTablets=backend.tablets_info,
|
|
||||||
)
|
|
||||||
|
|
||||||
assert matrix_info["MatrixId"] == str(int(run_time))
|
|
||||||
assert matrix_info["MatrixName"] == f"protocol_{run_time}"
|
|
||||||
assert "WorkTablets" in matrix_info
|
|
||||||
|
|
||||||
|
|
||||||
class TestPRCXIContainerOperations:
|
|
||||||
"""测试 PRCXI 容器操作功能"""
|
|
||||||
|
|
||||||
def test_container_serialization(self, tip_rack_300ul):
|
|
||||||
"""测试容器序列化"""
|
|
||||||
serialized = tip_rack_300ul.serialize_state()
|
|
||||||
assert "Material" in serialized
|
|
||||||
assert serialized["Material"]["Name"] == "300μL Tip头"
|
|
||||||
|
|
||||||
def test_container_deserialization(self, tip_rack_300ul):
|
|
||||||
"""测试容器反序列化"""
|
|
||||||
# 序列化
|
|
||||||
serialized = tip_rack_300ul.serialize_state()
|
|
||||||
|
|
||||||
# 创建新容器并反序列化
|
|
||||||
new_tip_rack = PRCXI9300Container(
|
|
||||||
name="new_tip_rack",
|
|
||||||
size_x=50,
|
|
||||||
size_y=50,
|
|
||||||
size_z=10,
|
|
||||||
category="tip_rack",
|
|
||||||
ordering=collections.OrderedDict()
|
|
||||||
)
|
|
||||||
new_tip_rack.load_state(serialized)
|
|
||||||
|
|
||||||
assert new_tip_rack._unilabos_state["Material"]["Name"] == "300μL Tip头"
|
|
||||||
|
|
||||||
def test_trash_container_creation(self, prcxi_materials):
|
|
||||||
"""测试垃圾桶容器创建"""
|
|
||||||
trash = PRCXI9300Trash(name="trash", size_x=50, size_y=50, size_z=10, category="trash")
|
|
||||||
trash.load_state({
|
|
||||||
"Material": {
|
|
||||||
"uuid": prcxi_materials["废弃槽"]["uuid"]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
assert trash.name == "trash"
|
|
||||||
assert trash._unilabos_state["Material"]["uuid"] == prcxi_materials["废弃槽"]["uuid"]
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
# 运行测试
|
|
||||||
pytest.main([__file__, "-v"])
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# Liquid handling 集成测试
|
|
||||||
|
|
||||||
`test_transfer_liquid.py` 现在会调用 PRCXI 的 RViz 仿真 backend,运行前请确保:
|
|
||||||
|
|
||||||
1. 已安装包含 `pylabrobot`、`rclpy` 的运行环境;
|
|
||||||
2. 启动 ROS 依赖(`rviz` 可选,但是 `rviz_backend` 会创建 ROS 节点);
|
|
||||||
3. 在 shell 中设置 `UNILAB_SIM_TEST=1`,否则 pytest 会自动跳过这些慢速用例:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
export UNILAB_SIM_TEST=1
|
|
||||||
pytest tests/devices/liquid_handling/test_transfer_liquid.py -m slow
|
|
||||||
```
|
|
||||||
|
|
||||||
如果只需验证逻辑层(不依赖仿真),可以直接运行 `tests/devices/liquid_handling/unit_test.py`,该文件使用 Fake backend,适合作为 CI 的快速测试。***
|
|
||||||
|
|
||||||
@@ -39,11 +39,6 @@ class FakeLiquidHandler(LiquidHandlerAbstract):
|
|||||||
self.current_tip = iter(make_tip_iter())
|
self.current_tip = iter(make_tip_iter())
|
||||||
self.calls: List[Tuple[str, Any]] = []
|
self.calls: List[Tuple[str, Any]] = []
|
||||||
|
|
||||||
def set_tiprack(self, tip_racks):
|
|
||||||
if not tip_racks:
|
|
||||||
return
|
|
||||||
super().set_tiprack(tip_racks)
|
|
||||||
|
|
||||||
async def pick_up_tips(self, tip_spots, use_channels=None, offsets=None, **backend_kwargs):
|
async def pick_up_tips(self, tip_spots, use_channels=None, offsets=None, **backend_kwargs):
|
||||||
self.calls.append(("pick_up_tips", {"tips": list(tip_spots), "use_channels": use_channels}))
|
self.calls.append(("pick_up_tips", {"tips": list(tip_spots), "use_channels": use_channels}))
|
||||||
|
|
||||||
|
|||||||
@@ -1,608 +0,0 @@
|
|||||||
import asyncio
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from typing import Any, Iterable, List, Optional, Sequence, Tuple
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from unilabos.devices.liquid_handling.liquid_handler_abstract import LiquidHandlerAbstract
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class DummyContainer:
|
|
||||||
name: str
|
|
||||||
|
|
||||||
def __repr__(self) -> str: # pragma: no cover
|
|
||||||
return f"DummyContainer({self.name})"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class DummyTipSpot:
|
|
||||||
name: str
|
|
||||||
|
|
||||||
def __repr__(self) -> str: # pragma: no cover
|
|
||||||
return f"DummyTipSpot({self.name})"
|
|
||||||
|
|
||||||
|
|
||||||
def make_tip_iter(n: int = 256) -> Iterable[List[DummyTipSpot]]:
|
|
||||||
"""Yield lists so code can safely call `tip.extend(next(self.current_tip))`."""
|
|
||||||
for i in range(n):
|
|
||||||
yield [DummyTipSpot(f"tip_{i}")]
|
|
||||||
|
|
||||||
|
|
||||||
class FakeLiquidHandler(LiquidHandlerAbstract):
|
|
||||||
"""不初始化真实 backend/deck;仅用来记录 transfer_liquid 内部调用序列。"""
|
|
||||||
|
|
||||||
def __init__(self, channel_num: int = 8):
|
|
||||||
# 不调用 super().__init__,避免真实硬件/后端依赖
|
|
||||||
self.channel_num = channel_num
|
|
||||||
self.support_touch_tip = True
|
|
||||||
self.current_tip = iter(make_tip_iter())
|
|
||||||
self.calls: List[Tuple[str, Any]] = []
|
|
||||||
|
|
||||||
def set_tiprack(self, tip_racks):
|
|
||||||
# transfer_liquid 总会调用 set_tiprack;测试用 Dummy 枪头时 tip_racks 为空,需保留自种子的 current_tip
|
|
||||||
if not tip_racks:
|
|
||||||
return
|
|
||||||
super().set_tiprack(tip_racks)
|
|
||||||
|
|
||||||
async def pick_up_tips(self, tip_spots, use_channels=None, offsets=None, **backend_kwargs):
|
|
||||||
self.calls.append(("pick_up_tips", {"tips": list(tip_spots), "use_channels": use_channels}))
|
|
||||||
|
|
||||||
async def aspirate(
|
|
||||||
self,
|
|
||||||
resources: Sequence[Any],
|
|
||||||
vols: List[float],
|
|
||||||
use_channels: Optional[List[int]] = None,
|
|
||||||
flow_rates: Optional[List[Optional[float]]] = None,
|
|
||||||
offsets: Any = None,
|
|
||||||
liquid_height: Any = None,
|
|
||||||
blow_out_air_volume: Any = None,
|
|
||||||
spread: str = "wide",
|
|
||||||
**backend_kwargs,
|
|
||||||
):
|
|
||||||
self.calls.append(
|
|
||||||
(
|
|
||||||
"aspirate",
|
|
||||||
{
|
|
||||||
"resources": list(resources),
|
|
||||||
"vols": list(vols),
|
|
||||||
"use_channels": list(use_channels) if use_channels is not None else None,
|
|
||||||
"flow_rates": list(flow_rates) if flow_rates is not None else None,
|
|
||||||
"offsets": list(offsets) if offsets is not None else None,
|
|
||||||
"liquid_height": list(liquid_height) if liquid_height is not None else None,
|
|
||||||
"blow_out_air_volume": list(blow_out_air_volume) if blow_out_air_volume is not None else None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def dispense(
|
|
||||||
self,
|
|
||||||
resources: Sequence[Any],
|
|
||||||
vols: List[float],
|
|
||||||
use_channels: Optional[List[int]] = None,
|
|
||||||
flow_rates: Optional[List[Optional[float]]] = None,
|
|
||||||
offsets: Any = None,
|
|
||||||
liquid_height: Any = None,
|
|
||||||
blow_out_air_volume: Any = None,
|
|
||||||
spread: str = "wide",
|
|
||||||
**backend_kwargs,
|
|
||||||
):
|
|
||||||
self.calls.append(
|
|
||||||
(
|
|
||||||
"dispense",
|
|
||||||
{
|
|
||||||
"resources": list(resources),
|
|
||||||
"vols": list(vols),
|
|
||||||
"use_channels": list(use_channels) if use_channels is not None else None,
|
|
||||||
"flow_rates": list(flow_rates) if flow_rates is not None else None,
|
|
||||||
"offsets": list(offsets) if offsets is not None else None,
|
|
||||||
"liquid_height": list(liquid_height) if liquid_height is not None else None,
|
|
||||||
"blow_out_air_volume": list(blow_out_air_volume) if blow_out_air_volume is not None else None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def discard_tips(self, use_channels=None, *args, **kwargs):
|
|
||||||
# 有的分支是 discard_tips(use_channels=[0]),有的分支是 discard_tips([0..7])(位置参数)
|
|
||||||
self.calls.append(("discard_tips", {"use_channels": list(use_channels) if use_channels is not None else None}))
|
|
||||||
|
|
||||||
async def custom_delay(self, seconds=0, msg=None):
|
|
||||||
self.calls.append(("custom_delay", {"seconds": seconds, "msg": msg}))
|
|
||||||
|
|
||||||
async def touch_tip(self, targets):
|
|
||||||
# 原实现会访问 targets.get_size_x() 等;测试里只记录调用
|
|
||||||
self.calls.append(("touch_tip", {"targets": targets}))
|
|
||||||
|
|
||||||
def run(coro):
|
|
||||||
return asyncio.run(coro)
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_single_channel_basic_calls():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(64))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(3)]
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(3)]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1, 2, 3],
|
|
||||||
dis_vols=[4, 5, 6],
|
|
||||||
mix_times=None, # 应该仍能执行(不 mix)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
assert [c[0] for c in lh.calls].count("pick_up_tips") == 3
|
|
||||||
assert [c[0] for c in lh.calls].count("aspirate") == 3
|
|
||||||
assert [c[0] for c in lh.calls].count("dispense") == 3
|
|
||||||
assert [c[0] for c in lh.calls].count("discard_tips") == 3
|
|
||||||
|
|
||||||
# 每次 aspirate/dispense 都是单孔列表
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
assert aspirates[0]["resources"] == [sources[0]]
|
|
||||||
assert aspirates[0]["vols"] == [1.0]
|
|
||||||
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert dispenses[2]["resources"] == [targets[2]]
|
|
||||||
assert dispenses[2]["vols"] == [6.0]
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_single_channel_before_stage_mixes_prior_to_aspirate():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(16))
|
|
||||||
|
|
||||||
source = DummyContainer("S0")
|
|
||||||
target = DummyContainer("T0")
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=[source],
|
|
||||||
targets=[target],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[5],
|
|
||||||
dis_vols=[5],
|
|
||||||
mix_stage="before",
|
|
||||||
mix_times=1,
|
|
||||||
mix_vol=3,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirate_calls = [(idx, payload) for idx, (name, payload) in enumerate(lh.calls) if name == "aspirate"]
|
|
||||||
assert len(aspirate_calls) >= 2
|
|
||||||
mix_idx, mix_payload = aspirate_calls[0]
|
|
||||||
assert mix_payload["resources"] == [target]
|
|
||||||
assert mix_payload["vols"] == [3]
|
|
||||||
transfer_idx, transfer_payload = aspirate_calls[1]
|
|
||||||
assert transfer_payload["resources"] == [source]
|
|
||||||
assert mix_idx < transfer_idx
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_eight_channel_groups_by_8():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(256))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(16)]
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(16)]
|
|
||||||
asp_vols = list(range(1, 17))
|
|
||||||
dis_vols = list(range(101, 117))
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=dis_vols,
|
|
||||||
mix_times=0, # 触发逻辑但不 mix
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# 16 个任务 -> 2 组,每组 8 通道一起做
|
|
||||||
assert [c[0] for c in lh.calls].count("pick_up_tips") == 2
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert len(aspirates) == 2
|
|
||||||
assert len(dispenses) == 2
|
|
||||||
|
|
||||||
assert aspirates[0]["resources"] == sources[0:8]
|
|
||||||
assert aspirates[0]["vols"] == [float(v) for v in asp_vols[0:8]]
|
|
||||||
assert dispenses[1]["resources"] == targets[8:16]
|
|
||||||
assert dispenses[1]["vols"] == [float(v) for v in dis_vols[8:16]]
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_eight_channel_requires_multiple_of_8_targets():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(64))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(9)]
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(9)]
|
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="multiple of 8"):
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=[1] * 9,
|
|
||||||
dis_vols=[1] * 9,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_eight_channel_parameter_lists_are_chunked_per_8():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(512))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(16)]
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(16)]
|
|
||||||
asp_vols = [i + 1 for i in range(16)]
|
|
||||||
dis_vols = [200 + i for i in range(16)]
|
|
||||||
asp_flow_rates = [0.1 * (i + 1) for i in range(16)]
|
|
||||||
dis_flow_rates = [0.2 * (i + 1) for i in range(16)]
|
|
||||||
offsets = [f"offset_{i}" for i in range(16)]
|
|
||||||
liquid_heights = [i * 0.5 for i in range(16)]
|
|
||||||
blow_out_air_volume = [i + 0.05 for i in range(16)]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=dis_vols,
|
|
||||||
asp_flow_rates=asp_flow_rates,
|
|
||||||
dis_flow_rates=dis_flow_rates,
|
|
||||||
offsets=offsets,
|
|
||||||
liquid_height=liquid_heights,
|
|
||||||
blow_out_air_volume=blow_out_air_volume,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert len(aspirates) == len(dispenses) == 2
|
|
||||||
|
|
||||||
for batch_idx in range(2):
|
|
||||||
start = batch_idx * 8
|
|
||||||
end = start + 8
|
|
||||||
asp_call = aspirates[batch_idx]
|
|
||||||
dis_call = dispenses[batch_idx]
|
|
||||||
assert asp_call["resources"] == sources[start:end]
|
|
||||||
assert asp_call["flow_rates"] == asp_flow_rates[start:end]
|
|
||||||
assert asp_call["offsets"] == offsets[start:end]
|
|
||||||
assert asp_call["liquid_height"] == liquid_heights[start:end]
|
|
||||||
assert asp_call["blow_out_air_volume"] == blow_out_air_volume[start:end]
|
|
||||||
assert dis_call["flow_rates"] == dis_flow_rates[start:end]
|
|
||||||
assert dis_call["offsets"] == offsets[start:end]
|
|
||||||
assert dis_call["liquid_height"] == liquid_heights[start:end]
|
|
||||||
assert dis_call["blow_out_air_volume"] == blow_out_air_volume[start:end]
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_one_eight_channel_handles_32_tasks_four_batches():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(1024))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(32)]
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(32)]
|
|
||||||
asp_vols = [i + 1 for i in range(32)]
|
|
||||||
dis_vols = [300 + i for i in range(32)]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=dis_vols,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
pick_calls = [name for name, _ in lh.calls if name == "pick_up_tips"]
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert len(pick_calls) == 4
|
|
||||||
assert len(aspirates) == len(dispenses) == 4
|
|
||||||
assert aspirates[0]["resources"] == sources[0:8]
|
|
||||||
assert aspirates[-1]["resources"] == sources[24:32]
|
|
||||||
assert dispenses[0]["resources"] == targets[0:8]
|
|
||||||
assert dispenses[-1]["resources"] == targets[24:32]
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_many_single_channel_aspirates_total_when_asp_vol_too_small():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(64))
|
|
||||||
|
|
||||||
source = DummyContainer("SRC")
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(3)]
|
|
||||||
dis_vols = [10, 20, 30] # sum=60
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=[source],
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=10, # 小于 sum(dis_vols) -> 应吸 60
|
|
||||||
dis_vols=dis_vols,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
assert len(aspirates) == 1
|
|
||||||
assert aspirates[0]["resources"] == [source]
|
|
||||||
assert aspirates[0]["vols"] == [60.0]
|
|
||||||
assert aspirates[0]["use_channels"] == [0]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert [d["vols"][0] for d in dispenses] == [10.0, 20.0, 30.0]
|
|
||||||
|
|
||||||
|
|
||||||
def test_one_to_many_eight_channel_basic():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(128))
|
|
||||||
|
|
||||||
source = DummyContainer("SRC")
|
|
||||||
targets = [DummyContainer(f"T{i}") for i in range(8)]
|
|
||||||
dis_vols = [i + 1 for i in range(8)]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=[source],
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=999, # one-to-many 8ch 会按 dis_vols 吸(每通道各自)
|
|
||||||
dis_vols=dis_vols,
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
assert aspirates[0]["resources"] == [source] * 8
|
|
||||||
assert aspirates[0]["vols"] == [float(v) for v in dis_vols]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert dispenses[0]["resources"] == targets
|
|
||||||
assert dispenses[0]["vols"] == [float(v) for v in dis_vols]
|
|
||||||
|
|
||||||
|
|
||||||
def test_many_to_one_single_channel_standard_dispense_equals_asp_by_default():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(128))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(3)]
|
|
||||||
target = DummyContainer("T")
|
|
||||||
asp_vols = [5, 6, 7]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=[target],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=1, # many-to-one 允许标量;非比例模式下实际每次分液=对应 asp_vol
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert [d["vols"][0] for d in dispenses] == [float(v) for v in asp_vols]
|
|
||||||
assert all(d["resources"] == [target] for d in dispenses)
|
|
||||||
|
|
||||||
|
|
||||||
def test_many_to_one_single_channel_before_stage_mixes_target_once():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(128))
|
|
||||||
|
|
||||||
sources = [DummyContainer("S0"), DummyContainer("S1")]
|
|
||||||
target = DummyContainer("T")
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=[target],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[5, 6],
|
|
||||||
dis_vols=1,
|
|
||||||
mix_stage="before",
|
|
||||||
mix_times=2,
|
|
||||||
mix_vol=4,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirate_calls = [(idx, payload) for idx, (name, payload) in enumerate(lh.calls) if name == "aspirate"]
|
|
||||||
assert len(aspirate_calls) >= 1
|
|
||||||
mix_idx, mix_payload = aspirate_calls[0]
|
|
||||||
assert mix_payload["resources"] == [target]
|
|
||||||
assert mix_payload["vols"] == [4]
|
|
||||||
# 第一個 mix 之後會真正開始吸 source
|
|
||||||
assert any(call["resources"] == [sources[0]] for _, call in aspirate_calls[1:])
|
|
||||||
|
|
||||||
|
|
||||||
def test_many_to_one_single_channel_proportional_mixing_uses_dis_vols_per_source():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
lh.current_tip = iter(make_tip_iter(128))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(3)]
|
|
||||||
target = DummyContainer("T")
|
|
||||||
asp_vols = [5, 6, 7]
|
|
||||||
dis_vols = [1, 2, 3]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=[target],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=dis_vols, # 比例模式
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert [d["vols"][0] for d in dispenses] == [float(v) for v in dis_vols]
|
|
||||||
|
|
||||||
|
|
||||||
def test_many_to_one_eight_channel_basic():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(256))
|
|
||||||
|
|
||||||
sources = [DummyContainer(f"S{i}") for i in range(8)]
|
|
||||||
target = DummyContainer("T")
|
|
||||||
asp_vols = [10 + i for i in range(8)]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=[target],
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=list(range(8)),
|
|
||||||
asp_vols=asp_vols,
|
|
||||||
dis_vols=999, # 非比例模式下每通道分液=对应 asp_vol
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert aspirates[0]["resources"] == sources
|
|
||||||
assert aspirates[0]["vols"] == [float(v) for v in asp_vols]
|
|
||||||
assert dispenses[0]["resources"] == [target] * 8
|
|
||||||
assert dispenses[0]["vols"] == [float(v) for v in asp_vols]
|
|
||||||
|
|
||||||
|
|
||||||
def test_transfer_liquid_mode_detection_unsupported_shape_raises():
|
|
||||||
lh = FakeLiquidHandler(channel_num=8)
|
|
||||||
lh.current_tip = iter(make_tip_iter(64))
|
|
||||||
|
|
||||||
sources = [DummyContainer("S0"), DummyContainer("S1")]
|
|
||||||
targets = [DummyContainer("T0"), DummyContainer("T1"), DummyContainer("T2")]
|
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="Unsupported transfer mode"):
|
|
||||||
run(
|
|
||||||
lh.transfer_liquid(
|
|
||||||
sources=sources,
|
|
||||||
targets=targets,
|
|
||||||
tip_racks=[],
|
|
||||||
use_channels=[0],
|
|
||||||
asp_vols=[1, 1],
|
|
||||||
dis_vols=[1, 1, 1],
|
|
||||||
mix_times=0,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_mix_single_target_produces_matching_cycles():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
target = DummyContainer("T_mix")
|
|
||||||
|
|
||||||
run(lh.mix(targets=[target], mix_time=2, mix_vol=5))
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
dispenses = [payload for name, payload in lh.calls if name == "dispense"]
|
|
||||||
assert len(aspirates) == len(dispenses) == 2
|
|
||||||
assert all(call["resources"] == [target] for call in aspirates)
|
|
||||||
assert all(call["vols"] == [5] for call in aspirates)
|
|
||||||
assert all(call["resources"] == [target] for call in dispenses)
|
|
||||||
assert all(call["vols"] == [5] for call in dispenses)
|
|
||||||
|
|
||||||
|
|
||||||
def test_mix_multiple_targets_supports_per_target_offsets():
|
|
||||||
lh = FakeLiquidHandler(channel_num=1)
|
|
||||||
targets = [DummyContainer("T0"), DummyContainer("T1")]
|
|
||||||
offsets = ["left", "right"]
|
|
||||||
heights = [0.1, 0.2]
|
|
||||||
rates = [0.5, 1.0]
|
|
||||||
|
|
||||||
run(
|
|
||||||
lh.mix(
|
|
||||||
targets=targets,
|
|
||||||
mix_time=1,
|
|
||||||
mix_vol=3,
|
|
||||||
offsets=offsets,
|
|
||||||
height_to_bottom=heights,
|
|
||||||
mix_rate=rates,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
aspirates = [payload for name, payload in lh.calls if name == "aspirate"]
|
|
||||||
assert len(aspirates) == 2
|
|
||||||
assert aspirates[0]["resources"] == [targets[0]]
|
|
||||||
assert aspirates[0]["offsets"] == [offsets[0]]
|
|
||||||
assert aspirates[0]["liquid_height"] == [heights[0]]
|
|
||||||
assert aspirates[0]["flow_rates"] == [rates[0]]
|
|
||||||
assert aspirates[1]["resources"] == [targets[1]]
|
|
||||||
assert aspirates[1]["offsets"] == [offsets[1]]
|
|
||||||
assert aspirates[1]["liquid_height"] == [heights[1]]
|
|
||||||
assert aspirates[1]["flow_rates"] == [rates[1]]
|
|
||||||
|
|
||||||
|
|
||||||
def test_set_tiprack_per_type_resumes_first_physical_rack():
|
|
||||||
"""同型号多次 set_tiprack 时接续第一盒剩余孔位,而非从新盒 A1 开始。"""
|
|
||||||
from pylabrobot.liquid_handling import LiquidHandlerChatterboxBackend
|
|
||||||
from pylabrobot.resources import Deck, Tip, TipRack, TipSpot, create_equally_spaced
|
|
||||||
|
|
||||||
mk = lambda: Tip(
|
|
||||||
has_filter=False, total_tip_length=10.0, maximal_volume=300.0, fitting_depth=2.0
|
|
||||||
)
|
|
||||||
|
|
||||||
class TipTypeAlpha(TipRack):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class TipTypeBeta(TipRack):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def make_rack(cls: type, name: str) -> TipRack:
|
|
||||||
items = create_equally_spaced(
|
|
||||||
TipSpot,
|
|
||||||
num_items_x=12,
|
|
||||||
num_items_y=2,
|
|
||||||
dx=0,
|
|
||||||
dy=0,
|
|
||||||
dz=0,
|
|
||||||
item_dx=9,
|
|
||||||
item_dy=9,
|
|
||||||
size_x=1,
|
|
||||||
size_y=1,
|
|
||||||
make_tip=mk,
|
|
||||||
)
|
|
||||||
return cls(name, 120, 40, 10, items=items)
|
|
||||||
|
|
||||||
rack1 = make_rack(TipTypeAlpha, "rack_phys_1")
|
|
||||||
rack2 = make_rack(TipTypeBeta, "rack_phys_2")
|
|
||||||
rack3 = make_rack(TipTypeAlpha, "rack_phys_3")
|
|
||||||
|
|
||||||
lh = LiquidHandlerAbstract(
|
|
||||||
LiquidHandlerChatterboxBackend(1), Deck(), channel_num=1, simulator=False
|
|
||||||
)
|
|
||||||
flat1 = lh._flatten_tips_from_one(rack1)
|
|
||||||
assert len(flat1) == 24
|
|
||||||
|
|
||||||
lh.set_tiprack([rack1])
|
|
||||||
for i in range(12):
|
|
||||||
assert lh._get_next_tip() is flat1[i]
|
|
||||||
|
|
||||||
lh.set_tiprack([rack2])
|
|
||||||
spot_b = lh._get_next_tip()
|
|
||||||
assert "rack_phys_2" in spot_b.name
|
|
||||||
|
|
||||||
lh.set_tiprack([rack3])
|
|
||||||
spot_resume = lh._get_next_tip()
|
|
||||||
assert spot_resume is flat1[12], "第三次同型号应接续 rack1 第二行首孔,而非 rack3 首孔"
|
|
||||||
assert spot_resume is not lh._flatten_tips_from_one(rack3)[0]
|
|
||||||
|
|
||||||
|
|
||||||
6
unilabos/__main__.py
Normal file
6
unilabos/__main__.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
"""Entry point for `python -m unilabos`."""
|
||||||
|
|
||||||
|
from unilabos.app.main import main
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -233,7 +233,7 @@ def parse_args():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--addr",
|
"--addr",
|
||||||
type=str,
|
type=str,
|
||||||
default="https://uni-lab.bohrium.com/api/v1",
|
default="https://leap-lab.bohrium.com/api/v1",
|
||||||
help="Laboratory backend address",
|
help="Laboratory backend address",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -438,10 +438,10 @@ def main():
|
|||||||
if args.addr != parser.get_default("addr"):
|
if args.addr != parser.get_default("addr"):
|
||||||
if args.addr == "test":
|
if args.addr == "test":
|
||||||
print_status("使用测试环境地址", "info")
|
print_status("使用测试环境地址", "info")
|
||||||
HTTPConfig.remote_addr = "https://uni-lab.test.bohrium.com/api/v1"
|
HTTPConfig.remote_addr = "https://leap-lab.test.bohrium.com/api/v1"
|
||||||
elif args.addr == "uat":
|
elif args.addr == "uat":
|
||||||
print_status("使用uat环境地址", "info")
|
print_status("使用uat环境地址", "info")
|
||||||
HTTPConfig.remote_addr = "https://uni-lab.uat.bohrium.com/api/v1"
|
HTTPConfig.remote_addr = "https://leap-lab.uat.bohrium.com/api/v1"
|
||||||
elif args.addr == "local":
|
elif args.addr == "local":
|
||||||
print_status("使用本地环境地址", "info")
|
print_status("使用本地环境地址", "info")
|
||||||
HTTPConfig.remote_addr = "http://127.0.0.1:48197/api/v1"
|
HTTPConfig.remote_addr = "http://127.0.0.1:48197/api/v1"
|
||||||
@@ -553,7 +553,7 @@ def main():
|
|||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
if not BasicConfig.ak or not BasicConfig.sk:
|
if not BasicConfig.ak or not BasicConfig.sk:
|
||||||
print_status("后续运行必须拥有一个实验室,请前往 https://uni-lab.bohrium.com 注册实验室!", "warning")
|
print_status("后续运行必须拥有一个实验室,请前往 https://leap-lab.bohrium.com 注册实验室!", "warning")
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
graph: nx.Graph
|
graph: nx.Graph
|
||||||
resource_tree_set: ResourceTreeSet
|
resource_tree_set: ResourceTreeSet
|
||||||
@@ -621,6 +621,8 @@ def main():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# 如果从远端获取了物料信息,则与本地物料进行同步
|
# 如果从远端获取了物料信息,则与本地物料进行同步
|
||||||
|
# 仅在本地文件模式下有意义:本地文件只含设备结构,远端有已保存的物料,需要 merge
|
||||||
|
# 远端模式下 resource_tree_set 与 request_startup_json 来自同一份数据,merge 为空操作
|
||||||
if file_path is not None and request_startup_json and "nodes" in request_startup_json:
|
if file_path is not None and request_startup_json and "nodes" in request_startup_json:
|
||||||
print_status("开始同步远端物料到本地...", "info")
|
print_status("开始同步远端物料到本地...", "info")
|
||||||
remote_tree_set = ResourceTreeSet.from_raw_dict_list(request_startup_json["nodes"])
|
remote_tree_set = ResourceTreeSet.from_raw_dict_list(request_startup_json["nodes"])
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ class HTTPClient:
|
|||||||
auth_secret = BasicConfig.auth_secret()
|
auth_secret = BasicConfig.auth_secret()
|
||||||
self.auth = auth_secret
|
self.auth = auth_secret
|
||||||
info(f"正在使用ak sk作为授权信息:[{auth_secret}]")
|
info(f"正在使用ak sk作为授权信息:[{auth_secret}]")
|
||||||
|
# 复用 TCP/TLS 连接,避免每次请求重新握手
|
||||||
|
self._session = requests.Session()
|
||||||
|
self._session.headers.update({"Authorization": f"Lab {self.auth}"})
|
||||||
info(f"HTTPClient 初始化完成: remote_addr={self.remote_addr}")
|
info(f"HTTPClient 初始化完成: remote_addr={self.remote_addr}")
|
||||||
|
|
||||||
def resource_edge_add(self, resources: List[Dict[str, Any]]) -> requests.Response:
|
def resource_edge_add(self, resources: List[Dict[str, Any]]) -> requests.Response:
|
||||||
@@ -48,7 +51,7 @@ class HTTPClient:
|
|||||||
Returns:
|
Returns:
|
||||||
Response: API响应对象
|
Response: API响应对象
|
||||||
"""
|
"""
|
||||||
response = requests.post(
|
response = self._session.post(
|
||||||
f"{self.remote_addr}/edge/material/edge",
|
f"{self.remote_addr}/edge/material/edge",
|
||||||
json={
|
json={
|
||||||
"edges": resources,
|
"edges": resources,
|
||||||
@@ -75,26 +78,28 @@ class HTTPClient:
|
|||||||
Returns:
|
Returns:
|
||||||
Dict[str, str]: 旧UUID到新UUID的映射关系 {old_uuid: new_uuid}
|
Dict[str, str]: 旧UUID到新UUID的映射关系 {old_uuid: new_uuid}
|
||||||
"""
|
"""
|
||||||
with open(os.path.join(BasicConfig.working_dir, "req_resource_tree_add.json"), "w", encoding="utf-8") as f:
|
# dump() 只调用一次,复用给文件保存和 HTTP 请求
|
||||||
payload = {"nodes": [x for xs in resources.dump() for x in xs], "mount_uuid": mount_uuid}
|
|
||||||
f.write(json.dumps(payload, indent=4))
|
|
||||||
# 从序列化数据中提取所有节点的UUID(保存旧UUID)
|
|
||||||
old_uuids = {n.res_content.uuid: n for n in resources.all_nodes}
|
|
||||||
nodes_info = [x for xs in resources.dump() for x in xs]
|
nodes_info = [x for xs in resources.dump() for x in xs]
|
||||||
|
old_uuids = {n.res_content.uuid: n for n in resources.all_nodes}
|
||||||
|
payload = {"nodes": nodes_info, "mount_uuid": mount_uuid}
|
||||||
|
body_bytes = _fast_dumps(payload)
|
||||||
|
with open(os.path.join(BasicConfig.working_dir, "req_resource_tree_add.json"), "wb") as f:
|
||||||
|
f.write(_fast_dumps_pretty(payload))
|
||||||
|
http_headers = {"Content-Type": "application/json"}
|
||||||
if not self.initialized or first_add:
|
if not self.initialized or first_add:
|
||||||
self.initialized = True
|
self.initialized = True
|
||||||
info(f"首次添加资源,当前远程地址: {self.remote_addr}")
|
info(f"首次添加资源,当前远程地址: {self.remote_addr}")
|
||||||
response = requests.post(
|
response = self._session.post(
|
||||||
f"{self.remote_addr}/edge/material",
|
f"{self.remote_addr}/edge/material",
|
||||||
json={"nodes": nodes_info, "mount_uuid": mount_uuid},
|
data=body_bytes,
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers=http_headers,
|
||||||
timeout=60,
|
timeout=60,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
response = requests.put(
|
response = self._session.put(
|
||||||
f"{self.remote_addr}/edge/material",
|
f"{self.remote_addr}/edge/material",
|
||||||
json={"nodes": nodes_info, "mount_uuid": mount_uuid},
|
data=body_bytes,
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers=http_headers,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -133,7 +138,7 @@ class HTTPClient:
|
|||||||
"""
|
"""
|
||||||
with open(os.path.join(BasicConfig.working_dir, "req_resource_tree_get.json"), "w", encoding="utf-8") as f:
|
with open(os.path.join(BasicConfig.working_dir, "req_resource_tree_get.json"), "w", encoding="utf-8") as f:
|
||||||
f.write(json.dumps({"uuids": uuid_list, "with_children": with_children}, indent=4))
|
f.write(json.dumps({"uuids": uuid_list, "with_children": with_children}, indent=4))
|
||||||
response = requests.post(
|
response = self._session.post(
|
||||||
f"{self.remote_addr}/edge/material/query",
|
f"{self.remote_addr}/edge/material/query",
|
||||||
json={"uuids": uuid_list, "with_children": with_children},
|
json={"uuids": uuid_list, "with_children": with_children},
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers={"Authorization": f"Lab {self.auth}"},
|
||||||
@@ -147,6 +152,7 @@ class HTTPClient:
|
|||||||
logger.error(f"查询物料失败: {response.text}")
|
logger.error(f"查询物料失败: {response.text}")
|
||||||
else:
|
else:
|
||||||
data = res["data"]["nodes"]
|
data = res["data"]["nodes"]
|
||||||
|
logger.trace(f"resource_tree_get查询到物料: {data}")
|
||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
logger.error(f"查询物料失败: {response.text}")
|
logger.error(f"查询物料失败: {response.text}")
|
||||||
@@ -164,14 +170,14 @@ class HTTPClient:
|
|||||||
if not self.initialized:
|
if not self.initialized:
|
||||||
self.initialized = True
|
self.initialized = True
|
||||||
info(f"首次添加资源,当前远程地址: {self.remote_addr}")
|
info(f"首次添加资源,当前远程地址: {self.remote_addr}")
|
||||||
response = requests.post(
|
response = self._session.post(
|
||||||
f"{self.remote_addr}/lab/material",
|
f"{self.remote_addr}/lab/material",
|
||||||
json={"nodes": resources},
|
json={"nodes": resources},
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers={"Authorization": f"Lab {self.auth}"},
|
||||||
timeout=100,
|
timeout=100,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
response = requests.put(
|
response = self._session.put(
|
||||||
f"{self.remote_addr}/lab/material",
|
f"{self.remote_addr}/lab/material",
|
||||||
json={"nodes": resources},
|
json={"nodes": resources},
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers={"Authorization": f"Lab {self.auth}"},
|
||||||
@@ -198,7 +204,7 @@ class HTTPClient:
|
|||||||
"""
|
"""
|
||||||
with open(os.path.join(BasicConfig.working_dir, "req_resource_get.json"), "w", encoding="utf-8") as f:
|
with open(os.path.join(BasicConfig.working_dir, "req_resource_get.json"), "w", encoding="utf-8") as f:
|
||||||
f.write(json.dumps({"id": id, "with_children": with_children}, indent=4))
|
f.write(json.dumps({"id": id, "with_children": with_children}, indent=4))
|
||||||
response = requests.get(
|
response = self._session.get(
|
||||||
f"{self.remote_addr}/lab/material",
|
f"{self.remote_addr}/lab/material",
|
||||||
params={"id": id, "with_children": with_children},
|
params={"id": id, "with_children": with_children},
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers={"Authorization": f"Lab {self.auth}"},
|
||||||
@@ -239,14 +245,14 @@ class HTTPClient:
|
|||||||
if not self.initialized:
|
if not self.initialized:
|
||||||
self.initialized = True
|
self.initialized = True
|
||||||
info(f"首次添加资源,当前远程地址: {self.remote_addr}")
|
info(f"首次添加资源,当前远程地址: {self.remote_addr}")
|
||||||
response = requests.post(
|
response = self._session.post(
|
||||||
f"{self.remote_addr}/lab/material",
|
f"{self.remote_addr}/lab/material",
|
||||||
json={"nodes": resources},
|
json={"nodes": resources},
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers={"Authorization": f"Lab {self.auth}"},
|
||||||
timeout=100,
|
timeout=100,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
response = requests.put(
|
response = self._session.put(
|
||||||
f"{self.remote_addr}/lab/material",
|
f"{self.remote_addr}/lab/material",
|
||||||
json={"nodes": resources},
|
json={"nodes": resources},
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers={"Authorization": f"Lab {self.auth}"},
|
||||||
@@ -276,7 +282,7 @@ class HTTPClient:
|
|||||||
with open(file_path, "rb") as file:
|
with open(file_path, "rb") as file:
|
||||||
files = {"files": file}
|
files = {"files": file}
|
||||||
logger.info(f"上传文件: {file_path} 到 {scene}")
|
logger.info(f"上传文件: {file_path} 到 {scene}")
|
||||||
response = requests.post(
|
response = self._session.post(
|
||||||
f"{self.remote_addr}/api/account/file_upload/{scene}",
|
f"{self.remote_addr}/api/account/file_upload/{scene}",
|
||||||
files=files,
|
files=files,
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers={"Authorization": f"Lab {self.auth}"},
|
||||||
@@ -316,7 +322,7 @@ class HTTPClient:
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Content-Encoding": "gzip",
|
"Content-Encoding": "gzip",
|
||||||
}
|
}
|
||||||
response = requests.post(
|
response = self._session.post(
|
||||||
f"{self.remote_addr}/lab/resource",
|
f"{self.remote_addr}/lab/resource",
|
||||||
data=compressed_body,
|
data=compressed_body,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
@@ -350,7 +356,7 @@ class HTTPClient:
|
|||||||
Returns:
|
Returns:
|
||||||
Response: API响应对象
|
Response: API响应对象
|
||||||
"""
|
"""
|
||||||
response = requests.get(
|
response = self._session.get(
|
||||||
f"{self.remote_addr}/edge/material/download",
|
f"{self.remote_addr}/edge/material/download",
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers={"Authorization": f"Lab {self.auth}"},
|
||||||
timeout=(3, 30),
|
timeout=(3, 30),
|
||||||
@@ -411,7 +417,7 @@ class HTTPClient:
|
|||||||
with open(os.path.join(BasicConfig.working_dir, "req_workflow_upload.json"), "w", encoding="utf-8") as f:
|
with open(os.path.join(BasicConfig.working_dir, "req_workflow_upload.json"), "w", encoding="utf-8") as f:
|
||||||
f.write(json.dumps(payload, indent=4, ensure_ascii=False))
|
f.write(json.dumps(payload, indent=4, ensure_ascii=False))
|
||||||
|
|
||||||
response = requests.post(
|
response = self._session.post(
|
||||||
f"{self.remote_addr}/lab/workflow/owner/import",
|
f"{self.remote_addr}/lab/workflow/owner/import",
|
||||||
json=payload,
|
json=payload,
|
||||||
headers={"Authorization": f"Lab {self.auth}"},
|
headers={"Authorization": f"Lab {self.auth}"},
|
||||||
|
|||||||
@@ -58,14 +58,14 @@ class JobResultStore:
|
|||||||
feedback=feedback or {},
|
feedback=feedback or {},
|
||||||
timestamp=time.time(),
|
timestamp=time.time(),
|
||||||
)
|
)
|
||||||
logger.debug(f"[JobResultStore] Stored result for job {job_id[:8]}, status={status}")
|
logger.trace(f"[JobResultStore] Stored result for job {job_id[:8]}, status={status}")
|
||||||
|
|
||||||
def get_and_remove(self, job_id: str) -> Optional[JobResult]:
|
def get_and_remove(self, job_id: str) -> Optional[JobResult]:
|
||||||
"""获取并删除任务结果"""
|
"""获取并删除任务结果"""
|
||||||
with self._results_lock:
|
with self._results_lock:
|
||||||
result = self._results.pop(job_id, None)
|
result = self._results.pop(job_id, None)
|
||||||
if result:
|
if result:
|
||||||
logger.debug(f"[JobResultStore] Retrieved and removed result for job {job_id[:8]}")
|
logger.trace(f"[JobResultStore] Retrieved and removed result for job {job_id[:8]}")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_result(self, job_id: str) -> Optional[JobResult]:
|
def get_result(self, job_id: str) -> Optional[JobResult]:
|
||||||
|
|||||||
@@ -1269,7 +1269,13 @@ class QueueProcessor:
|
|||||||
if not queued_jobs:
|
if not queued_jobs:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug(f"[QueueProcessor] Sending busy status for {len(queued_jobs)} queued jobs")
|
queue_summary = {}
|
||||||
|
for j in queued_jobs:
|
||||||
|
key = f"{j.device_id}/{j.action_name}"
|
||||||
|
queue_summary[key] = queue_summary.get(key, 0) + 1
|
||||||
|
logger.debug(
|
||||||
|
f"[QueueProcessor] Sending busy status for {len(queued_jobs)} queued jobs: {queue_summary}"
|
||||||
|
)
|
||||||
|
|
||||||
for job_info in queued_jobs:
|
for job_info in queued_jobs:
|
||||||
# 快照可能已过期:在遍历过程中 end_job() 可能已将此 job 移至 READY,
|
# 快照可能已过期:在遍历过程中 end_job() 可能已将此 job 移至 READY,
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class WSConfig:
|
|||||||
|
|
||||||
# HTTP配置
|
# HTTP配置
|
||||||
class HTTPConfig:
|
class HTTPConfig:
|
||||||
remote_addr = "https://uni-lab.bohrium.com/api/v1"
|
remote_addr = "https://leap-lab.bohrium.com/api/v1"
|
||||||
|
|
||||||
|
|
||||||
# ROS配置
|
# ROS配置
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -201,42 +201,17 @@ class ResourceVisualization:
|
|||||||
self.moveit_controllers_yaml['moveit_simple_controller_manager'][f"{name}_{controller_name}"] = moveit_dict['moveit_simple_controller_manager'][controller_name]
|
self.moveit_controllers_yaml['moveit_simple_controller_manager'][f"{name}_{controller_name}"] = moveit_dict['moveit_simple_controller_manager'][controller_name]
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _ensure_ros2_env() -> dict:
|
|
||||||
"""确保 ROS2 环境变量正确设置,返回可用于子进程的 env dict"""
|
|
||||||
import sys
|
|
||||||
env = dict(os.environ)
|
|
||||||
conda_prefix = os.path.dirname(os.path.dirname(sys.executable))
|
|
||||||
|
|
||||||
if "AMENT_PREFIX_PATH" not in env or not env["AMENT_PREFIX_PATH"].strip():
|
|
||||||
candidate = os.pathsep.join([conda_prefix, os.path.join(conda_prefix, "Library")])
|
|
||||||
env["AMENT_PREFIX_PATH"] = candidate
|
|
||||||
os.environ["AMENT_PREFIX_PATH"] = candidate
|
|
||||||
|
|
||||||
extra_bin_dirs = [
|
|
||||||
os.path.join(conda_prefix, "Library", "bin"),
|
|
||||||
os.path.join(conda_prefix, "Library", "lib"),
|
|
||||||
os.path.join(conda_prefix, "Scripts"),
|
|
||||||
conda_prefix,
|
|
||||||
]
|
|
||||||
current_path = env.get("PATH", "")
|
|
||||||
for d in extra_bin_dirs:
|
|
||||||
if d not in current_path:
|
|
||||||
current_path = d + os.pathsep + current_path
|
|
||||||
env["PATH"] = current_path
|
|
||||||
os.environ["PATH"] = current_path
|
|
||||||
|
|
||||||
return env
|
|
||||||
|
|
||||||
def create_launch_description(self) -> LaunchDescription:
|
def create_launch_description(self) -> LaunchDescription:
|
||||||
"""
|
"""
|
||||||
创建launch描述,包含robot_state_publisher和move_group节点
|
创建launch描述,包含robot_state_publisher和move_group节点
|
||||||
|
|
||||||
|
Args:
|
||||||
|
urdf_str: URDF文本
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
LaunchDescription: launch描述对象
|
LaunchDescription: launch描述对象
|
||||||
"""
|
"""
|
||||||
launch_env = self._ensure_ros2_env()
|
# 检查ROS 2环境变量
|
||||||
|
|
||||||
if "AMENT_PREFIX_PATH" not in os.environ:
|
if "AMENT_PREFIX_PATH" not in os.environ:
|
||||||
raise OSError(
|
raise OSError(
|
||||||
"ROS 2环境未正确设置。需要设置 AMENT_PREFIX_PATH 环境变量。\n"
|
"ROS 2环境未正确设置。需要设置 AMENT_PREFIX_PATH 环境变量。\n"
|
||||||
@@ -315,7 +290,7 @@ class ResourceVisualization:
|
|||||||
{"robot_description": robot_description},
|
{"robot_description": robot_description},
|
||||||
ros2_controllers,
|
ros2_controllers,
|
||||||
],
|
],
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for controller in self.moveit_controllers_yaml['moveit_simple_controller_manager']['controller_names']:
|
for controller in self.moveit_controllers_yaml['moveit_simple_controller_manager']['controller_names']:
|
||||||
@@ -325,7 +300,7 @@ class ResourceVisualization:
|
|||||||
executable="spawner",
|
executable="spawner",
|
||||||
arguments=[f"{controller}", "--controller-manager", f"controller_manager"],
|
arguments=[f"{controller}", "--controller-manager", f"controller_manager"],
|
||||||
output="screen",
|
output="screen",
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
controllers.append(
|
controllers.append(
|
||||||
@@ -334,7 +309,7 @@ class ResourceVisualization:
|
|||||||
executable="spawner",
|
executable="spawner",
|
||||||
arguments=["joint_state_broadcaster", "--controller-manager", f"controller_manager"],
|
arguments=["joint_state_broadcaster", "--controller-manager", f"controller_manager"],
|
||||||
output="screen",
|
output="screen",
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for i in controllers:
|
for i in controllers:
|
||||||
@@ -342,6 +317,7 @@ class ResourceVisualization:
|
|||||||
else:
|
else:
|
||||||
ros2_controllers = None
|
ros2_controllers = None
|
||||||
|
|
||||||
|
# 创建robot_state_publisher节点
|
||||||
robot_state_publisher = nd(
|
robot_state_publisher = nd(
|
||||||
package='robot_state_publisher',
|
package='robot_state_publisher',
|
||||||
executable='robot_state_publisher',
|
executable='robot_state_publisher',
|
||||||
@@ -351,8 +327,9 @@ class ResourceVisualization:
|
|||||||
'robot_description': robot_description,
|
'robot_description': robot_description,
|
||||||
'use_sim_time': False
|
'use_sim_time': False
|
||||||
},
|
},
|
||||||
|
# kinematics_dict
|
||||||
],
|
],
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -384,7 +361,7 @@ class ResourceVisualization:
|
|||||||
executable='move_group',
|
executable='move_group',
|
||||||
output='screen',
|
output='screen',
|
||||||
parameters=moveit_params,
|
parameters=moveit_params,
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -402,11 +379,13 @@ class ResourceVisualization:
|
|||||||
arguments=['-d', f"{str(self.mesh_path)}/view_robot.rviz"],
|
arguments=['-d', f"{str(self.mesh_path)}/view_robot.rviz"],
|
||||||
output='screen',
|
output='screen',
|
||||||
parameters=[
|
parameters=[
|
||||||
{'robot_description_kinematics': kinematics_dict},
|
{'robot_description_kinematics': kinematics_dict,
|
||||||
|
},
|
||||||
robot_description_planning,
|
robot_description_planning,
|
||||||
planning_pipelines,
|
planning_pipelines,
|
||||||
|
|
||||||
],
|
],
|
||||||
env=launch_env,
|
env=dict(os.environ)
|
||||||
)
|
)
|
||||||
self.launch_description.add_action(rviz_node)
|
self.launch_description.add_action(rviz_node)
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,150 +0,0 @@
|
|||||||
from typing import Any, Dict, Optional
|
|
||||||
|
|
||||||
from .prcxi import PRCXI9300ModuleSite
|
|
||||||
|
|
||||||
|
|
||||||
class PRCXI9300FunctionalModule(PRCXI9300ModuleSite):
|
|
||||||
"""
|
|
||||||
PRCXI 9300 功能模块基类(加热/冷却/震荡/加热震荡/磁吸等)。
|
|
||||||
|
|
||||||
设计目标:
|
|
||||||
- 作为一个可以在工作台上拖拽摆放的实体资源(继承自 PRCXI9300ModuleSite -> ItemizedCarrier)。
|
|
||||||
- 顶面存在一个站点(site),可吸附标准板类资源(plate / tip_rack / tube_rack 等)。
|
|
||||||
- 支持注入 `material_info` (UUID 等),并且在 serialize_state 时做安全过滤。
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
name: str,
|
|
||||||
size_x: float,
|
|
||||||
size_y: float,
|
|
||||||
size_z: float,
|
|
||||||
module_type: Optional[str] = None,
|
|
||||||
category: str = "module",
|
|
||||||
model: Optional[str] = None,
|
|
||||||
material_info: Optional[Dict[str, Any]] = None,
|
|
||||||
**kwargs: Any,
|
|
||||||
):
|
|
||||||
super().__init__(
|
|
||||||
name=name,
|
|
||||||
size_x=size_x,
|
|
||||||
size_y=size_y,
|
|
||||||
size_z=size_z,
|
|
||||||
material_info=material_info,
|
|
||||||
model=model,
|
|
||||||
category=category,
|
|
||||||
**kwargs,
|
|
||||||
)
|
|
||||||
|
|
||||||
# 记录模块类型(加热 / 冷却 / 震荡 / 加热震荡 / 磁吸)
|
|
||||||
self.module_type = module_type or "generic"
|
|
||||||
|
|
||||||
# 与 PRCXI9300PlateAdapter 一致,使用 _unilabos_state 保存扩展信息
|
|
||||||
if not hasattr(self, "_unilabos_state") or self._unilabos_state is None:
|
|
||||||
self._unilabos_state = {}
|
|
||||||
|
|
||||||
# super().__init__ 已经在有 material_info 时写入 "Material",这里仅确保存在
|
|
||||||
if material_info is not None and "Material" not in self._unilabos_state:
|
|
||||||
self._unilabos_state["Material"] = material_info
|
|
||||||
|
|
||||||
# 额外标记 category 和模块类型,便于前端或上层逻辑区分
|
|
||||||
self._unilabos_state.setdefault("category", category)
|
|
||||||
self._unilabos_state["module_type"] = module_type
|
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
|
||||||
# 具体功能模块定义
|
|
||||||
# 这里的尺寸和 material_info 目前为占位参数,后续可根据实际测量/JSON 配置进行更新。
|
|
||||||
# 顶面站点尺寸与模块外形一致,保证可以吸附标准 96 板/储液槽等。
|
|
||||||
# ============================================================================
|
|
||||||
|
|
||||||
|
|
||||||
def PRCXI_Heating_Module(name: str) -> PRCXI9300FunctionalModule:
|
|
||||||
"""加热模块(顶面可吸附标准板)。"""
|
|
||||||
return PRCXI9300FunctionalModule(
|
|
||||||
name=name,
|
|
||||||
size_x=127.76,
|
|
||||||
size_y=85.48,
|
|
||||||
size_z=40.0,
|
|
||||||
module_type="heating",
|
|
||||||
model="PRCXI_Heating_Module",
|
|
||||||
material_info={
|
|
||||||
"uuid": "TODO-HEATING-MODULE-UUID",
|
|
||||||
"Code": "HEAT-MOD",
|
|
||||||
"Name": "PRCXI 加热模块",
|
|
||||||
"SupplyType": 3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def PRCXI_MetalCooling_Module(name: str) -> PRCXI9300FunctionalModule:
|
|
||||||
"""金属冷却模块(顶面可吸附标准板)。"""
|
|
||||||
return PRCXI9300FunctionalModule(
|
|
||||||
name=name,
|
|
||||||
size_x=127.76,
|
|
||||||
size_y=85.48,
|
|
||||||
size_z=40.0,
|
|
||||||
module_type="metal_cooling",
|
|
||||||
model="PRCXI_MetalCooling_Module",
|
|
||||||
material_info={
|
|
||||||
"uuid": "TODO-METAL-COOLING-MODULE-UUID",
|
|
||||||
"Code": "METAL-COOL-MOD",
|
|
||||||
"Name": "PRCXI 金属冷却模块",
|
|
||||||
"SupplyType": 3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def PRCXI_Shaking_Module(name: str) -> PRCXI9300FunctionalModule:
|
|
||||||
"""震荡模块(顶面可吸附标准板)。"""
|
|
||||||
return PRCXI9300FunctionalModule(
|
|
||||||
name=name,
|
|
||||||
size_x=127.76,
|
|
||||||
size_y=85.48,
|
|
||||||
size_z=50.0,
|
|
||||||
module_type="shaking",
|
|
||||||
model="PRCXI_Shaking_Module",
|
|
||||||
material_info={
|
|
||||||
"uuid": "TODO-SHAKING-MODULE-UUID",
|
|
||||||
"Code": "SHAKE-MOD",
|
|
||||||
"Name": "PRCXI 震荡模块",
|
|
||||||
"SupplyType": 3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def PRCXI_Heating_Shaking_Module(name: str) -> PRCXI9300FunctionalModule:
|
|
||||||
"""加热震荡模块(顶面可吸附标准板)。"""
|
|
||||||
return PRCXI9300FunctionalModule(
|
|
||||||
name=name,
|
|
||||||
size_x=127.76,
|
|
||||||
size_y=85.48,
|
|
||||||
size_z=55.0,
|
|
||||||
module_type="heating_shaking",
|
|
||||||
model="PRCXI_Heating_Shaking_Module",
|
|
||||||
material_info={
|
|
||||||
"uuid": "TODO-HEATING-SHAKING-MODULE-UUID",
|
|
||||||
"Code": "HEAT-SHAKE-MOD",
|
|
||||||
"Name": "PRCXI 加热震荡模块",
|
|
||||||
"SupplyType": 3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def PRCXI_Magnetic_Module(name: str) -> PRCXI9300FunctionalModule:
|
|
||||||
"""磁吸模块(顶面可吸附标准板)。"""
|
|
||||||
return PRCXI9300FunctionalModule(
|
|
||||||
name=name,
|
|
||||||
size_x=127.76,
|
|
||||||
size_y=85.48,
|
|
||||||
size_z=30.0,
|
|
||||||
module_type="magnetic",
|
|
||||||
model="PRCXI_Magnetic_Module",
|
|
||||||
material_info={
|
|
||||||
"uuid": "TODO-MAGNETIC-MODULE-UUID",
|
|
||||||
"Code": "MAG-MOD",
|
|
||||||
"Name": "PRCXI 磁吸模块",
|
|
||||||
"SupplyType": 3,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -59,7 +59,6 @@ class UniLiquidHandlerRvizBackend(LiquidHandlerBackend):
|
|||||||
self.total_height = total_height
|
self.total_height = total_height
|
||||||
self.joint_config = kwargs.get("joint_config", None)
|
self.joint_config = kwargs.get("joint_config", None)
|
||||||
self.lh_device_id = kwargs.get("lh_device_id", "lh_joint_publisher")
|
self.lh_device_id = kwargs.get("lh_device_id", "lh_joint_publisher")
|
||||||
self.simulate_rviz = kwargs.get("simulate_rviz", False)
|
|
||||||
if not rclpy.ok():
|
if not rclpy.ok():
|
||||||
rclpy.init()
|
rclpy.init()
|
||||||
self.joint_state_publisher = None
|
self.joint_state_publisher = None
|
||||||
@@ -70,7 +69,7 @@ class UniLiquidHandlerRvizBackend(LiquidHandlerBackend):
|
|||||||
self.joint_state_publisher = LiquidHandlerJointPublisher(
|
self.joint_state_publisher = LiquidHandlerJointPublisher(
|
||||||
joint_config=self.joint_config,
|
joint_config=self.joint_config,
|
||||||
lh_device_id=self.lh_device_id,
|
lh_device_id=self.lh_device_id,
|
||||||
simulate_rviz=self.simulate_rviz)
|
simulate_rviz=True)
|
||||||
|
|
||||||
# 启动ROS executor
|
# 启动ROS executor
|
||||||
self.executor = rclpy.executors.MultiThreadedExecutor()
|
self.executor = rclpy.executors.MultiThreadedExecutor()
|
||||||
|
|||||||
@@ -219,10 +219,10 @@ device = NewareBatteryTestSystem(
|
|||||||
|
|
||||||
#### 步骤 2:提交测试任务
|
#### 步骤 2:提交测试任务
|
||||||
|
|
||||||
使用 `submit_from_csv` 提交测试任务:
|
使用 `submit_from_csv_export_ndax` 提交测试任务:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
result = device.submit_from_csv(
|
result = device.submit_from_csv_export_ndax(
|
||||||
csv_path="test_data.csv",
|
csv_path="test_data.csv",
|
||||||
output_dir="D:/neware_output"
|
output_dir="D:/neware_output"
|
||||||
)
|
)
|
||||||
@@ -489,7 +489,7 @@ A: 重新获取新的 Token 并更新环境变量 `UNI_LAB_AUTH_TOKEN`。
|
|||||||
**Q: 可以自定义上传路径吗?**
|
**Q: 可以自定义上传路径吗?**
|
||||||
A: 当前版本路径由统一 API 自动分配,`oss_prefix` 参数暂不使用(保留接口兼容性)。
|
A: 当前版本路径由统一 API 自动分配,`oss_prefix` 参数暂不使用(保留接口兼容性)。
|
||||||
|
|
||||||
**Q: 为什么不在 `submit_from_csv` 中自动上传?**
|
**Q: 为什么不在 `submit_from_csv_export_ndax` 中自动上传?**
|
||||||
A: 因为备份文件在测试进行中逐步生成,方法返回时可能文件尚未完全生成,因此提供独立的上传方法更灵活。
|
A: 因为备份文件在测试进行中逐步生成,方法返回时可能文件尚未完全生成,因此提供独立的上传方法更灵活。
|
||||||
|
|
||||||
**Q: 上传后如何访问文件?**
|
**Q: 上传后如何访问文件?**
|
||||||
|
|||||||
@@ -230,10 +230,10 @@ device = NewareBatteryTestSystem(
|
|||||||
|
|
||||||
#### Step 2: Submit Test Tasks
|
#### Step 2: Submit Test Tasks
|
||||||
|
|
||||||
Use `submit_from_csv` to submit test tasks:
|
Use `submit_from_csv_export_ndax` to submit test tasks:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
result = device.submit_from_csv(
|
result = device.submit_from_csv_export_ndax(
|
||||||
csv_path="test_data.csv",
|
csv_path="test_data.csv",
|
||||||
output_dir="D:/neware_output"
|
output_dir="D:/neware_output"
|
||||||
)
|
)
|
||||||
@@ -500,7 +500,7 @@ A: Obtain a new API Key and update the `UNI_LAB_AUTH_TOKEN` environment variable
|
|||||||
**Q: Can I customize upload paths?**
|
**Q: Can I customize upload paths?**
|
||||||
A: Current version has paths automatically assigned by unified API. `oss_prefix` parameter is currently unused (retained for interface compatibility).
|
A: Current version has paths automatically assigned by unified API. `oss_prefix` parameter is currently unused (retained for interface compatibility).
|
||||||
|
|
||||||
**Q: Why not auto-upload in `submit_from_csv`?**
|
**Q: Why not auto-upload in `submit_from_csv_export_ndax`?**
|
||||||
A: Because backup files are generated progressively during testing, they may not be fully generated when the method returns. A separate upload method provides more flexibility.
|
A: Because backup files are generated progressively during testing, they may not be fully generated when the method returns. A separate upload method provides more flexibility.
|
||||||
|
|
||||||
**Q: How to access files after upload?**
|
**Q: How to access files after upload?**
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"config": {
|
"config": {
|
||||||
"ip": "127.0.0.1",
|
"ip": "127.0.0.1",
|
||||||
"port": 502,
|
"port": 502,
|
||||||
"machine_id": 1,
|
"machine_ids": [1, 2, 3, 4, 5, 6, 86],
|
||||||
"devtype": "27",
|
"devtype": "27",
|
||||||
"timeout": 20,
|
"timeout": 20,
|
||||||
"size_x": 500.0,
|
"size_x": 500.0,
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
"data": {
|
"data": {
|
||||||
"功能说明": "新威电池测试系统,提供720通道监控和CSV批量提交功能",
|
"功能说明": "新威电池测试系统,提供720通道监控和CSV批量提交功能",
|
||||||
"监控功能": "支持720个通道的实时状态监控、2盘电池物料管理、状态导出等",
|
"监控功能": "支持720个通道的实时状态监控、2盘电池物料管理、状态导出等",
|
||||||
"提交功能": "通过submit_from_csv action从CSV文件批量提交测试任务。CSV必须包含: Battery_Code, Pole_Weight, 集流体质量, 活性物质含量, 克容量mah/g, 电池体系, 设备号, 排号, 通道号"
|
"提交功能": "通过submit_from_csv action从CSV文件批量提交测试任务(NDA备份),或通过submit_from_csv_export_excel action提交并备份为Excel格式。CSV必须包含: Battery_Code, Pole_Weight, 集流体质量, 活性物质含量, 克容量mah/g, 电池体系, 设备号, 排号, 通道号"
|
||||||
},
|
},
|
||||||
"children": []
|
"children": []
|
||||||
}
|
}
|
||||||
|
|||||||
1644
unilabos/devices/neware_battery_test_system/generate_xml_content.py
Normal file
1644
unilabos/devices/neware_battery_test_system/generate_xml_content.py
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
56
unilabos/devices/neware_battery_test_system/neware_driver.py
Normal file
56
unilabos/devices/neware_battery_test_system/neware_driver.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import socket
|
||||||
|
END_MARKS = [b"\r\n#\r\n", b"</bts>"] # 读到任一标志即可判定完整响应
|
||||||
|
|
||||||
|
def build_start_command(devid, subdevid, chlid, CoinID,
|
||||||
|
ip_in_xml="127.0.0.1",
|
||||||
|
devtype:int=27,
|
||||||
|
recipe_path:str=f"D:\\HHM_test\\A001.xml",
|
||||||
|
backup_dir:str=f"D:\\HHM_test\\backup",
|
||||||
|
filetype:int=1) -> str:
|
||||||
|
"""
|
||||||
|
filetype: 备份文件类型。0=NDA(新威原生),1=Excel。默认 1。
|
||||||
|
"""
|
||||||
|
lines = [
|
||||||
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
||||||
|
'<bts version="1.0">',
|
||||||
|
' <cmd>start</cmd>',
|
||||||
|
' <list count="1">',
|
||||||
|
f' <start ip="{ip_in_xml}" devtype="{devtype}" devid="{devid}" subdevid="{subdevid}" chlid="{chlid}" barcode="{CoinID}">{recipe_path}</start>',
|
||||||
|
f' <backup backupdir="{backup_dir}" remotedir="" filenametype="1" customfilename="" createdirbydate="0" filetype="{int(filetype)}" backupontime="1" backupontimeinterval="1" backupfree="0" />',
|
||||||
|
' </list>',
|
||||||
|
'</bts>',
|
||||||
|
]
|
||||||
|
# TCP 模式:请求必须以 #\r\n 结束(协议要求)
|
||||||
|
return "\r\n".join(lines) + "\r\n#\r\n"
|
||||||
|
|
||||||
|
def recv_until_marks(sock: socket.socket, timeout=60):
|
||||||
|
sock.settimeout(timeout) # 上限给足,协议允许到 30s:contentReference[oaicite:2]{index=2}
|
||||||
|
buf = bytearray()
|
||||||
|
while True:
|
||||||
|
chunk = sock.recv(8192)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
buf += chunk
|
||||||
|
# 读到结束标志就停,避免等对端断开
|
||||||
|
for m in END_MARKS:
|
||||||
|
if m in buf:
|
||||||
|
return bytes(buf)
|
||||||
|
# 保险:读到完整 XML 结束标签也停
|
||||||
|
if b"</bts>" in buf:
|
||||||
|
return bytes(buf)
|
||||||
|
return bytes(buf)
|
||||||
|
|
||||||
|
def start_test(ip="127.0.0.1", port=502, devid=3, subdevid=2, chlid=1, CoinID="A001", recipe_path=f"D:\\HHM_test\\A001.xml", backup_dir=f"D:\\HHM_test\\backup", filetype:int=1):
|
||||||
|
"""
|
||||||
|
filetype: 备份文件类型,0=NDA,1=Excel。默认 1。
|
||||||
|
"""
|
||||||
|
xml_cmd = build_start_command(devid=devid, subdevid=subdevid, chlid=chlid, CoinID=CoinID, recipe_path=recipe_path, backup_dir=backup_dir, filetype=filetype)
|
||||||
|
#print(xml_cmd)
|
||||||
|
with socket.create_connection((ip, port), timeout=60) as s:
|
||||||
|
s.sendall(xml_cmd.encode("utf-8"))
|
||||||
|
data = recv_until_marks(s, timeout=60)
|
||||||
|
return data.decode("utf-8", errors="replace")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
resp = start_test(ip="127.0.0.1", port=502, devid=4, subdevid=10, chlid=1, CoinID="A001", recipe_path=f"D:\\HHM_test\\A001.xml", backup_dir=f"D:\\HHM_test\\backup")
|
||||||
|
print(resp)
|
||||||
@@ -42,7 +42,6 @@ class LiquidHandlerJointPublisher(Node):
|
|||||||
while self.resource_action is None:
|
while self.resource_action is None:
|
||||||
self.resource_action = self.check_tf_update_actions()
|
self.resource_action = self.check_tf_update_actions()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
self.get_logger().info(f'Waiting for TfUpdate server: {self.resource_action}')
|
|
||||||
|
|
||||||
self.resource_action_client = ActionClient(self, SendCmd, self.resource_action)
|
self.resource_action_client = ActionClient(self, SendCmd, self.resource_action)
|
||||||
while not self.resource_action_client.wait_for_server(timeout_sec=1.0):
|
while not self.resource_action_client.wait_for_server(timeout_sec=1.0):
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import json
|
|||||||
import time
|
import time
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Sequence
|
|
||||||
|
|
||||||
from moveit_msgs.msg import JointConstraint, Constraints
|
from moveit_msgs.msg import JointConstraint, Constraints
|
||||||
from rclpy.action import ActionClient
|
from rclpy.action import ActionClient
|
||||||
@@ -172,160 +171,173 @@ class MoveitInterface:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def pick_and_place(
|
def pick_and_place(self, command: str):
|
||||||
self,
|
|
||||||
option: str,
|
|
||||||
move_group: str,
|
|
||||||
status: str,
|
|
||||||
resource: Optional[str] = None,
|
|
||||||
x_distance: Optional[float] = None,
|
|
||||||
y_distance: Optional[float] = None,
|
|
||||||
lift_height: Optional[float] = None,
|
|
||||||
retry: Optional[int] = None,
|
|
||||||
speed: Optional[float] = None,
|
|
||||||
target: Optional[str] = None,
|
|
||||||
constraints: Optional[Sequence[float]] = None,
|
|
||||||
) -> None:
|
|
||||||
"""
|
"""
|
||||||
使用 MoveIt 完成抓取/放置等序列(pick/place/side_pick/side_place)。
|
Using MoveIt to make the robotic arm pick or place materials to a target point.
|
||||||
|
|
||||||
必选:option, move_group, status。
|
Args:
|
||||||
可选:resource, x_distance, y_distance, lift_height, retry, speed, target, constraints。
|
command: A JSON-formatted string that includes option, target, speed, lift_height, mt_height
|
||||||
无返回值;失败时提前 return 或打印异常。
|
|
||||||
|
*option (string) : Action type: pick/place/side_pick/side_place
|
||||||
|
*move_group (string): The move group moveit will plan
|
||||||
|
*status(string) : Target pose
|
||||||
|
resource(string) : The target resource
|
||||||
|
x_distance (float) : The distance to the target in x direction(meters)
|
||||||
|
y_distance (float) : The distance to the target in y direction(meters)
|
||||||
|
lift_height (float) : The height at which the material should be lifted(meters)
|
||||||
|
retry (float) : Retry times when moveit plan fails
|
||||||
|
speed (float) : The speed of the movement, speed > 0
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
"""
|
"""
|
||||||
|
result = SendCmd.Result()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if option not in self.move_option:
|
cmd_str = str(command).replace("'", '"')
|
||||||
raise ValueError(f"Invalid option: {option}")
|
cmd_dict = json.loads(cmd_str)
|
||||||
|
|
||||||
option_index = self.move_option.index(option)
|
if cmd_dict["option"] in self.move_option:
|
||||||
place_flag = option_index % 2
|
option_index = self.move_option.index(cmd_dict["option"])
|
||||||
|
place_flag = option_index % 2
|
||||||
|
|
||||||
config: dict = {"move_group": move_group}
|
config = {}
|
||||||
if speed is not None:
|
function_list = []
|
||||||
config["speed"] = speed
|
|
||||||
if retry is not None:
|
|
||||||
config["retry"] = retry
|
|
||||||
|
|
||||||
function_list = []
|
status = cmd_dict["status"]
|
||||||
joint_positions_ = self.joint_poses[move_group][status]
|
joint_positions_ = self.joint_poses[cmd_dict["move_group"]][status]
|
||||||
|
|
||||||
# 夹取 / 放置:绑定 resource 与 parent
|
config.update({k: cmd_dict[k] for k in ["speed", "retry", "move_group"] if k in cmd_dict})
|
||||||
if not place_flag:
|
|
||||||
if target is not None:
|
|
||||||
function_list.append(lambda r=resource, t=target: self.resource_manager(r, t))
|
|
||||||
else:
|
|
||||||
ee = self.moveit2[move_group].end_effector_name
|
|
||||||
function_list.append(lambda r=resource: self.resource_manager(r, ee))
|
|
||||||
else:
|
|
||||||
function_list.append(lambda r=resource: self.resource_manager(r, "world"))
|
|
||||||
|
|
||||||
joint_constraint_msgs: list = []
|
# 夹取
|
||||||
if constraints is not None:
|
if not place_flag:
|
||||||
for i, c in enumerate(constraints):
|
if "target" in cmd_dict.keys():
|
||||||
v = float(c)
|
function_list.append(lambda: self.resource_manager(cmd_dict["resource"], cmd_dict["target"]))
|
||||||
if v > 0:
|
else:
|
||||||
joint_constraint_msgs.append(
|
function_list.append(
|
||||||
JointConstraint(
|
lambda: self.resource_manager(
|
||||||
joint_name=self.moveit2[move_group].joint_names[i],
|
cmd_dict["resource"], self.moveit2[cmd_dict["move_group"]].end_effector_name
|
||||||
position=joint_positions_[i],
|
|
||||||
tolerance_above=v,
|
|
||||||
tolerance_below=v,
|
|
||||||
weight=1.0,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
function_list.append(lambda: self.resource_manager(cmd_dict["resource"], "world"))
|
||||||
|
|
||||||
if lift_height is not None:
|
constraints = []
|
||||||
retval = None
|
if "constraints" in cmd_dict.keys():
|
||||||
attempts = config.get("retry", 10)
|
|
||||||
while retval is None and attempts > 0:
|
|
||||||
retval = self.moveit2[move_group].compute_fk(joint_positions_)
|
|
||||||
time.sleep(0.1)
|
|
||||||
attempts -= 1
|
|
||||||
if retval is None:
|
|
||||||
raise ValueError("Failed to compute forward kinematics")
|
|
||||||
pose = [retval.pose.position.x, retval.pose.position.y, retval.pose.position.z]
|
|
||||||
quaternion = [
|
|
||||||
retval.pose.orientation.x,
|
|
||||||
retval.pose.orientation.y,
|
|
||||||
retval.pose.orientation.z,
|
|
||||||
retval.pose.orientation.w,
|
|
||||||
]
|
|
||||||
|
|
||||||
function_list = [
|
for i in range(len(cmd_dict["constraints"])):
|
||||||
lambda: self.moveit_task(
|
v = float(cmd_dict["constraints"][i])
|
||||||
position=[retval.pose.position.x, retval.pose.position.y, retval.pose.position.z],
|
if v > 0:
|
||||||
quaternion=quaternion,
|
constraints.append(
|
||||||
**config,
|
JointConstraint(
|
||||||
cartesian=self.cartesian_flag,
|
joint_name=self.moveit2[cmd_dict["move_group"]].joint_names[i],
|
||||||
)
|
position=joint_positions_[i],
|
||||||
] + function_list
|
tolerance_above=v,
|
||||||
|
tolerance_below=v,
|
||||||
|
weight=1.0,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
pose[2] += float(lift_height)
|
if "lift_height" in cmd_dict.keys():
|
||||||
function_list.append(
|
retval = None
|
||||||
lambda p=pose.copy(), q=quaternion, cfg=config: self.moveit_task(
|
retry = config.get("retry", 10)
|
||||||
position=p, quaternion=q, **cfg, cartesian=self.cartesian_flag
|
while retval is None and retry > 0:
|
||||||
)
|
retval = self.moveit2[cmd_dict["move_group"]].compute_fk(joint_positions_)
|
||||||
)
|
time.sleep(0.1)
|
||||||
end_pose = list(pose)
|
retry -= 1
|
||||||
|
if retval is None:
|
||||||
if x_distance is not None or y_distance is not None:
|
result.success = False
|
||||||
if x_distance is not None:
|
return result
|
||||||
deep_pose = deepcopy(pose)
|
pose = [retval.pose.position.x, retval.pose.position.y, retval.pose.position.z]
|
||||||
deep_pose[0] += float(x_distance)
|
quaternion = [
|
||||||
elif y_distance is not None:
|
retval.pose.orientation.x,
|
||||||
deep_pose = deepcopy(pose)
|
retval.pose.orientation.y,
|
||||||
deep_pose[1] += float(y_distance)
|
retval.pose.orientation.z,
|
||||||
|
retval.pose.orientation.w,
|
||||||
|
]
|
||||||
|
|
||||||
function_list = [
|
function_list = [
|
||||||
lambda p=pose.copy(), q=quaternion, cfg=config: self.moveit_task(
|
lambda: self.moveit_task(
|
||||||
position=p, quaternion=q, **cfg, cartesian=self.cartesian_flag
|
position=[retval.pose.position.x, retval.pose.position.y, retval.pose.position.z],
|
||||||
|
quaternion=quaternion,
|
||||||
|
**config,
|
||||||
|
cartesian=self.cartesian_flag,
|
||||||
)
|
)
|
||||||
] + function_list
|
] + function_list
|
||||||
|
|
||||||
|
pose[2] += float(cmd_dict["lift_height"])
|
||||||
function_list.append(
|
function_list.append(
|
||||||
lambda dp=deep_pose.copy(), q=quaternion, cfg=config: self.moveit_task(
|
lambda: self.moveit_task(
|
||||||
position=dp, quaternion=q, **cfg, cartesian=self.cartesian_flag
|
position=pose, quaternion=quaternion, **config, cartesian=self.cartesian_flag
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
end_pose = list(deep_pose)
|
end_pose = pose
|
||||||
|
|
||||||
retval_ik = None
|
if "x_distance" in cmd_dict.keys() or "y_distance" in cmd_dict.keys():
|
||||||
attempts_ik = config.get("retry", 10)
|
if "x_distance" in cmd_dict.keys():
|
||||||
while retval_ik is None and attempts_ik > 0:
|
deep_pose = deepcopy(pose)
|
||||||
retval_ik = self.moveit2[move_group].compute_ik(
|
deep_pose[0] += float(cmd_dict["x_distance"])
|
||||||
position=end_pose,
|
elif "y_distance" in cmd_dict.keys():
|
||||||
quat_xyzw=quaternion,
|
deep_pose = deepcopy(pose)
|
||||||
constraints=Constraints(joint_constraints=joint_constraint_msgs),
|
deep_pose[1] += float(cmd_dict["y_distance"])
|
||||||
)
|
|
||||||
time.sleep(0.1)
|
|
||||||
attempts_ik -= 1
|
|
||||||
if retval_ik is None:
|
|
||||||
raise ValueError("Failed to compute inverse kinematics")
|
|
||||||
position_ = [
|
|
||||||
retval_ik.position[retval_ik.name.index(i)] for i in self.moveit2[move_group].joint_names
|
|
||||||
]
|
|
||||||
jn = self.moveit2[move_group].joint_names
|
|
||||||
function_list = [
|
|
||||||
lambda pos=position_, names=jn, cfg=config: self.moveit_joint_task(
|
|
||||||
joint_positions=pos, joint_names=names, **cfg
|
|
||||||
)
|
|
||||||
] + function_list
|
|
||||||
else:
|
|
||||||
function_list = [lambda cfg=config, jp=joint_positions_: self.moveit_joint_task(**cfg, joint_positions=jp)] + function_list
|
|
||||||
|
|
||||||
for i in range(len(function_list)):
|
function_list = [
|
||||||
if i == 0:
|
lambda: self.moveit_task(
|
||||||
self.cartesian_flag = False
|
position=pose, quaternion=quaternion, **config, cartesian=self.cartesian_flag
|
||||||
|
)
|
||||||
|
] + function_list
|
||||||
|
function_list.append(
|
||||||
|
lambda: self.moveit_task(
|
||||||
|
position=deep_pose, quaternion=quaternion, **config, cartesian=self.cartesian_flag
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end_pose = deep_pose
|
||||||
|
|
||||||
|
retval_ik = None
|
||||||
|
retry = config.get("retry", 10)
|
||||||
|
while retval_ik is None and retry > 0:
|
||||||
|
retval_ik = self.moveit2[cmd_dict["move_group"]].compute_ik(
|
||||||
|
position=end_pose, quat_xyzw=quaternion, constraints=Constraints(joint_constraints=constraints)
|
||||||
|
)
|
||||||
|
time.sleep(0.1)
|
||||||
|
retry -= 1
|
||||||
|
if retval_ik is None:
|
||||||
|
result.success = False
|
||||||
|
return result
|
||||||
|
position_ = [
|
||||||
|
retval_ik.position[retval_ik.name.index(i)]
|
||||||
|
for i in self.moveit2[cmd_dict["move_group"]].joint_names
|
||||||
|
]
|
||||||
|
function_list = [
|
||||||
|
lambda: self.moveit_joint_task(
|
||||||
|
joint_positions=position_,
|
||||||
|
joint_names=self.moveit2[cmd_dict["move_group"]].joint_names,
|
||||||
|
**config,
|
||||||
|
)
|
||||||
|
] + function_list
|
||||||
else:
|
else:
|
||||||
self.cartesian_flag = True
|
function_list = [
|
||||||
|
lambda: self.moveit_joint_task(**config, joint_positions=joint_positions_)
|
||||||
|
] + function_list
|
||||||
|
|
||||||
re = function_list[i]()
|
for i in range(len(function_list)):
|
||||||
if not re:
|
if i == 0:
|
||||||
print(i, re)
|
self.cartesian_flag = False
|
||||||
raise ValueError(f"Failed to execute moveit task: {i}")
|
else:
|
||||||
|
self.cartesian_flag = True
|
||||||
|
|
||||||
|
re = function_list[i]()
|
||||||
|
if not re:
|
||||||
|
print(i, re)
|
||||||
|
result.success = False
|
||||||
|
return result
|
||||||
|
result.success = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
self.cartesian_flag = False
|
self.cartesian_flag = False
|
||||||
raise e
|
result.success = False
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def set_status(self, command: str):
|
def set_status(self, command: str):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ from threading import Lock, RLock
|
|||||||
from typing_extensions import TypedDict
|
from typing_extensions import TypedDict
|
||||||
|
|
||||||
from unilabos.registry.decorators import (
|
from unilabos.registry.decorators import (
|
||||||
device, action, ActionInputHandle, ActionOutputHandle, DataSource, topic_config, not_action
|
device, action, ActionInputHandle, ActionOutputHandle, DataSource, topic_config, not_action, NodeType
|
||||||
)
|
)
|
||||||
from unilabos.ros.nodes.base_device_node import BaseROS2DeviceNode
|
from unilabos.registry.placeholder_type import ResourceSlot, DeviceSlot
|
||||||
from unilabos.resources.resource_tracker import SampleUUIDsType, LabSample
|
from unilabos.ros.nodes.base_device_node import BaseROS2DeviceNode, ROS2DeviceNode
|
||||||
|
from unilabos.resources.resource_tracker import SampleUUIDsType, LabSample, ResourceTreeSet
|
||||||
|
|
||||||
|
|
||||||
# ============ TypedDict 返回类型定义 ============
|
# ============ TypedDict 返回类型定义 ============
|
||||||
@@ -290,6 +291,126 @@ class VirtualWorkbench:
|
|||||||
self._update_data_status(f"机械臂已释放 (完成: {task})")
|
self._update_data_status(f"机械臂已释放 (完成: {task})")
|
||||||
self.logger.info(f"机械臂已释放 (完成: {task})")
|
self.logger.info(f"机械臂已释放 (完成: {task})")
|
||||||
|
|
||||||
|
@action(
|
||||||
|
always_free=True, node_type=NodeType.MANUAL_CONFIRM, placeholder_keys={
|
||||||
|
"assignee_user_ids": "unilabos_manual_confirm"
|
||||||
|
}, goal_default={
|
||||||
|
"timeout_seconds": 3600,
|
||||||
|
"assignee_user_ids": []
|
||||||
|
}, feedback_interval=300,
|
||||||
|
handles=[
|
||||||
|
ActionInputHandle(key="target_device", data_type="device_id",
|
||||||
|
label="目标设备", data_key="target_device", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="resource", data_type="resource",
|
||||||
|
label="待转移资源", data_key="resource", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="mount_resource", data_type="resource",
|
||||||
|
label="目标孔位", data_key="mount_resource", data_source=DataSource.HANDLE),
|
||||||
|
|
||||||
|
ActionInputHandle(key="collector_mass", data_type="collector_mass",
|
||||||
|
label="极流体质量", data_key="collector_mass", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="active_material", data_type="active_material",
|
||||||
|
label="活性物质含量", data_key="active_material", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="capacity", data_type="capacity",
|
||||||
|
label="克容量", data_key="capacity", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="battery_system", data_type="battery_system",
|
||||||
|
label="电池体系", data_key="battery_system", data_source=DataSource.HANDLE),
|
||||||
|
# transfer使用
|
||||||
|
ActionOutputHandle(key="target_device", data_type="device_id",
|
||||||
|
label="目标设备", data_key="target_device", data_source=DataSource.EXECUTOR),
|
||||||
|
ActionOutputHandle(key="resource", data_type="resource",
|
||||||
|
label="待转移资源", data_key="resource.@flatten", data_source=DataSource.EXECUTOR),
|
||||||
|
ActionOutputHandle(key="mount_resource", data_type="resource",
|
||||||
|
label="目标孔位", data_key="mount_resource.@flatten", data_source=DataSource.EXECUTOR),
|
||||||
|
# test使用
|
||||||
|
ActionOutputHandle(key="collector_mass", data_type="collector_mass",
|
||||||
|
label="极流体质量", data_key="collector_mass", data_source=DataSource.EXECUTOR),
|
||||||
|
ActionOutputHandle(key="active_material", data_type="active_material",
|
||||||
|
label="活性物质含量", data_key="active_material", data_source=DataSource.EXECUTOR),
|
||||||
|
ActionOutputHandle(key="capacity", data_type="capacity",
|
||||||
|
label="克容量", data_key="capacity", data_source=DataSource.EXECUTOR),
|
||||||
|
ActionOutputHandle(key="battery_system", data_type="battery_system",
|
||||||
|
label="电池体系", data_key="battery_system", data_source=DataSource.EXECUTOR),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def manual_confirm(
|
||||||
|
self,
|
||||||
|
resource: List[ResourceSlot],
|
||||||
|
target_device: DeviceSlot,
|
||||||
|
mount_resource: List[ResourceSlot],
|
||||||
|
collector_mass: List[float],
|
||||||
|
active_material: List[float],
|
||||||
|
capacity: List[float],
|
||||||
|
battery_system: List[str],
|
||||||
|
timeout_seconds: int,
|
||||||
|
assignee_user_ids: list[str],
|
||||||
|
**kwargs
|
||||||
|
) -> dict:
|
||||||
|
"""
|
||||||
|
timeout_seconds: 超时时间(秒),默认3600秒
|
||||||
|
collector_mass: 极流体质量
|
||||||
|
active_material: 活性物质含量
|
||||||
|
capacity: 克容量(mAh/g)
|
||||||
|
battery_system: 电池体系
|
||||||
|
修改的结果无效,是只读的
|
||||||
|
"""
|
||||||
|
resource = ResourceTreeSet.from_plr_resources(resource).dump()
|
||||||
|
mount_resource = ResourceTreeSet.from_plr_resources(mount_resource).dump()
|
||||||
|
kwargs.update(locals())
|
||||||
|
kwargs.pop("kwargs")
|
||||||
|
kwargs.pop("self")
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
@action(
|
||||||
|
description="转移物料",
|
||||||
|
handles=[
|
||||||
|
ActionInputHandle(key="target_device", data_type="device_id",
|
||||||
|
label="目标设备", data_key="target_device", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="resource", data_type="resource",
|
||||||
|
label="待转移资源", data_key="resource", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="mount_resource", data_type="resource",
|
||||||
|
label="目标孔位", data_key="mount_resource", data_source=DataSource.HANDLE),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
async def transfer(self, resource: List[ResourceSlot], target_device: DeviceSlot, mount_resource: List[ResourceSlot]):
|
||||||
|
future = ROS2DeviceNode.run_async_func(self._ros_node.transfer_resource_to_another, True,
|
||||||
|
**{
|
||||||
|
"plr_resources": resource,
|
||||||
|
"target_device_id": target_device,
|
||||||
|
"target_resources": mount_resource,
|
||||||
|
"sites": [None] * len(mount_resource),
|
||||||
|
})
|
||||||
|
result = await future
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@action(
|
||||||
|
description="扣电测试启动",
|
||||||
|
handles=[
|
||||||
|
ActionInputHandle(key="resource", data_type="resource",
|
||||||
|
label="待转移资源", data_key="resource", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="mount_resource", data_type="resource",
|
||||||
|
label="目标孔位", data_key="mount_resource", data_source=DataSource.HANDLE),
|
||||||
|
|
||||||
|
ActionInputHandle(key="collector_mass", data_type="collector_mass",
|
||||||
|
label="极流体质量", data_key="collector_mass", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="active_material", data_type="active_material",
|
||||||
|
label="活性物质含量", data_key="active_material", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="capacity", data_type="capacity",
|
||||||
|
label="克容量", data_key="capacity", data_source=DataSource.HANDLE),
|
||||||
|
ActionInputHandle(key="battery_system", data_type="battery_system",
|
||||||
|
label="电池体系", data_key="battery_system", data_source=DataSource.HANDLE),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
async def test(
|
||||||
|
self, resource: List[ResourceSlot], mount_resource: List[ResourceSlot], collector_mass: List[float], active_material: List[float], capacity: List[float], battery_system: list[str]
|
||||||
|
):
|
||||||
|
print(resource)
|
||||||
|
print(mount_resource)
|
||||||
|
print(collector_mass)
|
||||||
|
print(active_material)
|
||||||
|
print(capacity)
|
||||||
|
print(battery_system)
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
auto_prefix=True,
|
auto_prefix=True,
|
||||||
description="批量准备物料 - 虚拟起始节点, 生成A1-A5物料, 输出5个handle供后续节点使用",
|
description="批量准备物料 - 虚拟起始节点, 生成A1-A5物料, 输出5个handle供后续节点使用",
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
# 工作站抽象基类物料系统架构说明
|
# 工作站抽象基类物料系统架构说明
|
||||||
|
|
||||||
## 设计理念
|
|
||||||
|
|
||||||
基于用户需求"请你帮我系统思考一下,工作站抽象基类的物料系统基类该如何构建",我们最终确定了一个**PyLabRobot Deck为中心**的简化架构。
|
|
||||||
|
|
||||||
### 核心原则
|
### 核心原则
|
||||||
|
|
||||||
1. **PyLabRobot为物料管理核心**:使用PyLabRobot的Deck系统作为物料管理的基础,利用其成熟的Resource体系
|
1. **PyLabRobot为物料管理核心**:使用PyLabRobot的Deck系统作为物料管理的基础,利用其成熟的Resource体系
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
# Bioyond Cell 工作站 - 多订单返回示例
|
||||||
|
|
||||||
|
本文档说明了 `create_orders` 函数如何收集并返回所有订单的完成报文。
|
||||||
|
|
||||||
|
## 问题描述
|
||||||
|
|
||||||
|
之前的实现只会等待并返回第一个订单的完成报文,如果有多个订单(例如从 Excel 解析出 3 个订单),只能得到第一个订单的推送信息。
|
||||||
|
|
||||||
|
## 解决方案
|
||||||
|
|
||||||
|
修改后的 `create_orders` 函数现在会:
|
||||||
|
|
||||||
|
1. **提取所有 orderCode**:从 LIMS 接口返回的 `data` 列表中提取所有订单编号
|
||||||
|
2. **逐个等待完成**:遍历所有 orderCode,调用 `wait_for_order_finish` 等待每个订单完成
|
||||||
|
3. **收集所有报文**:将每个订单的完成报文存入 `all_reports` 列表
|
||||||
|
4. **统一返回**:返回包含所有订单报文的 JSON 格式数据
|
||||||
|
|
||||||
|
## 返回格式
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "all_completed",
|
||||||
|
"total_orders": 3,
|
||||||
|
"reports": [
|
||||||
|
{
|
||||||
|
"token": "",
|
||||||
|
"request_time": "2025-12-24T15:32:09.2148671+08:00",
|
||||||
|
"data": {
|
||||||
|
"orderId": "3a1e614d-a082-c44a-60be-68647a35e6f1",
|
||||||
|
"orderCode": "BSO2025122400024",
|
||||||
|
"orderName": "DP20251224001",
|
||||||
|
"status": "30",
|
||||||
|
"workflowStatus": "completed",
|
||||||
|
"usedMaterials": [...]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "",
|
||||||
|
"request_time": "2025-12-24T15:32:09.9999039+08:00",
|
||||||
|
"data": {
|
||||||
|
"orderId": "3a1e614d-a0a2-f7a9-9360-610021c9479d",
|
||||||
|
"orderCode": "BSO2025122400025",
|
||||||
|
"orderName": "DP20251224002",
|
||||||
|
"status": "30",
|
||||||
|
"workflowStatus": "completed",
|
||||||
|
"usedMaterials": [...]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"token": "",
|
||||||
|
"request_time": "2025-12-24T15:34:00.4139986+08:00",
|
||||||
|
"data": {
|
||||||
|
"orderId": "3a1e614d-a0cd-81ca-9f7f-2f4e93af01cd",
|
||||||
|
"orderCode": "BSO2025122400026",
|
||||||
|
"orderName": "DP20251224003",
|
||||||
|
"status": "30",
|
||||||
|
"workflowStatus": "completed",
|
||||||
|
"usedMaterials": [...]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"original_response": {...}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用示例
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 调用 create_orders
|
||||||
|
result = workstation.create_orders("20251224.xlsx")
|
||||||
|
|
||||||
|
# 访问返回数据
|
||||||
|
print(f"总订单数: {result['total_orders']}")
|
||||||
|
print(f"状态: {result['status']}")
|
||||||
|
|
||||||
|
# 遍历所有订单的报文
|
||||||
|
for i, report in enumerate(result['reports'], 1):
|
||||||
|
order_data = report.get('data', {})
|
||||||
|
print(f"\n订单 {i}:")
|
||||||
|
print(f" orderCode: {order_data.get('orderCode')}")
|
||||||
|
print(f" orderName: {order_data.get('orderName')}")
|
||||||
|
print(f" status: {order_data.get('status')}")
|
||||||
|
print(f" 使用物料数: {len(order_data.get('usedMaterials', []))}")
|
||||||
|
```
|
||||||
|
|
||||||
|
## 控制台输出示例
|
||||||
|
|
||||||
|
```
|
||||||
|
[create_orders] 即将提交订单数量: 3
|
||||||
|
[create_orders] 接口返回: {...}
|
||||||
|
[create_orders] 等待 3 个订单完成: ['BSO2025122400024', 'BSO2025122400025', 'BSO2025122400026']
|
||||||
|
[create_orders] 正在等待第 1/3 个订单: BSO2025122400024
|
||||||
|
[create_orders] ✓ 订单 BSO2025122400024 完成
|
||||||
|
[create_orders] 正在等待第 2/3 个订单: BSO2025122400025
|
||||||
|
[create_orders] ✓ 订单 BSO2025122400025 完成
|
||||||
|
[create_orders] 正在等待第 3/3 个订单: BSO2025122400026
|
||||||
|
[create_orders] ✓ 订单 BSO2025122400026 完成
|
||||||
|
[create_orders] 所有订单已完成,共收集 3 个报文
|
||||||
|
实验记录本========================create_orders========================
|
||||||
|
返回报文数量: 3
|
||||||
|
报文 1: orderCode=BSO2025122400024, status=30
|
||||||
|
报文 2: orderCode=BSO2025122400025, status=30
|
||||||
|
报文 3: orderCode=BSO2025122400026, status=30
|
||||||
|
========================
|
||||||
|
```
|
||||||
|
|
||||||
|
## 关键改进
|
||||||
|
|
||||||
|
1. ✅ **等待所有订单**:不再只等待第一个订单,而是遍历所有 orderCode
|
||||||
|
2. ✅ **收集完整报文**:每个订单的完整推送报文都被保存在 `reports` 数组中
|
||||||
|
3. ✅ **详细日志**:清晰显示正在等待哪个订单,以及完成情况
|
||||||
|
4. ✅ **错误处理**:即使某个订单失败,也会记录其状态信息
|
||||||
|
5. ✅ **统一格式**:返回的 JSON 格式便于后续处理和分析
|
||||||
Binary file not shown.
@@ -0,0 +1,204 @@
|
|||||||
|
# BioyondCellWorkstation JSON 配置迁移经验总结
|
||||||
|
|
||||||
|
**日期**: 2026-01-13
|
||||||
|
**目的**: 从 `config.py` 迁移到 JSON 配置文件
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 问题背景
|
||||||
|
|
||||||
|
原系统通过 `config.py` 管理配置,导致:
|
||||||
|
1. HTTP 服务重复启动(父类 `BioyondWorkstation` 和子类都启动)
|
||||||
|
2. 配置分散在代码中,不便于管理
|
||||||
|
3. 无法通过 JSON 统一配置所有参数
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 解决方案:嵌套配置结构
|
||||||
|
|
||||||
|
### JSON 结构设计
|
||||||
|
|
||||||
|
**正确示例** (嵌套在 `config` 中):
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"nodes": [{
|
||||||
|
"id": "bioyond_cell_workstation",
|
||||||
|
"config": {
|
||||||
|
"deck": {...},
|
||||||
|
"protocol_type": [],
|
||||||
|
"bioyond_config": {
|
||||||
|
"api_host": "http://172.16.11.219:44388",
|
||||||
|
"api_key": "8A819E5C",
|
||||||
|
"timeout": 30,
|
||||||
|
"HTTP_host": "172.16.11.206",
|
||||||
|
"HTTP_port": 8080,
|
||||||
|
"debug_mode": false,
|
||||||
|
"material_type_mappings": {...},
|
||||||
|
"warehouse_mapping": {...},
|
||||||
|
"solid_liquid_mappings": {...}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"data": {}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**关键点**:
|
||||||
|
- ✅ `bioyond_config` 放在 `config` 中(会传递到 `__init__`)
|
||||||
|
- ❌ **不要**放在 `data` 中(`data` 是运行时状态,不会传递)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Python 代码适配
|
||||||
|
|
||||||
|
### 1. 修改 `BioyondCellWorkstation.__init__` 签名
|
||||||
|
|
||||||
|
**文件**: `bioyond_cell_workstation.py`
|
||||||
|
|
||||||
|
```python
|
||||||
|
def __init__(self, bioyond_config: dict = None, deck=None, protocol_type=None, **kwargs):
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
bioyond_config: 从 JSON 加载的配置字典
|
||||||
|
deck: Deck 配置
|
||||||
|
protocol_type: 协议类型
|
||||||
|
"""
|
||||||
|
# 验证配置
|
||||||
|
if bioyond_config is None:
|
||||||
|
raise ValueError("需要 bioyond_config 参数")
|
||||||
|
|
||||||
|
# 保存配置
|
||||||
|
self.bioyond_config = bioyond_config
|
||||||
|
|
||||||
|
# 设置 HTTP 服务去重标志
|
||||||
|
self.bioyond_config["_disable_auto_http_service"] = True
|
||||||
|
|
||||||
|
# 调用父类
|
||||||
|
super().__init__(bioyond_config=self.bioyond_config, deck=deck, **kwargs)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 替换全局变量引用
|
||||||
|
|
||||||
|
**修改前**(使用全局变量):
|
||||||
|
```python
|
||||||
|
from config import MATERIAL_TYPE_MAPPINGS, WAREHOUSE_MAPPING
|
||||||
|
|
||||||
|
def create_sample(self, board_type, ...):
|
||||||
|
carrier_type_id = MATERIAL_TYPE_MAPPINGS[board_type][1]
|
||||||
|
location_id = WAREHOUSE_MAPPING[warehouse_name]["site_uuids"][location_code]
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**(从配置读取):
|
||||||
|
```python
|
||||||
|
def create_sample(self, board_type, ...):
|
||||||
|
carrier_type_id = self.bioyond_config['material_type_mappings'][board_type][1]
|
||||||
|
location_id = self.bioyond_config['warehouse_mapping'][warehouse_name]["site_uuids"][location_code]
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 修复父类配置访问
|
||||||
|
|
||||||
|
在 `station.py` 中安全访问配置默认值:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 修改前(会 KeyError)
|
||||||
|
self._http_service_config = {
|
||||||
|
"host": bioyond_config.get("http_service_host", HTTP_SERVICE_CONFIG["http_service_host"])
|
||||||
|
}
|
||||||
|
|
||||||
|
# 修改后(安全访问)
|
||||||
|
self._http_service_config = {
|
||||||
|
"host": bioyond_config.get("http_service_host", HTTP_SERVICE_CONFIG.get("http_service_host", ""))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 常见陷阱
|
||||||
|
|
||||||
|
### ❌ 错误1:将配置放在 `data` 字段
|
||||||
|
```json
|
||||||
|
"config": {"deck": {...}},
|
||||||
|
"data": {"bioyond_config": {...}} // ❌ 不会传递到 __init__
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ 错误2:扁平化配置(已废弃方案)
|
||||||
|
虽然扁平化也能工作,但不推荐:
|
||||||
|
```json
|
||||||
|
"config": {
|
||||||
|
"deck": {...},
|
||||||
|
"api_host": "...", // ❌ 不够清晰
|
||||||
|
"api_key": "...",
|
||||||
|
"HTTP_host": "..."
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### ❌ 错误3:忘记替换全局变量引用
|
||||||
|
代码中直接使用 `MATERIAL_TYPE_MAPPINGS` 等全局变量会导致 `NameError`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 云端同步注意事项
|
||||||
|
|
||||||
|
使用 `--upload_registry` 时,云端配置可能覆盖本地配置:
|
||||||
|
- 首次上传时确保 JSON 完整
|
||||||
|
- 或使用新的 `ak/sk` 避免旧配置干扰
|
||||||
|
- 调试时可暂时移除 `--upload_registry` 参数
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 验证清单
|
||||||
|
|
||||||
|
启动成功后应看到:
|
||||||
|
```
|
||||||
|
✅ 从 JSON 配置加载 bioyond_config 成功
|
||||||
|
API Host: http://...
|
||||||
|
HTTP Service: ...
|
||||||
|
✅ BioyondCellWorkstation 初始化完成
|
||||||
|
Loaded ResourceTreeSet with ... nodes
|
||||||
|
```
|
||||||
|
|
||||||
|
运行时不应出现:
|
||||||
|
- ❌ `NameError: name 'MATERIAL_TYPE_MAPPINGS' is not defined`
|
||||||
|
- ❌ `KeyError: 'http_service_host'`
|
||||||
|
- ❌ `bioyond_config 缺少必需参数`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 调试经验
|
||||||
|
|
||||||
|
1. **添加调试日志**查看参数传递链路:
|
||||||
|
- `graphio.py`: JSON 加载后的 config 内容
|
||||||
|
- `initialize_device.py`: `device_config.res_content.config` 的键
|
||||||
|
- `bioyond_cell_workstation.py`: `__init__` 接收到的参数
|
||||||
|
|
||||||
|
2. **config vs data 区别**:
|
||||||
|
- `config`: 初始化参数,传递给 `__init__`
|
||||||
|
- `data`: 运行时状态,不传递给 `__init__`
|
||||||
|
|
||||||
|
3. **参数名必须匹配**:
|
||||||
|
- JSON 中的键名必须与 `__init__` 参数名完全一致
|
||||||
|
|
||||||
|
4. **调试代码清理**:完成后记得删除调试日志(🔍 DEBUG 标记)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 修改文件清单
|
||||||
|
|
||||||
|
| 文件 | 修改内容 |
|
||||||
|
|------|----------|
|
||||||
|
| `yibin_electrolyte_config.json` | 创建嵌套 `config.bioyond_config` 结构 |
|
||||||
|
| `bioyond_cell_workstation.py` | 修改 `__init__` 接收 `bioyond_config`,替换所有全局变量引用 |
|
||||||
|
| `station.py` | 安全访问 `HTTP_SERVICE_CONFIG` 默认值 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 参考代码位置
|
||||||
|
|
||||||
|
- JSON 配置示例: `yibin_electrolyte_config.json` L12-L353
|
||||||
|
- `__init__` 实现: `bioyond_cell_workstation.py` L39-L94
|
||||||
|
- 全局变量替换示例: `bioyond_cell_workstation.py` L2005, L1863, L1966
|
||||||
|
- HTTP 服务配置: `station.py` L629-L634
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**总结**: 使用嵌套结构将所有配置放在 `config.bioyond_config` 中,修改 `__init__` 直接接收该参数,并替换所有全局变量引用为 `self.bioyond_config` 访问。
|
||||||
@@ -0,0 +1,312 @@
|
|||||||
|
# BioyondCell 配置迁移修改总结
|
||||||
|
|
||||||
|
**日期**: 2026-01-13
|
||||||
|
**目标**: 从 `config.py` 完全迁移到 JSON 配置,消除所有全局变量依赖
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 修改概览
|
||||||
|
|
||||||
|
本次修改完成了 BioyondCell 模块从 Python 配置文件到 JSON 配置的完整迁移,并清理了所有对 `config.py` 全局变量的依赖。
|
||||||
|
|
||||||
|
### 核心成果
|
||||||
|
|
||||||
|
- ✅ 完全移除对 `config.py` 的导入依赖
|
||||||
|
- ✅ 使用嵌套 JSON 结构 `config.bioyond_config`
|
||||||
|
- ✅ 修复 7 处 `bioyond_cell_workstation.py` 中的全局变量引用
|
||||||
|
- ✅ 修复 3 处其他文件中的全局变量引用
|
||||||
|
- ✅ HTTP 服务去重机制完善
|
||||||
|
- ✅ 系统成功启动并正常运行
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 修改文件清单
|
||||||
|
|
||||||
|
### 1. JSON 配置文件
|
||||||
|
|
||||||
|
**文件**: `yibin_electrolyte_config.json`
|
||||||
|
|
||||||
|
**修改**:
|
||||||
|
- 采用嵌套结构将所有配置放在 `config.bioyond_config` 中
|
||||||
|
- 包含:`api_host`, `api_key`, `HTTP_host`, `HTTP_port`, `material_type_mappings`, `warehouse_mapping`, `solid_liquid_mappings` 等
|
||||||
|
|
||||||
|
**示例结构**:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"nodes": [{
|
||||||
|
"id": "bioyond_cell_workstation",
|
||||||
|
"config": {
|
||||||
|
"deck": {...},
|
||||||
|
"protocol_type": [],
|
||||||
|
"bioyond_config": {
|
||||||
|
"api_host": "http://172.16.11.219:44388",
|
||||||
|
"api_key": "8A819E5C",
|
||||||
|
"HTTP_host": "172.16.11.206",
|
||||||
|
"HTTP_port": 8080,
|
||||||
|
"material_type_mappings": {...},
|
||||||
|
"warehouse_mapping": {...},
|
||||||
|
"solid_liquid_mappings": {...}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2. bioyond_cell_workstation.py
|
||||||
|
|
||||||
|
**位置**: `unilabos/devices/workstation/bioyond_studio/bioyond_cell/bioyond_cell_workstation.py`
|
||||||
|
|
||||||
|
#### 修改 A: `__init__` 方法签名 (L39-99)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
def __init__(self, deck=None, protocol_type=None, **kwargs):
|
||||||
|
# 从 kwargs 收集配置字段
|
||||||
|
self.bioyond_config = {}
|
||||||
|
for field in bioyond_field_names:
|
||||||
|
if field in kwargs:
|
||||||
|
self.bioyond_config[field] = kwargs.pop(field)
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
def __init__(self, bioyond_config: dict = None, deck=None, protocol_type=None, **kwargs):
|
||||||
|
"""直接接收 bioyond_config 参数"""
|
||||||
|
if bioyond_config is None:
|
||||||
|
raise ValueError("需要 bioyond_config 参数")
|
||||||
|
|
||||||
|
self.bioyond_config = bioyond_config
|
||||||
|
|
||||||
|
# 设置 HTTP 服务去重标志
|
||||||
|
self.bioyond_config["_disable_auto_http_service"] = True
|
||||||
|
|
||||||
|
super().__init__(bioyond_config=self.bioyond_config, deck=deck, **kwargs)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 修改 B: 替换全局变量引用 (7 处)
|
||||||
|
|
||||||
|
| 位置 | 原代码 | 修改后 |
|
||||||
|
|------|--------|--------|
|
||||||
|
| L2005 | `MATERIAL_TYPE_MAPPINGS[board_type][1]` | `self.bioyond_config['material_type_mappings'][board_type][1]` |
|
||||||
|
| L2006 | `MATERIAL_TYPE_MAPPINGS[bottle_type][1]` | `self.bioyond_config['material_type_mappings'][bottle_type][1]` |
|
||||||
|
| L2009 | `WAREHOUSE_MAPPING` | `self.bioyond_config['warehouse_mapping']` |
|
||||||
|
| L2013 | `WAREHOUSE_MAPPING[warehouse_name]` | `self.bioyond_config['warehouse_mapping'][warehouse_name]` |
|
||||||
|
| L2017 | `WAREHOUSE_MAPPING[warehouse_name]["site_uuids"]` | `self.bioyond_config['warehouse_mapping'][warehouse_name]["site_uuids"]` |
|
||||||
|
| L1863 | `SOLID_LIQUID_MAPPINGS.get(material_name)` | `self.bioyond_config.get('solid_liquid_mappings', {}).get(material_name)` |
|
||||||
|
| L1966, L1976 | `MATERIAL_TYPE_MAPPINGS.items()` | `self.bioyond_config['material_type_mappings'].items()` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3. station.py
|
||||||
|
|
||||||
|
**位置**: `unilabos/devices/workstation/bioyond_studio/station.py`
|
||||||
|
|
||||||
|
#### 修改 A: 删除 config 导入 (L26-28)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
from unilabos.devices.workstation.bioyond_studio.config import (
|
||||||
|
API_CONFIG, WORKFLOW_MAPPINGS, MATERIAL_TYPE_MAPPINGS, WAREHOUSE_MAPPING, HTTP_SERVICE_CONFIG
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
# 已删除此导入
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 修改 B: `_create_communication_module` 方法 (L691-702)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
def _create_communication_module(self, config: Optional[Dict[str, Any]] = None) -> None:
|
||||||
|
default_config = {
|
||||||
|
**API_CONFIG,
|
||||||
|
"workflow_mappings": WORKFLOW_MAPPINGS,
|
||||||
|
"material_type_mappings": MATERIAL_TYPE_MAPPINGS,
|
||||||
|
"warehouse_mapping": WAREHOUSE_MAPPING
|
||||||
|
}
|
||||||
|
if config:
|
||||||
|
self.bioyond_config = {**default_config, **config}
|
||||||
|
else:
|
||||||
|
self.bioyond_config = default_config
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
def _create_communication_module(self, config: Optional[Dict[str, Any]] = None) -> None:
|
||||||
|
"""创建Bioyond通信模块"""
|
||||||
|
# 使用传入的 config 参数(来自 bioyond_config)
|
||||||
|
# 不再依赖全局变量 API_CONFIG 等
|
||||||
|
if config:
|
||||||
|
self.bioyond_config = config
|
||||||
|
else:
|
||||||
|
# 如果没有传入配置,创建空配置(用于测试或兼容性)
|
||||||
|
self.bioyond_config = {}
|
||||||
|
|
||||||
|
self.hardware_interface = BioyondV1RPC(self.bioyond_config)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 修改 C: HTTP 服务配置 (L627-632)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
self._http_service_config = {
|
||||||
|
"host": bioyond_config.get("http_service_host", HTTP_SERVICE_CONFIG.get("http_service_host", "")),
|
||||||
|
"port": bioyond_config.get("http_service_port", HTTP_SERVICE_CONFIG.get("http_service_port", 0))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
self._http_service_config = {
|
||||||
|
"host": bioyond_config.get("http_service_host", bioyond_config.get("HTTP_host", "")),
|
||||||
|
"port": bioyond_config.get("http_service_port", bioyond_config.get("HTTP_port", 0))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. bioyond_rpc.py
|
||||||
|
|
||||||
|
**位置**: `unilabos/devices/workstation/bioyond_studio/bioyond_rpc.py`
|
||||||
|
|
||||||
|
#### 修改 A: 删除 config 导入 (L12)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
from unilabos.devices.workstation.bioyond_studio.config import LOCATION_MAPPING
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
# 已删除此导入
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 修改 B: `material_outbound` 方法 (L278-280)
|
||||||
|
|
||||||
|
**修改前**:
|
||||||
|
```python
|
||||||
|
def material_outbound(self, material_id: str, location_name: str, quantity: int) -> dict:
|
||||||
|
"""指定库位出库物料(通过库位名称)"""
|
||||||
|
location_id = LOCATION_MAPPING.get(location_name, location_name)
|
||||||
|
```
|
||||||
|
|
||||||
|
**修改后**:
|
||||||
|
```python
|
||||||
|
def material_outbound(self, material_id: str, location_name: str, quantity: int) -> dict:
|
||||||
|
"""指定库位出库物料(通过库位名称)"""
|
||||||
|
# location_name 参数实际上应该直接是 location_id (UUID)
|
||||||
|
location_id = location_name
|
||||||
|
```
|
||||||
|
|
||||||
|
**说明**: `LOCATION_MAPPING` 在 `config-0113.py` 中本来就是空字典 `{}`,所以直接使用 `location_name` 逻辑等价。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 关键设计决策
|
||||||
|
|
||||||
|
### 1. 嵌套 vs 扁平配置
|
||||||
|
|
||||||
|
**选择**: 嵌套结构 `config.bioyond_config`
|
||||||
|
|
||||||
|
**理由**:
|
||||||
|
- ✅ 语义清晰,配置分组明确
|
||||||
|
- ✅ 参数传递直观,直接对应 `__init__` 参数
|
||||||
|
- ✅ 易于维护,不需要硬编码字段列表
|
||||||
|
- ✅ 符合 UniLab 设计模式
|
||||||
|
|
||||||
|
### 2. HTTP 服务去重
|
||||||
|
|
||||||
|
**实现**: 子类设置 `_disable_auto_http_service` 标志
|
||||||
|
|
||||||
|
```python
|
||||||
|
# bioyond_cell_workstation.py
|
||||||
|
self.bioyond_config["_disable_auto_http_service"] = True
|
||||||
|
|
||||||
|
# station.py (post_init)
|
||||||
|
if self.bioyond_config.get("_disable_auto_http_service"):
|
||||||
|
logger.info("子类已自行管理HTTP服务,跳过自动启动")
|
||||||
|
return
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 全局变量替换策略
|
||||||
|
|
||||||
|
**原则**: 所有配置从 `self.bioyond_config` 获取
|
||||||
|
|
||||||
|
**模式**:
|
||||||
|
```python
|
||||||
|
# 修改前
|
||||||
|
from config import MATERIAL_TYPE_MAPPINGS
|
||||||
|
carrier_type_id = MATERIAL_TYPE_MAPPINGS[board_type][1]
|
||||||
|
|
||||||
|
# 修改后
|
||||||
|
carrier_type_id = self.bioyond_config['material_type_mappings'][board_type][1]
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ 验证结果
|
||||||
|
|
||||||
|
### 启动成功日志
|
||||||
|
```
|
||||||
|
✅ 从 JSON 配置加载 bioyond_config 成功
|
||||||
|
API Host: http://172.16.11.219:44388
|
||||||
|
HTTP Service: 172.16.11.206:8080
|
||||||
|
🔧 已设置 _disable_auto_http_service 标志,防止 HTTP 服务重复启动
|
||||||
|
✅ BioyondCellWorkstation 初始化完成
|
||||||
|
Loaded ResourceTreeSet with 1 trees, 1785 total nodes
|
||||||
|
```
|
||||||
|
|
||||||
|
### 功能验证
|
||||||
|
- ✅ 订单创建 (`create_orders_v2`)
|
||||||
|
- ✅ 质量比计算
|
||||||
|
- ✅ 物料转移 (`transfer_3_to_2_to_1`)
|
||||||
|
- ✅ HTTP 报送接收 (step_finish, sample_finish, order_finish)
|
||||||
|
- ✅ 等待机制 (`wait_for_order_finish`)
|
||||||
|
- ✅ 仓库 UUID 映射
|
||||||
|
- ✅ 物料类型映射
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 相关文档
|
||||||
|
|
||||||
|
- **配置迁移经验**: `2026-01-13_JSON配置迁移经验.md`
|
||||||
|
- **任务清单**: `C:\Users\AndyXie\.gemini\antigravity\brain\...\task.md`
|
||||||
|
- **实施计划**: `C:\Users\AndyXie\.gemini\antigravity\brain\...\implementation_plan.md`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚠️ 注意事项
|
||||||
|
|
||||||
|
### 其他工作站模块
|
||||||
|
|
||||||
|
以下文件仍在使用 `config.py` 全局变量(未包含在本次修改中):
|
||||||
|
- `reaction_station.py` - 使用 `API_CONFIG`
|
||||||
|
- `experiment.py` - 使用 `API_CONFIG`, `WORKFLOW_MAPPINGS`, `MATERIAL_TYPE_MAPPINGS`
|
||||||
|
- `dispensing_station.py` - 使用 `API_CONFIG`, `WAREHOUSE_MAPPING`
|
||||||
|
- `station.py` L176, L177, L529, L530 - 动态导入 `WAREHOUSE_MAPPING`
|
||||||
|
|
||||||
|
**建议**: 后续可以统一迁移这些模块到 JSON 配置。
|
||||||
|
|
||||||
|
### config.py 文件
|
||||||
|
|
||||||
|
`config.py` 文件已恢复但**不再被 bioyond_cell 使用**。可以:
|
||||||
|
- 保留作为其他模块的参考
|
||||||
|
- 或者完全删除(如果其他模块也迁移完成)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 下一步建议
|
||||||
|
|
||||||
|
1. **清理调试代码** ✅ (已完成)
|
||||||
|
2. **提交代码到 Git**
|
||||||
|
3. **迁移其他工作站模块** (可选)
|
||||||
|
4. **更新文档和启动脚本**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**修改完成日期**: 2026-01-13
|
||||||
|
**系统状态**: ✅ 稳定运行
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,157 @@
|
|||||||
|
# 批量出库 Excel 模板使用说明
|
||||||
|
|
||||||
|
**文件**: `outbound_template.xlsx`
|
||||||
|
**用途**: 配合 `auto_batch_outbound_from_xlsx()` 方法进行批量出库操作
|
||||||
|
**API 端点**: `/api/lims/storage/auto-batch-out-bound`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 Excel 列说明
|
||||||
|
|
||||||
|
| 列名 | 说明 | 示例 | 必填 |
|
||||||
|
|------|------|------|------|
|
||||||
|
| `locationId` | **库位 ID(UUID)** | `3a19da43-57b5-294f-d663-154a1cc32270` | ✅ 是 |
|
||||||
|
| `warehouseId` | **仓库 ID 或名称** | `配液站内试剂仓库` | ✅ 是 |
|
||||||
|
| `quantity` | **出库数量** | `1.0`, `2.0` | ✅ 是 |
|
||||||
|
| `x` | **X 坐标(库位横向位置)** | `1`, `2`, `3` | ✅ 是 |
|
||||||
|
| `y` | **Y 坐标(库位纵向位置)** | `1`, `2`, `3` | ✅ 是 |
|
||||||
|
| `z` | **Z 坐标(库位层数/高度)** | `1`, `2`, `3` | ✅ 是 |
|
||||||
|
| `备注说明` | 可选备注信息 | `配液站内试剂仓库-A01` | ❌ 否 |
|
||||||
|
|
||||||
|
### 📐 坐标说明
|
||||||
|
|
||||||
|
**x, y, z** 是库位在仓库内的**三维坐标**:
|
||||||
|
|
||||||
|
```
|
||||||
|
仓库(例如 WH4)
|
||||||
|
├── Z=1(第1层/加样头面)
|
||||||
|
│ ├── X=1, Y=1(位置 A)
|
||||||
|
│ ├── X=2, Y=1(位置 B)
|
||||||
|
│ ├── X=3, Y=1(位置 C)
|
||||||
|
│ └── ...
|
||||||
|
│
|
||||||
|
└── Z=2(第2层/原液瓶面)
|
||||||
|
├── X=1, Y=1(位置 A)
|
||||||
|
├── X=2, Y=1(位置 B)
|
||||||
|
└── ...
|
||||||
|
```
|
||||||
|
|
||||||
|
- **warehouseId**: 指定哪个仓库(WH3, WH4, 配液站等)
|
||||||
|
- **x, y, z**: 在该仓库内的三维坐标
|
||||||
|
- **locationId**: 该坐标位置的唯一 UUID
|
||||||
|
|
||||||
|
### 🎯 起点与终点
|
||||||
|
|
||||||
|
**重要说明**:批量出库模板**只规定了出库的"起点"**(从哪里取物料),**没有指定"终点"**(放到哪里)。
|
||||||
|
|
||||||
|
```
|
||||||
|
出库流程:
|
||||||
|
起点(Excel 指定) → ?终点(LIMS/工作流决定)
|
||||||
|
↓
|
||||||
|
locationId, x, y, z → 由 LIMS 系统或当前工作流自动分配
|
||||||
|
```
|
||||||
|
|
||||||
|
**终点由以下方式确定:**
|
||||||
|
- **LIMS 系统自动分配**:根据当前任务自动规划目标位置
|
||||||
|
- **工作流预定义**:在创建出库任务时已绑定目标位置
|
||||||
|
- **暂存区**:默认放到出库暂存区,等待下一步操作
|
||||||
|
|
||||||
|
💡 **对比**:上料操作(`auto_feeding4to3`)则有 `targetWH` 参数可以指定目标仓库
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔍 如何获取 UUID?
|
||||||
|
|
||||||
|
### 方法 1:从配置文件获取
|
||||||
|
|
||||||
|
参考 `yibin_electrolyte_config.json` 中的 `warehouse_mapping`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"warehouse_mapping": {
|
||||||
|
"配液站内试剂仓库": {
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a19da43-57b5-294f-d663-154a1cc32270",
|
||||||
|
"B01": "3a19da43-57b5-7394-5f49-54efe2c9bef2",
|
||||||
|
"C01": "3a19da43-57b5-5e75-552f-8dbd0ad1075f"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"手动堆栈": {
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a19deae-2c7a-36f5-5e41-02c5b66feaea",
|
||||||
|
"A02": "3a19deae-2c7a-dc6d-c41e-ef285d946cfe"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方法 2:通过 API 查询
|
||||||
|
|
||||||
|
```python
|
||||||
|
material_info = hardware_interface.material_id_query(workflow_id)
|
||||||
|
locations = material_info.get("locations", [])
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 填写示例
|
||||||
|
|
||||||
|
### 示例 1:从配液站内试剂仓库出库
|
||||||
|
|
||||||
|
| locationId | warehouseId | quantity | x | y | z | 备注说明 |
|
||||||
|
|------------|-------------|----------|---|---|---|----------|
|
||||||
|
| `3a19da43-57b5-294f-d663-154a1cc32270` | 配液站内试剂仓库 | 1 | 1 | 1 | 1 | A01 位置 |
|
||||||
|
| `3a19da43-57b5-7394-5f49-54efe2c9bef2` | 配液站内试剂仓库 | 2 | 2 | 1 | 1 | B01 位置 |
|
||||||
|
|
||||||
|
### 示例 2:从手动堆栈出库
|
||||||
|
|
||||||
|
| locationId | warehouseId | quantity | x | y | z | 备注说明 |
|
||||||
|
|------------|-------------|----------|---|---|---|----------|
|
||||||
|
| `3a19deae-2c7a-36f5-5e41-02c5b66feaea` | 手动堆栈 | 1 | 1 | 1 | 1 | A01 |
|
||||||
|
| `3a19deae-2c7a-dc6d-c41e-ef285d946cfe` | 手动堆栈 | 1 | 1 | 2 | 1 | A02 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💻 使用方法
|
||||||
|
|
||||||
|
```python
|
||||||
|
from bioyond_cell_workstation import BioyondCellWorkstation
|
||||||
|
|
||||||
|
# 初始化工作站
|
||||||
|
workstation = BioyondCellWorkstation(config=config, deck=deck)
|
||||||
|
|
||||||
|
# 调用批量出库方法
|
||||||
|
result = workstation.auto_batch_outbound_from_xlsx(
|
||||||
|
xlsx_path="outbound_template.xlsx"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚠️ 注意事项
|
||||||
|
|
||||||
|
1. **locationId 必须是有效的 UUID**,不能使用库位名称
|
||||||
|
2. **x, y, z 坐标必须与 locationId 对应**,表示该库位在仓库内的位置
|
||||||
|
3. **quantity 必须是数字**,可以是整数或浮点数
|
||||||
|
4. Excel 文件必须包含表头行
|
||||||
|
5. 空行会被自动跳过
|
||||||
|
6. 确保 UUID 与实际库位对应,否则 API 会报错
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 相关文件
|
||||||
|
|
||||||
|
- **配置文件**: `yibin_electrolyte_config.json`
|
||||||
|
- **Python 代码**: `bioyond_cell_workstation.py` (L630-695)
|
||||||
|
- **生成脚本**: `create_outbound_template.py`
|
||||||
|
- **上料模板**: `material_template.xlsx`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 重新生成模板
|
||||||
|
|
||||||
|
```bash
|
||||||
|
conda activate newunilab
|
||||||
|
python create_outbound_template.py
|
||||||
|
```
|
||||||
@@ -9,7 +9,7 @@ from datetime import datetime, timezone
|
|||||||
from unilabos.device_comms.rpc import BaseRequest
|
from unilabos.device_comms.rpc import BaseRequest
|
||||||
from typing import Optional, List, Dict, Any
|
from typing import Optional, List, Dict, Any
|
||||||
import json
|
import json
|
||||||
from unilabos.devices.workstation.bioyond_studio.config import LOCATION_MAPPING
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleLogger:
|
class SimpleLogger:
|
||||||
@@ -49,6 +49,14 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
self.config = config
|
self.config = config
|
||||||
self.api_key = config["api_key"]
|
self.api_key = config["api_key"]
|
||||||
self.host = config["api_host"]
|
self.host = config["api_host"]
|
||||||
|
|
||||||
|
# 初始化 location_mapping
|
||||||
|
# 直接从 warehouse_mapping 构建,确保数据源所谓的单一和结构化
|
||||||
|
self.location_mapping = {}
|
||||||
|
warehouse_mapping = self.config.get("warehouse_mapping", {})
|
||||||
|
for warehouse_name, warehouse_config in warehouse_mapping.items():
|
||||||
|
if "site_uuids" in warehouse_config:
|
||||||
|
self.location_mapping.update(warehouse_config["site_uuids"])
|
||||||
self._logger = SimpleLogger()
|
self._logger = SimpleLogger()
|
||||||
self.material_cache = {}
|
self.material_cache = {}
|
||||||
self._load_material_cache()
|
self._load_material_cache()
|
||||||
@@ -176,7 +184,40 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
print(f"add material data: {response['data']}")
|
print(f"add material data: {response['data']}")
|
||||||
return response.get("data", {})
|
|
||||||
|
# 自动更新缓存
|
||||||
|
data = response.get("data", {})
|
||||||
|
if data:
|
||||||
|
if isinstance(data, str):
|
||||||
|
# 如果返回的是字符串,通常是ID
|
||||||
|
mat_id = data
|
||||||
|
name = params.get("name")
|
||||||
|
else:
|
||||||
|
# 如果返回的是字典,尝试获取name和id
|
||||||
|
name = data.get("name") or params.get("name")
|
||||||
|
mat_id = data.get("id")
|
||||||
|
|
||||||
|
if name and mat_id:
|
||||||
|
self.material_cache[name] = mat_id
|
||||||
|
print(f"已自动更新缓存: {name} -> {mat_id}")
|
||||||
|
|
||||||
|
# 处理返回数据中的 details (如果有)
|
||||||
|
# 有些 API 返回结构可能直接包含 details,或者在 data 字段中
|
||||||
|
details = data.get("details", []) if isinstance(data, dict) else []
|
||||||
|
if not details and isinstance(data, dict):
|
||||||
|
details = data.get("detail", [])
|
||||||
|
|
||||||
|
if details:
|
||||||
|
for detail in details:
|
||||||
|
d_name = detail.get("name")
|
||||||
|
# 尝试从不同字段获取 ID
|
||||||
|
d_id = detail.get("id") or detail.get("detailMaterialId")
|
||||||
|
|
||||||
|
if d_name and d_id:
|
||||||
|
self.material_cache[d_name] = d_id
|
||||||
|
print(f"已自动更新 detail 缓存: {d_name} -> {d_id}")
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
def query_matial_type_id(self, data) -> list:
|
def query_matial_type_id(self, data) -> list:
|
||||||
"""查找物料typeid"""
|
"""查找物料typeid"""
|
||||||
@@ -203,7 +244,7 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
params={
|
params={
|
||||||
"apiKey": self.api_key,
|
"apiKey": self.api_key,
|
||||||
"requestTime": self.get_current_time_iso8601(),
|
"requestTime": self.get_current_time_iso8601(),
|
||||||
"data": {},
|
"data": 0,
|
||||||
})
|
})
|
||||||
if not response or response['code'] != 1:
|
if not response or response['code'] != 1:
|
||||||
return []
|
return []
|
||||||
@@ -273,11 +314,19 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
|
|
||||||
if not response or response['code'] != 1:
|
if not response or response['code'] != 1:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
# 自动更新缓存 - 移除被删除的物料
|
||||||
|
for name, mid in list(self.material_cache.items()):
|
||||||
|
if mid == material_id:
|
||||||
|
del self.material_cache[name]
|
||||||
|
print(f"已从缓存移除物料: {name}")
|
||||||
|
break
|
||||||
|
|
||||||
return response.get("data", {})
|
return response.get("data", {})
|
||||||
|
|
||||||
def material_outbound(self, material_id: str, location_name: str, quantity: int) -> dict:
|
def material_outbound(self, material_id: str, location_name: str, quantity: int) -> dict:
|
||||||
"""指定库位出库物料(通过库位名称)"""
|
"""指定库位出库物料(通过库位名称)"""
|
||||||
location_id = LOCATION_MAPPING.get(location_name, location_name)
|
location_id = self.location_mapping.get(location_name, location_name)
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
"materialId": material_id,
|
"materialId": material_id,
|
||||||
@@ -1103,6 +1152,10 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
for detail_material in detail_materials:
|
for detail_material in detail_materials:
|
||||||
detail_name = detail_material.get("name")
|
detail_name = detail_material.get("name")
|
||||||
detail_id = detail_material.get("detailMaterialId")
|
detail_id = detail_material.get("detailMaterialId")
|
||||||
|
if not detail_id:
|
||||||
|
# 尝试其他可能的字段
|
||||||
|
detail_id = detail_material.get("id")
|
||||||
|
|
||||||
if detail_name and detail_id:
|
if detail_name and detail_id:
|
||||||
self.material_cache[detail_name] = detail_id
|
self.material_cache[detail_name] = detail_id
|
||||||
print(f"加载detail材料: {detail_name} -> ID: {detail_id}")
|
print(f"加载detail材料: {detail_name} -> ID: {detail_id}")
|
||||||
@@ -1123,6 +1176,14 @@ class BioyondV1RPC(BaseRequest):
|
|||||||
print(f"从缓存找到材料: {material_name_or_id} -> ID: {material_id}")
|
print(f"从缓存找到材料: {material_name_or_id} -> ID: {material_id}")
|
||||||
return material_id
|
return material_id
|
||||||
|
|
||||||
|
# 如果缓存中没有,尝试刷新缓存
|
||||||
|
print(f"缓存中未找到材料 '{material_name_or_id}',尝试刷新缓存...")
|
||||||
|
self.refresh_material_cache()
|
||||||
|
if material_name_or_id in self.material_cache:
|
||||||
|
material_id = self.material_cache[material_name_or_id]
|
||||||
|
print(f"刷新缓存后找到材料: {material_name_or_id} -> ID: {material_id}")
|
||||||
|
return material_id
|
||||||
|
|
||||||
print(f"警告: 未在缓存中找到材料名称 '{material_name_or_id}',将使用原值")
|
print(f"警告: 未在缓存中找到材料名称 '{material_name_or_id}',将使用原值")
|
||||||
return material_name_or_id
|
return material_name_or_id
|
||||||
|
|
||||||
|
|||||||
@@ -1,142 +0,0 @@
|
|||||||
# config.py
|
|
||||||
"""
|
|
||||||
配置文件 - 包含所有配置信息和映射关系
|
|
||||||
"""
|
|
||||||
|
|
||||||
# API配置
|
|
||||||
API_CONFIG = {
|
|
||||||
"api_key": "",
|
|
||||||
"api_host": ""
|
|
||||||
}
|
|
||||||
|
|
||||||
# 工作流映射配置
|
|
||||||
WORKFLOW_MAPPINGS = {
|
|
||||||
"reactor_taken_out": "",
|
|
||||||
"reactor_taken_in": "",
|
|
||||||
"Solid_feeding_vials": "",
|
|
||||||
"Liquid_feeding_vials(non-titration)": "",
|
|
||||||
"Liquid_feeding_solvents": "",
|
|
||||||
"Liquid_feeding(titration)": "",
|
|
||||||
"liquid_feeding_beaker": "",
|
|
||||||
"Drip_back": "",
|
|
||||||
}
|
|
||||||
|
|
||||||
# 工作流名称到DisplaySectionName的映射
|
|
||||||
WORKFLOW_TO_SECTION_MAP = {
|
|
||||||
'reactor_taken_in': '反应器放入',
|
|
||||||
'liquid_feeding_beaker': '液体投料-烧杯',
|
|
||||||
'Liquid_feeding_vials(non-titration)': '液体投料-小瓶(非滴定)',
|
|
||||||
'Liquid_feeding_solvents': '液体投料-溶剂',
|
|
||||||
'Solid_feeding_vials': '固体投料-小瓶',
|
|
||||||
'Liquid_feeding(titration)': '液体投料-滴定',
|
|
||||||
'reactor_taken_out': '反应器取出'
|
|
||||||
}
|
|
||||||
|
|
||||||
# 库位映射配置
|
|
||||||
WAREHOUSE_MAPPING = {
|
|
||||||
"粉末堆栈": {
|
|
||||||
"uuid": "",
|
|
||||||
"site_uuids": {
|
|
||||||
# 样品板
|
|
||||||
"A1": "3a14198e-6929-31f0-8a22-0f98f72260df",
|
|
||||||
"A2": "3a14198e-6929-4379-affa-9a2935c17f99",
|
|
||||||
"A3": "3a14198e-6929-56da-9a1c-7f5fbd4ae8af",
|
|
||||||
"A4": "3a14198e-6929-5e99-2b79-80720f7cfb54",
|
|
||||||
"B1": "3a14198e-6929-f525-9a1b-1857552b28ee",
|
|
||||||
"B2": "3a14198e-6929-bf98-0fd5-26e1d68bf62d",
|
|
||||||
"B3": "3a14198e-6929-2d86-a468-602175a2b5aa",
|
|
||||||
"B4": "3a14198e-6929-1a98-ae57-e97660c489ad",
|
|
||||||
# 分装板
|
|
||||||
"C1": "3a14198e-6929-46fe-841e-03dd753f1e4a",
|
|
||||||
"C2": "3a14198e-6929-1bc9-a9bd-3b7ca66e7f95",
|
|
||||||
"C3": "3a14198e-6929-72ac-32ce-9b50245682b8",
|
|
||||||
"C4": "3a14198e-6929-3bd8-e6c7-4a9fd93be118",
|
|
||||||
"D1": "3a14198e-6929-8a0b-b686-6f4a2955c4e2",
|
|
||||||
"D2": "3a14198e-6929-dde1-fc78-34a84b71afdf",
|
|
||||||
"D3": "3a14198e-6929-a0ec-5f15-c0f9f339f963",
|
|
||||||
"D4": "3a14198e-6929-7ac8-915a-fea51cb2e884"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"溶液堆栈": {
|
|
||||||
"uuid": "",
|
|
||||||
"site_uuids": {
|
|
||||||
"A1": "3a14198e-d724-e036-afdc-2ae39a7f3383",
|
|
||||||
"A2": "3a14198e-d724-afa4-fc82-0ac8a9016791",
|
|
||||||
"A3": "3a14198e-d724-ca48-bb9e-7e85751e55b6",
|
|
||||||
"A4": "3a14198e-d724-df6d-5e32-5483b3cab583",
|
|
||||||
"B1": "3a14198e-d724-d818-6d4f-5725191a24b5",
|
|
||||||
"B2": "3a14198e-d724-be8a-5e0b-012675e195c6",
|
|
||||||
"B3": "3a14198e-d724-cc1e-5c2c-228a130f40a8",
|
|
||||||
"B4": "3a14198e-d724-1e28-c885-574c3df468d0",
|
|
||||||
"C1": "3a14198e-d724-b5bb-adf3-4c5a0da6fb31",
|
|
||||||
"C2": "3a14198e-d724-ab4e-48cb-817c3c146707",
|
|
||||||
"C3": "3a14198e-d724-7f18-1853-39d0c62e1d33",
|
|
||||||
"C4": "3a14198e-d724-28a2-a760-baa896f46b66",
|
|
||||||
"D1": "3a14198e-d724-d378-d266-2508a224a19f",
|
|
||||||
"D2": "3a14198e-d724-f56e-468b-0110a8feb36a",
|
|
||||||
"D3": "3a14198e-d724-0cf1-dea9-a1f40fe7e13c",
|
|
||||||
"D4": "3a14198e-d724-0ddd-9654-f9352a421de9"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"试剂堆栈": {
|
|
||||||
"uuid": "",
|
|
||||||
"site_uuids": {
|
|
||||||
"A1": "3a14198c-c2cf-8b40-af28-b467808f1c36",
|
|
||||||
"A2": "3a14198c-c2d0-f3e7-871a-e470d144296f",
|
|
||||||
"A3": "3a14198c-c2d0-dc7d-b8d0-e1d88cee3094",
|
|
||||||
"A4": "3a14198c-c2d0-2070-efc8-44e245f10c6f",
|
|
||||||
"B1": "3a14198c-c2d0-354f-39ad-642e1a72fcb8",
|
|
||||||
"B2": "3a14198c-c2d0-1559-105d-0ea30682cab4",
|
|
||||||
"B3": "3a14198c-c2d0-725e-523d-34c037ac2440",
|
|
||||||
"B4": "3a14198c-c2d0-efce-0939-69ca5a7dfd39"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# 物料类型配置
|
|
||||||
MATERIAL_TYPE_MAPPINGS = {
|
|
||||||
"烧杯": ("BIOYOND_PolymerStation_1FlaskCarrier", "3a14196b-24f2-ca49-9081-0cab8021bf1a"),
|
|
||||||
"试剂瓶": ("BIOYOND_PolymerStation_1BottleCarrier", ""),
|
|
||||||
"样品板": ("BIOYOND_PolymerStation_6StockCarrier", "3a14196e-b7a0-a5da-1931-35f3000281e9"),
|
|
||||||
"分装板": ("BIOYOND_PolymerStation_6VialCarrier", "3a14196e-5dfe-6e21-0c79-fe2036d052c4"),
|
|
||||||
"样品瓶": ("BIOYOND_PolymerStation_Solid_Stock", "3a14196a-cf7d-8aea-48d8-b9662c7dba94"),
|
|
||||||
"90%分装小瓶": ("BIOYOND_PolymerStation_Solid_Vial", "3a14196c-cdcf-088d-dc7d-5cf38f0ad9ea"),
|
|
||||||
"10%分装小瓶": ("BIOYOND_PolymerStation_Liquid_Vial", "3a14196c-76be-2279-4e22-7310d69aed68"),
|
|
||||||
}
|
|
||||||
|
|
||||||
# 步骤参数配置(各工作流的步骤UUID)
|
|
||||||
WORKFLOW_STEP_IDS = {
|
|
||||||
"reactor_taken_in": {
|
|
||||||
"config": ""
|
|
||||||
},
|
|
||||||
"liquid_feeding_beaker": {
|
|
||||||
"liquid": "",
|
|
||||||
"observe": ""
|
|
||||||
},
|
|
||||||
"liquid_feeding_vials_non_titration": {
|
|
||||||
"liquid": "",
|
|
||||||
"observe": ""
|
|
||||||
},
|
|
||||||
"liquid_feeding_solvents": {
|
|
||||||
"liquid": "",
|
|
||||||
"observe": ""
|
|
||||||
},
|
|
||||||
"solid_feeding_vials": {
|
|
||||||
"feeding": "",
|
|
||||||
"observe": ""
|
|
||||||
},
|
|
||||||
"liquid_feeding_titration": {
|
|
||||||
"liquid": "",
|
|
||||||
"observe": ""
|
|
||||||
},
|
|
||||||
"drip_back": {
|
|
||||||
"liquid": "",
|
|
||||||
"observe": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOCATION_MAPPING = {}
|
|
||||||
|
|
||||||
ACTION_NAMES = {}
|
|
||||||
|
|
||||||
HTTP_SERVICE_CONFIG = {}
|
|
||||||
329
unilabos/devices/workstation/bioyond_studio/config.py.deprecated
Normal file
329
unilabos/devices/workstation/bioyond_studio/config.py.deprecated
Normal file
@@ -0,0 +1,329 @@
|
|||||||
|
# config.py
|
||||||
|
"""
|
||||||
|
Bioyond工作站配置文件
|
||||||
|
包含API配置、工作流映射、物料类型映射、仓库库位映射等所有配置信息
|
||||||
|
"""
|
||||||
|
|
||||||
|
from unilabos.resources.bioyond.decks import BIOYOND_PolymerReactionStation_Deck
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 基础配置
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
# API配置
|
||||||
|
API_CONFIG = {
|
||||||
|
"api_key": "DE9BDDA0",
|
||||||
|
"api_host": "http://192.168.1.200:44402"
|
||||||
|
}
|
||||||
|
|
||||||
|
# HTTP 报送服务配置
|
||||||
|
HTTP_SERVICE_CONFIG = {
|
||||||
|
"http_service_host": "127.0.0.1", # 监听地址
|
||||||
|
"http_service_port": 8080, # 监听端口
|
||||||
|
}
|
||||||
|
|
||||||
|
# Deck配置 - 反应站工作台配置
|
||||||
|
DECK_CONFIG = BIOYOND_PolymerReactionStation_Deck(setup=True)
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 工作流配置
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
# 工作流ID映射
|
||||||
|
WORKFLOW_MAPPINGS = {
|
||||||
|
"reactor_taken_out": "3a16081e-4788-ca37-eff4-ceed8d7019d1",
|
||||||
|
"reactor_taken_in": "3a160df6-76b3-0957-9eb0-cb496d5721c6",
|
||||||
|
"Solid_feeding_vials": "3a160877-87e7-7699-7bc6-ec72b05eb5e6",
|
||||||
|
"Liquid_feeding_vials(non-titration)": "3a167d99-6158-c6f0-15b5-eb030f7d8e47",
|
||||||
|
"Liquid_feeding_solvents": "3a160824-0665-01ed-285a-51ef817a9046",
|
||||||
|
"Liquid_feeding(titration)": "3a16082a-96ac-0449-446a-4ed39f3365b6",
|
||||||
|
"liquid_feeding_beaker": "3a16087e-124f-8ddb-8ec1-c2dff09ca784",
|
||||||
|
"Drip_back": "3a162cf9-6aac-565a-ddd7-682ba1796a4a",
|
||||||
|
}
|
||||||
|
|
||||||
|
# 工作流名称到显示名称的映射
|
||||||
|
WORKFLOW_TO_SECTION_MAP = {
|
||||||
|
'reactor_taken_in': '反应器放入',
|
||||||
|
'reactor_taken_out': '反应器取出',
|
||||||
|
'Solid_feeding_vials': '固体投料-小瓶',
|
||||||
|
'Liquid_feeding_vials(non-titration)': '液体投料-小瓶(非滴定)',
|
||||||
|
'Liquid_feeding_solvents': '液体投料-溶剂',
|
||||||
|
'Liquid_feeding(titration)': '液体投料-滴定',
|
||||||
|
'liquid_feeding_beaker': '液体投料-烧杯',
|
||||||
|
'Drip_back': '液体回滴'
|
||||||
|
}
|
||||||
|
|
||||||
|
# 工作流步骤ID配置
|
||||||
|
WORKFLOW_STEP_IDS = {
|
||||||
|
"reactor_taken_in": {
|
||||||
|
"config": "60a06f85-c5b3-29eb-180f-4f62dd7e2154"
|
||||||
|
},
|
||||||
|
"liquid_feeding_beaker": {
|
||||||
|
"liquid": "6808cda7-fee7-4092-97f0-5f9c2ffa60e3",
|
||||||
|
"observe": "1753c0de-dffc-4ee6-8458-805a2e227362"
|
||||||
|
},
|
||||||
|
"liquid_feeding_vials_non_titration": {
|
||||||
|
"liquid": "62ea6e95-3d5d-43db-bc1e-9a1802673861",
|
||||||
|
"observe": "3a167d99-6172-b67b-5f22-a7892197142e"
|
||||||
|
},
|
||||||
|
"liquid_feeding_solvents": {
|
||||||
|
"liquid": "1fcea355-2545-462b-b727-350b69a313bf",
|
||||||
|
"observe": "0553dfb3-9ac5-4ace-8e00-2f11029919a8"
|
||||||
|
},
|
||||||
|
"solid_feeding_vials": {
|
||||||
|
"feeding": "f7ae7448-4f20-4c1d-8096-df6fbadd787a",
|
||||||
|
"observe": "263c7ed5-7277-426b-bdff-d6fbf77bcc05"
|
||||||
|
},
|
||||||
|
"liquid_feeding_titration": {
|
||||||
|
"liquid": "a00ec41b-e666-4422-9c20-bfcd3cd15c54",
|
||||||
|
"observe": "ac738ff6-4c58-4155-87b1-d6f65a2c9ab5"
|
||||||
|
},
|
||||||
|
"drip_back": {
|
||||||
|
"liquid": "371be86a-ab77-4769-83e5-54580547c48a",
|
||||||
|
"observe": "ce024b9d-bd20-47b8-9f78-ca5ce7f44cf1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 工作流动作名称配置
|
||||||
|
ACTION_NAMES = {
|
||||||
|
"reactor_taken_in": {
|
||||||
|
"config": "通量-配置",
|
||||||
|
"stirring": "反应模块-开始搅拌"
|
||||||
|
},
|
||||||
|
"solid_feeding_vials": {
|
||||||
|
"feeding": "粉末加样模块-投料",
|
||||||
|
"observe": "反应模块-观察搅拌结果"
|
||||||
|
},
|
||||||
|
"liquid_feeding_vials_non_titration": {
|
||||||
|
"liquid": "稀释液瓶加液位-液体投料",
|
||||||
|
"observe": "反应模块-滴定结果观察"
|
||||||
|
},
|
||||||
|
"liquid_feeding_solvents": {
|
||||||
|
"liquid": "试剂AB放置位-试剂吸液分液",
|
||||||
|
"observe": "反应模块-观察搅拌结果"
|
||||||
|
},
|
||||||
|
"liquid_feeding_titration": {
|
||||||
|
"liquid": "稀释液瓶加液位-稀释液吸液分液",
|
||||||
|
"observe": "反应模块-滴定结果观察"
|
||||||
|
},
|
||||||
|
"liquid_feeding_beaker": {
|
||||||
|
"liquid": "烧杯溶液放置位-烧杯吸液分液",
|
||||||
|
"observe": "反应模块-观察搅拌结果"
|
||||||
|
},
|
||||||
|
"drip_back": {
|
||||||
|
"liquid": "试剂AB放置位-试剂吸液分液",
|
||||||
|
"observe": "反应模块-向下滴定结果观察"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 仓库配置
|
||||||
|
# ============================================================================
|
||||||
|
# 说明:
|
||||||
|
# - 出库和入库操作都需要UUID
|
||||||
|
WAREHOUSE_MAPPING = {
|
||||||
|
# ========== 反应站仓库 ==========
|
||||||
|
|
||||||
|
# 堆栈1左 - 反应站左侧堆栈 (4行×4列=16个库位, A01~D04)
|
||||||
|
"堆栈1左": {
|
||||||
|
"uuid": "3a14aa17-0d49-dce4-486e-4b5c85c8b366",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14aa17-0d49-11d7-a6e1-f236b3e5e5a3",
|
||||||
|
"A02": "3a14aa17-0d49-4bc5-8836-517b75473f5f",
|
||||||
|
"A03": "3a14aa17-0d49-c2bc-6222-5cee8d2d94f8",
|
||||||
|
"A04": "3a14aa17-0d49-3ce2-8e9a-008c38d116fb",
|
||||||
|
"B01": "3a14aa17-0d49-f49c-6b66-b27f185a3b32",
|
||||||
|
"B02": "3a14aa17-0d49-cf46-df85-a979c9c9920c",
|
||||||
|
"B03": "3a14aa17-0d49-7698-4a23-f7ffb7d48ba3",
|
||||||
|
"B04": "3a14aa17-0d49-1231-99be-d5870e6478e9",
|
||||||
|
"C01": "3a14aa17-0d49-be34-6fae-4aed9d48b70b",
|
||||||
|
"C02": "3a14aa17-0d49-11d7-0897-34921dcf6b7c",
|
||||||
|
"C03": "3a14aa17-0d49-9840-0bd5-9c63c1bb2c29",
|
||||||
|
"C04": "3a14aa17-0d49-8335-3bff-01da69ea4911",
|
||||||
|
"D01": "3a14aa17-0d49-2bea-c8e5-2b32094935d5",
|
||||||
|
"D02": "3a14aa17-0d49-cff4-e9e8-5f5f0bc1ef32",
|
||||||
|
"D03": "3a14aa17-0d49-4948-cb0a-78f30d1ca9b8",
|
||||||
|
"D04": "3a14aa17-0d49-fd2f-9dfb-a29b11e84099",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
# 堆栈1右 - 反应站右侧堆栈 (4行×4列=16个库位, A05~D08)
|
||||||
|
"堆栈1右": {
|
||||||
|
"uuid": "3a14aa17-0d49-dce4-486e-4b5c85c8b366",
|
||||||
|
"site_uuids": {
|
||||||
|
"A05": "3a14aa17-0d49-2c61-edc8-72a8ca7192dd",
|
||||||
|
"A06": "3a14aa17-0d49-60c8-2b00-40b17198f397",
|
||||||
|
"A07": "3a14aa17-0d49-ec5b-0b75-634dce8eed25",
|
||||||
|
"A08": "3a14aa17-0d49-3ec9-55b3-f3189c4ec53d",
|
||||||
|
"B05": "3a14aa17-0d49-6a4e-abcf-4c113eaaeaad",
|
||||||
|
"B06": "3a14aa17-0d49-e3f6-2dd6-28c2e8194fbe",
|
||||||
|
"B07": "3a14aa17-0d49-11a6-b861-ee895121bf52",
|
||||||
|
"B08": "3a14aa17-0d49-9c7d-1145-d554a6e482f0",
|
||||||
|
"C05": "3a14aa17-0d49-45c4-7a34-5105bc3e2368",
|
||||||
|
"C06": "3a14aa17-0d49-867e-39ab-31b3fe9014be",
|
||||||
|
"C07": "3a14aa17-0d49-ec56-c4b4-39fd9b2131e7",
|
||||||
|
"C08": "3a14aa17-0d49-1128-d7d9-ffb1231c98c0",
|
||||||
|
"D05": "3a14aa17-0d49-e843-f961-ea173326a14b",
|
||||||
|
"D06": "3a14aa17-0d49-4d26-a985-f188359c4f8b",
|
||||||
|
"D07": "3a14aa17-0d49-223a-b520-bc092bb42fe0",
|
||||||
|
"D08": "3a14aa17-0d49-4fa3-401a-6a444e1cca22",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
# 站内试剂存放堆栈
|
||||||
|
"站内试剂存放堆栈": {
|
||||||
|
"uuid": "3a14aa3b-9fab-9d8e-d1a7-828f01f51f0c",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14aa3b-9fab-adac-7b9c-e1ee446b51d5",
|
||||||
|
"A02": "3a14aa3b-9fab-ca72-febc-b7c304476c78"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
# 测量小瓶仓库(测密度)
|
||||||
|
"测量小瓶仓库": {
|
||||||
|
"uuid": "3a15012f-705b-c0de-3f9e-950c205f9921",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a15012f-705e-0524-3161-c523b5aebc97",
|
||||||
|
"A02": "3a15012f-705e-7cd1-32ab-ad4fd1ab75c8",
|
||||||
|
"A03": "3a15012f-705e-a5d6-edac-bdbfec236260",
|
||||||
|
"B01": "3a15012f-705e-e0ee-80e0-10a6b3fc500d",
|
||||||
|
"B02": "3a15012f-705e-e499-180d-de06d60d0b21",
|
||||||
|
"B03": "3a15012f-705e-eff6-63f1-09f742096b26"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
# 站内Tip盒堆栈 - 用于存放枪头盒 (耗材)
|
||||||
|
"站内Tip盒堆栈": {
|
||||||
|
"uuid": "3a14aa3a-2d3c-b5c1-9ddf-7c4a957d459a",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14aa3a-2d3d-e700-411a-0ddf85e1f18a",
|
||||||
|
"A02": "3a14aa3a-2d3d-a7ce-099a-d5632fdafa24",
|
||||||
|
"A03": "3a14aa3a-2d3d-bdf6-a702-c60b38b08501",
|
||||||
|
"B01": "3a14aa3a-2d3d-d704-f076-2a8d5bc72cb8",
|
||||||
|
"B02": "3a14aa3a-2d3d-c350-2526-0778d173a5ac",
|
||||||
|
"B03": "3a14aa3a-2d3d-bc38-b356-f0de2e44e0c7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
# ========== 配液站仓库 ==========
|
||||||
|
"粉末堆栈": {
|
||||||
|
"uuid": "3a14198e-6928-121f-7ca6-88ad3ae7e6a0",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14198e-6929-31f0-8a22-0f98f72260df",
|
||||||
|
"A02": "3a14198e-6929-4379-affa-9a2935c17f99",
|
||||||
|
"A03": "3a14198e-6929-56da-9a1c-7f5fbd4ae8af",
|
||||||
|
"A04": "3a14198e-6929-5e99-2b79-80720f7cfb54",
|
||||||
|
"B01": "3a14198e-6929-f525-9a1b-1857552b28ee",
|
||||||
|
"B02": "3a14198e-6929-bf98-0fd5-26e1d68bf62d",
|
||||||
|
"B03": "3a14198e-6929-2d86-a468-602175a2b5aa",
|
||||||
|
"B04": "3a14198e-6929-1a98-ae57-e97660c489ad",
|
||||||
|
"C01": "3a14198e-6929-46fe-841e-03dd753f1e4a",
|
||||||
|
"C02": "3a14198e-6929-72ac-32ce-9b50245682b8",
|
||||||
|
"C03": "3a14198e-6929-8a0b-b686-6f4a2955c4e2",
|
||||||
|
"C04": "3a14198e-6929-a0ec-5f15-c0f9f339f963",
|
||||||
|
"D01": "3a14198e-6929-1bc9-a9bd-3b7ca66e7f95",
|
||||||
|
"D02": "3a14198e-6929-3bd8-e6c7-4a9fd93be118",
|
||||||
|
"D03": "3a14198e-6929-dde1-fc78-34a84b71afdf",
|
||||||
|
"D04": "3a14198e-6929-7ac8-915a-fea51cb2e884"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"溶液堆栈": {
|
||||||
|
"uuid": "3a14198e-d723-2c13-7d12-50143e190a23",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14198e-d724-e036-afdc-2ae39a7f3383",
|
||||||
|
"A02": "3a14198e-d724-d818-6d4f-5725191a24b5",
|
||||||
|
"A03": "3a14198e-d724-b5bb-adf3-4c5a0da6fb31",
|
||||||
|
"A04": "3a14198e-d724-d378-d266-2508a224a19f",
|
||||||
|
"B01": "3a14198e-d724-afa4-fc82-0ac8a9016791",
|
||||||
|
"B02": "3a14198e-d724-be8a-5e0b-012675e195c6",
|
||||||
|
"B03": "3a14198e-d724-ab4e-48cb-817c3c146707",
|
||||||
|
"B04": "3a14198e-d724-f56e-468b-0110a8feb36a",
|
||||||
|
"C01": "3a14198e-d724-ca48-bb9e-7e85751e55b6",
|
||||||
|
"C02": "3a14198e-d724-cc1e-5c2c-228a130f40a8",
|
||||||
|
"C03": "3a14198e-d724-7f18-1853-39d0c62e1d33",
|
||||||
|
"C04": "3a14198e-d724-0cf1-dea9-a1f40fe7e13c",
|
||||||
|
"D01": "3a14198e-d724-df6d-5e32-5483b3cab583",
|
||||||
|
"D02": "3a14198e-d724-1e28-c885-574c3df468d0",
|
||||||
|
"D03": "3a14198e-d724-28a2-a760-baa896f46b66",
|
||||||
|
"D04": "3a14198e-d724-0ddd-9654-f9352a421de9"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"试剂堆栈": {
|
||||||
|
"uuid": "3a14198c-c2cc-0290-e086-44a428fba248",
|
||||||
|
"site_uuids": {
|
||||||
|
"A01": "3a14198c-c2cf-8b40-af28-b467808f1c36", # x=1, y=1, code=0001-0001
|
||||||
|
"A02": "3a14198c-c2d0-dc7d-b8d0-e1d88cee3094", # x=1, y=2, code=0001-0002
|
||||||
|
"A03": "3a14198c-c2d0-354f-39ad-642e1a72fcb8", # x=1, y=3, code=0001-0003
|
||||||
|
"A04": "3a14198c-c2d0-725e-523d-34c037ac2440", # x=1, y=4, code=0001-0004
|
||||||
|
"B01": "3a14198c-c2d0-f3e7-871a-e470d144296f", # x=2, y=1, code=0001-0005
|
||||||
|
"B02": "3a14198c-c2d0-2070-efc8-44e245f10c6f", # x=2, y=2, code=0001-0006
|
||||||
|
"B03": "3a14198c-c2d0-1559-105d-0ea30682cab4", # x=2, y=3, code=0001-0007
|
||||||
|
"B04": "3a14198c-c2d0-efce-0939-69ca5a7dfd39" # x=2, y=4, code=0001-0008
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 物料类型配置
|
||||||
|
# ============================================================================
|
||||||
|
# 说明:
|
||||||
|
# - 格式: PyLabRobot资源类型名称 → Bioyond系统typeId的UUID
|
||||||
|
# - 这个映射基于 resource.model 属性 (不是显示名称!)
|
||||||
|
# - UUID为空表示该类型暂未在Bioyond系统中定义
|
||||||
|
MATERIAL_TYPE_MAPPINGS = {
|
||||||
|
# ================================================配液站资源============================================================
|
||||||
|
# ==================================================样品===============================================================
|
||||||
|
"BIOYOND_PolymerStation_1FlaskCarrier": ("烧杯", "3a14196b-24f2-ca49-9081-0cab8021bf1a"), # 配液站-样品-烧杯
|
||||||
|
"BIOYOND_PolymerStation_1BottleCarrier": ("试剂瓶", "3a14196b-8bcf-a460-4f74-23f21ca79e72"), # 配液站-样品-试剂瓶
|
||||||
|
"BIOYOND_PolymerStation_6StockCarrier": ("分装板", "3a14196e-5dfe-6e21-0c79-fe2036d052c4"), # 配液站-样品-分装板
|
||||||
|
"BIOYOND_PolymerStation_Liquid_Vial": ("10%分装小瓶", "3a14196c-76be-2279-4e22-7310d69aed68"), # 配液站-样品-分装板-第一排小瓶
|
||||||
|
"BIOYOND_PolymerStation_Solid_Vial": ("90%分装小瓶", "3a14196c-cdcf-088d-dc7d-5cf38f0ad9ea"), # 配液站-样品-分装板-第二排小瓶
|
||||||
|
# ==================================================试剂===============================================================
|
||||||
|
"BIOYOND_PolymerStation_8StockCarrier": ("样品板", "3a14196e-b7a0-a5da-1931-35f3000281e9"), # 配液站-试剂-样品板(8孔)
|
||||||
|
"BIOYOND_PolymerStation_Solid_Stock": ("样品瓶", "3a14196a-cf7d-8aea-48d8-b9662c7dba94"), # 配液站-试剂-样品板-样品瓶
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 动态生成的库位UUID映射(从WAREHOUSE_MAPPING中提取)
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
LOCATION_MAPPING = {}
|
||||||
|
for warehouse_name, warehouse_config in WAREHOUSE_MAPPING.items():
|
||||||
|
if "site_uuids" in warehouse_config:
|
||||||
|
LOCATION_MAPPING.update(warehouse_config["site_uuids"])
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 物料默认参数配置
|
||||||
|
# ============================================================================
|
||||||
|
# 说明:
|
||||||
|
# - 为特定物料名称自动添加默认参数(如密度、分子量、单位等)
|
||||||
|
# - 格式: 物料名称 → {参数字典}
|
||||||
|
# - 在创建或更新物料时,会自动合并这些参数到 Parameters 字段
|
||||||
|
# - unit: 物料的计量单位(会用于 unit 字段)
|
||||||
|
# - density/densityUnit: 密度信息(会添加到 Parameters 中)
|
||||||
|
|
||||||
|
MATERIAL_DEFAULT_PARAMETERS = {
|
||||||
|
# 溶剂类
|
||||||
|
"NMP": {
|
||||||
|
"unit": "毫升",
|
||||||
|
"density": "1.03",
|
||||||
|
"densityUnit": "g/mL",
|
||||||
|
"description": "N-甲基吡咯烷酮 (N-Methyl-2-pyrrolidone)"
|
||||||
|
},
|
||||||
|
# 可以继续添加其他物料...
|
||||||
|
}
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# 物料类型默认参数配置
|
||||||
|
# ============================================================================
|
||||||
|
# 说明:
|
||||||
|
# - 为特定物料类型(UUID)自动添加默认参数
|
||||||
|
# - 格式: Bioyond类型UUID → {参数字典}
|
||||||
|
# - 优先级低于按名称匹配的配置
|
||||||
|
MATERIAL_TYPE_PARAMETERS = {
|
||||||
|
# 示例:
|
||||||
|
# "3a14196b-24f2-ca49-9081-0cab8021bf1a": { # 烧杯
|
||||||
|
# "unit": "个"
|
||||||
|
# }
|
||||||
|
}
|
||||||
@@ -4,7 +4,8 @@ import time
|
|||||||
from typing import Optional, Dict, Any, List
|
from typing import Optional, Dict, Any, List
|
||||||
from typing_extensions import TypedDict
|
from typing_extensions import TypedDict
|
||||||
import requests
|
import requests
|
||||||
from unilabos.devices.workstation.bioyond_studio.config import API_CONFIG
|
import pint
|
||||||
|
|
||||||
|
|
||||||
from unilabos.devices.workstation.bioyond_studio.bioyond_rpc import BioyondException
|
from unilabos.devices.workstation.bioyond_studio.bioyond_rpc import BioyondException
|
||||||
from unilabos.devices.workstation.bioyond_studio.station import BioyondWorkstation
|
from unilabos.devices.workstation.bioyond_studio.station import BioyondWorkstation
|
||||||
@@ -25,13 +26,89 @@ class ComputeExperimentDesignReturn(TypedDict):
|
|||||||
class BioyondDispensingStation(BioyondWorkstation):
|
class BioyondDispensingStation(BioyondWorkstation):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config,
|
config: dict = None,
|
||||||
# 桌子
|
deck=None,
|
||||||
deck,
|
protocol_type=None,
|
||||||
*args,
|
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
super().__init__(config, deck, *args, **kwargs)
|
"""初始化配液站
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config: 配置字典,应包含material_type_mappings等配置
|
||||||
|
deck: Deck对象
|
||||||
|
protocol_type: 协议类型(由ROS系统传递,此处忽略)
|
||||||
|
**kwargs: 其他可能的参数
|
||||||
|
"""
|
||||||
|
if config is None:
|
||||||
|
config = {}
|
||||||
|
|
||||||
|
# 将 kwargs 合并到 config 中 (处理扁平化配置如 api_key)
|
||||||
|
config.update(kwargs)
|
||||||
|
|
||||||
|
if deck is None and config:
|
||||||
|
deck = config.get('deck')
|
||||||
|
|
||||||
|
# 🔧 修复: 确保 Deck 上的 warehouses 具有正确的 UUID (必须在 super().__init__ 之前执行,因为父类会触发同步)
|
||||||
|
# 从配置中读取 warehouse_mapping,并应用到实际的 deck 资源上
|
||||||
|
if config and "warehouse_mapping" in config and deck:
|
||||||
|
warehouse_mapping = config["warehouse_mapping"]
|
||||||
|
print(f"正在根据配置更新 Deck warehouse UUIDs... (共有 {len(warehouse_mapping)} 个配置)")
|
||||||
|
|
||||||
|
user_deck = deck
|
||||||
|
# 初始化 warehouses 字典
|
||||||
|
if not hasattr(user_deck, "warehouses") or user_deck.warehouses is None:
|
||||||
|
user_deck.warehouses = {}
|
||||||
|
|
||||||
|
# 1. 尝试从 children 中查找匹配的资源
|
||||||
|
for child in user_deck.children:
|
||||||
|
# 简单判断: 如果名字在 mapping 中,就认为是 warehouse
|
||||||
|
if child.name in warehouse_mapping:
|
||||||
|
user_deck.warehouses[child.name] = child
|
||||||
|
print(f" - 从子资源中找到 warehouse: {child.name}")
|
||||||
|
|
||||||
|
# 2. 如果还是没找到,且 Deck 类有 setup 方法,尝试调用 setup (针对 Deck 对象正确但未初始化的情况)
|
||||||
|
if not user_deck.warehouses and hasattr(user_deck, "setup"):
|
||||||
|
print(" - 尝试调用 deck.setup() 初始化仓库...")
|
||||||
|
try:
|
||||||
|
user_deck.setup()
|
||||||
|
# setup 后重新检查
|
||||||
|
if hasattr(user_deck, "warehouses") and user_deck.warehouses:
|
||||||
|
print(f" - setup() 成功,找到 {len(user_deck.warehouses)} 个仓库")
|
||||||
|
except Exception as e:
|
||||||
|
print(f" - 调用 setup() 失败: {e}")
|
||||||
|
|
||||||
|
# 3. 如果仍然为空,可能需要手动创建 (仅针对特定已知的 Deck 类型进行补救,这里暂时只打印警告)
|
||||||
|
if not user_deck.warehouses:
|
||||||
|
print(" - ⚠️ 仍然无法找到任何 warehouse 资源!")
|
||||||
|
|
||||||
|
for wh_name, wh_config in warehouse_mapping.items():
|
||||||
|
target_uuid = wh_config.get("uuid")
|
||||||
|
|
||||||
|
# 尝试在 deck.warehouses 中查找
|
||||||
|
wh_resource = None
|
||||||
|
if hasattr(user_deck, "warehouses") and wh_name in user_deck.warehouses:
|
||||||
|
wh_resource = user_deck.warehouses[wh_name]
|
||||||
|
|
||||||
|
# 如果没找到,尝试在所有子资源中查找
|
||||||
|
if not wh_resource:
|
||||||
|
wh_resource = user_deck.get_resource(wh_name)
|
||||||
|
|
||||||
|
if wh_resource:
|
||||||
|
if target_uuid:
|
||||||
|
current_uuid = getattr(wh_resource, "uuid", None)
|
||||||
|
print(f"✅ 更新仓库 '{wh_name}' UUID: {current_uuid} -> {target_uuid}")
|
||||||
|
|
||||||
|
# 动态添加 uuid 属性
|
||||||
|
wh_resource.uuid = target_uuid
|
||||||
|
# 同时也确保 category 正确,避免 graphio 识别错误
|
||||||
|
# wh_resource.category = "warehouse"
|
||||||
|
else:
|
||||||
|
print(f"⚠️ 仓库 '{wh_name}' 在配置中没有 UUID")
|
||||||
|
else:
|
||||||
|
print(f"❌ 在 Deck 中未找到配置的仓库: '{wh_name}'")
|
||||||
|
|
||||||
|
super().__init__(bioyond_config=config, deck=deck)
|
||||||
|
|
||||||
# self.config = config
|
# self.config = config
|
||||||
# self.api_key = config["api_key"]
|
# self.api_key = config["api_key"]
|
||||||
# self.host = config["api_host"]
|
# self.host = config["api_host"]
|
||||||
@@ -43,6 +120,41 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
# 用于跟踪任务完成状态的字典: {orderCode: {status, order_id, timestamp}}
|
# 用于跟踪任务完成状态的字典: {orderCode: {status, order_id, timestamp}}
|
||||||
self.order_completion_status = {}
|
self.order_completion_status = {}
|
||||||
|
|
||||||
|
# 初始化 pint 单位注册表
|
||||||
|
self.ureg = pint.UnitRegistry()
|
||||||
|
|
||||||
|
# 化合物信息
|
||||||
|
self.compound_info = {
|
||||||
|
"MolWt": {
|
||||||
|
"MDA": 108.14 * self.ureg.g / self.ureg.mol,
|
||||||
|
"TDA": 122.16 * self.ureg.g / self.ureg.mol,
|
||||||
|
"PAPP": 521.62 * self.ureg.g / self.ureg.mol,
|
||||||
|
"BTDA": 322.23 * self.ureg.g / self.ureg.mol,
|
||||||
|
"BPDA": 294.22 * self.ureg.g / self.ureg.mol,
|
||||||
|
"6FAP": 366.26 * self.ureg.g / self.ureg.mol,
|
||||||
|
"PMDA": 218.12 * self.ureg.g / self.ureg.mol,
|
||||||
|
"MPDA": 108.14 * self.ureg.g / self.ureg.mol,
|
||||||
|
"SIDA": 248.51 * self.ureg.g / self.ureg.mol,
|
||||||
|
"ODA": 200.236 * self.ureg.g / self.ureg.mol,
|
||||||
|
"4,4'-ODA": 200.236 * self.ureg.g / self.ureg.mol,
|
||||||
|
"134": 292.34 * self.ureg.g / self.ureg.mol,
|
||||||
|
},
|
||||||
|
"FuncGroup": {
|
||||||
|
"MDA": "Amine",
|
||||||
|
"TDA": "Amine",
|
||||||
|
"PAPP": "Amine",
|
||||||
|
"BTDA": "Anhydride",
|
||||||
|
"BPDA": "Anhydride",
|
||||||
|
"6FAP": "Amine",
|
||||||
|
"MPDA": "Amine",
|
||||||
|
"SIDA": "Amine",
|
||||||
|
"PMDA": "Anhydride",
|
||||||
|
"ODA": "Amine",
|
||||||
|
"4,4'-ODA": "Amine",
|
||||||
|
"134": "Amine",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def _post_project_api(self, endpoint: str, data: Any) -> Dict[str, Any]:
|
def _post_project_api(self, endpoint: str, data: Any) -> Dict[str, Any]:
|
||||||
"""项目接口通用POST调用
|
"""项目接口通用POST调用
|
||||||
|
|
||||||
@@ -54,7 +166,7 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
dict: 服务端响应,失败时返回 {code:0,message,...}
|
dict: 服务端响应,失败时返回 {code:0,message,...}
|
||||||
"""
|
"""
|
||||||
request_data = {
|
request_data = {
|
||||||
"apiKey": API_CONFIG["api_key"],
|
"apiKey": self.bioyond_config["api_key"],
|
||||||
"requestTime": self.hardware_interface.get_current_time_iso8601(),
|
"requestTime": self.hardware_interface.get_current_time_iso8601(),
|
||||||
"data": data
|
"data": data
|
||||||
}
|
}
|
||||||
@@ -85,7 +197,7 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
dict: 服务端响应,失败时返回 {code:0,message,...}
|
dict: 服务端响应,失败时返回 {code:0,message,...}
|
||||||
"""
|
"""
|
||||||
request_data = {
|
request_data = {
|
||||||
"apiKey": API_CONFIG["api_key"],
|
"apiKey": self.bioyond_config["api_key"],
|
||||||
"requestTime": self.hardware_interface.get_current_time_iso8601(),
|
"requestTime": self.hardware_interface.get_current_time_iso8601(),
|
||||||
"data": data
|
"data": data
|
||||||
}
|
}
|
||||||
@@ -118,20 +230,22 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
ratio = json.loads(ratio)
|
ratio = json.loads(ratio)
|
||||||
except Exception:
|
except Exception:
|
||||||
ratio = {}
|
ratio = {}
|
||||||
root = str(Path(__file__).resolve().parents[3])
|
|
||||||
if root not in sys.path:
|
|
||||||
sys.path.append(root)
|
|
||||||
try:
|
|
||||||
mod = importlib.import_module("tem.compute")
|
|
||||||
except Exception as e:
|
|
||||||
raise BioyondException(f"无法导入计算模块: {e}")
|
|
||||||
try:
|
try:
|
||||||
wp = float(wt_percent) if isinstance(wt_percent, str) else wt_percent
|
wp = float(wt_percent) if isinstance(wt_percent, str) else wt_percent
|
||||||
mt = float(m_tot) if isinstance(m_tot, str) else m_tot
|
mt = float(m_tot) if isinstance(m_tot, str) else m_tot
|
||||||
tp = float(titration_percent) if isinstance(titration_percent, str) else titration_percent
|
tp = float(titration_percent) if isinstance(titration_percent, str) else titration_percent
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise BioyondException(f"参数解析失败: {e}")
|
raise BioyondException(f"参数解析失败: {e}")
|
||||||
res = mod.generate_experiment_design(ratio=ratio, wt_percent=wp, m_tot=mt, titration_percent=tp)
|
|
||||||
|
# 2. 调用内部计算方法
|
||||||
|
res = self._generate_experiment_design(
|
||||||
|
ratio=ratio,
|
||||||
|
wt_percent=wp,
|
||||||
|
m_tot=mt,
|
||||||
|
titration_percent=tp
|
||||||
|
)
|
||||||
|
|
||||||
|
# 3. 构造返回结果
|
||||||
out = {
|
out = {
|
||||||
"solutions": res.get("solutions", []),
|
"solutions": res.get("solutions", []),
|
||||||
"titration": res.get("titration", {}),
|
"titration": res.get("titration", {}),
|
||||||
@@ -140,11 +254,248 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
"return_info": json.dumps(res, ensure_ascii=False)
|
"return_info": json.dumps(res, ensure_ascii=False)
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
||||||
except BioyondException:
|
except BioyondException:
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise BioyondException(str(e))
|
raise BioyondException(str(e))
|
||||||
|
|
||||||
|
def _generate_experiment_design(
|
||||||
|
self,
|
||||||
|
ratio: dict,
|
||||||
|
wt_percent: float = 0.25,
|
||||||
|
m_tot: float = 70,
|
||||||
|
titration_percent: float = 0.03,
|
||||||
|
) -> dict:
|
||||||
|
"""内部方法:生成实验设计
|
||||||
|
|
||||||
|
根据FuncGroup自动区分二胺和二酐,每种二胺单独配溶液,严格按照ratio顺序投料。
|
||||||
|
|
||||||
|
参数:
|
||||||
|
ratio: 化合物配比字典,格式: {"compound_name": ratio_value}
|
||||||
|
wt_percent: 固体重量百分比
|
||||||
|
m_tot: 反应混合物总质量(g)
|
||||||
|
titration_percent: 滴定溶液百分比
|
||||||
|
|
||||||
|
返回:
|
||||||
|
包含实验设计详细参数的字典
|
||||||
|
"""
|
||||||
|
# 溶剂密度
|
||||||
|
ρ_solvent = 1.03 * self.ureg.g / self.ureg.ml
|
||||||
|
# 二酐溶解度
|
||||||
|
solubility = 0.02 * self.ureg.g / self.ureg.ml
|
||||||
|
# 投入固体时最小溶剂体积
|
||||||
|
V_min = 30 * self.ureg.ml
|
||||||
|
m_tot = m_tot * self.ureg.g
|
||||||
|
|
||||||
|
# 保持ratio中的顺序
|
||||||
|
compound_names = list(ratio.keys())
|
||||||
|
compound_ratios = list(ratio.values())
|
||||||
|
|
||||||
|
# 验证所有化合物是否在 compound_info 中定义
|
||||||
|
undefined_compounds = [name for name in compound_names if name not in self.compound_info["MolWt"]]
|
||||||
|
if undefined_compounds:
|
||||||
|
available = list(self.compound_info["MolWt"].keys())
|
||||||
|
raise ValueError(
|
||||||
|
f"以下化合物未在 compound_info 中定义: {undefined_compounds}。"
|
||||||
|
f"可用的化合物: {available}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 获取各化合物的分子量和官能团类型
|
||||||
|
molecular_weights = [self.compound_info["MolWt"][name] for name in compound_names]
|
||||||
|
func_groups = [self.compound_info["FuncGroup"][name] for name in compound_names]
|
||||||
|
|
||||||
|
# 记录化合物信息用于调试
|
||||||
|
self.hardware_interface._logger.info(f"化合物名称: {compound_names}")
|
||||||
|
self.hardware_interface._logger.info(f"官能团类型: {func_groups}")
|
||||||
|
|
||||||
|
# 按原始顺序分离二胺和二酐
|
||||||
|
ordered_compounds = list(zip(compound_names, compound_ratios, molecular_weights, func_groups))
|
||||||
|
diamine_compounds = [(name, ratio_val, mw, i) for i, (name, ratio_val, mw, fg) in enumerate(ordered_compounds) if fg == "Amine"]
|
||||||
|
anhydride_compounds = [(name, ratio_val, mw, i) for i, (name, ratio_val, mw, fg) in enumerate(ordered_compounds) if fg == "Anhydride"]
|
||||||
|
|
||||||
|
if not diamine_compounds or not anhydride_compounds:
|
||||||
|
raise ValueError(
|
||||||
|
f"需要同时包含二胺(Amine)和二酐(Anhydride)化合物。"
|
||||||
|
f"当前二胺: {[c[0] for c in diamine_compounds]}, "
|
||||||
|
f"当前二酐: {[c[0] for c in anhydride_compounds]}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 计算加权平均分子量 (基于摩尔比)
|
||||||
|
total_molar_ratio = sum(compound_ratios)
|
||||||
|
weighted_molecular_weight = sum(ratio_val * mw for ratio_val, mw in zip(compound_ratios, molecular_weights))
|
||||||
|
|
||||||
|
# 取最后一个二酐用于滴定
|
||||||
|
titration_anhydride = anhydride_compounds[-1]
|
||||||
|
solid_anhydrides = anhydride_compounds[:-1] if len(anhydride_compounds) > 1 else []
|
||||||
|
|
||||||
|
# 二胺溶液配制参数 - 每种二胺单独配制
|
||||||
|
diamine_solutions = []
|
||||||
|
total_diamine_volume = 0 * self.ureg.ml
|
||||||
|
|
||||||
|
# 计算反应物的总摩尔量
|
||||||
|
n_reactant = m_tot * wt_percent / weighted_molecular_weight
|
||||||
|
|
||||||
|
for name, ratio_val, mw, order_index in diamine_compounds:
|
||||||
|
# 跳过 SIDA
|
||||||
|
if name == "SIDA":
|
||||||
|
continue
|
||||||
|
|
||||||
|
# 计算该二胺需要的摩尔数
|
||||||
|
n_diamine_needed = n_reactant * ratio_val
|
||||||
|
|
||||||
|
# 二胺溶液配制参数 (每种二胺固定配制参数)
|
||||||
|
m_diamine_solid = 5.0 * self.ureg.g # 每种二胺固体质量
|
||||||
|
V_solvent_for_this = 20 * self.ureg.ml # 每种二胺溶剂体积
|
||||||
|
m_solvent_for_this = ρ_solvent * V_solvent_for_this
|
||||||
|
|
||||||
|
# 计算该二胺溶液的浓度
|
||||||
|
c_diamine = (m_diamine_solid / mw) / V_solvent_for_this
|
||||||
|
|
||||||
|
# 计算需要移取的溶液体积
|
||||||
|
V_diamine_needed = n_diamine_needed / c_diamine
|
||||||
|
|
||||||
|
diamine_solutions.append({
|
||||||
|
"name": name,
|
||||||
|
"order": order_index,
|
||||||
|
"solid_mass": m_diamine_solid.magnitude,
|
||||||
|
"solvent_volume": V_solvent_for_this.magnitude,
|
||||||
|
"concentration": c_diamine.magnitude,
|
||||||
|
"volume_needed": V_diamine_needed.magnitude,
|
||||||
|
"molar_ratio": ratio_val
|
||||||
|
})
|
||||||
|
|
||||||
|
total_diamine_volume += V_diamine_needed
|
||||||
|
|
||||||
|
# 按原始顺序排序
|
||||||
|
diamine_solutions.sort(key=lambda x: x["order"])
|
||||||
|
|
||||||
|
# 计算滴定二酐的质量
|
||||||
|
titration_name, titration_ratio, titration_mw, _ = titration_anhydride
|
||||||
|
m_titration_anhydride = n_reactant * titration_ratio * titration_mw
|
||||||
|
m_titration_90 = m_titration_anhydride * (1 - titration_percent)
|
||||||
|
m_titration_10 = m_titration_anhydride * titration_percent
|
||||||
|
|
||||||
|
# 计算其他固体二酐的质量 (按顺序)
|
||||||
|
solid_anhydride_masses = []
|
||||||
|
for name, ratio_val, mw, order_index in solid_anhydrides:
|
||||||
|
mass = n_reactant * ratio_val * mw
|
||||||
|
solid_anhydride_masses.append({
|
||||||
|
"name": name,
|
||||||
|
"order": order_index,
|
||||||
|
"mass": mass.magnitude,
|
||||||
|
"molar_ratio": ratio_val
|
||||||
|
})
|
||||||
|
|
||||||
|
# 按原始顺序排序
|
||||||
|
solid_anhydride_masses.sort(key=lambda x: x["order"])
|
||||||
|
|
||||||
|
# 计算溶剂用量
|
||||||
|
total_diamine_solution_mass = sum(
|
||||||
|
sol["volume_needed"] * ρ_solvent for sol in diamine_solutions
|
||||||
|
) * self.ureg.ml
|
||||||
|
|
||||||
|
# 预估滴定溶剂量、计算补加溶剂量
|
||||||
|
m_solvent_titration = m_titration_10 / solubility * ρ_solvent
|
||||||
|
m_solvent_add = m_tot * (1 - wt_percent) - total_diamine_solution_mass - m_solvent_titration
|
||||||
|
|
||||||
|
# 检查最小溶剂体积要求
|
||||||
|
total_liquid_volume = (total_diamine_solution_mass + m_solvent_add) / ρ_solvent
|
||||||
|
m_tot_min = V_min / total_liquid_volume * m_tot
|
||||||
|
|
||||||
|
# 如果需要,按比例放大
|
||||||
|
scale_factor = 1.0
|
||||||
|
if m_tot_min > m_tot:
|
||||||
|
scale_factor = (m_tot_min / m_tot).magnitude
|
||||||
|
m_titration_90 *= scale_factor
|
||||||
|
m_titration_10 *= scale_factor
|
||||||
|
m_solvent_add *= scale_factor
|
||||||
|
m_solvent_titration *= scale_factor
|
||||||
|
|
||||||
|
# 更新二胺溶液用量
|
||||||
|
for sol in diamine_solutions:
|
||||||
|
sol["volume_needed"] *= scale_factor
|
||||||
|
|
||||||
|
# 更新固体二酐用量
|
||||||
|
for anhydride in solid_anhydride_masses:
|
||||||
|
anhydride["mass"] *= scale_factor
|
||||||
|
|
||||||
|
m_tot = m_tot_min
|
||||||
|
|
||||||
|
# 生成投料顺序
|
||||||
|
feeding_order = []
|
||||||
|
|
||||||
|
# 1. 固体二酐 (按顺序)
|
||||||
|
for anhydride in solid_anhydride_masses:
|
||||||
|
feeding_order.append({
|
||||||
|
"step": len(feeding_order) + 1,
|
||||||
|
"type": "solid_anhydride",
|
||||||
|
"name": anhydride["name"],
|
||||||
|
"amount": anhydride["mass"],
|
||||||
|
"order": anhydride["order"]
|
||||||
|
})
|
||||||
|
|
||||||
|
# 2. 二胺溶液 (按顺序)
|
||||||
|
for sol in diamine_solutions:
|
||||||
|
feeding_order.append({
|
||||||
|
"step": len(feeding_order) + 1,
|
||||||
|
"type": "diamine_solution",
|
||||||
|
"name": sol["name"],
|
||||||
|
"amount": sol["volume_needed"],
|
||||||
|
"order": sol["order"]
|
||||||
|
})
|
||||||
|
|
||||||
|
# 3. 主要二酐粉末
|
||||||
|
feeding_order.append({
|
||||||
|
"step": len(feeding_order) + 1,
|
||||||
|
"type": "main_anhydride",
|
||||||
|
"name": titration_name,
|
||||||
|
"amount": m_titration_90.magnitude,
|
||||||
|
"order": titration_anhydride[3]
|
||||||
|
})
|
||||||
|
|
||||||
|
# 4. 补加溶剂
|
||||||
|
if m_solvent_add > 0:
|
||||||
|
feeding_order.append({
|
||||||
|
"step": len(feeding_order) + 1,
|
||||||
|
"type": "additional_solvent",
|
||||||
|
"name": "溶剂",
|
||||||
|
"amount": m_solvent_add.magnitude,
|
||||||
|
"order": 999
|
||||||
|
})
|
||||||
|
|
||||||
|
# 5. 滴定二酐溶液
|
||||||
|
feeding_order.append({
|
||||||
|
"step": len(feeding_order) + 1,
|
||||||
|
"type": "titration_anhydride",
|
||||||
|
"name": f"{titration_name} 滴定液",
|
||||||
|
"amount": m_titration_10.magnitude,
|
||||||
|
"titration_solvent": m_solvent_titration.magnitude,
|
||||||
|
"order": titration_anhydride[3]
|
||||||
|
})
|
||||||
|
|
||||||
|
# 返回实验设计结果
|
||||||
|
results = {
|
||||||
|
"total_mass": m_tot.magnitude,
|
||||||
|
"scale_factor": scale_factor,
|
||||||
|
"solutions": diamine_solutions,
|
||||||
|
"solids": solid_anhydride_masses,
|
||||||
|
"titration": {
|
||||||
|
"name": titration_name,
|
||||||
|
"main_portion": m_titration_90.magnitude,
|
||||||
|
"titration_portion": m_titration_10.magnitude,
|
||||||
|
"titration_solvent": m_solvent_titration.magnitude,
|
||||||
|
},
|
||||||
|
"solvents": {
|
||||||
|
"additional_solvent": m_solvent_add.magnitude,
|
||||||
|
"total_liquid_volume": total_liquid_volume.magnitude
|
||||||
|
},
|
||||||
|
"feeding_order": feeding_order,
|
||||||
|
"minimum_required_mass": m_tot_min.magnitude
|
||||||
|
}
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
# 90%10%小瓶投料任务创建方法
|
# 90%10%小瓶投料任务创建方法
|
||||||
def create_90_10_vial_feeding_task(self,
|
def create_90_10_vial_feeding_task(self,
|
||||||
order_name: str = None,
|
order_name: str = None,
|
||||||
@@ -961,6 +1312,108 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
'actualVolume': actual_volume
|
'actualVolume': actual_volume
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _simplify_report(self, report) -> Dict[str, Any]:
|
||||||
|
"""简化实验报告,只保留关键信息,去除冗余的工作流参数"""
|
||||||
|
if not isinstance(report, dict):
|
||||||
|
return report
|
||||||
|
|
||||||
|
data = report.get('data', {})
|
||||||
|
if not isinstance(data, dict):
|
||||||
|
return report
|
||||||
|
|
||||||
|
# 提取关键信息
|
||||||
|
simplified = {
|
||||||
|
'name': data.get('name'),
|
||||||
|
'code': data.get('code'),
|
||||||
|
'requester': data.get('requester'),
|
||||||
|
'workflowName': data.get('workflowName'),
|
||||||
|
'workflowStep': data.get('workflowStep'),
|
||||||
|
'requestTime': data.get('requestTime'),
|
||||||
|
'startPreparationTime': data.get('startPreparationTime'),
|
||||||
|
'completeTime': data.get('completeTime'),
|
||||||
|
'useTime': data.get('useTime'),
|
||||||
|
'status': data.get('status'),
|
||||||
|
'statusName': data.get('statusName'),
|
||||||
|
}
|
||||||
|
|
||||||
|
# 提取物料信息(简化版)
|
||||||
|
pre_intakes = data.get('preIntakes', [])
|
||||||
|
if pre_intakes and isinstance(pre_intakes, list):
|
||||||
|
first_intake = pre_intakes[0]
|
||||||
|
sample_materials = first_intake.get('sampleMaterials', [])
|
||||||
|
|
||||||
|
# 简化物料信息
|
||||||
|
simplified_materials = []
|
||||||
|
for material in sample_materials:
|
||||||
|
if isinstance(material, dict):
|
||||||
|
mat_info = {
|
||||||
|
'materialName': material.get('materialName'),
|
||||||
|
'materialTypeName': material.get('materialTypeName'),
|
||||||
|
'materialCode': material.get('materialCode'),
|
||||||
|
'materialLocation': material.get('materialLocation'),
|
||||||
|
}
|
||||||
|
|
||||||
|
# 解析parameters中的关键信息(如密度、加料历史等)
|
||||||
|
params_str = material.get('parameters', '{}')
|
||||||
|
try:
|
||||||
|
params = json.loads(params_str) if isinstance(params_str, str) else params_str
|
||||||
|
if isinstance(params, dict):
|
||||||
|
# 只保留关键参数
|
||||||
|
if 'density' in params:
|
||||||
|
mat_info['density'] = params['density']
|
||||||
|
if 'feedingHistory' in params:
|
||||||
|
mat_info['feedingHistory'] = params['feedingHistory']
|
||||||
|
if 'liquidVolume' in params:
|
||||||
|
mat_info['liquidVolume'] = params['liquidVolume']
|
||||||
|
if 'm_diamine_tot' in params:
|
||||||
|
mat_info['m_diamine_tot'] = params['m_diamine_tot']
|
||||||
|
if 'wt_diamine' in params:
|
||||||
|
mat_info['wt_diamine'] = params['wt_diamine']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
simplified_materials.append(mat_info)
|
||||||
|
|
||||||
|
simplified['sampleMaterials'] = simplified_materials
|
||||||
|
|
||||||
|
# 提取extraProperties中的实际值
|
||||||
|
extra_props = first_intake.get('extraProperties', {})
|
||||||
|
if isinstance(extra_props, dict):
|
||||||
|
simplified_extra = {}
|
||||||
|
for key, value in extra_props.items():
|
||||||
|
try:
|
||||||
|
parsed_value = json.loads(value) if isinstance(value, str) else value
|
||||||
|
simplified_extra[key] = parsed_value
|
||||||
|
except:
|
||||||
|
simplified_extra[key] = value
|
||||||
|
simplified['extraProperties'] = simplified_extra
|
||||||
|
|
||||||
|
return {
|
||||||
|
'data': simplified,
|
||||||
|
'code': report.get('code'),
|
||||||
|
'message': report.get('message'),
|
||||||
|
'timestamp': report.get('timestamp')
|
||||||
|
}
|
||||||
|
|
||||||
|
def scheduler_start(self) -> dict:
|
||||||
|
"""启动调度器 - 启动Bioyond工作站的任务调度器,开始执行队列中的任务
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: 包含return_info的字典,return_info为整型(1=成功)
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
BioyondException: 调度器启动失败时抛出异常
|
||||||
|
"""
|
||||||
|
result = self.hardware_interface.scheduler_start()
|
||||||
|
self.hardware_interface._logger.info(f"调度器启动结果: {result}")
|
||||||
|
|
||||||
|
if result != 1:
|
||||||
|
error_msg = "启动调度器失败: 有未处理错误,调度无法启动。请检查Bioyond系统状态。"
|
||||||
|
self.hardware_interface._logger.error(error_msg)
|
||||||
|
raise BioyondException(error_msg)
|
||||||
|
|
||||||
|
return {"return_info": result}
|
||||||
|
|
||||||
# 等待多个任务完成并获取实验报告
|
# 等待多个任务完成并获取实验报告
|
||||||
def wait_for_multiple_orders_and_get_reports(self,
|
def wait_for_multiple_orders_and_get_reports(self,
|
||||||
batch_create_result: str = None,
|
batch_create_result: str = None,
|
||||||
@@ -1002,7 +1455,12 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
|
|
||||||
# 验证batch_create_result参数
|
# 验证batch_create_result参数
|
||||||
if not batch_create_result or batch_create_result == "":
|
if not batch_create_result or batch_create_result == "":
|
||||||
raise BioyondException("batch_create_result参数为空,请确保从batch_create节点正确连接handle")
|
raise BioyondException(
|
||||||
|
"batch_create_result参数为空,请确保:\n"
|
||||||
|
"1. batch_create节点与wait节点之间正确连接了handle\n"
|
||||||
|
"2. batch_create节点成功执行并返回了结果\n"
|
||||||
|
"3. 检查上游batch_create任务是否成功创建了订单"
|
||||||
|
)
|
||||||
|
|
||||||
# 解析batch_create_result JSON对象
|
# 解析batch_create_result JSON对象
|
||||||
try:
|
try:
|
||||||
@@ -1031,7 +1489,17 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
|
|
||||||
# 验证提取的数据
|
# 验证提取的数据
|
||||||
if not order_codes:
|
if not order_codes:
|
||||||
raise BioyondException("batch_create_result中未找到order_codes字段或为空")
|
self.hardware_interface._logger.error(
|
||||||
|
f"batch_create任务未生成任何订单。batch_create_result内容: {batch_create_result}"
|
||||||
|
)
|
||||||
|
raise BioyondException(
|
||||||
|
"batch_create_result中未找到order_codes或为空。\n"
|
||||||
|
"可能的原因:\n"
|
||||||
|
"1. batch_create任务执行失败(检查任务是否报错)\n"
|
||||||
|
"2. 物料配置问题(如'物料样品板分配失败')\n"
|
||||||
|
"3. Bioyond系统状态异常\n"
|
||||||
|
f"请检查batch_create任务的执行结果"
|
||||||
|
)
|
||||||
if not order_ids:
|
if not order_ids:
|
||||||
raise BioyondException("batch_create_result中未找到order_ids字段或为空")
|
raise BioyondException("batch_create_result中未找到order_ids字段或为空")
|
||||||
|
|
||||||
@@ -1114,6 +1582,8 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
self.hardware_interface._logger.info(
|
self.hardware_interface._logger.info(
|
||||||
f"成功获取任务 {order_code} 的实验报告"
|
f"成功获取任务 {order_code} 的实验报告"
|
||||||
)
|
)
|
||||||
|
# 简化报告,去除冗余信息
|
||||||
|
report = self._simplify_report(report)
|
||||||
|
|
||||||
reports.append({
|
reports.append({
|
||||||
"order_code": order_code,
|
"order_code": order_code,
|
||||||
@@ -1288,7 +1758,7 @@ class BioyondDispensingStation(BioyondWorkstation):
|
|||||||
f"开始执行批量物料转移: {len(transfer_groups)}组任务 -> {target_device_id}"
|
f"开始执行批量物料转移: {len(transfer_groups)}组任务 -> {target_device_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
from .config import WAREHOUSE_MAPPING
|
warehouse_mapping = self.bioyond_config.get("warehouse_mapping", {})
|
||||||
results = []
|
results = []
|
||||||
successful_count = 0
|
successful_count = 0
|
||||||
failed_count = 0
|
failed_count = 0
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@ Bioyond Workstation Implementation
|
|||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
import threading
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict, Any, List, Optional, Union
|
from typing import Dict, Any, List, Optional, Union
|
||||||
import json
|
import json
|
||||||
@@ -23,12 +24,94 @@ from unilabos.ros.nodes.presets.workstation import ROS2WorkstationNode
|
|||||||
from unilabos.ros.msgs.message_converter import convert_to_ros_msg, Float64, String
|
from unilabos.ros.msgs.message_converter import convert_to_ros_msg, Float64, String
|
||||||
from pylabrobot.resources.resource import Resource as ResourcePLR
|
from pylabrobot.resources.resource import Resource as ResourcePLR
|
||||||
|
|
||||||
from unilabos.devices.workstation.bioyond_studio.config import (
|
|
||||||
API_CONFIG, WORKFLOW_MAPPINGS, MATERIAL_TYPE_MAPPINGS, WAREHOUSE_MAPPING, HTTP_SERVICE_CONFIG
|
|
||||||
)
|
|
||||||
from unilabos.devices.workstation.workstation_http_service import WorkstationHTTPService
|
from unilabos.devices.workstation.workstation_http_service import WorkstationHTTPService
|
||||||
|
|
||||||
|
|
||||||
|
class ConnectionMonitor:
|
||||||
|
"""Bioyond连接监控器"""
|
||||||
|
def __init__(self, workstation, check_interval=30):
|
||||||
|
self.workstation = workstation
|
||||||
|
self.check_interval = check_interval
|
||||||
|
self._running = False
|
||||||
|
self._thread = None
|
||||||
|
self._last_status = "unknown"
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
if self._running:
|
||||||
|
return
|
||||||
|
self._running = True
|
||||||
|
self._thread = threading.Thread(target=self._monitor_loop, daemon=True, name="BioyondConnectionMonitor")
|
||||||
|
self._thread.start()
|
||||||
|
logger.info("Bioyond连接监控器已启动")
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self._running = False
|
||||||
|
if self._thread:
|
||||||
|
self._thread.join(timeout=2)
|
||||||
|
logger.info("Bioyond连接监控器已停止")
|
||||||
|
|
||||||
|
def _monitor_loop(self):
|
||||||
|
while self._running:
|
||||||
|
try:
|
||||||
|
# 使用 lightweight API 检查连接
|
||||||
|
# query_matial_type_list 是比较快的查询
|
||||||
|
start_time = time.time()
|
||||||
|
result = self.workstation.hardware_interface.material_type_list()
|
||||||
|
|
||||||
|
status = "online" if result else "offline"
|
||||||
|
msg = "Connection established" if status == "online" else "Failed to get material type list"
|
||||||
|
|
||||||
|
if status != self._last_status:
|
||||||
|
logger.info(f"Bioyond连接状态变更: {self._last_status} -> {status}")
|
||||||
|
self._publish_event(status, msg)
|
||||||
|
self._last_status = status
|
||||||
|
|
||||||
|
# 发布心跳 (可选,或者只在状态变更时发布)
|
||||||
|
# self._publish_event(status, msg)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Bioyond连接检查异常: {e}")
|
||||||
|
if self._last_status != "error":
|
||||||
|
self._publish_event("error", str(e))
|
||||||
|
self._last_status = "error"
|
||||||
|
|
||||||
|
time.sleep(self.check_interval)
|
||||||
|
|
||||||
|
def _publish_event(self, status, message):
|
||||||
|
try:
|
||||||
|
if hasattr(self.workstation, "_ros_node") and self.workstation._ros_node:
|
||||||
|
event_data = {
|
||||||
|
"status": status,
|
||||||
|
"message": message,
|
||||||
|
"timestamp": datetime.now().isoformat()
|
||||||
|
}
|
||||||
|
|
||||||
|
# 动态发布消息,需要在 ROS2DeviceNode 中有对应支持
|
||||||
|
# 这里假设通用事件发布机制,使用 String 类型的 topic
|
||||||
|
# 话题: /<namespace>/events/device_status
|
||||||
|
ns = self.workstation._ros_node.namespace
|
||||||
|
topic = f"{ns}/events/device_status"
|
||||||
|
|
||||||
|
# 使用 ROS2DeviceNode 的发布功能
|
||||||
|
# 如果没有预定义的 publisher,需要动态创建
|
||||||
|
# 注意:workstation base node 可能没有自动创建 arbitrary publishers 的机制
|
||||||
|
# 这里我们先尝试用 String json 发布
|
||||||
|
|
||||||
|
# 在 ROS2DeviceNode 中通常需要先 create_publisher
|
||||||
|
# 为了简单起见,我们检查是否已有 publisher,没有则创建
|
||||||
|
if not hasattr(self.workstation, "_device_status_pub"):
|
||||||
|
self.workstation._device_status_pub = self.workstation._ros_node.create_publisher(
|
||||||
|
String, topic, 10
|
||||||
|
)
|
||||||
|
|
||||||
|
self.workstation._device_status_pub.publish(
|
||||||
|
convert_to_ros_msg(String, json.dumps(event_data, ensure_ascii=False))
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"发布设备状态事件失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
class BioyondResourceSynchronizer(ResourceSynchronizer):
|
class BioyondResourceSynchronizer(ResourceSynchronizer):
|
||||||
"""Bioyond资源同步器
|
"""Bioyond资源同步器
|
||||||
|
|
||||||
@@ -174,9 +257,8 @@ class BioyondResourceSynchronizer(ResourceSynchronizer):
|
|||||||
else:
|
else:
|
||||||
logger.info(f"[同步→Bioyond] ➕ 物料不存在于 Bioyond,将创建新物料并入库")
|
logger.info(f"[同步→Bioyond] ➕ 物料不存在于 Bioyond,将创建新物料并入库")
|
||||||
|
|
||||||
# 第1步:获取仓库配置
|
# 第1步:从配置中获取仓库配置
|
||||||
from .config import WAREHOUSE_MAPPING
|
warehouse_mapping = self.workstation.bioyond_config.get("warehouse_mapping", {})
|
||||||
warehouse_mapping = WAREHOUSE_MAPPING
|
|
||||||
|
|
||||||
# 确定目标仓库名称
|
# 确定目标仓库名称
|
||||||
parent_name = None
|
parent_name = None
|
||||||
@@ -238,14 +320,20 @@ class BioyondResourceSynchronizer(ResourceSynchronizer):
|
|||||||
# 第2步:转换为 Bioyond 格式
|
# 第2步:转换为 Bioyond 格式
|
||||||
logger.info(f"[同步→Bioyond] 🔄 转换物料为 Bioyond 格式...")
|
logger.info(f"[同步→Bioyond] 🔄 转换物料为 Bioyond 格式...")
|
||||||
|
|
||||||
# 导入物料默认参数配置
|
# 从配置中获取物料默认参数
|
||||||
from .config import MATERIAL_DEFAULT_PARAMETERS
|
material_default_params = self.workstation.bioyond_config.get("material_default_parameters", {})
|
||||||
|
material_type_params = self.workstation.bioyond_config.get("material_type_parameters", {})
|
||||||
|
|
||||||
|
# 合并参数配置:物料名称参数 + typeId参数(转换为 type:<uuid> 格式)
|
||||||
|
merged_params = material_default_params.copy()
|
||||||
|
for type_id, params in material_type_params.items():
|
||||||
|
merged_params[f"type:{type_id}"] = params
|
||||||
|
|
||||||
bioyond_material = resource_plr_to_bioyond(
|
bioyond_material = resource_plr_to_bioyond(
|
||||||
[resource],
|
[resource],
|
||||||
type_mapping=self.workstation.bioyond_config["material_type_mappings"],
|
type_mapping=self.workstation.bioyond_config["material_type_mappings"],
|
||||||
warehouse_mapping=self.workstation.bioyond_config["warehouse_mapping"],
|
warehouse_mapping=self.workstation.bioyond_config["warehouse_mapping"],
|
||||||
material_params=MATERIAL_DEFAULT_PARAMETERS
|
material_params=merged_params
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
logger.info(f"[同步→Bioyond] 🔧 准备覆盖locations字段,目标仓库: {parent_name}, 库位: {update_site}, UUID: {target_location_uuid[:8]}...")
|
logger.info(f"[同步→Bioyond] 🔧 准备覆盖locations字段,目标仓库: {parent_name}, 库位: {update_site}, UUID: {target_location_uuid[:8]}...")
|
||||||
@@ -468,13 +556,20 @@ class BioyondResourceSynchronizer(ResourceSynchronizer):
|
|||||||
return material_bioyond_id
|
return material_bioyond_id
|
||||||
|
|
||||||
# 转换为 Bioyond 格式
|
# 转换为 Bioyond 格式
|
||||||
from .config import MATERIAL_DEFAULT_PARAMETERS
|
# 从配置中获取物料默认参数
|
||||||
|
material_default_params = self.workstation.bioyond_config.get("material_default_parameters", {})
|
||||||
|
material_type_params = self.workstation.bioyond_config.get("material_type_parameters", {})
|
||||||
|
|
||||||
|
# 合并参数配置:物料名称参数 + typeId参数(转换为 type:<uuid> 格式)
|
||||||
|
merged_params = material_default_params.copy()
|
||||||
|
for type_id, params in material_type_params.items():
|
||||||
|
merged_params[f"type:{type_id}"] = params
|
||||||
|
|
||||||
bioyond_material = resource_plr_to_bioyond(
|
bioyond_material = resource_plr_to_bioyond(
|
||||||
[resource],
|
[resource],
|
||||||
type_mapping=self.workstation.bioyond_config["material_type_mappings"],
|
type_mapping=self.workstation.bioyond_config["material_type_mappings"],
|
||||||
warehouse_mapping=self.workstation.bioyond_config["warehouse_mapping"],
|
warehouse_mapping=self.workstation.bioyond_config["warehouse_mapping"],
|
||||||
material_params=MATERIAL_DEFAULT_PARAMETERS
|
material_params=merged_params
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
# ⚠️ 关键:创建物料时不设置 locations,让 Bioyond 系统暂不分配库位
|
# ⚠️ 关键:创建物料时不设置 locations,让 Bioyond 系统暂不分配库位
|
||||||
@@ -528,8 +623,7 @@ class BioyondResourceSynchronizer(ResourceSynchronizer):
|
|||||||
logger.info(f"[物料入库] 目标库位: {update_site}")
|
logger.info(f"[物料入库] 目标库位: {update_site}")
|
||||||
|
|
||||||
# 获取仓库配置和目标库位 UUID
|
# 获取仓库配置和目标库位 UUID
|
||||||
from .config import WAREHOUSE_MAPPING
|
warehouse_mapping = self.workstation.bioyond_config.get("warehouse_mapping", {})
|
||||||
warehouse_mapping = WAREHOUSE_MAPPING
|
|
||||||
|
|
||||||
parent_name = None
|
parent_name = None
|
||||||
target_location_uuid = None
|
target_location_uuid = None
|
||||||
@@ -584,6 +678,44 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
集成Bioyond物料管理的工作站实现
|
集成Bioyond物料管理的工作站实现
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def _publish_task_status(
|
||||||
|
self,
|
||||||
|
task_id: str,
|
||||||
|
task_type: str,
|
||||||
|
status: str,
|
||||||
|
result: dict = None,
|
||||||
|
progress: float = 0.0,
|
||||||
|
task_code: str = None
|
||||||
|
):
|
||||||
|
"""发布任务状态事件"""
|
||||||
|
try:
|
||||||
|
if not getattr(self, "_ros_node", None):
|
||||||
|
return
|
||||||
|
|
||||||
|
event_data = {
|
||||||
|
"task_id": task_id,
|
||||||
|
"task_code": task_code,
|
||||||
|
"task_type": task_type,
|
||||||
|
"status": status,
|
||||||
|
"progress": progress,
|
||||||
|
"timestamp": datetime.now().isoformat()
|
||||||
|
}
|
||||||
|
if result:
|
||||||
|
event_data["result"] = result
|
||||||
|
|
||||||
|
topic = f"{self._ros_node.namespace}/events/task_status"
|
||||||
|
|
||||||
|
if not hasattr(self, "_task_status_pub"):
|
||||||
|
self._task_status_pub = self._ros_node.create_publisher(
|
||||||
|
String, topic, 10
|
||||||
|
)
|
||||||
|
|
||||||
|
self._task_status_pub.publish(
|
||||||
|
convert_to_ros_msg(String, json.dumps(event_data, ensure_ascii=False))
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"发布任务状态事件失败: {e}")
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
bioyond_config: Optional[Dict[str, Any]] = None,
|
bioyond_config: Optional[Dict[str, Any]] = None,
|
||||||
@@ -605,15 +737,32 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
raise ValueError("Deck 配置不能为空,请在配置文件中添加正确的 deck 配置")
|
raise ValueError("Deck 配置不能为空,请在配置文件中添加正确的 deck 配置")
|
||||||
|
|
||||||
# 初始化 warehouses 属性
|
# 初始化 warehouses 属性
|
||||||
self.deck.warehouses = {}
|
if not hasattr(self.deck, "warehouses") or self.deck.warehouses is None:
|
||||||
for resource in self.deck.children:
|
self.deck.warehouses = {}
|
||||||
if isinstance(resource, WareHouse):
|
|
||||||
self.deck.warehouses[resource.name] = resource
|
|
||||||
|
|
||||||
# 创建通信模块
|
# 仅当 warehouses 为空时尝试重新扫描(避免覆盖子类的修复)
|
||||||
|
if not self.deck.warehouses:
|
||||||
|
for resource in self.deck.children:
|
||||||
|
# 兼容性增强: 只要是仓库类别或者是 WareHouse 实例均可
|
||||||
|
is_warehouse = isinstance(resource, WareHouse) or getattr(resource, "category", "") == "warehouse"
|
||||||
|
|
||||||
|
# 如果配置中有定义,也可以认定为 warehouse
|
||||||
|
if not is_warehouse and "warehouse_mapping" in bioyond_config:
|
||||||
|
if resource.name in bioyond_config["warehouse_mapping"]:
|
||||||
|
is_warehouse = True
|
||||||
|
|
||||||
|
if is_warehouse:
|
||||||
|
self.deck.warehouses[resource.name] = resource
|
||||||
|
# 确保 category 被正确设置,方便后续使用
|
||||||
|
if getattr(resource, "category", "") != "warehouse":
|
||||||
|
try:
|
||||||
|
resource.category = "warehouse"
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 创建通信模块;同步器将在 post_init 中初始化并执行首次同步
|
||||||
self._create_communication_module(bioyond_config)
|
self._create_communication_module(bioyond_config)
|
||||||
self.resource_synchronizer = BioyondResourceSynchronizer(self)
|
self.resource_synchronizer = None
|
||||||
self.resource_synchronizer.sync_from_external()
|
|
||||||
|
|
||||||
# TODO: self._ros_node里面拿属性
|
# TODO: self._ros_node里面拿属性
|
||||||
|
|
||||||
@@ -627,18 +776,22 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
self._set_workflow_mappings(bioyond_config["workflow_mappings"])
|
self._set_workflow_mappings(bioyond_config["workflow_mappings"])
|
||||||
|
|
||||||
# 准备 HTTP 报送接收服务配置(延迟到 post_init 启动)
|
# 准备 HTTP 报送接收服务配置(延迟到 post_init 启动)
|
||||||
# 从 bioyond_config 中获取,如果没有则使用 HTTP_SERVICE_CONFIG 的默认值
|
# 从 bioyond_config 中的 http_service_config 获取
|
||||||
|
http_service_cfg = bioyond_config.get("http_service_config", {})
|
||||||
self._http_service_config = {
|
self._http_service_config = {
|
||||||
"host": bioyond_config.get("http_service_host", HTTP_SERVICE_CONFIG["http_service_host"]),
|
"host": http_service_cfg.get("http_service_host", "127.0.0.1"),
|
||||||
"port": bioyond_config.get("http_service_port", HTTP_SERVICE_CONFIG["http_service_port"])
|
"port": http_service_cfg.get("http_service_port", 8080)
|
||||||
}
|
}
|
||||||
self.http_service = None # 将在 post_init 中启动
|
self.http_service = None # 将在 post_init 启动
|
||||||
|
self.connection_monitor = None # 将在 post_init 启动
|
||||||
|
|
||||||
logger.info(f"Bioyond工作站初始化完成")
|
logger.info(f"Bioyond工作站初始化完成")
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"""析构函数:清理资源,停止 HTTP 服务"""
|
"""析构函数:清理资源,停止 HTTP 服务"""
|
||||||
try:
|
try:
|
||||||
|
if hasattr(self, 'connection_monitor') and self.connection_monitor:
|
||||||
|
self.connection_monitor.stop()
|
||||||
if hasattr(self, 'http_service') and self.http_service is not None:
|
if hasattr(self, 'http_service') and self.http_service is not None:
|
||||||
logger.info("正在停止 HTTP 报送服务...")
|
logger.info("正在停止 HTTP 报送服务...")
|
||||||
self.http_service.stop()
|
self.http_service.stop()
|
||||||
@@ -648,8 +801,28 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
def post_init(self, ros_node: ROS2WorkstationNode):
|
def post_init(self, ros_node: ROS2WorkstationNode):
|
||||||
self._ros_node = ros_node
|
self._ros_node = ros_node
|
||||||
|
|
||||||
|
# Deck 为空时(反序列化未恢复子节点),主动调用 setup() 初始化仓库
|
||||||
|
if self.deck and not self.deck.children and hasattr(self.deck, "setup") and callable(self.deck.setup):
|
||||||
|
logger.info("Deck 无仓库子节点,调用 setup() 初始化仓库")
|
||||||
|
self.deck.setup()
|
||||||
|
|
||||||
|
# 初始化同步器并执行首次同步(需在仓库初始化之后)
|
||||||
|
self.resource_synchronizer = BioyondResourceSynchronizer(self)
|
||||||
|
self.resource_synchronizer.sync_from_external()
|
||||||
|
|
||||||
|
# 启动连接监控
|
||||||
|
try:
|
||||||
|
self.connection_monitor = ConnectionMonitor(self)
|
||||||
|
self.connection_monitor.start()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"启动连接监控失败: {e}")
|
||||||
|
|
||||||
# 启动 HTTP 报送接收服务(现在 device_id 已可用)
|
# 启动 HTTP 报送接收服务(现在 device_id 已可用)
|
||||||
if hasattr(self, '_http_service_config'):
|
# ⚠️ 检查子类是否已经自己管理 HTTP 服务
|
||||||
|
if self.bioyond_config.get("_disable_auto_http_service"):
|
||||||
|
logger.info("🔧 检测到 _disable_auto_http_service 标志,跳过自动启动 HTTP 服务")
|
||||||
|
logger.info(" 子类(BioyondCellWorkstation)已自行管理 HTTP 服务")
|
||||||
|
elif hasattr(self, '_http_service_config'):
|
||||||
try:
|
try:
|
||||||
self.http_service = WorkstationHTTPService(
|
self.http_service = WorkstationHTTPService(
|
||||||
workstation_instance=self,
|
workstation_instance=self,
|
||||||
@@ -688,19 +861,14 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
|
|
||||||
def _create_communication_module(self, config: Optional[Dict[str, Any]] = None) -> None:
|
def _create_communication_module(self, config: Optional[Dict[str, Any]] = None) -> None:
|
||||||
"""创建Bioyond通信模块"""
|
"""创建Bioyond通信模块"""
|
||||||
# 创建默认配置
|
# 直接使用传入的配置,不再使用默认值
|
||||||
default_config = {
|
# 所有配置必须从 JSON 文件中提供
|
||||||
**API_CONFIG,
|
|
||||||
"workflow_mappings": WORKFLOW_MAPPINGS,
|
|
||||||
"material_type_mappings": MATERIAL_TYPE_MAPPINGS,
|
|
||||||
"warehouse_mapping": WAREHOUSE_MAPPING
|
|
||||||
}
|
|
||||||
|
|
||||||
# 如果传入了 config,合并配置(config 中的值会覆盖默认值)
|
|
||||||
if config:
|
if config:
|
||||||
self.bioyond_config = {**default_config, **config}
|
self.bioyond_config = config
|
||||||
else:
|
else:
|
||||||
self.bioyond_config = default_config
|
# 如果没有配置,使用空字典(会导致后续错误,但这是预期的)
|
||||||
|
self.bioyond_config = {}
|
||||||
|
print("警告: 未提供 bioyond_config,请确保在 JSON 配置文件中提供完整配置")
|
||||||
|
|
||||||
self.hardware_interface = BioyondV1RPC(self.bioyond_config)
|
self.hardware_interface = BioyondV1RPC(self.bioyond_config)
|
||||||
|
|
||||||
@@ -1014,7 +1182,15 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
|
|
||||||
workflow_id = self._get_workflow(actual_workflow_name)
|
workflow_id = self._get_workflow(actual_workflow_name)
|
||||||
if workflow_id:
|
if workflow_id:
|
||||||
self.workflow_sequence.append(workflow_id)
|
# 兼容 BioyondReactionStation 中 workflow_sequence 被重写为 property 的情况
|
||||||
|
if isinstance(self.workflow_sequence, list):
|
||||||
|
self.workflow_sequence.append(workflow_id)
|
||||||
|
elif hasattr(self, "_cached_workflow_sequence") and isinstance(self._cached_workflow_sequence, list):
|
||||||
|
self._cached_workflow_sequence.append(workflow_id)
|
||||||
|
else:
|
||||||
|
print(f"❌ 无法添加工作流: workflow_sequence 类型错误 {type(self.workflow_sequence)}")
|
||||||
|
return False
|
||||||
|
|
||||||
print(f"添加工作流到执行顺序: {actual_workflow_name} -> {workflow_id}")
|
print(f"添加工作流到执行顺序: {actual_workflow_name} -> {workflow_id}")
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@@ -1215,6 +1391,22 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
# TODO: 根据实际业务需求处理步骤完成逻辑
|
# TODO: 根据实际业务需求处理步骤完成逻辑
|
||||||
# 例如:更新数据库、触发后续流程等
|
# 例如:更新数据库、触发后续流程等
|
||||||
|
|
||||||
|
# 发布任务状态事件 (running/progress update)
|
||||||
|
self._publish_task_status(
|
||||||
|
task_id=data.get('orderCode'), # 使用 OrderCode 作为关联 ID
|
||||||
|
task_code=data.get('orderCode'),
|
||||||
|
task_type="bioyond_step",
|
||||||
|
status="running",
|
||||||
|
progress=0.5, # 步骤完成视为任务进行中
|
||||||
|
result={"step_name": data.get('stepName'), "step_id": data.get('stepId')}
|
||||||
|
)
|
||||||
|
|
||||||
|
# 更新物料信息
|
||||||
|
# 步骤完成后,物料状态可能发生变化(如位置、用量等),触发同步
|
||||||
|
logger.info(f"[步骤完成报送] 触发物料同步...")
|
||||||
|
self.resource_synchronizer.sync_from_external()
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"processed": True,
|
"processed": True,
|
||||||
"step_id": data.get('stepId'),
|
"step_id": data.get('stepId'),
|
||||||
@@ -1249,6 +1441,17 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
|
|
||||||
# TODO: 根据实际业务需求处理通量完成逻辑
|
# TODO: 根据实际业务需求处理通量完成逻辑
|
||||||
|
|
||||||
|
# 发布任务状态事件
|
||||||
|
self._publish_task_status(
|
||||||
|
task_id=data.get('orderCode'),
|
||||||
|
task_code=data.get('orderCode'),
|
||||||
|
task_type="bioyond_sample",
|
||||||
|
status="running",
|
||||||
|
progress=0.7,
|
||||||
|
result={"sample_id": data.get('sampleId'), "status": status_desc}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"processed": True,
|
"processed": True,
|
||||||
"sample_id": data.get('sampleId'),
|
"sample_id": data.get('sampleId'),
|
||||||
@@ -1288,6 +1491,32 @@ class BioyondWorkstation(WorkstationBase):
|
|||||||
# TODO: 根据实际业务需求处理任务完成逻辑
|
# TODO: 根据实际业务需求处理任务完成逻辑
|
||||||
# 例如:更新物料库存、生成报表等
|
# 例如:更新物料库存、生成报表等
|
||||||
|
|
||||||
|
# 映射状态到事件状态
|
||||||
|
event_status = "completed"
|
||||||
|
if str(data.get('status')) in ["-11", "-12"]:
|
||||||
|
event_status = "error"
|
||||||
|
elif str(data.get('status')) == "30":
|
||||||
|
event_status = "completed"
|
||||||
|
else:
|
||||||
|
event_status = "running" # 其他状态视为运行中(或根据实际定义)
|
||||||
|
|
||||||
|
# 发布任务状态事件
|
||||||
|
self._publish_task_status(
|
||||||
|
task_id=data.get('orderCode'),
|
||||||
|
task_code=data.get('orderCode'),
|
||||||
|
task_type="bioyond_order",
|
||||||
|
status=event_status,
|
||||||
|
progress=1.0 if event_status in ["completed", "error"] else 0.9,
|
||||||
|
result={"order_name": data.get('orderName'), "status": status_desc, "materials_count": len(used_materials)}
|
||||||
|
)
|
||||||
|
|
||||||
|
# 更新物料信息
|
||||||
|
# 任务完成后,且状态为完成时,触发同步以更新最终物料状态
|
||||||
|
if event_status == "completed":
|
||||||
|
logger.info(f"[任务完成报送] 触发物料同步...")
|
||||||
|
self.resource_synchronizer.sync_from_external()
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"processed": True,
|
"processed": True,
|
||||||
"order_code": data.get('orderCode'),
|
"order_code": data.get('orderCode'),
|
||||||
|
|||||||
219
unilabos/devices/workstation/changelog_2026-03-12.md
Normal file
219
unilabos/devices/workstation/changelog_2026-03-12.md
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
# 代码变更说明 — 2026-03-12
|
||||||
|
|
||||||
|
> 本次变更基于 `implementation_plan_v2.md` 执行,目标:**物理几何结构初始化与物料内容物填充彻底解耦**,消除 PLR 反序列化时的 `Resource already assigned to deck` 错误,并修复若干运行时新增问题。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 一、物料系统标准化重构(主线任务)
|
||||||
|
|
||||||
|
### 1. `unilabos/resources/battery/magazine.py`
|
||||||
|
|
||||||
|
**改动**:`MagazineHolder_6_Cathode`、`MagazineHolder_6_Anode`、`MagazineHolder_4_Cathode` 三个工厂函数的 `klasses` 参数改为 `None`。
|
||||||
|
|
||||||
|
**原因**:原来三个工厂函数在初始化时就向洞位填满极片对象(`ElectrodeSheet`),导致 PLR 反序列化时"几何结构已创建子节点 + DB 再次 assign"双重冲突。
|
||||||
|
|
||||||
|
**原则**:物料余量改由寄存器直读(阶段 F),资源树不再追踪每个极片实体。`MagazineHolder_6_Battery` 原本就是 `klasses=None`,三者现在保持一致。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2. `unilabos/resources/battery/magazine.py`(追加,响应重复 UUID 问题)
|
||||||
|
|
||||||
|
**改动**:为 `Magazine`(洞位类)新增 `serialize` 和 `deserialize` 重写:
|
||||||
|
- `serialize`:序列化时强制将 `children` 置空,不再把极片写回数据库。
|
||||||
|
- `deserialize`:反序列化时强制忽略 `children` 字段,阻止数据库中旧极片记录被恢复。
|
||||||
|
|
||||||
|
**原因**:数据库中遗留有旧的 `ElectrodeSheet` 记录(`A1_sheet100` 等),启动时被 PLR 反序列化进来,导致同一 UUID 出现在多个 Magazine 洞位中,触发 `发现重复的uuid` 错误。此修复从源头截断旧数据,经过一次完整的"启动 → 资源树写回"后,数据库旧极片记录也会被干净覆盖。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3. `unilabos/resources/battery/bottle_carriers.py`
|
||||||
|
|
||||||
|
**改动**:删除 `YIHUA_Electrolyte_12VialCarrier` 末尾的 12 瓶填充循环及对应 `import`。
|
||||||
|
|
||||||
|
**原因**:`bottle_rack_6x2` 和 `bottle_rack_6x2_2` 应初始化为空载架,瓶子由 Bioyond 侧实际转运后再填入。原来初始化时直接塞满 `YB_pei_ye_xiao_Bottle`,反序列化时产生重复 assign。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. `unilabos/resources/bioyond/decks.py`
|
||||||
|
|
||||||
|
**改动**:
|
||||||
|
- 将 `BIOYOND_YB_Deck` 重命名为 `BioyondElectrolyteDeck`,保留 `BIOYOND_YB_Deck` 作为向后兼容别名。
|
||||||
|
- 工厂函数 `YB_Deck()` 重命名为 `bioyond_electrolyte_deck()`,保留 `YB_Deck` 作为别名。
|
||||||
|
- `BIOYOND_PolymerReactionStation_Deck`、`BIOYOND_PolymerPreparationStation_Deck`、`BioyondElectrolyteDeck` 三个 Deck 类:
|
||||||
|
- 移除 `__init__` 中的 `setup: bool = False` 参数及 `if setup: self.setup()` 调用。
|
||||||
|
- 删除临时 `deserialize` 补丁(该补丁是为了强制 `setup=False`,根本原因消除后不再需要)。
|
||||||
|
|
||||||
|
**原因**:`setup` 参数导致 PLR 反序列化时先通过 `__init__` 创建所有子资源,再从 JSON `children` 字段再次 assign,产生 `already assigned to deck` 错误。正确模式:`__init__` 只初始化自身几何,`setup()` 由工厂函数调用,反序列化由 PLR 从 DB 数据重建子资源。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 5. `unilabos/devices/workstation/coin_cell_assembly/YB_YH_materials.py`
|
||||||
|
|
||||||
|
**改动**:
|
||||||
|
- `CoincellDeck` 重命名为 `YihuaCoinCellDeck`,保留 `CoincellDeck` 作为向后兼容别名。
|
||||||
|
- 工厂函数 `YH_Deck()` 重命名为 `yihua_coin_cell_deck()`,保留 `YH_Deck` 作为别名。
|
||||||
|
- 移除 `YihuaCoinCellDeck.__init__` 中的 `setup: bool = False` 参数及调用,删除 `deserialize` 补丁(原因同 decks.py)。
|
||||||
|
- `MaterialPlate.__init__` 移除 `fill` 参数和 `fill=True` 分支,新增类方法 `MaterialPlate.create_with_holes()` 作为"带洞位"的工厂方法,`setup()` 改为调用该工厂方法。
|
||||||
|
- `YihuaCoinCellDeck.setup()` 末尾新增 `electrolyte_buffer`(`ResourceStack`)接驳槽,用于接收来自 Bioyond 侧的分液瓶板,命名与 `bioyond_cell_workstation.py` 中 `sites=["electrolyte_buffer"]` 一致。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 6. `unilabos/resources/resource_tracker.py`
|
||||||
|
|
||||||
|
**改动 1**:`to_plr_resources` 中,`load_all_state` 调用前预填 `Container` 类资源缺失的键:
|
||||||
|
|
||||||
|
```python
|
||||||
|
state.setdefault("liquid_history", [])
|
||||||
|
state.setdefault("pending_liquids", {})
|
||||||
|
```
|
||||||
|
|
||||||
|
**原因**:新版 PLR 要求 `Container` 状态中必须包含这两个键,旧数据库记录缺失时 `load_all_state` 会抛出 `KeyError`。
|
||||||
|
|
||||||
|
**改动 2**:`_validate_tree` 中,遇到重复 UUID 时改为自动重新分配新 UUID 并打 `WARNING`,不再直接抛异常崩溃。
|
||||||
|
|
||||||
|
**原因**:旧数据库中存在多个同名同 UUID 的极片对象(历史脏数据),严格校验会导致节点无法启动。改为 WARNING + 自动修复,确保启动成功,下次资源树写回后脏数据自然清除。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 7. `unilabos/resources/itemized_carrier.py`
|
||||||
|
|
||||||
|
**改动**:将原来的 `idx is None` 兜底补丁(静默调用 `super().assign_child_resource`,不更新槽位追踪)替换为两段式逻辑:
|
||||||
|
|
||||||
|
1. **XY 近似匹配**(容差 2mm):精确三维坐标匹配失败时,仅对比 XY 二维坐标,找到最近槽位后用槽位的正确坐标(含 Z)完成 assign,并打 `WARNING`。
|
||||||
|
2. **XY 也失败才抛异常**:给出详细的槽位列表和传入坐标,便于问题排查。
|
||||||
|
|
||||||
|
**原因**:数据库中存储的资源坐标 Z=0,而 `warehouse_factory` 定义的槽位 Z=dz(如 10mm)。精确匹配永远失败,原补丁静默兜底掩盖了这一问题。近似匹配修复了 Z 偏移,同时保留了真正异常时的报错能力。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 8. `unilabos/devices/workstation/bioyond_studio/bioyond_cell/bioyond_cell_workstation.py`
|
||||||
|
|
||||||
|
**改动 1**:更新导入:`BIOYOND_YB_Deck` → `BioyondElectrolyteDeck, bioyond_electrolyte_deck`。
|
||||||
|
|
||||||
|
**改动 2**:`__main__` 入口处改为调用 `bioyond_electrolyte_deck(name="YB_Deck")`。
|
||||||
|
|
||||||
|
**改动 3**:新增 `_get_resource_from_device(device_id, resource_name)` 方法,用于从目标设备的资源树中动态查找 PLR 资源对象(带降级回退逻辑)。
|
||||||
|
|
||||||
|
**改动 4**:跨站转运逻辑中,将原来"创建 `size=1,1,1` 的虚拟 `ResourcePLR` + 硬编码 UUID"的方式,改为通过 `_get_resource_from_device` 从目标设备获取真实的 `electrolyte_buffer` 资源对象。
|
||||||
|
|
||||||
|
**原因**:原代码使用硬编码 UUID 的虚拟资源作为转运目标,该对象在 YihuaCoinCellDeck 的资源树中不存在,转移后资源树状态混乱。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 9. `unilabos/devices/workstation/coin_cell_assembly/coin_cell_assembly.py`
|
||||||
|
|
||||||
|
**改动 1**:更新导入:`CoincellDeck` → `YihuaCoinCellDeck, yihua_coin_cell_deck`,`__main__` 入口改为调用 `yihua_coin_cell_deck()`。
|
||||||
|
|
||||||
|
**改动 2**:新增 10 个 `@property`,实现对依华扣电工站 Modbus 寄存器的直读:
|
||||||
|
|
||||||
|
| 属性名 | 寄存器地址 | 说明 |
|
||||||
|
|---|---|---|
|
||||||
|
| `data_10mm_positive_plate_remaining` | 520 | 10mm正极片余量 |
|
||||||
|
| `data_12mm_positive_plate_remaining` | 522 | 12mm正极片余量 |
|
||||||
|
| `data_16mm_positive_plate_remaining` | 524 | 16mm正极片余量 |
|
||||||
|
| `data_aluminum_foil_remaining` | 526 | 铝箔余量 |
|
||||||
|
| `data_positive_shell_remaining` | 528 | 正极壳余量 |
|
||||||
|
| `data_flat_washer_remaining` | 530 | 平垫余量 |
|
||||||
|
| `data_negative_shell_remaining` | 532 | 负极壳余量 |
|
||||||
|
| `data_spring_washer_remaining` | 534 | 弹垫余量 |
|
||||||
|
| `data_finished_battery_remaining_capacity` | 536 | 成品电池余量 |
|
||||||
|
| `data_finished_battery_ng_remaining_capacity` | 538 | 成品电池NG槽余量 |
|
||||||
|
|
||||||
|
**原因**:`coin_cell_workstation.yaml` 的 `status_types` 中定义了这 10 个属性,但代码中从未实现,导致每次前端轮询时均报 `AttributeError`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 二、配置与注册表更新
|
||||||
|
|
||||||
|
### 10. `yibin_electrolyte_config.json`
|
||||||
|
- `BIOYOND_YB_Deck` → `BioyondElectrolyteDeck`(class、type、_resource_type 三处)
|
||||||
|
- `CoincellDeck` → `YihuaCoinCellDeck`(class、type、_resource_type 三处)
|
||||||
|
- 移除 `"setup": true` 字段
|
||||||
|
|
||||||
|
### 11. `yibin_coin_cell_only_config.json`
|
||||||
|
- `CoincellDeck` → `YihuaCoinCellDeck`
|
||||||
|
- 移除 `"setup": true`
|
||||||
|
|
||||||
|
### 12. `yibin_electrolyte_only_config.json`
|
||||||
|
- `BIOYOND_YB_Deck` → `BioyondElectrolyteDeck`
|
||||||
|
- 移除 `"setup": true`
|
||||||
|
|
||||||
|
### 13. `unilabos/registry/resources/bioyond/deck.yaml`
|
||||||
|
- `BIOYOND_YB_Deck` → `BioyondElectrolyteDeck`,工厂函数路径更新为 `bioyond_electrolyte_deck`
|
||||||
|
- `CoincellDeck` → `YihuaCoinCellDeck`,工厂函数路径更新为 `yihua_coin_cell_deck`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 三、独立 Bug 修复
|
||||||
|
|
||||||
|
### 14. `unilabos/devices/workstation/coin_cell_assembly/coin_cell_assembly_b.csv`
|
||||||
|
|
||||||
|
**改动**:10 条余量寄存器记录的 `DataType` 列从 `REAL` 改为 `FLOAT32`。
|
||||||
|
|
||||||
|
**原因**:`REAL` 是 IEC 61131-3 PLC 工程师惯用名称,但 pymodbus 的 `DATATYPE` 枚举只有 `FLOAT32`,`DataType['REAL']` 查表时抛 `KeyError: 'REAL'`,导致 `CoinCellAssemblyWorkstation` 节点启动失败。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 四、运行期新增 Bug 修复(第二轮,2026-03-12 18:12 日志)
|
||||||
|
|
||||||
|
### 15. `unilabos/devices/workstation/bioyond_studio/station.py`
|
||||||
|
|
||||||
|
**改动**:第 261 行 `self.bioyond_config` → `self.workstation.bioyond_config`。
|
||||||
|
|
||||||
|
**原因**:`BioyondResourceSynchronizer.sync_to_external` 内部误用了 `self.bioyond_config`,而该类从未设置此属性(应通过 `self.workstation.bioyond_config` 访问)。触发场景:用户在前端将任意物料拖入仓库时,同步到 Bioyond 必定抛出 `AttributeError: 'BioyondResourceSynchronizer' object has no attribute 'bioyond_config'`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 16. `unilabos/devices/workstation/bioyond_studio/bioyond_cell/bioyond_cell_workstation.py`
|
||||||
|
|
||||||
|
**改动**:`_get_type_id_by_name` 方法新增"直接英文 key 命中"分支:
|
||||||
|
|
||||||
|
- **原逻辑**:仅按 `value[0]`(中文名,如 `"5ml分液瓶板"`)遍历比较。
|
||||||
|
- **新逻辑**:先以 `type_name` 直接查找 `material_type_mappings` 字典 key(英文 model 名,如 `"YB_Vial_5mL_Carrier"`),命中则立即返回 UUID;否则再按中文名兜底遍历。
|
||||||
|
|
||||||
|
**原因**:`resource_tree_transfer` 将 `plr_resource.model`(英文 key)作为 `board_type` / `bottle_type` 传给 `create_sample`,后者再调用 `_get_type_id_by_name`。旧版函数只按中文名查,导致英文 key 永远匹配不到 → `ValueError: 未找到板类型 'YB_Vial_5mL_Carrier' 的配置`。新函数兼容两种查找方式,同时保持向后兼容。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 五、运行期新增 Bug 修复(第三轮,2026-03-12 20:30 日志)
|
||||||
|
|
||||||
|
### 17. `unilabos/resources/resource_tracker.py`(追加)
|
||||||
|
|
||||||
|
**改动**:在 `to_plr_resources` 中,`sub_cls.deserialize` 调用前新增 `_deduplicate_plr_dict(plr_dict)` 预处理函数。
|
||||||
|
|
||||||
|
**函数逻辑**:递归遍历整个 `plr_dict` 树,在**全树范围**对 `children` 列表按 `name` 去重——保留首次出现的同名节点,跳过重复项并打 `WARNING`。
|
||||||
|
|
||||||
|
**根本原因**:
|
||||||
|
1. 用户通过前端将 `YB_Vial_5mL_Carrier` 拖入仓库 E01,carrier 及其子 vial(`YB_Vial_5mL_Carrier_vial_A1` 等)被写入数据库。
|
||||||
|
2. 随后 `sync_from_external`(Bioyond 定期同步)以**新 UUID** 重新创建同名 carrier 并赋给同一槽位,PLR 内存树中的旧 carrier 被替换,但**数据库旧记录未被清除**。
|
||||||
|
3. 下次重启时,数据库同一 `WareHouse` 下存在两条同名 `BottleCarrier`(不同 UUID),`node_to_plr_dict` 将二者都放入 `children` 列表,PLR 反序列化第二个 carrier 时子 vial 命名冲突,抛出 `ValueError: Resource with name 'YB_Vial_5mL_Carrier_vial_A1' already exists in the tree.`,整个 deck 无法加载,系统启动失败。
|
||||||
|
|
||||||
|
**连锁错误(随根因修复自动消除)**:
|
||||||
|
- `TypeError: Deck.__init__() got an unexpected keyword argument 'data'` — deck 加载失败后 `driver_creator.py` 触发降级路径,参数类型错误
|
||||||
|
- `AttributeError: 'ResourceDictInstance' object has no attribute 'copy'` — 另一条降级路径失败
|
||||||
|
- `ValueError: Deck 配置不能为空` — 所有 deck 创建路径失败,`deck=None` 传入工作站
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
> **验证状态**:2026-03-12 20:56 日志确认系统正常运行,无新增 ERROR 级错误。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 六、变更文件汇总(最终)
|
||||||
|
|
||||||
|
| 文件 | 变更类型 | 轮次 |
|
||||||
|
|---|---|---|
|
||||||
|
| `resources/battery/magazine.py` | 重构 + Bug 修复(极片子节点解耦 + 旧数据清理) | 第一轮 |
|
||||||
|
| `resources/battery/bottle_carriers.py` | 重构(移除初始化时自动填瓶) | 第一轮 |
|
||||||
|
| `resources/bioyond/decks.py` | 重构 + 重命名(BioyondElectrolyteDeck) | 第一轮 |
|
||||||
|
| `devices/workstation/coin_cell_assembly/YB_YH_materials.py` | 重构 + 重命名(YihuaCoinCellDeck)+ 新增 electrolyte_buffer 槽位 | 第一轮 |
|
||||||
|
| `resources/resource_tracker.py` | Bug 修复 × 3(Container 状态键预填 + 重复 UUID 自动修复 + 树级名称去重) | 第一/三轮 |
|
||||||
|
| `resources/itemized_carrier.py` | Bug 修复(XY 近似坐标匹配,修复 Z 偏移) | 第一轮 |
|
||||||
|
| `devices/workstation/bioyond_studio/bioyond_cell/bioyond_cell_workstation.py` | 重构 + Bug 修复(跨站转运 + 类型映射双模式查找) | 第一/二轮 |
|
||||||
|
| `devices/workstation/bioyond_studio/station.py` | Bug 修复(sync_to_external 属性访问路径) | 第二轮 |
|
||||||
|
| `devices/workstation/coin_cell_assembly/coin_cell_assembly.py` | 新增 10 个 Modbus 余量属性 + 更新导入 | 第一轮 |
|
||||||
|
| `yibin_electrolyte_config.json` | 配置更新(类名 + 移除 setup) | 第一轮 |
|
||||||
|
| `yibin_coin_cell_only_config.json` | 配置更新(类名 + 移除 setup) | 第一轮 |
|
||||||
|
| `yibin_electrolyte_only_config.json` | 配置更新(类名 + 移除 setup) | 第一轮 |
|
||||||
|
| `registry/resources/bioyond/deck.yaml` | 注册表更新(类名 + 工厂函数路径) | 第一轮 |
|
||||||
|
| `devices/workstation/coin_cell_assembly/coin_cell_assembly_b.csv` | Bug 修复(REAL → FLOAT32) | 第一轮 |
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
# Modbus CSV 地址映射说明
|
||||||
|
|
||||||
|
本文档说明 `coin_cell_assembly_a.csv` 文件如何将命名节点映射到实际的 Modbus 地址,以及如何在代码中使用它们。
|
||||||
|
|
||||||
|
## 1. CSV 文件结构
|
||||||
|
|
||||||
|
地址表文件位于同级目录下:`coin_cell_assembly_a.csv`
|
||||||
|
|
||||||
|
每一行定义了一个 Modbus 节点,包含以下关键列:
|
||||||
|
|
||||||
|
| 列名 | 说明 | 示例 |
|
||||||
|
|------|------|------|
|
||||||
|
| **Name** | **节点名称** (代码中引用的 Key) | `COIL_ALUMINUM_FOIL` |
|
||||||
|
| **DataType** | 数据类型 (BOOL, INT16, FLOAT32, STRING) | `BOOL` |
|
||||||
|
| **Comment** | 注释说明 | `使用铝箔垫` |
|
||||||
|
| **Attribute** | 属性 (通常留空或用于额外标记) | |
|
||||||
|
| **DeviceType** | Modbus 寄存器类型 (`coil`, `hold_register`) | `coil` |
|
||||||
|
| **Address** | **Modbus 地址** (十进制) | `8340` |
|
||||||
|
|
||||||
|
### 示例行 (铝箔垫片)
|
||||||
|
|
||||||
|
```csv
|
||||||
|
COIL_ALUMINUM_FOIL,BOOL,,使用铝箔垫,,coil,8340,
|
||||||
|
```
|
||||||
|
|
||||||
|
- **名称**: `COIL_ALUMINUM_FOIL`
|
||||||
|
- **类型**: `coil` (线圈,读写单个位)
|
||||||
|
- **地址**: `8340`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 加载与注册流程
|
||||||
|
|
||||||
|
在 `coin_cell_assembly.py` 的初始化代码中:
|
||||||
|
|
||||||
|
1. **加载 CSV**: `BaseClient.load_csv()` 读取 CSV 并解析每行定义。
|
||||||
|
2. **注册节点**: `modbus_client.register_node_list()` 将解析后的节点注册到 Modbus 客户端实例中。
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 代码位置: coin_cell_assembly.py (L174-175)
|
||||||
|
self.nodes = BaseClient.load_csv(os.path.join(os.path.dirname(__file__), 'coin_cell_assembly_a.csv'))
|
||||||
|
self.client = modbus_client.register_node_list(self.nodes)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 代码中的使用方式
|
||||||
|
|
||||||
|
注册后,通过 `self.client.use_node('节点名称')` 即可获取该节点对象并进行读写操作,无需关心具体地址。
|
||||||
|
|
||||||
|
### 控制铝箔垫片 (COIL_ALUMINUM_FOIL)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 代码位置: qiming_coin_cell_code 函数 (L1048)
|
||||||
|
self.client.use_node('COIL_ALUMINUM_FOIL').write(not lvbodian)
|
||||||
|
```
|
||||||
|
|
||||||
|
- **写入 True**: 对应 Modbus 功能码 05 (Write Single Coil),向地址 `8340` 写入 `1` (ON)。
|
||||||
|
- **写入 False**: 向地址 `8340` 写入 `0` (OFF)。
|
||||||
|
|
||||||
|
> **注意**: 代码中使用了 `not lvbodian`,这意味着逻辑是反转的。如果 `lvbodian` 参数为 `True` (默认),写入的是 `False` (不使用铝箔垫)。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 地址转换注意事项 (Modbus vs PLC)
|
||||||
|
|
||||||
|
CSV 中的 `Address` 列(如 `8340`)是 **Modbus 协议地址**。
|
||||||
|
|
||||||
|
如果使用 InoProShop (汇川 PLC 编程软件),看到的可能是 **PLC 内部地址** (如 `%QX...` 或 `%MW...`)。这两者之间通常需要转换。
|
||||||
|
|
||||||
|
### 常见的转换规则 (示例)
|
||||||
|
|
||||||
|
- **Coil (线圈) %QX**:
|
||||||
|
- `Modbus地址 = 字节地址 * 8 + 位偏移`
|
||||||
|
- *例子*: `%QX834.0` -> `834 * 8 + 0` = `6672`
|
||||||
|
- *注意*: 如果 CSV 中配置的是 `8340`,这可能是一个自定义映射,或者是基于不同规则(如直接对应 Word 地址的某种映射,或者可能就是地址写错了/使用了非标准映射)。
|
||||||
|
|
||||||
|
- **Register (寄存器) %MW**:
|
||||||
|
- 通常直接对应,或者有偏移量 (如 Modbus 40001 = PLC MW0)。
|
||||||
|
|
||||||
|
### 验证方法
|
||||||
|
由于 `test_unilab_interact.py` 中发现 `8450` (CSV风格) 不工作,而 `6760` (%QX845.0 计算值) 工作正常,**建议对 CSV 中的其他地址也进行核实**,特别是像 `8340` 这样以 0 结尾看起来像是 "字节地址+0" 的数值,可能实际上应该是 `%QX834.0` 对应的 `6672`。
|
||||||
|
|
||||||
|
如果发现设备控制无反应,请尝试按照标准的 Modbus 计算方式转换 PLC 地址。
|
||||||
@@ -0,0 +1,352 @@
|
|||||||
|
# 2026-01-13 物料搜寻确认弹窗自动处理功能
|
||||||
|
|
||||||
|
## 概述
|
||||||
|
|
||||||
|
本次更新为设备初始化流程添加了**物料搜寻确认弹窗自动检测与处理功能**。在设备初始化过程中,PLC 会弹出物料搜寻确认对话框,现在系统可以根据用户参数自动点击"是"或"否"按钮,无需手动干预。
|
||||||
|
|
||||||
|
## 背景问题
|
||||||
|
|
||||||
|
### 原有流程
|
||||||
|
1. 调用 `func_pack_device_init_auto_start_combined()` 初始化设备
|
||||||
|
2. PLC 在初始化过程中弹出物料搜寻确认对话框
|
||||||
|
3. **需要人工手动点击**"是"或"否"按钮
|
||||||
|
4. PLC 继续完成初始化并启动
|
||||||
|
|
||||||
|
### 存在的问题
|
||||||
|
- 需要人工干预,无法实现全自动化
|
||||||
|
- 影响批量生产效率
|
||||||
|
- 容易遗忘点击导致流程卡住
|
||||||
|
|
||||||
|
## 解决方案
|
||||||
|
|
||||||
|
### 新增 Modbus 地址配置
|
||||||
|
|
||||||
|
在 `coin_cell_assembly_b.csv` 第 69-71 行添加三个 coil:
|
||||||
|
|
||||||
|
| Name | DeviceType | Address | 说明 |
|
||||||
|
|------|-----------|---------|------|
|
||||||
|
| COIL_MATERIAL_SEARCH_DIALOG_APPEAR | coil | 6470 | 物料搜寻确认弹窗画面是否出现 |
|
||||||
|
| COIL_MATERIAL_SEARCH_CONFIRM_YES | coil | 6480 | 初始化物料搜寻确认按钮"是" |
|
||||||
|
| COIL_MATERIAL_SEARCH_CONFIRM_NO | coil | 6490 | 初始化物料搜寻确认按钮"否" |
|
||||||
|
|
||||||
|
**Modbus 地址转换:**
|
||||||
|
- CSV 6470 → Modbus 5176 (弹窗出现)
|
||||||
|
- CSV 6480 → Modbus 5184 (按钮"是")
|
||||||
|
- CSV 6490 → Modbus 5192 (按钮"否")
|
||||||
|
|
||||||
|
## 代码修改详情
|
||||||
|
|
||||||
|
### 1. coin_cell_assembly.py
|
||||||
|
|
||||||
|
#### 1.1 新增辅助方法 `_handle_material_search_dialog()`
|
||||||
|
|
||||||
|
**位置:** 第 799-901 行
|
||||||
|
|
||||||
|
**功能:**
|
||||||
|
- 监测物料搜寻确认弹窗是否出现(Coil 5176)
|
||||||
|
- 根据 `enable_search` 参数自动点击对应按钮
|
||||||
|
- 使用**脉冲模式**模拟真实按钮操作:`True` → 保持 0.5 秒 → `False`
|
||||||
|
|
||||||
|
**参数:**
|
||||||
|
- `enable_search: bool` - True=点击"是"(启用物料搜寻), False=点击"否"(不启用)
|
||||||
|
- `timeout: int = 30` - 等待弹窗出现的最大时间(秒)
|
||||||
|
|
||||||
|
**逻辑流程:**
|
||||||
|
```python
|
||||||
|
1. 监测 COIL_MATERIAL_SEARCH_DIALOG_APPEAR (每 0.5 秒检查一次)
|
||||||
|
2. 检测到弹窗出现 (Coil = True)
|
||||||
|
3. 选择按钮:
|
||||||
|
- enable_search=True → COIL_MATERIAL_SEARCH_CONFIRM_YES
|
||||||
|
- enable_search=False → COIL_MATERIAL_SEARCH_CONFIRM_NO
|
||||||
|
4. 执行脉冲操作:
|
||||||
|
- 写入 True (按下按钮)
|
||||||
|
- 等待 0.5 秒
|
||||||
|
- 写入 False (释放按钮)
|
||||||
|
- 验证状态
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 1.2 修改 `func_pack_device_init_auto_start_combined()`
|
||||||
|
|
||||||
|
**位置:** 第 904-1115 行
|
||||||
|
|
||||||
|
**主要改动:**
|
||||||
|
|
||||||
|
1. **添加新参数**
|
||||||
|
```python
|
||||||
|
def func_pack_device_init_auto_start_combined(
|
||||||
|
self,
|
||||||
|
material_search_enable: bool = False # 新增参数
|
||||||
|
) -> bool:
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **内联初始化逻辑并集成弹窗检测**
|
||||||
|
- 不再调用 `self.func_pack_device_init()`
|
||||||
|
- 将初始化逻辑直接实现在函数内
|
||||||
|
- **在等待初始化完成的循环中实时检测弹窗**
|
||||||
|
- 避免死锁:PLC 等待弹窗确认 ↔ 代码等待初始化完成
|
||||||
|
|
||||||
|
3. **关键代码片段**
|
||||||
|
```python
|
||||||
|
# 等待初始化完成,同时检测物料搜寻弹窗
|
||||||
|
while (self._sys_init_status()) == False:
|
||||||
|
# 检查超时
|
||||||
|
if time.time() - start_wait > max_wait_time:
|
||||||
|
raise RuntimeError(f"初始化超时")
|
||||||
|
|
||||||
|
# 如果还没处理弹窗,检测弹窗是否出现
|
||||||
|
if not dialog_handled:
|
||||||
|
dialog_state = self.client.use_node('COIL_MATERIAL_SEARCH_DIALOG_APPEAR').read(1)
|
||||||
|
if dialog_actual: # 弹窗出现
|
||||||
|
# 执行脉冲按钮点击
|
||||||
|
button_node.write(True) # 按下
|
||||||
|
time.sleep(0.5) # 保持
|
||||||
|
button_node.write(False) # 释放
|
||||||
|
dialog_handled = True
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **步骤调整**
|
||||||
|
- 步骤 0: 前置条件检查
|
||||||
|
- 步骤 1: 设备初始化(**包含弹窗检测**)
|
||||||
|
- 步骤 1.5: 已在步骤 1 中完成
|
||||||
|
- 步骤 2: 切换自动模式
|
||||||
|
- 步骤 3: 启动设备
|
||||||
|
|
||||||
|
### 2. coin_cell_workstation.yaml
|
||||||
|
|
||||||
|
**位置:** 第 292-312 行
|
||||||
|
|
||||||
|
**修改内容:**
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
auto-func_pack_device_init_auto_start_combined:
|
||||||
|
goal_default:
|
||||||
|
material_search_enable: false # 新增默认值
|
||||||
|
|
||||||
|
schema:
|
||||||
|
description: 组合函数:设备初始化 + 物料搜寻确认 + 切换自动模式 + 启动。初始化过程中会自动检测物料搜寻确认弹窗,并根据参数自动点击"是"或"否"按钮
|
||||||
|
|
||||||
|
goal:
|
||||||
|
properties:
|
||||||
|
material_search_enable: # 新增参数配置
|
||||||
|
default: false
|
||||||
|
description: 是否启用物料搜寻功能。设备初始化后会弹出物料搜寻确认弹窗,此参数控制自动点击"是"(启用)或"否"(不启用)。默认为false(不启用物料搜寻)
|
||||||
|
type: boolean
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 测试脚本(已创建,用户已删除)
|
||||||
|
|
||||||
|
#### 3.1 test_material_search_dialog.py
|
||||||
|
- 从 CSV 动态加载 Modbus 地址
|
||||||
|
- 支持 4 种测试模式:
|
||||||
|
- `query` - 查询所有状态
|
||||||
|
- `dialog <0|1>` - 设置弹窗出现/消失
|
||||||
|
- `yes` - 脉冲点击"是"按钮
|
||||||
|
- `no` - 脉冲点击"否"按钮
|
||||||
|
- 兼容 pymodbus 3.x API
|
||||||
|
|
||||||
|
#### 3.2 更新其他测试脚本
|
||||||
|
- `test_coin_cell_reset.py` - 更新为 pymodbus 3.x API
|
||||||
|
- `test_unilab_interact.py` - 更新为 pymodbus 3.x API
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
### 参数说明
|
||||||
|
|
||||||
|
| 参数 | 类型 | 默认值 | 说明 |
|
||||||
|
|------|------|--------|------|
|
||||||
|
| `material_search_enable` | boolean | `false` | 是否启用物料搜寻功能 |
|
||||||
|
|
||||||
|
### 调用示例
|
||||||
|
|
||||||
|
#### 1. 不启用物料搜寻(默认)
|
||||||
|
```python
|
||||||
|
# 默认参数,点击"否"按钮
|
||||||
|
await device.func_pack_device_init_auto_start_combined()
|
||||||
|
```
|
||||||
|
|
||||||
|
或在 YAML workflow 中:
|
||||||
|
```yaml
|
||||||
|
# 使用默认值 false,不启用物料搜寻
|
||||||
|
- BatteryStation/auto-func_pack_device_init_auto_start_combined: {}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2. 启用物料搜寻
|
||||||
|
```python
|
||||||
|
# 显式设置为 True,点击"是"按钮
|
||||||
|
await device.func_pack_device_init_auto_start_combined(
|
||||||
|
material_search_enable=True
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
或在 YAML workflow 中:
|
||||||
|
```yaml
|
||||||
|
- BatteryStation/auto-func_pack_device_init_auto_start_combined:
|
||||||
|
goal:
|
||||||
|
material_search_enable: true # 启用物料搜寻
|
||||||
|
```
|
||||||
|
|
||||||
|
## 执行日志示例
|
||||||
|
|
||||||
|
```
|
||||||
|
26-01-13 [21:32:44] [INFO] 开始组合操作:设备初始化 → 物料搜寻确认 → 自动模式 → 启动
|
||||||
|
26-01-13 [21:32:44] [INFO] 【步骤 0/4】前置条件检查...
|
||||||
|
26-01-13 [21:32:44] [INFO] ✓ REG_UNILAB_INTERACT 检查通过
|
||||||
|
26-01-13 [21:32:44] [INFO] ✓ COIL_GB_L_IGNORE_CMD 检查通过
|
||||||
|
26-01-13 [21:32:44] [INFO] 【步骤 1/4】设备初始化...
|
||||||
|
26-01-13 [21:32:44] [INFO] 切换手动模式...
|
||||||
|
26-01-13 [21:32:46] [INFO] 发送初始化命令...
|
||||||
|
26-01-13 [21:32:47] [INFO] 等待初始化完成(同时监测物料搜寻弹窗)...
|
||||||
|
26-01-13 [21:33:05] [INFO] ✓ 在初始化过程中检测到物料搜寻确认弹窗!
|
||||||
|
26-01-13 [21:33:05] [INFO] 用户选择: 不启用物料搜寻(点击否)
|
||||||
|
26-01-13 [21:33:05] [INFO] → 按下按钮 '否'
|
||||||
|
26-01-13 [21:33:06] [INFO] → 释放按钮 '否'
|
||||||
|
26-01-13 [21:33:07] [INFO] ✓ 成功处理物料搜寻确认弹窗(选择: 否)
|
||||||
|
26-01-13 [21:33:08] [INFO] ✓ 初始化状态完成
|
||||||
|
26-01-13 [21:33:12] [INFO] ✓ 设备初始化完成
|
||||||
|
26-01-13 [21:33:12] [INFO] 【步骤 1.5/4】物料搜寻确认已在初始化过程中完成
|
||||||
|
26-01-13 [21:33:12] [INFO] 【步骤 2/4】切换自动模式...
|
||||||
|
26-01-13 [21:33:15] [INFO] ✓ 切换自动模式完成
|
||||||
|
26-01-13 [21:33:15] [INFO] 【步骤 3/4】启动设备...
|
||||||
|
26-01-13 [21:33:18] [INFO] ✓ 启动设备完成
|
||||||
|
26-01-13 [21:33:18] [INFO] 组合操作完成:设备已成功初始化、确认物料搜寻、切换自动模式并启动
|
||||||
|
```
|
||||||
|
|
||||||
|
## 技术要点
|
||||||
|
|
||||||
|
### 1. 脉冲模式按钮操作
|
||||||
|
模拟真实按钮按压过程:
|
||||||
|
1. 写入 `True` (按下)
|
||||||
|
2. 保持 0.5 秒
|
||||||
|
3. 写入 `False` (释放)
|
||||||
|
4. 验证状态
|
||||||
|
|
||||||
|
### 2. 避免死锁
|
||||||
|
**问题:** PLC 在初始化过程中等待弹窗确认,而代码等待初始化完成
|
||||||
|
**解决:** 在初始化等待循环中实时检测弹窗,一旦出现立即处理
|
||||||
|
|
||||||
|
### 3. 超时保护
|
||||||
|
- 弹窗检测超时:30 秒(在 `_handle_material_search_dialog` 中)
|
||||||
|
- 初始化超时:120 秒(在 `func_pack_device_init_auto_start_combined` 中)
|
||||||
|
|
||||||
|
### 4. PyModbus 3.x API 兼容
|
||||||
|
所有 Modbus 操作使用 keyword arguments:
|
||||||
|
```python
|
||||||
|
# 读取
|
||||||
|
client.read_coils(address=5176, count=1)
|
||||||
|
|
||||||
|
# 写入
|
||||||
|
client.write_coil(address=5184, value=True)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 向后兼容性
|
||||||
|
|
||||||
|
### 保留的原有函数
|
||||||
|
- `func_pack_device_init()` - 单独的初始化函数,不包含弹窗处理
|
||||||
|
- 仍可在 YAML 中通过 `auto-func_pack_device_init` 调用
|
||||||
|
- 用于不需要自动处理弹窗的场景
|
||||||
|
|
||||||
|
### 新增的功能
|
||||||
|
- 在 `func_pack_device_init_auto_start_combined()` 中集成弹窗处理
|
||||||
|
- 通过参数控制,默认行为与之前兼容(点击"否")
|
||||||
|
|
||||||
|
## 验证测试
|
||||||
|
|
||||||
|
### 测试场景
|
||||||
|
|
||||||
|
#### 场景 1:默认参数(不启用物料搜寻)
|
||||||
|
```bash
|
||||||
|
# 调用时不传参数
|
||||||
|
BatteryStation/auto-func_pack_device_init_auto_start_combined: {}
|
||||||
|
```
|
||||||
|
**预期结果:**
|
||||||
|
- ✅ 检测到弹窗
|
||||||
|
- ✅ 自动点击"否"按钮
|
||||||
|
- ✅ 初始化完成并启动成功
|
||||||
|
|
||||||
|
#### 场景 2:启用物料搜寻
|
||||||
|
```bash
|
||||||
|
# 设置 material_search_enable=true
|
||||||
|
BatteryStation/auto-func_pack_device_init_auto_start_combined:
|
||||||
|
goal:
|
||||||
|
material_search_enable: true
|
||||||
|
```
|
||||||
|
**预期结果:**
|
||||||
|
- ✅ 检测到弹窗
|
||||||
|
- ✅ 自动点击"是"按钮
|
||||||
|
- ✅ 初始化完成并启动成功
|
||||||
|
|
||||||
|
### 实际测试结果
|
||||||
|
|
||||||
|
**测试时间:** 2026-01-13 21:32:43
|
||||||
|
**测试参数:** `material_search_enable: false`
|
||||||
|
**测试结果:** ✅ 成功
|
||||||
|
|
||||||
|
**关键时间节点:**
|
||||||
|
- 21:33:05 - 检测到弹窗
|
||||||
|
- 21:33:05 - 按下"否"按钮
|
||||||
|
- 21:33:06 - 释放"否"按钮
|
||||||
|
- 21:33:07 - 弹窗处理完成
|
||||||
|
- 21:33:08 - 初始化状态完成
|
||||||
|
- 21:33:18 - 整个流程完成
|
||||||
|
|
||||||
|
**总耗时:** 约 35 秒(包含初始化全过程)
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. **CSV 配置依赖**
|
||||||
|
- 确保 `coin_cell_assembly_b.csv` 包含 69-71 行的 coil 配置
|
||||||
|
- 地址转换逻辑:`modbus_addr = (csv_addr // 10) * 8 + (csv_addr % 10)`
|
||||||
|
|
||||||
|
2. **默认行为**
|
||||||
|
- 默认 `material_search_enable=false`,即不启用物料搜寻
|
||||||
|
- 如需启用,必须显式设置为 `true`
|
||||||
|
|
||||||
|
3. **日志级别**
|
||||||
|
- 弹窗检测过程中的 `waiting for init_cmd` 使用 DEBUG 级别
|
||||||
|
- 关键操作(检测到弹窗、按钮操作)使用 INFO 级别
|
||||||
|
|
||||||
|
4. **原有函数保留**
|
||||||
|
- `func_pack_device_init()` 仍然可用,但不包含弹窗处理
|
||||||
|
- 如果单独调用此函数,仍需手动处理弹窗
|
||||||
|
|
||||||
|
## 文件清单
|
||||||
|
|
||||||
|
### 修改的文件
|
||||||
|
1. `d:\UniLabdev\Uni-Lab-OS\unilabos\devices\workstation\coin_cell_assembly\coin_cell_assembly.py`
|
||||||
|
- 新增 `_handle_material_search_dialog()` 方法
|
||||||
|
- 修改 `func_pack_device_init_auto_start_combined()` 函数
|
||||||
|
|
||||||
|
2. `d:\UniLabdev\Uni-Lab-OS\unilabos\registry\devices\coin_cell_workstation.yaml`
|
||||||
|
- 更新 `auto-func_pack_device_init_auto_start_combined` 配置
|
||||||
|
- 添加 `material_search_enable` 参数说明
|
||||||
|
|
||||||
|
3. `d:\UniLabdev\Uni-Lab-OS\unilabos\devices\workstation\coin_cell_assembly\coin_cell_assembly_b.csv`
|
||||||
|
- 第 69-71 行添加三个 coil 配置
|
||||||
|
|
||||||
|
### 创建的测试文件(已删除)
|
||||||
|
1. `test_material_search_dialog.py` - 物料搜寻弹窗测试脚本
|
||||||
|
2. `test_coin_cell_reset.py` - 复位功能测试(更新为 pymodbus 3.x)
|
||||||
|
3. `test_unilab_interact.py` - Unilab 交互测试(更新为 pymodbus 3.x)
|
||||||
|
|
||||||
|
## 总结
|
||||||
|
|
||||||
|
本次更新成功实现了设备初始化过程中物料搜寻确认弹窗的自动化处理,主要优势:
|
||||||
|
|
||||||
|
✅ **全自动化** - 无需人工干预
|
||||||
|
✅ **参数可配** - 灵活控制是否启用物料搜寻
|
||||||
|
✅ **实时检测** - 在初始化等待循环中检测,避免死锁
|
||||||
|
✅ **脉冲模式** - 模拟真实按钮操作
|
||||||
|
✅ **向后兼容** - 保留原有函数,不影响现有流程
|
||||||
|
✅ **完整日志** - 详细记录每一步操作
|
||||||
|
✅ **超时保护** - 防止无限等待
|
||||||
|
|
||||||
|
该功能已通过实际测试验证,可投入生产使用。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**文档版本:** 1.0
|
||||||
|
**创建日期:** 2026-01-13
|
||||||
|
**作者:** Antigravity AI Assistant
|
||||||
|
**最后更新:** 2026-01-13 21:36
|
||||||
@@ -0,0 +1,649 @@
|
|||||||
|
"""
|
||||||
|
纽扣电池组装工作站物料类定义
|
||||||
|
Button Battery Assembly Station Resource Classes
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
from typing import Any, Dict, List, Optional, TypedDict, Union, cast
|
||||||
|
|
||||||
|
from pylabrobot.resources.coordinate import Coordinate
|
||||||
|
from pylabrobot.resources.container import Container
|
||||||
|
from pylabrobot.resources.deck import Deck
|
||||||
|
from pylabrobot.resources.itemized_resource import ItemizedResource
|
||||||
|
from pylabrobot.resources.resource import Resource
|
||||||
|
from pylabrobot.resources.resource_stack import ResourceStack
|
||||||
|
from pylabrobot.resources.tip_rack import TipRack, TipSpot
|
||||||
|
from pylabrobot.resources.trash import Trash
|
||||||
|
from pylabrobot.resources.utils import create_ordered_items_2d
|
||||||
|
|
||||||
|
from unilabos.resources.battery.magazine import MagazineHolder_4_Cathode, MagazineHolder_6_Cathode, MagazineHolder_6_Anode, MagazineHolder_6_Battery
|
||||||
|
from unilabos.resources.battery.bottle_carriers import YIHUA_Electrolyte_12VialCarrier
|
||||||
|
from unilabos.resources.battery.electrode_sheet import ElectrodeSheet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: 这个应该只能放一个极片
|
||||||
|
class MaterialHoleState(TypedDict):
|
||||||
|
diameter: int
|
||||||
|
depth: int
|
||||||
|
max_sheets: int
|
||||||
|
info: Optional[str] # 附加信息
|
||||||
|
|
||||||
|
class MaterialHole(Resource):
|
||||||
|
"""料板洞位类"""
|
||||||
|
children: List[ElectrodeSheet] = []
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
size_x: float,
|
||||||
|
size_y: float,
|
||||||
|
size_z: float,
|
||||||
|
category: str = "material_hole",
|
||||||
|
**kwargs
|
||||||
|
):
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=size_x,
|
||||||
|
size_y=size_y,
|
||||||
|
size_z=size_z,
|
||||||
|
category=category,
|
||||||
|
)
|
||||||
|
self._unilabos_state: MaterialHoleState = MaterialHoleState(
|
||||||
|
diameter=20,
|
||||||
|
depth=10,
|
||||||
|
max_sheets=1,
|
||||||
|
info=None
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_all_sheet_info(self):
|
||||||
|
info_list = []
|
||||||
|
for sheet in self.children:
|
||||||
|
info_list.append(sheet._unilabos_state["info"])
|
||||||
|
return info_list
|
||||||
|
|
||||||
|
#这个函数函数好像没用,一般不会集中赋值质量
|
||||||
|
def set_all_sheet_mass(self):
|
||||||
|
for sheet in self.children:
|
||||||
|
sheet._unilabos_state["mass"] = 0.5 # 示例:设置质量为0.5g
|
||||||
|
|
||||||
|
def load_state(self, state: Dict[str, Any]) -> None:
|
||||||
|
"""格式不变"""
|
||||||
|
super().load_state(state)
|
||||||
|
self._unilabos_state = state
|
||||||
|
|
||||||
|
def serialize_state(self) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""格式不变"""
|
||||||
|
data = super().serialize_state()
|
||||||
|
data.update(self._unilabos_state) # Container自身的信息,云端物料将保存这一data,本地也通过这里的data进行读写,当前类用来表示这个物料的长宽高大小的属性,而data(state用来表示物料的内容,细节等)
|
||||||
|
return data
|
||||||
|
#移动极片前先取出对象
|
||||||
|
def get_sheet_with_name(self, name: str) -> Optional[ElectrodeSheet]:
|
||||||
|
for sheet in self.children:
|
||||||
|
if sheet.name == name:
|
||||||
|
return sheet
|
||||||
|
return None
|
||||||
|
|
||||||
|
def has_electrode_sheet(self) -> bool:
|
||||||
|
"""检查洞位是否有极片"""
|
||||||
|
return len(self.children) > 0
|
||||||
|
|
||||||
|
def assign_child_resource(
|
||||||
|
self,
|
||||||
|
resource: ElectrodeSheet,
|
||||||
|
location: Optional[Coordinate],
|
||||||
|
reassign: bool = True,
|
||||||
|
):
|
||||||
|
"""放置极片"""
|
||||||
|
# TODO: 这里要改,diameter找不到,加入._unilabos_state后应该没问题
|
||||||
|
#if resource._unilabos_state["diameter"] > self._unilabos_state["diameter"]:
|
||||||
|
# raise ValueError(f"极片直径 {resource._unilabos_state['diameter']} 超过洞位直径 {self._unilabos_state['diameter']}")
|
||||||
|
#if len(self.children) >= self._unilabos_state["max_sheets"]:
|
||||||
|
# raise ValueError(f"洞位已满,无法放置更多极片")
|
||||||
|
super().assign_child_resource(resource, location, reassign)
|
||||||
|
|
||||||
|
# 根据children的编号取物料对象。
|
||||||
|
def get_electrode_sheet_info(self, index: int) -> ElectrodeSheet:
|
||||||
|
return self.children[index]
|
||||||
|
|
||||||
|
|
||||||
|
class MaterialPlateState(TypedDict):
|
||||||
|
hole_spacing_x: float
|
||||||
|
hole_spacing_y: float
|
||||||
|
hole_diameter: float
|
||||||
|
info: Optional[str] # 附加信息
|
||||||
|
|
||||||
|
class MaterialPlate(ItemizedResource[MaterialHole]):
|
||||||
|
"""料板类 - 4x4个洞位,每个洞位放1个极片"""
|
||||||
|
|
||||||
|
children: List[MaterialHole]
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
size_x: float,
|
||||||
|
size_y: float,
|
||||||
|
size_z: float,
|
||||||
|
ordered_items: Optional[Dict[str, MaterialHole]] = None,
|
||||||
|
ordering: Optional[OrderedDict[str, str]] = None,
|
||||||
|
category: str = "material_plate",
|
||||||
|
model: Optional[str] = None,
|
||||||
|
):
|
||||||
|
"""初始化料板(不主动填充洞位,由工厂方法或反序列化恢复)
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 料板名称
|
||||||
|
size_x: 长度 (mm)
|
||||||
|
size_y: 宽度 (mm)
|
||||||
|
size_z: 高度 (mm)
|
||||||
|
category: 类别
|
||||||
|
model: 型号
|
||||||
|
"""
|
||||||
|
self._unilabos_state: MaterialPlateState = MaterialPlateState(
|
||||||
|
hole_spacing_x=24.0,
|
||||||
|
hole_spacing_y=24.0,
|
||||||
|
hole_diameter=20.0,
|
||||||
|
info="",
|
||||||
|
)
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=size_x,
|
||||||
|
size_y=size_y,
|
||||||
|
size_z=size_z,
|
||||||
|
ordered_items=ordered_items,
|
||||||
|
ordering=ordering,
|
||||||
|
category=category,
|
||||||
|
model=model,
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_with_holes(
|
||||||
|
cls,
|
||||||
|
name: str,
|
||||||
|
size_x: float,
|
||||||
|
size_y: float,
|
||||||
|
size_z: float,
|
||||||
|
category: str = "material_plate",
|
||||||
|
model: Optional[str] = None,
|
||||||
|
) -> "MaterialPlate":
|
||||||
|
"""工厂方法:创建带 4x4 洞位的料板(仅用于初始 setup,不在反序列化路径调用)"""
|
||||||
|
# 默认洞位间距(与 _unilabos_state 默认值保持一致)
|
||||||
|
hole_spacing_x = 24.0
|
||||||
|
hole_spacing_y = 24.0
|
||||||
|
# 先建洞位,再作为 ordered_items 传入构造函数
|
||||||
|
# (ItemizedResource.__init__ 要求 ordered_items 或 ordering 二选一必须有值)
|
||||||
|
holes = create_ordered_items_2d(
|
||||||
|
klass=MaterialHole,
|
||||||
|
num_items_x=4,
|
||||||
|
num_items_y=4,
|
||||||
|
dx=(size_x - 4 * hole_spacing_x) / 2,
|
||||||
|
dy=(size_y - 4 * hole_spacing_y) / 2,
|
||||||
|
dz=size_z,
|
||||||
|
item_dx=hole_spacing_x,
|
||||||
|
item_dy=hole_spacing_y,
|
||||||
|
size_x=16,
|
||||||
|
size_y=16,
|
||||||
|
size_z=16,
|
||||||
|
)
|
||||||
|
return cls(
|
||||||
|
name=name, size_x=size_x, size_y=size_y, size_z=size_z,
|
||||||
|
ordered_items=holes, category=category, model=model,
|
||||||
|
)
|
||||||
|
|
||||||
|
def update_locations(self):
|
||||||
|
# TODO:调多次相加
|
||||||
|
holes = create_ordered_items_2d(
|
||||||
|
klass=MaterialHole,
|
||||||
|
num_items_x=4,
|
||||||
|
num_items_y=4,
|
||||||
|
dx=(self._size_x - 3 * self._unilabos_state["hole_spacing_x"]) / 2, # 居中
|
||||||
|
dy=(self._size_y - 3 * self._unilabos_state["hole_spacing_y"]) / 2, # 居中
|
||||||
|
dz=self._size_z,
|
||||||
|
item_dx=self._unilabos_state["hole_spacing_x"],
|
||||||
|
item_dy=self._unilabos_state["hole_spacing_y"],
|
||||||
|
size_x = 1,
|
||||||
|
size_y = 1,
|
||||||
|
size_z = 1,
|
||||||
|
)
|
||||||
|
for item, original_item in zip(holes.items(), self.children):
|
||||||
|
original_item.location = item[1].location
|
||||||
|
|
||||||
|
|
||||||
|
class PlateSlot(ResourceStack):
|
||||||
|
"""板槽位类 - 1个槽上能堆放8个板,移板只能操作最上方的板"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
size_x: float,
|
||||||
|
size_y: float,
|
||||||
|
size_z: float,
|
||||||
|
max_plates: int = 8,
|
||||||
|
category: str = "plate_slot",
|
||||||
|
model: Optional[str] = None
|
||||||
|
):
|
||||||
|
"""初始化板槽位
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 槽位名称
|
||||||
|
max_plates: 最大板数量
|
||||||
|
category: 类别
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
direction="z", # Z方向堆叠
|
||||||
|
resources=[],
|
||||||
|
)
|
||||||
|
self.max_plates = max_plates
|
||||||
|
self.category = category
|
||||||
|
|
||||||
|
def can_add_plate(self) -> bool:
|
||||||
|
"""检查是否可以添加板"""
|
||||||
|
return len(self.children) < self.max_plates
|
||||||
|
|
||||||
|
def add_plate(self, plate: MaterialPlate) -> None:
|
||||||
|
"""添加料板"""
|
||||||
|
if not self.can_add_plate():
|
||||||
|
raise ValueError(f"槽位 {self.name} 已满,无法添加更多板")
|
||||||
|
self.assign_child_resource(plate)
|
||||||
|
|
||||||
|
def get_top_plate(self) -> MaterialPlate:
|
||||||
|
"""获取最上方的板"""
|
||||||
|
if len(self.children) == 0:
|
||||||
|
raise ValueError(f"槽位 {self.name} 为空")
|
||||||
|
return cast(MaterialPlate, self.get_top_item())
|
||||||
|
|
||||||
|
def take_top_plate(self) -> MaterialPlate:
|
||||||
|
"""取出最上方的板"""
|
||||||
|
top_plate = self.get_top_plate()
|
||||||
|
self.unassign_child_resource(top_plate)
|
||||||
|
return top_plate
|
||||||
|
|
||||||
|
def can_access_for_picking(self) -> bool:
|
||||||
|
"""检查是否可以进行取料操作(只有最上方的板能进行取料操作)"""
|
||||||
|
return len(self.children) > 0
|
||||||
|
|
||||||
|
def serialize(self) -> dict:
|
||||||
|
return {
|
||||||
|
**super().serialize(),
|
||||||
|
"max_plates": self.max_plates,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#是一种类型注解,不用self
|
||||||
|
class BatteryState(TypedDict):
|
||||||
|
"""电池状态字典"""
|
||||||
|
diameter: float
|
||||||
|
height: float
|
||||||
|
assembly_pressure: float
|
||||||
|
electrolyte_volume: float
|
||||||
|
electrolyte_name: str
|
||||||
|
|
||||||
|
class Battery(Resource):
|
||||||
|
"""电池类 - 可容纳极片"""
|
||||||
|
children: List[ElectrodeSheet] = []
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
size_x=1,
|
||||||
|
size_y=1,
|
||||||
|
size_z=1,
|
||||||
|
category: str = "battery",
|
||||||
|
):
|
||||||
|
"""初始化电池
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 电池名称
|
||||||
|
diameter: 直径 (mm)
|
||||||
|
height: 高度 (mm)
|
||||||
|
max_volume: 最大容量 (μL)
|
||||||
|
barcode: 二维码编号
|
||||||
|
category: 类别
|
||||||
|
model: 型号
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=1,
|
||||||
|
size_y=1,
|
||||||
|
size_z=1,
|
||||||
|
category=category,
|
||||||
|
)
|
||||||
|
self._unilabos_state: BatteryState = BatteryState(
|
||||||
|
diameter = 1.0,
|
||||||
|
height = 1.0,
|
||||||
|
assembly_pressure = 1.0,
|
||||||
|
electrolyte_volume = 1.0,
|
||||||
|
electrolyte_name = "DP001"
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_electrolyte_with_bottle(self, bottle: Bottle) -> bool:
|
||||||
|
to_add_name = bottle._unilabos_state["electrolyte_name"]
|
||||||
|
if bottle.aspirate_electrolyte(10):
|
||||||
|
if self.add_electrolyte(to_add_name, 10):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
bottle._unilabos_state["electrolyte_volume"] += 10
|
||||||
|
|
||||||
|
def set_electrolyte(self, name: str, volume: float) -> None:
|
||||||
|
"""设置电解液信息"""
|
||||||
|
self._unilabos_state["electrolyte_name"] = name
|
||||||
|
self._unilabos_state["electrolyte_volume"] = volume
|
||||||
|
#这个应该没用,不会有加了后再加的事情
|
||||||
|
def add_electrolyte(self, name: str, volume: float) -> bool:
|
||||||
|
"""添加电解液信息"""
|
||||||
|
if name != self._unilabos_state["electrolyte_name"]:
|
||||||
|
return False
|
||||||
|
self._unilabos_state["electrolyte_volume"] += volume
|
||||||
|
|
||||||
|
def load_state(self, state: Dict[str, Any]) -> None:
|
||||||
|
"""格式不变"""
|
||||||
|
super().load_state(state)
|
||||||
|
self._unilabos_state = state
|
||||||
|
|
||||||
|
def serialize_state(self) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""格式不变"""
|
||||||
|
data = super().serialize_state()
|
||||||
|
data.update(self._unilabos_state) # Container自身的信息,云端物料将保存这一data,本地也通过这里的data进行读写,当前类用来表示这个物料的长宽高大小的属性,而data(state用来表示物料的内容,细节等)
|
||||||
|
return data
|
||||||
|
|
||||||
|
# 电解液作为属性放进去
|
||||||
|
|
||||||
|
class BatteryPressSlotState(TypedDict):
|
||||||
|
"""电池状态字典"""
|
||||||
|
diameter: float =20.0
|
||||||
|
depth: float = 4.0
|
||||||
|
|
||||||
|
class BatteryPressSlot(Resource):
|
||||||
|
"""电池压制槽类 - 设备,可容纳一个电池"""
|
||||||
|
children: List[Battery] = []
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str = "BatteryPressSlot",
|
||||||
|
category: str = "battery_press_slot",
|
||||||
|
):
|
||||||
|
"""初始化电池压制槽
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 压制槽名称
|
||||||
|
diameter: 直径 (mm)
|
||||||
|
depth: 深度 (mm)
|
||||||
|
category: 类别
|
||||||
|
model: 型号
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=10,
|
||||||
|
size_y=12,
|
||||||
|
size_z=13,
|
||||||
|
category=category,
|
||||||
|
)
|
||||||
|
self._unilabos_state: BatteryPressSlotState = BatteryPressSlotState()
|
||||||
|
|
||||||
|
def has_battery(self) -> bool:
|
||||||
|
"""检查是否有电池"""
|
||||||
|
return len(self.children) > 0
|
||||||
|
|
||||||
|
def load_state(self, state: Dict[str, Any]) -> None:
|
||||||
|
"""格式不变"""
|
||||||
|
super().load_state(state)
|
||||||
|
self._unilabos_state = state
|
||||||
|
|
||||||
|
def serialize_state(self) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""格式不变"""
|
||||||
|
data = super().serialize_state()
|
||||||
|
data.update(self._unilabos_state) # Container自身的信息,云端物料将保存这一data,本地也通过这里的data进行读写,当前类用来表示这个物料的长宽高大小的属性,而data(state用来表示物料的内容,细节等)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def assign_child_resource(
|
||||||
|
self,
|
||||||
|
resource: Battery,
|
||||||
|
location: Optional[Coordinate],
|
||||||
|
reassign: bool = True,
|
||||||
|
):
|
||||||
|
"""放置极片"""
|
||||||
|
# TODO: 让高京看下槽位只有一个电池时是否这么写。
|
||||||
|
if self.has_battery():
|
||||||
|
raise ValueError(f"槽位已含有一个电池,无法再放置其他电池")
|
||||||
|
super().assign_child_resource(resource, location, reassign)
|
||||||
|
|
||||||
|
# 根据children的编号取物料对象。
|
||||||
|
def get_battery_info(self, index: int) -> Battery:
|
||||||
|
return self.children[0]
|
||||||
|
|
||||||
|
|
||||||
|
def TipBox64(
|
||||||
|
name: str,
|
||||||
|
size_x: float = 127.8,
|
||||||
|
size_y: float = 85.5,
|
||||||
|
size_z: float = 60.0,
|
||||||
|
category: str = "tip_rack",
|
||||||
|
model: Optional[str] = None,
|
||||||
|
):
|
||||||
|
"""64孔枪头盒类"""
|
||||||
|
from pylabrobot.resources.tip import Tip
|
||||||
|
|
||||||
|
# 创建12x8=96个枪头位
|
||||||
|
def make_tip():
|
||||||
|
return Tip(
|
||||||
|
has_filter=False,
|
||||||
|
total_tip_length=20.0,
|
||||||
|
maximal_volume=1000, # 1mL
|
||||||
|
fitting_depth=8.0,
|
||||||
|
)
|
||||||
|
|
||||||
|
tip_spots = create_ordered_items_2d(
|
||||||
|
klass=TipSpot,
|
||||||
|
num_items_x=12,
|
||||||
|
num_items_y=8,
|
||||||
|
dx=8.0,
|
||||||
|
dy=8.0,
|
||||||
|
dz=0.0,
|
||||||
|
item_dx=9.0,
|
||||||
|
item_dy=9.0,
|
||||||
|
size_x=10,
|
||||||
|
size_y=10,
|
||||||
|
size_z=0.0,
|
||||||
|
make_tip=make_tip,
|
||||||
|
)
|
||||||
|
idx_available = list(range(0, 32)) + list(range(64, 96))
|
||||||
|
tip_spots_available = {k: v for i, (k, v) in enumerate(tip_spots.items()) if i in idx_available}
|
||||||
|
tip_rack = TipRack(
|
||||||
|
name=name,
|
||||||
|
size_x=size_x,
|
||||||
|
size_y=size_y,
|
||||||
|
size_z=size_z,
|
||||||
|
# ordered_items=tip_spots_available,
|
||||||
|
ordered_items=tip_spots,
|
||||||
|
category=category,
|
||||||
|
model=model,
|
||||||
|
with_tips=False,
|
||||||
|
)
|
||||||
|
tip_rack.set_tip_state([True]*32 + [False]*32 + [True]*32) # 前32和后32个有枪头,中间32个无枪头
|
||||||
|
return tip_rack
|
||||||
|
|
||||||
|
|
||||||
|
class WasteTipBoxstate(TypedDict):
|
||||||
|
""""废枪头盒状态字典"""
|
||||||
|
max_tips: int = 100
|
||||||
|
tip_count: int = 0
|
||||||
|
|
||||||
|
#枪头不是一次性的(同一溶液则反复使用),根据寄存器判断
|
||||||
|
class WasteTipBox(Trash):
|
||||||
|
"""废枪头盒类 - 100个枪头容量"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
size_x: float = 127.8,
|
||||||
|
size_y: float = 85.5,
|
||||||
|
size_z: float = 60.0,
|
||||||
|
material_z_thickness=0,
|
||||||
|
max_volume=float("inf"),
|
||||||
|
category="trash",
|
||||||
|
model=None,
|
||||||
|
compute_volume_from_height=None,
|
||||||
|
compute_height_from_volume=None,
|
||||||
|
):
|
||||||
|
"""初始化废枪头盒
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: 废枪头盒名称
|
||||||
|
size_x: 长度 (mm)
|
||||||
|
size_y: 宽度 (mm)
|
||||||
|
size_z: 高度 (mm)
|
||||||
|
max_tips: 最大枪头容量
|
||||||
|
category: 类别
|
||||||
|
model: 型号
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=size_x,
|
||||||
|
size_y=size_y,
|
||||||
|
size_z=size_z,
|
||||||
|
category=category,
|
||||||
|
model=model,
|
||||||
|
)
|
||||||
|
self._unilabos_state: WasteTipBoxstate = WasteTipBoxstate()
|
||||||
|
|
||||||
|
def add_tip(self) -> None:
|
||||||
|
"""添加废枪头"""
|
||||||
|
if self._unilabos_state["tip_count"] >= self._unilabos_state["max_tips"]:
|
||||||
|
raise ValueError(f"废枪头盒 {self.name} 已满")
|
||||||
|
self._unilabos_state["tip_count"] += 1
|
||||||
|
|
||||||
|
def get_tip_count(self) -> int:
|
||||||
|
"""获取枪头数量"""
|
||||||
|
return self._unilabos_state["tip_count"]
|
||||||
|
|
||||||
|
def empty(self) -> None:
|
||||||
|
"""清空废枪头盒"""
|
||||||
|
self._unilabos_state["tip_count"] = 0
|
||||||
|
|
||||||
|
|
||||||
|
def load_state(self, state: Dict[str, Any]) -> None:
|
||||||
|
"""格式不变"""
|
||||||
|
super().load_state(state)
|
||||||
|
self._unilabos_state = state
|
||||||
|
|
||||||
|
def serialize_state(self) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""格式不变"""
|
||||||
|
data = super().serialize_state()
|
||||||
|
data.update(self._unilabos_state) # Container自身的信息,云端物料将保存这一data,本地也通过这里的data进行读写,当前类用来表示这个物料的长宽高大小的属性,而data(state用来表示物料的内容,细节等)
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
class YihuaCoinCellDeck(Deck):
|
||||||
|
"""依华纽扣电池组装工作站台面类"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str = "coin_cell_deck",
|
||||||
|
size_x: float = 1450.0,
|
||||||
|
size_y: float = 1450.0,
|
||||||
|
size_z: float = 100.0,
|
||||||
|
origin: Coordinate = Coordinate(-2200, 0, 0),
|
||||||
|
category: str = "coin_cell_deck",
|
||||||
|
setup: bool = False,
|
||||||
|
):
|
||||||
|
super().__init__(
|
||||||
|
name=name,
|
||||||
|
size_x=1450.0,
|
||||||
|
size_y=1450.0,
|
||||||
|
size_z=100.0,
|
||||||
|
origin=origin,
|
||||||
|
)
|
||||||
|
if setup:
|
||||||
|
self.setup()
|
||||||
|
|
||||||
|
def setup(self) -> None:
|
||||||
|
"""设置工作站的标准布局 - 包含子弹夹、料盘、瓶架等完整配置"""
|
||||||
|
# ====================================== 子弹夹 ============================================
|
||||||
|
|
||||||
|
# 正极片(4个洞位,2x2布局)
|
||||||
|
zhengji_zip = MagazineHolder_4_Cathode("正极&铝箔弹夹")
|
||||||
|
self.assign_child_resource(zhengji_zip, Coordinate(x=402.0, y=830.0, z=0))
|
||||||
|
|
||||||
|
# 正极壳、平垫片(6个洞位,2x2+2布局)
|
||||||
|
zhengjike_zip = MagazineHolder_6_Cathode("正极壳&平垫片弹夹")
|
||||||
|
self.assign_child_resource(zhengjike_zip, Coordinate(x=566.0, y=272.0, z=0))
|
||||||
|
|
||||||
|
# 负极壳、弹垫片(6个洞位,2x2+2布局)
|
||||||
|
fujike_zip = MagazineHolder_6_Anode("负极壳&弹垫片弹夹")
|
||||||
|
self.assign_child_resource(fujike_zip, Coordinate(x=474.0, y=276.0, z=0))
|
||||||
|
|
||||||
|
# 成品弹夹(6个洞位,3x2布局)
|
||||||
|
chengpindanjia_zip = MagazineHolder_6_Battery("成品弹夹")
|
||||||
|
self.assign_child_resource(chengpindanjia_zip, Coordinate(x=260.0, y=156.0, z=0))
|
||||||
|
|
||||||
|
# ====================================== 物料板 ============================================
|
||||||
|
# 创建物料板(料盘carrier)- 4x4布局
|
||||||
|
# 负极料盘
|
||||||
|
fujiliaopan = MaterialPlate.create_with_holes(name="负极料盘", size_x=120, size_y=100, size_z=10.0)
|
||||||
|
self.assign_child_resource(fujiliaopan, Coordinate(x=708.0, y=794.0, z=0))
|
||||||
|
|
||||||
|
# 隔膜料盘
|
||||||
|
gemoliaopan = MaterialPlate.create_with_holes(name="隔膜料盘", size_x=120, size_y=100, size_z=10.0)
|
||||||
|
self.assign_child_resource(gemoliaopan, Coordinate(x=718.0, y=918.0, z=0))
|
||||||
|
# for i in range(16):
|
||||||
|
# gemopian = ElectrodeSheet(name=f"{gemoliaopan.name}_jipian_{i}", size_x=12, size_y=12, size_z=0.1)
|
||||||
|
# gemoliaopan.children[i].assign_child_resource(gemopian, location=None)
|
||||||
|
|
||||||
|
# ====================================== 瓶架、移液枪 ============================================
|
||||||
|
# 在台面上放置 3x4 瓶架、6x2 瓶架 与 64孔移液枪头盒
|
||||||
|
# 奔耀上料5ml分液瓶小板 - 由奔曜跨站转运而来,不单独写,但是这里应该有一个堆栈用于摆放分液瓶小板
|
||||||
|
|
||||||
|
# bottle_rack_3x4 = BottleRack(
|
||||||
|
# name="bottle_rack_3x4",
|
||||||
|
# size_x=210.0,
|
||||||
|
# size_y=140.0,
|
||||||
|
# size_z=100.0,
|
||||||
|
# num_items_x=2,
|
||||||
|
# num_items_y=4,
|
||||||
|
# position_spacing=35.0,
|
||||||
|
# orientation="vertical",
|
||||||
|
# )
|
||||||
|
# self.assign_child_resource(bottle_rack_3x4, Coordinate(x=1542.0, y=717.0, z=0))
|
||||||
|
|
||||||
|
# 电解液缓存位 - 6x2布局
|
||||||
|
bottle_rack_6x2 = YIHUA_Electrolyte_12VialCarrier(name="bottle_rack_6x2")
|
||||||
|
self.assign_child_resource(bottle_rack_6x2, Coordinate(x=1050.0, y=358.0, z=0))
|
||||||
|
# 电解液回收位6x2
|
||||||
|
bottle_rack_6x2_2 = YIHUA_Electrolyte_12VialCarrier(name="bottle_rack_6x2_2")
|
||||||
|
self.assign_child_resource(bottle_rack_6x2_2, Coordinate(x=914.0, y=358.0, z=0))
|
||||||
|
|
||||||
|
tip_box = TipBox64(name="tip_box_64")
|
||||||
|
self.assign_child_resource(tip_box, Coordinate(x=782.0, y=514.0, z=0))
|
||||||
|
|
||||||
|
waste_tip_box = WasteTipBox(name="waste_tip_box")
|
||||||
|
self.assign_child_resource(waste_tip_box, Coordinate(x=778.0, y=622.0, z=0))
|
||||||
|
|
||||||
|
# 分液瓶板接驳区 - 接收来自 BioyondElectrolyte 侧的完整 Vial Carrier 板
|
||||||
|
# 命名 electrolyte_buffer 与 bioyond_cell_workstation.py 中 sites=["electrolyte_buffer"] 对应
|
||||||
|
electrolyte_buffer = ResourceStack(
|
||||||
|
name="electrolyte_buffer",
|
||||||
|
direction="z",
|
||||||
|
resources=[],
|
||||||
|
)
|
||||||
|
self.assign_child_resource(electrolyte_buffer, Coordinate(x=1050.0, y=700.0, z=0))
|
||||||
|
|
||||||
|
|
||||||
|
def yihua_coin_cell_deck(name: str = "coin_cell_deck") -> YihuaCoinCellDeck:
|
||||||
|
deck = YihuaCoinCellDeck(name=name)
|
||||||
|
deck.setup()
|
||||||
|
return deck
|
||||||
|
|
||||||
|
|
||||||
|
# 向后兼容别名,日后废弃
|
||||||
|
CoincellDeck = YihuaCoinCellDeck
|
||||||
|
|
||||||
|
def YH_Deck(name: str = "") -> YihuaCoinCellDeck:
|
||||||
|
return yihua_coin_cell_deck(name=name or "coin_cell_deck")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
deck = create_coin_cell_deck()
|
||||||
|
print(deck)
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,145 @@
|
|||||||
|
Name,DataType,InitValue,Comment,Attribute,DeviceType,Address,
|
||||||
|
COIL_SYS_START_CMD,BOOL,,,,coil,8010,
|
||||||
|
COIL_SYS_STOP_CMD,BOOL,,,,coil,8020,
|
||||||
|
COIL_SYS_RESET_CMD,BOOL,,,,coil,8030,
|
||||||
|
COIL_SYS_HAND_CMD,BOOL,,,,coil,8040,
|
||||||
|
COIL_SYS_AUTO_CMD,BOOL,,,,coil,8050,
|
||||||
|
COIL_SYS_INIT_CMD,BOOL,,,,coil,8060,
|
||||||
|
COIL_UNILAB_SEND_MSG_SUCC_CMD,BOOL,,,,coil,8700,
|
||||||
|
COIL_UNILAB_REC_MSG_SUCC_CMD,BOOL,,,,coil,8710,unilab_rec_msg_succ_cmd
|
||||||
|
COIL_SYS_START_STATUS,BOOL,,,,coil,8210,
|
||||||
|
COIL_SYS_STOP_STATUS,BOOL,,,,coil,8220,
|
||||||
|
COIL_SYS_RESET_STATUS,BOOL,,,,coil,8230,
|
||||||
|
COIL_SYS_HAND_STATUS,BOOL,,,,coil,8240,
|
||||||
|
COIL_SYS_AUTO_STATUS,BOOL,,,,coil,8250,
|
||||||
|
COIL_SYS_INIT_STATUS,BOOL,,,,coil,8260,
|
||||||
|
COIL_REQUEST_REC_MSG_STATUS,BOOL,,,,coil,8500,
|
||||||
|
COIL_REQUEST_SEND_MSG_STATUS,BOOL,,,,coil,8510,request_send_msg_status
|
||||||
|
REG_MSG_ELECTROLYTE_USE_NUM,INT16,,,,hold_register,11000,
|
||||||
|
REG_MSG_ELECTROLYTE_NUM,INT16,,,,hold_register,11002,unilab_send_msg_electrolyte_num
|
||||||
|
REG_MSG_ELECTROLYTE_VOLUME,INT16,,,,hold_register,11004,unilab_send_msg_electrolyte_vol
|
||||||
|
REG_MSG_ASSEMBLY_TYPE,INT16,,,,hold_register,11006,unilab_send_msg_assembly_type
|
||||||
|
REG_MSG_ASSEMBLY_PRESSURE,INT16,,,,hold_register,11008,unilab_send_msg_assembly_pressure
|
||||||
|
REG_DATA_ASSEMBLY_COIN_CELL_NUM,INT16,,,,hold_register,10000,data_assembly_coin_cell_num
|
||||||
|
REG_DATA_OPEN_CIRCUIT_VOLTAGE,FLOAT32,,,,hold_register,10002,data_open_circuit_voltage
|
||||||
|
REG_DATA_AXIS_X_POS,FLOAT32,,,,hold_register,10004,
|
||||||
|
REG_DATA_AXIS_Y_POS,FLOAT32,,,,hold_register,10006,
|
||||||
|
REG_DATA_AXIS_Z_POS,FLOAT32,,,,hold_register,10008,
|
||||||
|
REG_DATA_POLE_WEIGHT,FLOAT32,,,,hold_register,10010,data_pole_weight
|
||||||
|
REG_DATA_ASSEMBLY_PER_TIME,FLOAT32,,,,hold_register,10012,data_assembly_time
|
||||||
|
REG_DATA_ASSEMBLY_PRESSURE,INT16,,,,hold_register,10014,data_assembly_pressure
|
||||||
|
REG_DATA_ELECTROLYTE_VOLUME,INT16,,,,hold_register,10016,data_electrolyte_volume
|
||||||
|
REG_DATA_COIN_TYPE,INT16,,,,hold_register,10018,data_coin_type
|
||||||
|
REG_DATA_CURRENT_ASSEMBLING_COUNT,INT16,,,,hold_register,10072,data_current_assembling_count
|
||||||
|
REG_DATA_CURRENT_COMPLETED_COUNT,INT16,,,,hold_register,10074,data_current_completed_count
|
||||||
|
REG_DATA_ELECTROLYTE_CODE,STRING,,,,hold_register,10020,data_electrolyte_code()
|
||||||
|
REG_DATA_COIN_CELL_CODE,STRING,,,,hold_register,10030,data_coin_cell_code()
|
||||||
|
REG_DATA_STACK_VISON_CODE,STRING,,,,hold_register,12004,data_stack_vision_code()
|
||||||
|
REG_DATA_GLOVE_BOX_PRESSURE,FLOAT32,,,,hold_register,10050,data_glove_box_pressure
|
||||||
|
REG_DATA_GLOVE_BOX_WATER_CONTENT,FLOAT32,,,,hold_register,10052,data_glove_box_water_content
|
||||||
|
REG_DATA_GLOVE_BOX_O2_CONTENT,FLOAT32,,,,hold_register,10054,data_glove_box_o2_content
|
||||||
|
UNILAB_SEND_ELECTROLYTE_BOTTLE_NUM,BOOL,,,,coil,8720,
|
||||||
|
UNILAB_RECE_ELECTROLYTE_BOTTLE_NUM,BOOL,,,,coil,8520,
|
||||||
|
REG_MSG_ELECTROLYTE_NUM_USED,INT16,,,,hold_register,496,
|
||||||
|
REG_DATA_ELECTROLYTE_USE_NUM,INT16,,,,hold_register,10000,
|
||||||
|
UNILAB_SEND_FINISHED_CMD,BOOL,,,,coil,8730,
|
||||||
|
UNILAB_RECE_FINISHED_CMD,BOOL,,,,coil,8530,
|
||||||
|
REG_DATA_ASSEMBLY_TYPE,INT16,,,,hold_register,10018,ASSEMBLY_TYPE7or8
|
||||||
|
REG_UNILAB_INTERACT,BOOL,,,,coil,8450,
|
||||||
|
,,,,,coil,8320,
|
||||||
|
COIL_ALUMINUM_FOIL,BOOL,,,,coil,8340,
|
||||||
|
REG_MSG_NE_PLATE_MATRIX,INT16,,,,hold_register,440,
|
||||||
|
REG_MSG_SEPARATOR_PLATE_MATRIX,INT16,,,,hold_register,450,
|
||||||
|
REG_MSG_TIP_BOX_MATRIX,INT16,,,,hold_register,480,
|
||||||
|
REG_MSG_NE_PLATE_NUM,INT16,,,,hold_register,443,
|
||||||
|
REG_MSG_SEPARATOR_PLATE_NUM,INT16,,,,hold_register,453,
|
||||||
|
REG_MSG_PRESS_MODE,BOOL,,,,coil,8360,
|
||||||
|
,BOOL,,,,coil,8300,
|
||||||
|
,BOOL,,,,coil,8310,
|
||||||
|
COIL_GB_L_IGNORE_CMD,BOOL,,,,coil,8320,
|
||||||
|
COIL_GB_R_IGNORE_CMD,BOOL,,,,coil,8420,
|
||||||
|
,BOOL,,,,coil,8350,
|
||||||
|
COIL_ELECTROLYTE_DUAL_DROP_MODE,BOOL,,,,coil,8370,
|
||||||
|
,BOOL,,,,coil,8380,
|
||||||
|
,BOOL,,,,coil,8390,
|
||||||
|
,BOOL,,,,coil,8400,
|
||||||
|
,BOOL,,,,coil,8410,
|
||||||
|
REG_MSG_DUAL_DROP_FIRST_VOLUME,INT16,,,,hold_register,4001,
|
||||||
|
COIL_DUAL_DROP_SUCTION_TIMING,BOOL,,,,coil,8430,
|
||||||
|
COIL_DUAL_DROP_START_TIMING,BOOL,,,,coil,8470,
|
||||||
|
REG_MSG_BATTERY_CLEAN_IGNORE,BOOL,,,,coil,8460,
|
||||||
|
COIL_MATERIAL_SEARCH_DIALOG_APPEAR,BOOL,,,,coil,6470,
|
||||||
|
COIL_MATERIAL_SEARCH_CONFIRM_YES,BOOL,,,,coil,6480,
|
||||||
|
COIL_MATERIAL_SEARCH_CONFIRM_NO,BOOL,,,,coil,6490,
|
||||||
|
COIL_ALARM_100_SYSTEM_ERROR,BOOL,,,,coil,1000,??100-????
|
||||||
|
COIL_ALARM_101_EMERGENCY_STOP,BOOL,,,,coil,1010,??101-??
|
||||||
|
COIL_ALARM_111_GLOVEBOX_EMERGENCY_STOP,BOOL,,,,coil,1110,??111-?????
|
||||||
|
COIL_ALARM_112_GLOVEBOX_GRATING_BLOCKED,BOOL,,,,coil,1120,??112-????????
|
||||||
|
COIL_ALARM_160_PIPETTE_TIP_SHORTAGE,BOOL,,,,coil,1600,??160-??????
|
||||||
|
COIL_ALARM_161_POSITIVE_SHELL_SHORTAGE,BOOL,,,,coil,1610,??161-?????
|
||||||
|
COIL_ALARM_162_ALUMINUM_FOIL_SHORTAGE,BOOL,,,,coil,1620,??162-?????
|
||||||
|
COIL_ALARM_163_POSITIVE_PLATE_SHORTAGE,BOOL,,,,coil,1630,??163-?????
|
||||||
|
COIL_ALARM_164_SEPARATOR_SHORTAGE,BOOL,,,,coil,1640,??164-????
|
||||||
|
COIL_ALARM_165_NEGATIVE_PLATE_SHORTAGE,BOOL,,,,coil,1650,??165-?????
|
||||||
|
COIL_ALARM_166_FLAT_WASHER_SHORTAGE,BOOL,,,,coil,1660,??166-????
|
||||||
|
COIL_ALARM_167_SPRING_WASHER_SHORTAGE,BOOL,,,,coil,1670,??167-????
|
||||||
|
COIL_ALARM_168_NEGATIVE_SHELL_SHORTAGE,BOOL,,,,coil,1680,??168-?????
|
||||||
|
COIL_ALARM_169_FINISHED_BATTERY_FULL,BOOL,,,,coil,1690,??169-??????
|
||||||
|
COIL_ALARM_201_SERVO_AXIS_01_ERROR,BOOL,,,,coil,2010,??201-???01??
|
||||||
|
COIL_ALARM_202_SERVO_AXIS_02_ERROR,BOOL,,,,coil,2020,??202-???02??
|
||||||
|
COIL_ALARM_203_SERVO_AXIS_03_ERROR,BOOL,,,,coil,2030,??203-???03??
|
||||||
|
COIL_ALARM_204_SERVO_AXIS_04_ERROR,BOOL,,,,coil,2040,??204-???04??
|
||||||
|
COIL_ALARM_205_SERVO_AXIS_05_ERROR,BOOL,,,,coil,2050,??205-???05??
|
||||||
|
COIL_ALARM_206_SERVO_AXIS_06_ERROR,BOOL,,,,coil,2060,??206-???06??
|
||||||
|
COIL_ALARM_207_SERVO_AXIS_07_ERROR,BOOL,,,,coil,2070,??207-???07??
|
||||||
|
COIL_ALARM_208_SERVO_AXIS_08_ERROR,BOOL,,,,coil,2080,??208-???08??
|
||||||
|
COIL_ALARM_209_SERVO_AXIS_09_ERROR,BOOL,,,,coil,2090,??209-???09??
|
||||||
|
COIL_ALARM_210_SERVO_AXIS_10_ERROR,BOOL,,,,coil,2100,??210-???10??
|
||||||
|
COIL_ALARM_211_SERVO_AXIS_11_ERROR,BOOL,,,,coil,2110,??211-???11??
|
||||||
|
COIL_ALARM_212_SERVO_AXIS_12_ERROR,BOOL,,,,coil,2120,??212-???12??
|
||||||
|
COIL_ALARM_213_SERVO_AXIS_13_ERROR,BOOL,,,,coil,2130,??213-???13??
|
||||||
|
COIL_ALARM_214_SERVO_AXIS_14_ERROR,BOOL,,,,coil,2140,??214-???14??
|
||||||
|
COIL_ALARM_250_OTHER_COMPONENT_ERROR,BOOL,,,,coil,2500,??250-??????
|
||||||
|
COIL_ALARM_251_PIPETTE_COMM_ERROR,BOOL,,,,coil,2510,??251-???????
|
||||||
|
COIL_ALARM_252_PIPETTE_ALARM,BOOL,,,,coil,2520,??252-?????
|
||||||
|
COIL_ALARM_256_ELECTRIC_GRIPPER_ERROR,BOOL,,,,coil,2560,??256-????
|
||||||
|
COIL_ALARM_262_RB_UNKNOWN_POSITION_ERROR,BOOL,,,,coil,2620,??262-RB?????????
|
||||||
|
COIL_ALARM_263_RB_XYZ_PARAM_LIMIT_ERROR,BOOL,,,,coil,2630,??263-RB???X?Y?Z?????
|
||||||
|
COIL_ALARM_264_RB_VISION_PARAM_ERROR,BOOL,,,,coil,2640,??264-RB???????????
|
||||||
|
COIL_ALARM_265_RB_NOZZLE_1_PICK_FAIL,BOOL,,,,coil,2650,??265-RB???1#??????
|
||||||
|
COIL_ALARM_266_RB_NOZZLE_2_PICK_FAIL,BOOL,,,,coil,2660,??266-RB???2#??????
|
||||||
|
COIL_ALARM_267_RB_NOZZLE_3_PICK_FAIL,BOOL,,,,coil,2670,??267-RB???3#??????
|
||||||
|
COIL_ALARM_268_RB_NOZZLE_4_PICK_FAIL,BOOL,,,,coil,2680,??268-RB???4#??????
|
||||||
|
COIL_ALARM_269_RB_TRAY_PICK_FAIL,BOOL,,,,coil,2690,??269-RB?????????
|
||||||
|
COIL_ALARM_280_RB_COLLISION_ERROR,BOOL,,,,coil,2800,??280-RB????
|
||||||
|
COIL_ALARM_290_VISION_SYSTEM_COMM_ERROR,BOOL,,,,coil,2900,??290-????????
|
||||||
|
COIL_ALARM_291_VISION_ALIGNMENT_NG,BOOL,,,,coil,2910,??291-????NG??
|
||||||
|
COIL_ALARM_292_BARCODE_SCANNER_COMM_ERROR,BOOL,,,,coil,2920,??292-???????
|
||||||
|
COIL_ALARM_310_OCV_TRANSFER_NOZZLE_SUCTION_ERROR,BOOL,,,,coil,3100,??310-???????????
|
||||||
|
COIL_ALARM_311_OCV_TRANSFER_NOZZLE_BREAK_ERROR,BOOL,,,,coil,3110,??311-???????????
|
||||||
|
COIL_ALARM_312_WEIGHT_TRANSFER_NOZZLE_SUCTION_ERROR,BOOL,,,,coil,3120,??312-???????????
|
||||||
|
COIL_ALARM_313_WEIGHT_TRANSFER_NOZZLE_BREAK_ERROR,BOOL,,,,coil,3130,??313-???????????
|
||||||
|
COIL_ALARM_340_OCV_NOZZLE_TRANSFER_CYLINDER_ERROR,BOOL,,,,coil,3400,??340-????????????
|
||||||
|
COIL_ALARM_342_OCV_NOZZLE_LIFT_CYLINDER_ERROR,BOOL,,,,coil,3420,??342-????????????
|
||||||
|
COIL_ALARM_344_OCV_CRIMPING_CYLINDER_ERROR,BOOL,,,,coil,3440,??344-??????????
|
||||||
|
COIL_ALARM_350_WEIGHT_NOZZLE_TRANSFER_CYLINDER_ERROR,BOOL,,,,coil,3500,??350-??????????
|
||||||
|
COIL_ALARM_352_WEIGHT_NOZZLE_LIFT_CYLINDER_ERROR,BOOL,,,,coil,3520,??352-??????????
|
||||||
|
COIL_ALARM_354_CLEANING_CLOTH_TRANSFER_CYLINDER_ERROR,BOOL,,,,coil,3540,??354-???????????
|
||||||
|
COIL_ALARM_356_CLEANING_CLOTH_PRESS_CYLINDER_ERROR,BOOL,,,,coil,3560,??356-???????????
|
||||||
|
COIL_ALARM_360_ELECTROLYTE_BOTTLE_POSITION_CYLINDER_ERROR,BOOL,,,,coil,3600,??360-??????????
|
||||||
|
COIL_ALARM_362_PIPETTE_TIP_BOX_POSITION_CYLINDER_ERROR,BOOL,,,,coil,3620,??362-???????????
|
||||||
|
COIL_ALARM_364_REAGENT_BOTTLE_GRIPPER_LIFT_CYLINDER_ERROR,BOOL,,,,coil,3640,??364-???????????
|
||||||
|
COIL_ALARM_366_REAGENT_BOTTLE_GRIPPER_CYLINDER_ERROR,BOOL,,,,coil,3660,??366-?????????
|
||||||
|
COIL_ALARM_370_PRESS_MODULE_BLOW_CYLINDER_ERROR,BOOL,,,,coil,3700,??370-??????????
|
||||||
|
COIL_ALARM_151_ELECTROLYTE_BOTTLE_POSITION_ERROR,BOOL,,,,coil,1510,??151-??????????
|
||||||
|
COIL_ALARM_152_ELECTROLYTE_BOTTLE_CAP_ERROR,BOOL,,,,coil,1520,??152-?????????
|
||||||
|
REG_DATA_10MM_POSITIVE_PLATE_REMAINING_COUNT,FLOAT32,,,,hold_register,520,10mm??????????R?
|
||||||
|
REG_DATA_12MM_POSITIVE_PLATE_REMAINING_COUNT,FLOAT32,,,,hold_register,522,12mm??????????R?
|
||||||
|
REG_DATA_16MM_POSITIVE_PLATE_REMAINING_COUNT,FLOAT32,,,,hold_register,524,16mm??????????R?
|
||||||
|
REG_DATA_ALUMINUM_FOIL_REMAINING_COUNT,FLOAT32,,,,hold_register,526,?????????R?
|
||||||
|
REG_DATA_POSITIVE_SHELL_REMAINING_COUNT,FLOAT32,,,,hold_register,528,??????????R?
|
||||||
|
REG_DATA_FLAT_WASHER_REMAINING_COUNT,FLOAT32,,,,hold_register,530,?????????R?
|
||||||
|
REG_DATA_NEGATIVE_SHELL_REMAINING_COUNT,FLOAT32,,,,hold_register,532,??????????R?
|
||||||
|
REG_DATA_SPRING_WASHER_REMAINING_COUNT,FLOAT32,,,,hold_register,534,?????????R?
|
||||||
|
REG_DATA_FINISHED_BATTERY_REMAINING_CAPACITY,FLOAT32,,,,hold_register,536,????????????R?
|
||||||
|
REG_DATA_FINISHED_BATTERY_NG_REMAINING_CAPACITY,FLOAT32,,,,hold_register,538,????NG?????????R?
|
||||||
|
File diff suppressed because it is too large
Load Diff
88
unilabos/devices/workstation/implementation_plan.md
Normal file
88
unilabos/devices/workstation/implementation_plan.md
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
# 物料系统标准化重构方案
|
||||||
|
|
||||||
|
根据开发者的反馈,本方案旨在遵循“标准化而非绕过”的原则,对资源类(Deck、Carrier、Magazine)进行重构。核心目标是将物理结构的初始化与物料/极片的初始填充逻辑解耦,彻底解决反序列化过程中的初始化冲突。
|
||||||
|
|
||||||
|
## 拟议变更
|
||||||
|
|
||||||
|
### [参考] PRCXI9300 标准化模式
|
||||||
|
#### [参考文件] [prcxi.py](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/devices/liquid_handling/prcxi/prcxi.py)
|
||||||
|
* **PRCXI9300Deck**: 演示了如何在 `serialize` 中导出 `sites` 元数据,以及如何在 `assign_child_resource` 中实现稳健的槽位匹配(支持按名称、坐标或索引匹配)。
|
||||||
|
* **PRCXI9300Container**: 演示了标准的 `load_state` 和 `serialize_state` 模式,确保业务状态(如 `Material` UUID)能正确往返序列化。
|
||||||
|
|
||||||
|
### [组件] 台面 (Decks)
|
||||||
|
#### [修改] [decks.py](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/resources/bioyond/decks.py)
|
||||||
|
* 将 `BIOYOND_YB_Deck` 重命名为 **`BioyondElectrolyteDeck`**,对应工厂函数 `YB_Deck()` 重命名为 **`bioyond_electrolyte_deck()`**。
|
||||||
|
* `BIOYOND_PolymerReactionStation_Deck` 和 `BIOYOND_PolymerPreparationStation_Deck` **保持不变**。
|
||||||
|
* 以上三个 Deck 的 `__init__` 中均移除 `setup` 参数和 `setup()` 调用,删除临时的 `deserialize` 重写。
|
||||||
|
|
||||||
|
#### [修改 + 重命名] [YB_YH_materials.py](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/devices/workstation/coin_cell_assembly/YB_YH_materials.py) → `yihua_coin_cell_materials.py`
|
||||||
|
* 将 `CoincellDeck` 重命名为 **`YihuaCoinCellDeck`**,对应工厂函数 `YH_Deck()` 重命名为 **`yihua_coin_cell_deck()`**。
|
||||||
|
* 从 `YihuaCoinCellDeck.__init__` 中移除 `setup` 参数和 `setup()` 调用,删除临时的 `deserialize` 重写。
|
||||||
|
|
||||||
|
### [组件] 容器类与弹夹 (Itemized Carriers & Magazines)
|
||||||
|
#### [修改] [magazine.py](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/resources/battery/magazine.py)
|
||||||
|
* 重构 `magazine_factory`:将创建 `MagazineHolder` 几何结构(空槽位)的过程与填充 `ElectrodeSheet` 物料的过程分离。
|
||||||
|
* 确保 `MagazineHolder` 和 `Magazine` 的 `__init__` 过程中不主动创建任何内容物。
|
||||||
|
|
||||||
|
#### [修改] [warehouse.py](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/resources/warehouse.py)
|
||||||
|
* 确保 `WareHouse` 类和 `warehouse_factory` 遵循相同模式:先初始化几何结构,内容物另行处理。
|
||||||
|
|
||||||
|
#### [修改] [itemized_carrier.py](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/resources/itemized_carrier.py)
|
||||||
|
* 移除之前添加的 `idx is None` 兜底补丁。
|
||||||
|
* 修复命名规范,确保 `assign_child_resource` 在反序列化时能准确匹配资源。
|
||||||
|
|
||||||
|
### [组件] 状态兼容性 (State Compatibility)
|
||||||
|
#### [修改] [resource_tracker.py](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/resources/resource_tracker.py)
|
||||||
|
* 在 `to_plr_resources` 方法中调用 `load_all_state` 之前,预处理 `all_states` 字典。
|
||||||
|
* 对于 `Container` 类型的资源,如果其状态中缺少 `liquid_history` 或 `pending_liquids` 等 PLR 新版本要求的键,则填充默认值(如空列表/字典),防止反序列化中断。
|
||||||
|
|
||||||
|
### [组件] 料盘 (Material Plates)
|
||||||
|
#### [修改] [YB_YH_materials.py](file:///d:/UniLabdev/Uni-Lab-OS/unilabos/devices/workstation/coin_cell_assembly/YB_YH_materials.py)
|
||||||
|
* 重构 `MaterialPlate`:不在 `__init__` 中直接调用 `create_ordered_items_2d`。
|
||||||
|
* 重构 `YIHUA_Electrolyte_12VialCarrier`:将其修改为标准的基类定义或在工厂方法中彻底剥离内部 12 个 `YB_pei_ye_xiao_Bottle` 的强制初始化,以防反序列化冲突。
|
||||||
|
|
||||||
|
### [组件] 跨站转运与分液瓶板 (Vial Plate Transfer)
|
||||||
|
#### [修改] [bioyond_cell_workstation.py] & [YB_YH_materials.py]
|
||||||
|
* **分析**:目前的 `bioyond_cell_workstation.py` 在执行转移时,是用 `sites=["electrolyte_buffer"]` 试图把整块 `YB_Vial_5mL_Carrier` 板转移给目标。但由于实际工艺中,配液站将分液瓶板传往扣电工站后,是由扣电工站的机械臂**逐瓶抓取**并放入内部的 `bottle_rack_6x2`(电解液缓存位),用完后再放入 `bottle_rack_6x2_2`(废液位),因此配液站的这一次“跨工位资源树转移”在逻辑上存在偏差:目标槽位不应该是装单瓶的载体 `bottle_rack`。
|
||||||
|
* **修复方案**:
|
||||||
|
1. **目标端 (Yihua 侧)**:
|
||||||
|
* 在 `YB_YH_materials.py` 中为从配液站传过来的“分液瓶板”本身设置一个接驳专用的 `PlateSlot`(或者单纯直接移到 Deck 指定坐标)。这个位置负责真正在资源树层级上合法接收配液站传过来的完整 Board。
|
||||||
|
* 重构 `YIHUA_Electrolyte_12VialCarrier`:为了防止初始化反序列化冲突,取消内部在 `__init__` 中自动填充满 12 个 `YB_pei_ye_xiao_Bottle` 实例的逻辑。`bottle_rack_6x2` 和 `bottle_rack_6x2_2` 初始化时均应为空。
|
||||||
|
2. **转运端 (Bioyond 侧)**:
|
||||||
|
* 修改 `bioyond_cell_workstation.py` 的资源树数字转运代码,将其转移目标对应到 Yihua 侧新设立的“分液瓶板接驳区域”资源,或者干脆只更新资源树坐标位置(使其脱离 Bioyond Deck 加入 Yihua Deck),而不再强行挂载到一个无法容纳 Carrier 的 `bottle_rack_6x2` 内部。
|
||||||
|
|
||||||
|
### [组件] 依华扣电组装工站物料余量监控 (Material Monitoring)
|
||||||
|
#### [修改] 寄存器直读与前端集成
|
||||||
|
* **物理对象保留但虚化追踪**:原有的实体台面对象(如 `MaterialPlate`、`MagazineHolder` 各类型及其对应的洞位坐标)**仍然保留并使用**。保留它们是为了给机器臂提供基础的物理空间取放标定,以及作为前端页面的可视和可交互区块。
|
||||||
|
* **内部物料免追踪**:既然余量完全由寄存器接管,**我们将不再在这些弹夹或洞位内部显式生成、塞入和追踪每一个具体的极片或外壳对象 (如 `ElectrodeSheet` 等)**。这恰好与我们的重构主旨(不主动在 `__init__` 建子物料以避开反序列化冲突)完美结合,进一步极大地减轻了后台资源树对象的复杂度。
|
||||||
|
* **监控方式变更**:放弃现有的物料余量方式,直接读取依华扣电组装工站开放的寄存器地址以获取准确余量。
|
||||||
|
* **前端界面集成**:在前端界面点击负极壳、弹垫片等弹夹的 data view 时,直接读取并显示寄存器中的各自余量。
|
||||||
|
* **新增寄存器映射** (参考 `coin_cell_assembly_b.csv`):
|
||||||
|
* `10mm正极片剩余物料数量(R)`:`read hold_register 520` (REAL)
|
||||||
|
* `12mm正极片剩余物料数量(R)`:`read hold_register 522` (REAL)
|
||||||
|
* `16mm正极片剩余物料数量(R)`:`read hold_register 524` (REAL)
|
||||||
|
* `铝箔剩余物料数量(R)`:`read hold_register 526` (REAL)
|
||||||
|
* `正极壳剩余物料数量(R)`:`read hold_register 528` (REAL)
|
||||||
|
* `平垫剩余物料数量(R)`:`read hold_register 530` (REAL)
|
||||||
|
* `负极壳剩余物料数量(R)`:`read hold_register 532` (REAL)
|
||||||
|
* `弹垫剩余物料数量(R)`:`read hold_register 534` (REAL)
|
||||||
|
* `成品电池剩余可容纳数量(R)`:`read hold_register 536` (REAL)
|
||||||
|
* `成品电池NG槽剩余可容纳数量(R)`:`read hold_register 538` (REAL)
|
||||||
|
|
||||||
|
### [配置] JSON 配置文件 (Configuration Files)
|
||||||
|
#### [修改] 资源类型名称更新
|
||||||
|
* 更新以下配置文件,将其中的 `BIOYOND_YB_Deck` 替换为新的类名 **`BioyondElectrolyteDeck`**,以及将 `coin_cell_deck` 替换为 **`YihuaCoinCellDeck`**:
|
||||||
|
* `yibin_electrolyte_config.json`
|
||||||
|
* `yibin_coin_cell_only_config.json`
|
||||||
|
* `yibin_electrolyte_only_config.json`
|
||||||
|
|
||||||
|
## 验证计划
|
||||||
|
|
||||||
|
### 自动化测试
|
||||||
|
* 对重构后的类运行 `pylabrobot` 序列化/反序列化测试,确保状态能够完美恢复。
|
||||||
|
* 检查各工作站节点启动时是否仍存在 `ValueError: Resource '...' already assigned to deck` 报错。
|
||||||
|
* 检查 `resource_tracker` 中是否仍存在重复 UUID 报错。
|
||||||
|
|
||||||
|
### 手动验证
|
||||||
|
* 重启各工作站节点,验证资源树是否能根据数据库数据正确还还原。
|
||||||
|
* 验证“自动”与“手动”传输窗资源在台面上的分配是否正确。
|
||||||
388
unilabos/devices/workstation/implementation_plan_v2.md
Normal file
388
unilabos/devices/workstation/implementation_plan_v2.md
Normal file
@@ -0,0 +1,388 @@
|
|||||||
|
# 物料系统标准化重构方案 v2(增强版)
|
||||||
|
|
||||||
|
> **基于原始方案 (`implementation_plan.md`) 的补充与细化**。
|
||||||
|
> 本文档在原方案基础上:①增加当前代码现状核查结果;②明确各任务的执行顺序与文件级改动;③新增注意事项与回归测试命令。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 0. 核心原则(保持不变)
|
||||||
|
|
||||||
|
"**物理几何结构初始化(Deck / Carrier / Magazine 的 `__init__`)与物料内容物填充(`setup()` / `klasses` 参数)必须彻底解耦**",以消除 PLR 反序列化时的 `Resource already assigned to deck` 错误。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 当前代码现状核查(2026-03-12)
|
||||||
|
|
||||||
|
| 文件 | 计划要求 | 当前状态 | 是否完成 |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `resources/bioyond/decks.py` | 重命名类;移除 `setup` 参数和 `deserialize` 补丁 | 仍是 `BIOYOND_YB_Deck`;`setup` 参数和 `deserialize` 均存在 | ❌ |
|
||||||
|
| `coin_cell_assembly/YB_YH_materials.py` | 重命名类;文件迁移;移除补丁 | 仍是 `CoincellDeck`;`setup` 参数和 `deserialize` 均存在 | ❌ |
|
||||||
|
| `resources/battery/magazine.py` | `magazine_factory` 不主动填充物料 | `MagazineHolder_6_Cathode` / `_6_Anode` / `_4_Cathode` 仍传 `klasses`,初始化时填满极片 | ❌ |
|
||||||
|
| `resources/battery/bottle_carriers.py` | `YIHUA_Electrolyte_12VialCarrier` 初始化时不填充瓶子 | 第 54-55 行仍循环填充 12 个 `YB_pei_ye_xiao_Bottle` | ❌ |
|
||||||
|
| `resources/itemized_carrier.py` | 移除 `idx is None` 兜底补丁 | 第 182-190 行仍保留该兜底逻辑 | ❌(待前置任务完成后移除) |
|
||||||
|
| `resources/resource_tracker.py` | `load_all_state` 前预填 `Container` 缺失键 | 第 616 行直接调用,无预处理 | ❌ |
|
||||||
|
| `bioyond_cell_workstation.py` | 修正跨站转运目标为合法接驳槽 | 第 1563 行仍 `sites=["electrolyte_buffer"]`,目标 UUID 为硬编码虚拟资源 | ❌ |
|
||||||
|
| `yibin_*.json` 配置文件 | 更新类名 | 仍使用 `BIOYOND_YB_Deck` / `CoincellDeck` | ❌ |
|
||||||
|
| `registry/resources/bioyond/deck.yaml` | 更新类名(原计划未提及) | 仍使用 `BIOYOND_YB_Deck` / `CoincellDeck` | ❌(**新增**) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 执行顺序(含依赖关系)
|
||||||
|
|
||||||
|
```
|
||||||
|
阶段 A(底层资源类)
|
||||||
|
A1. magazine.py — 移除 klasses 填充
|
||||||
|
A2. bottle_carriers.py — 移除瓶子填充
|
||||||
|
|
||||||
|
阶段 B(Deck 层)
|
||||||
|
B1. decks.py — 移除 setup 参数和 deserialize 补丁;重命名
|
||||||
|
B2. YB_YH_materials.py → 重命名;移除 CoincellDeck 的 setup 参数和 deserialize 补丁
|
||||||
|
|
||||||
|
阶段 C(状态兼容)
|
||||||
|
C1. resource_tracker.py — 预填 Container 缺失键
|
||||||
|
C2. itemized_carrier.py — 移除 idx is None 兜底补丁(B 阶段完成后)
|
||||||
|
|
||||||
|
阶段 D(跨站转运修复)
|
||||||
|
D1. YB_YH_materials.py 新增 vial_plate_dock(接驳专用槽)
|
||||||
|
D2. bioyond_cell_workstation.py 修正 transfer 目标
|
||||||
|
|
||||||
|
阶段 E(配置与注册表)
|
||||||
|
E1. yibin_*.json 更新类名
|
||||||
|
E2. registry/resources/bioyond/deck.yaml 更新类名
|
||||||
|
E3. coin_cell_assembly.py 更新导入路径(若文件重命名)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 分阶段详细说明
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 阶段 A — 底层资源类
|
||||||
|
|
||||||
|
#### A1. `unilabos/resources/battery/magazine.py`
|
||||||
|
|
||||||
|
**问题**:`MagazineHolder_6_Cathode`、`MagazineHolder_6_Anode`、`MagazineHolder_4_Cathode` 在调用 `magazine_factory` 时传入 `klasses`,导致每次 `__init__` 就填满极片,反序列化时重复添加。
|
||||||
|
|
||||||
|
**修改**:
|
||||||
|
|
||||||
|
- 将三个函数中的 `klasses=[...]` 改为 `klasses=None`(与 `MagazineHolder_6_Battery` 保持一致)。
|
||||||
|
- **理由**:物料余量已由寄存器管理(见阶段 F),不需要在资源树中追踪每一个极片。
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 修改前(MagazineHolder_6_Cathode 举例)
|
||||||
|
klasses=[FlatWasher, PositiveCan, PositiveCan, FlatWasher, PositiveCan, PositiveCan],
|
||||||
|
|
||||||
|
# 修改后
|
||||||
|
klasses=None,
|
||||||
|
```
|
||||||
|
|
||||||
|
> **注意**:`magazine_factory` 中 `klasses` 参数及循环体代码保留(仍可按需在非序列化场景使用),只是各具体工厂函数不再传入。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### A2. `unilabos/resources/battery/bottle_carriers.py`
|
||||||
|
|
||||||
|
**问题**:`YIHUA_Electrolyte_12VialCarrier` 第 54-55 行在工厂函数末尾循环填充 12 个瓶子。
|
||||||
|
|
||||||
|
**修改**:删除以下两行:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 删除
|
||||||
|
for i in range(12):
|
||||||
|
carrier[i] = YB_pei_ye_xiao_Bottle(f"{name}_vial_{i+1}")
|
||||||
|
```
|
||||||
|
|
||||||
|
**理由**:`bottle_rack_6x2` 和 `bottle_rack_6x2_2` 均应初始化为空,瓶子由 Bioyond 侧实际转运后再填入。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 阶段 B — Deck 层重构
|
||||||
|
|
||||||
|
#### B1. `unilabos/resources/bioyond/decks.py`
|
||||||
|
|
||||||
|
**改动列表**:
|
||||||
|
|
||||||
|
1. **重命名** `BIOYOND_YB_Deck` → `BioyondElectrolyteDeck`
|
||||||
|
2. **重命名** `YB_Deck()` 工厂函数 → `bioyond_electrolyte_deck()`
|
||||||
|
3. **移除** `__init__` 中的 `setup: bool = False` 参数及 `if setup: self.setup()` 调用
|
||||||
|
4. **删除** `deserialize` 方法重写(该临时补丁在 `setup` 参数移除后自然失效,继续保留反而掩盖问题)
|
||||||
|
5. `BIOYOND_PolymerReactionStation_Deck` 和 `BIOYOND_PolymerPreparationStation_Deck` 同步执行第 3、4 步
|
||||||
|
|
||||||
|
**重构后初始化模式**:
|
||||||
|
|
||||||
|
```python
|
||||||
|
class BioyondElectrolyteDeck(Deck):
|
||||||
|
def __init__(self, name: str = "YB_Deck", ...):
|
||||||
|
super().__init__(name=name, ...)
|
||||||
|
# ❌ 不调用 self.setup()
|
||||||
|
# PLR 反序列化时只会调用 __init__,然后从 children JSON 重建子资源
|
||||||
|
|
||||||
|
def setup(self) -> None:
|
||||||
|
# 完整的子资源初始化逻辑保留在这里,只由工厂函数调用
|
||||||
|
...
|
||||||
|
|
||||||
|
def bioyond_electrolyte_deck(name: str) -> BioyondElectrolyteDeck:
|
||||||
|
deck = BioyondElectrolyteDeck(name=name)
|
||||||
|
deck.setup() # ✅ 工厂函数负责填充
|
||||||
|
return deck
|
||||||
|
```
|
||||||
|
|
||||||
|
**同步修改**:
|
||||||
|
- `bioyond_cell_workstation.py` 第 20 行:
|
||||||
|
```python
|
||||||
|
# 修改前
|
||||||
|
from unilabos.resources.bioyond.decks import BIOYOND_YB_Deck
|
||||||
|
# 修改后
|
||||||
|
from unilabos.resources.bioyond.decks import BioyondElectrolyteDeck
|
||||||
|
```
|
||||||
|
- 同文件第 2440 行:`BIOYOND_YB_Deck(setup=True)` → `bioyond_electrolyte_deck(name="YB_Deck")`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### B2. `unilabos/devices/workstation/coin_cell_assembly/YB_YH_materials.py`
|
||||||
|
|
||||||
|
**改动列表**:
|
||||||
|
|
||||||
|
1. **重命名** `CoincellDeck` → `YihuaCoinCellDeck`
|
||||||
|
2. **重命名** `YH_Deck()` → `yihua_coin_cell_deck()`(可保留 `YH_Deck` 作为兼容别名,日后废弃)
|
||||||
|
3. **移除** `CoincellDeck.__init__` 中 `setup: bool = False` 参数及调用
|
||||||
|
4. **删除** `CoincellDeck.deserialize` 重写方法
|
||||||
|
5. `MaterialPlate.__init__` 中移除 `fill` 参数,始终不主动调用 `create_ordered_items_2d`(当前 `fill=False` 路径已正确,只需删除 `fill=True` 分支)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 修改前(MaterialPlate.__init__ 片段)
|
||||||
|
if fill:
|
||||||
|
super().__init__(..., ordered_items=holes, ...)
|
||||||
|
else:
|
||||||
|
super().__init__(..., ordered_items=ordered_items, ...)
|
||||||
|
|
||||||
|
# 修改后(始终走 "不填充" 路径)
|
||||||
|
super().__init__(..., ordered_items=ordered_items, ...)
|
||||||
|
# holes 的创建代码整体移入独立工厂方法
|
||||||
|
```
|
||||||
|
|
||||||
|
**同步修改**:
|
||||||
|
- `coin_cell_assembly.py` 第 20 行导入:
|
||||||
|
```python
|
||||||
|
# 修改前
|
||||||
|
from unilabos.devices.workstation.coin_cell_assembly.YB_YH_materials import CoincellDeck
|
||||||
|
# 修改后
|
||||||
|
from unilabos.devices.workstation.coin_cell_assembly.YB_YH_materials import YihuaCoinCellDeck
|
||||||
|
```
|
||||||
|
- 同文件第 2245 行:`CoincellDeck(setup=True, name="coin_cell_deck")` → `yihua_coin_cell_deck(name="coin_cell_deck")`
|
||||||
|
- 文件重命名(可选):`YB_YH_materials.py` → `yihua_coin_cell_materials.py`(若重命名,所有 import 路径需全局替换)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 阶段 C — 状态兼容
|
||||||
|
|
||||||
|
#### C1. `unilabos/resources/resource_tracker.py`
|
||||||
|
|
||||||
|
**问题**:第 616 行直接调用 `plr_resource.load_all_state(all_states)`,若 `Container` 类资源的 `data` 字段缺少 `liquid_history` 或 `pending_liquids`,PLR 新版本会抛出 `KeyError`。
|
||||||
|
|
||||||
|
**修改**:在第 616 行前插入预处理:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 在 load_all_state 调用前预填缺失键
|
||||||
|
from pylabrobot.resources.container import Container as PLRContainer
|
||||||
|
for res_name, state in all_states.items():
|
||||||
|
if state and isinstance(state, dict):
|
||||||
|
# Container 类型要求这两个键存在
|
||||||
|
state.setdefault("liquid_history", [])
|
||||||
|
state.setdefault("pending_liquids", {})
|
||||||
|
|
||||||
|
plr_resource.load_all_state(all_states)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### C2. `unilabos/resources/itemized_carrier.py`
|
||||||
|
|
||||||
|
**前提**:B1、B2 阶段完成,Deck 类名与资源命名规范已对齐后再执行此步。
|
||||||
|
|
||||||
|
**修改**:删除第 182-190 行的兜底补丁:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 删除以下整个 if 块
|
||||||
|
if idx is None:
|
||||||
|
fallback_location = location if location is not None else Coordinate.zero()
|
||||||
|
super().assign_child_resource(resource, location=fallback_location, reassign=reassign)
|
||||||
|
return
|
||||||
|
```
|
||||||
|
|
||||||
|
**替代**:改为抛出带诊断信息的异常,便于后续问题排查:
|
||||||
|
|
||||||
|
```python
|
||||||
|
if idx is None:
|
||||||
|
raise ValueError(
|
||||||
|
f"[ItemizedCarrier] 无法为资源 '{resource.name}' 找到匹配的槽位。"
|
||||||
|
f"已知槽位:{list(self.child_locations.keys())},"
|
||||||
|
f"传入坐标:{location}"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 阶段 D — 跨站转运修复
|
||||||
|
|
||||||
|
#### D1. `YB_YH_materials.py` — 新增分液瓶板接驳槽
|
||||||
|
|
||||||
|
在 `YihuaCoinCellDeck.setup()` 中,新增一个专用于接收 Bioyond 侧传来的完整分液瓶板的 `ResourceStack`(或 `PlateSlot`):
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 在 setup() 末尾追加
|
||||||
|
from pylabrobot.resources.resource_stack import ResourceStack
|
||||||
|
|
||||||
|
vial_plate_dock = ResourceStack(
|
||||||
|
name="electrolyte_buffer", # 保持与 bioyond_cell_workstation.py 的 sites 键一致
|
||||||
|
direction="z",
|
||||||
|
resources=[],
|
||||||
|
)
|
||||||
|
self.assign_child_resource(vial_plate_dock, Coordinate(x=1050.0, y=700.0, z=0))
|
||||||
|
```
|
||||||
|
|
||||||
|
> **说明**:槽位命名 `electrolyte_buffer` 与 `bioyond_cell_workstation.py` 现有的 `sites=["electrolyte_buffer"]` 对应,减少改动量。如改名,D2 需同步。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### D2. `bioyond_cell_workstation.py` — 修正 transfer 目标
|
||||||
|
|
||||||
|
**问题**:第 1545-1552 行创建了一个 `size=1,1,1` 的虚拟 `ResourcePLR` 并硬编码 UUID,这个对象在 YihuaCoinCellDeck 的资源树中不存在,导致转移后资源树状态混乱。
|
||||||
|
|
||||||
|
**修改**:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# 修改前:创建虚拟目标资源
|
||||||
|
target_resource_obj = ResourcePLR(name=target_location, size_x=1.0, ...)
|
||||||
|
target_resource_obj.unilabos_uuid = "550e8400-e29b-41d4-a716-446655440001" # 硬编码
|
||||||
|
|
||||||
|
# 修改后:通过 ROS2/设备注册表查询真实资源
|
||||||
|
# (需要从 target_device 的资源树中取出 electrolyte_buffer 的真实对象)
|
||||||
|
target_resource_obj = self._get_resource_from_device(
|
||||||
|
device_id=target_device,
|
||||||
|
resource_name=target_location
|
||||||
|
)
|
||||||
|
if target_resource_obj is None:
|
||||||
|
raise RuntimeError(
|
||||||
|
f"目标设备 {target_device} 中未找到资源 '{target_location}',"
|
||||||
|
f"请确认 YihuaCoinCellDeck.setup() 中已添加 electrolyte_buffer 槽位"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
> **说明**:`_get_resource_from_device` 需根据现有 ROS2 资源同步机制实现,或复用已有的 `get_plr_resource_by_name` 类似方法。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 阶段 E — 配置与注册表
|
||||||
|
|
||||||
|
#### E1. `yibin_electrolyte_config.json` / `yibin_coin_cell_only_config.json` / `yibin_electrolyte_only_config.json`
|
||||||
|
|
||||||
|
全局替换以下字符串:
|
||||||
|
|
||||||
|
| 旧值 | 新值 |
|
||||||
|
|---|---|
|
||||||
|
| `BIOYOND_YB_Deck` | `BioyondElectrolyteDeck` |
|
||||||
|
| `unilabos.resources.bioyond.decks:BIOYOND_YB_Deck` | `unilabos.resources.bioyond.decks:BioyondElectrolyteDeck` |
|
||||||
|
| `CoincellDeck` | `YihuaCoinCellDeck` |
|
||||||
|
| `unilabos.devices.workstation.coin_cell_assembly.YB_YH_materials:CoincellDeck` | 若文件已重命名:`unilabos.devices.workstation.coin_cell_assembly.yihua_coin_cell_materials:YihuaCoinCellDeck` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### E2. `unilabos/registry/resources/bioyond/deck.yaml`(**原计划未覆盖,新增**)
|
||||||
|
|
||||||
|
当前第 25 行和第 37 行仍使用旧类名,需同步更新:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# 修改前
|
||||||
|
BIOYOND_YB_Deck:
|
||||||
|
...
|
||||||
|
CoincellDeck:
|
||||||
|
...
|
||||||
|
|
||||||
|
# 修改后
|
||||||
|
BioyondElectrolyteDeck:
|
||||||
|
...
|
||||||
|
YihuaCoinCellDeck:
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 阶段 F — 物料余量监控集成(原计划第5节细化)
|
||||||
|
|
||||||
|
**目标**:弃用资源树内极片对象计数,改为直读依华扣电工站寄存器。
|
||||||
|
|
||||||
|
#### F1. `coin_cell_assembly/coin_cell_assembly.py` — 新增寄存器读取方法
|
||||||
|
|
||||||
|
参考 `coin_cell_assembly_b.csv` 中的地址,封装读取工具方法:
|
||||||
|
|
||||||
|
```python
|
||||||
|
MATERIAL_REGISTER_MAP = {
|
||||||
|
"10mm正极片": (520, "REAL"),
|
||||||
|
"12mm正极片": (522, "REAL"),
|
||||||
|
"16mm正极片": (524, "REAL"),
|
||||||
|
"铝箔": (526, "REAL"),
|
||||||
|
"正极壳": (528, "REAL"),
|
||||||
|
"平垫": (530, "REAL"),
|
||||||
|
"负极壳": (532, "REAL"),
|
||||||
|
"弹垫": (534, "REAL"),
|
||||||
|
"成品容量": (536, "REAL"),
|
||||||
|
"成品NG容量": (538, "REAL"),
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_material_remaining(self, material_name: str) -> float:
|
||||||
|
"""通过寄存器直读指定物料的剩余数量"""
|
||||||
|
if material_name not in MATERIAL_REGISTER_MAP:
|
||||||
|
raise KeyError(f"未知物料名称: {material_name}")
|
||||||
|
address, dtype = MATERIAL_REGISTER_MAP[material_name]
|
||||||
|
return self.read_hold_register(address, dtype) # 复用现有 Modbus 读取方法
|
||||||
|
```
|
||||||
|
|
||||||
|
#### F2. 前端 data view 集成
|
||||||
|
|
||||||
|
- 前端点击 `MagazineHolder` 类资源的 data view 时,调用后端 `get_material_remaining` 接口(而非读取 `children` 长度)。
|
||||||
|
- 具体接口路径和前端调用代码需与前端开发同步,本文档不作具体实现约定。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 验证计划(细化)
|
||||||
|
|
||||||
|
### 4.1 单元测试(自动化)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 序列化/反序列化往返测试
|
||||||
|
python -m pytest unilabos/test/ -k "serial" -v
|
||||||
|
|
||||||
|
# 特别检查以下错误消失:
|
||||||
|
# - ValueError: Resource '...' already assigned to deck
|
||||||
|
# - KeyError: 'liquid_history'
|
||||||
|
# - 重复 UUID 报错
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 集成测试(手动)
|
||||||
|
|
||||||
|
按以下顺序逐步验证,确保每步正常后再进行下一步:
|
||||||
|
|
||||||
|
1. **单独启动 `BatteryStation` 节点**,检查 `CoincellDeck`(现 `YihuaCoinCellDeck`)能否从数据库状态正确还原,无 `already assigned` 报错。
|
||||||
|
2. **单独启动 `BioyondElectrolyte` 节点**,检查 `BioyondElectrolyteDeck` 反序列化正常。
|
||||||
|
3. **同时启动两个节点**,模拟执行一次分液→扣电的完整跨站转运,确认:
|
||||||
|
- `electrolyte_buffer` 槽位正确接收分液瓶板。
|
||||||
|
- `bottle_rack_6x2` 初始为空,不出现虚拟瓶子。
|
||||||
|
4. **重启两个节点**(模拟断电恢复),确认资源树从数据库还原后,`electrolyte_buffer` 中仍持有正确的分液瓶板对象。
|
||||||
|
5. **寄存器余量读取**:手动触发 `get_material_remaining("负极壳")`,确认返回值与设备显示一致。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 与原计划的差异对照
|
||||||
|
|
||||||
|
| 维度 | 原计划 | 本文档新增/修订 |
|
||||||
|
|---|---|---|
|
||||||
|
| 执行顺序 | 未排序 | 明确 A→B→C→D→E→F 的依赖顺序 |
|
||||||
|
| `itemized_carrier.py` | 移除兜底补丁 | 补充:替换为带诊断信息的异常,便于排查 |
|
||||||
|
| `bottle_carriers.py` | 提及 `YIHUA_Electrolyte_12VialCarrier` 需修改 | 明确:删除第 54-55 行的瓶子填充循环 |
|
||||||
|
| `MaterialPlate` | 提及移除 `fill` 参数 | 说明保留 `fill=False` 路径;整体删除 `fill=True` 分支 |
|
||||||
|
| `deck.yaml` | 未提及 | **新增**:该注册文件也需要同步更新类名 |
|
||||||
|
| `resource_tracker.py` | 简略描述 | 提供具体的 `setdefault` 预处理代码示例 |
|
||||||
|
| 跨站转运 | 描述了问题和方向 | 细化:新增 `electrolyte_buffer` 槽位的具体名称和坐标;修正 `transfer` 目标查找方式 |
|
||||||
|
| 验证计划 | 简述目标 | 提供具体测试命令和逐步手动验证流程 |
|
||||||
@@ -459,12 +459,12 @@ class WorkstationHTTPHandler(BaseHTTPRequestHandler):
|
|||||||
# 验证必需字段
|
# 验证必需字段
|
||||||
if 'brand' in request_data:
|
if 'brand' in request_data:
|
||||||
if request_data['brand'] == "bioyond": # 奔曜
|
if request_data['brand'] == "bioyond": # 奔曜
|
||||||
error_msg = request_data["text"]
|
material_data = request_data["text"]
|
||||||
logger.info(f"收到奔曜错误处理报送: {error_msg}")
|
logger.info(f"收到奔曜物料变更报送: {material_data}")
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
success=True,
|
success=True,
|
||||||
message=f"错误处理报送已收到: {error_msg}",
|
message=f"物料变更报送已收到: {material_data}",
|
||||||
acknowledgment_id=f"ERROR_{int(time.time() * 1000)}_{error_msg.get('action_id', 'unknown')}",
|
acknowledgment_id=f"MATERIAL_{int(time.time() * 1000)}_{material_data.get('id', 'unknown')}",
|
||||||
data=None
|
data=None
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
# PRCXI 耗材管理 Web 应用
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
"""启动入口: python -m unilabos.labware_manager"""
|
|
||||||
from unilabos.labware_manager.app import main
|
|
||||||
|
|
||||||
main()
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
"""FastAPI 应用 + CRUD API + 启动入口。
|
|
||||||
|
|
||||||
用法: python -m unilabos.labware_manager.app
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
from fastapi import FastAPI, HTTPException, Query, Request
|
|
||||||
from fastapi.responses import HTMLResponse, JSONResponse
|
|
||||||
from fastapi.staticfiles import StaticFiles
|
|
||||||
from fastapi.templating import Jinja2Templates
|
|
||||||
|
|
||||||
from unilabos.labware_manager.models import LabwareDB, LabwareItem
|
|
||||||
|
|
||||||
_HERE = Path(__file__).resolve().parent
|
|
||||||
_DB_PATH = _HERE / "labware_db.json"
|
|
||||||
|
|
||||||
app = FastAPI(title="PRCXI 耗材管理", version="1.0")
|
|
||||||
|
|
||||||
# 静态文件 + 模板
|
|
||||||
app.mount("/static", StaticFiles(directory=str(_HERE / "static")), name="static")
|
|
||||||
templates = Jinja2Templates(directory=str(_HERE / "templates"))
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- DB 读写 ----------
|
|
||||||
|
|
||||||
def _load_db() -> LabwareDB:
|
|
||||||
if not _DB_PATH.exists():
|
|
||||||
return LabwareDB()
|
|
||||||
with open(_DB_PATH, "r", encoding="utf-8") as f:
|
|
||||||
return LabwareDB(**json.load(f))
|
|
||||||
|
|
||||||
|
|
||||||
def _save_db(db: LabwareDB) -> None:
|
|
||||||
with open(_DB_PATH, "w", encoding="utf-8") as f:
|
|
||||||
json.dump(db.model_dump(), f, ensure_ascii=False, indent=2)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 页面路由 ----------
|
|
||||||
|
|
||||||
@app.get("/", response_class=HTMLResponse)
|
|
||||||
async def index_page(request: Request):
|
|
||||||
db = _load_db()
|
|
||||||
# 按 type 分组
|
|
||||||
groups = {}
|
|
||||||
for item in db.items:
|
|
||||||
groups.setdefault(item.type, []).append(item)
|
|
||||||
return templates.TemplateResponse("index.html", {
|
|
||||||
"request": request,
|
|
||||||
"groups": groups,
|
|
||||||
"total": len(db.items),
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/labware/new", response_class=HTMLResponse)
|
|
||||||
async def new_page(request: Request, type: str = "plate"):
|
|
||||||
return templates.TemplateResponse("edit.html", {
|
|
||||||
"request": request,
|
|
||||||
"item": None,
|
|
||||||
"labware_type": type,
|
|
||||||
"is_new": True,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/labware/{item_id}", response_class=HTMLResponse)
|
|
||||||
async def detail_page(request: Request, item_id: str):
|
|
||||||
db = _load_db()
|
|
||||||
item = _find_item(db, item_id)
|
|
||||||
if not item:
|
|
||||||
raise HTTPException(404, "耗材不存在")
|
|
||||||
return templates.TemplateResponse("detail.html", {
|
|
||||||
"request": request,
|
|
||||||
"item": item,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/labware/{item_id}/edit", response_class=HTMLResponse)
|
|
||||||
async def edit_page(request: Request, item_id: str):
|
|
||||||
db = _load_db()
|
|
||||||
item = _find_item(db, item_id)
|
|
||||||
if not item:
|
|
||||||
raise HTTPException(404, "耗材不存在")
|
|
||||||
return templates.TemplateResponse("edit.html", {
|
|
||||||
"request": request,
|
|
||||||
"item": item,
|
|
||||||
"labware_type": item.type,
|
|
||||||
"is_new": False,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- API 端点 ----------
|
|
||||||
|
|
||||||
@app.get("/api/labware")
|
|
||||||
async def api_list_labware():
|
|
||||||
db = _load_db()
|
|
||||||
return {"items": [item.model_dump() for item in db.items]}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/labware")
|
|
||||||
async def api_create_labware(request: Request):
|
|
||||||
data = await request.json()
|
|
||||||
db = _load_db()
|
|
||||||
item = LabwareItem(**data)
|
|
||||||
# 确保 id 唯一
|
|
||||||
existing_ids = {it.id for it in db.items}
|
|
||||||
while item.id in existing_ids:
|
|
||||||
import uuid
|
|
||||||
item.id = uuid.uuid4().hex[:8]
|
|
||||||
db.items.append(item)
|
|
||||||
_save_db(db)
|
|
||||||
return {"status": "ok", "id": item.id}
|
|
||||||
|
|
||||||
|
|
||||||
@app.put("/api/labware/{item_id}")
|
|
||||||
async def api_update_labware(item_id: str, request: Request):
|
|
||||||
data = await request.json()
|
|
||||||
db = _load_db()
|
|
||||||
for i, it in enumerate(db.items):
|
|
||||||
if it.id == item_id or it.function_name == item_id:
|
|
||||||
updated = LabwareItem(**{**it.model_dump(), **data, "id": it.id})
|
|
||||||
db.items[i] = updated
|
|
||||||
_save_db(db)
|
|
||||||
return {"status": "ok", "id": it.id}
|
|
||||||
raise HTTPException(404, "耗材不存在")
|
|
||||||
|
|
||||||
|
|
||||||
@app.delete("/api/labware/{item_id}")
|
|
||||||
async def api_delete_labware(item_id: str):
|
|
||||||
db = _load_db()
|
|
||||||
original_len = len(db.items)
|
|
||||||
db.items = [it for it in db.items if it.id != item_id and it.function_name != item_id]
|
|
||||||
if len(db.items) == original_len:
|
|
||||||
raise HTTPException(404, "耗材不存在")
|
|
||||||
_save_db(db)
|
|
||||||
return {"status": "ok"}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/generate-code")
|
|
||||||
async def api_generate_code(request: Request):
|
|
||||||
body = await request.json() if await request.body() else {}
|
|
||||||
test_mode = body.get("test_mode", True)
|
|
||||||
db = _load_db()
|
|
||||||
if not db.items:
|
|
||||||
raise HTTPException(400, "数据库为空,请先导入")
|
|
||||||
|
|
||||||
from unilabos.labware_manager.codegen import generate_code
|
|
||||||
from unilabos.labware_manager.yaml_gen import generate_yaml
|
|
||||||
|
|
||||||
py_path = generate_code(db, test_mode=test_mode)
|
|
||||||
yaml_paths = generate_yaml(db, test_mode=test_mode)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"status": "ok",
|
|
||||||
"python_file": str(py_path),
|
|
||||||
"yaml_files": [str(p) for p in yaml_paths],
|
|
||||||
"test_mode": test_mode,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/import-from-code")
|
|
||||||
async def api_import_from_code():
|
|
||||||
from unilabos.labware_manager.importer import import_from_code, save_db
|
|
||||||
db = import_from_code()
|
|
||||||
save_db(db)
|
|
||||||
return {
|
|
||||||
"status": "ok",
|
|
||||||
"count": len(db.items),
|
|
||||||
"items": [{"function_name": it.function_name, "type": it.type} for it in db.items],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 辅助函数 ----------
|
|
||||||
|
|
||||||
def _find_item(db: LabwareDB, item_id: str) -> Optional[LabwareItem]:
|
|
||||||
for item in db.items:
|
|
||||||
if item.id == item_id or item.function_name == item_id:
|
|
||||||
return item
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
# ---------- 启动入口 ----------
|
|
||||||
|
|
||||||
def main():
|
|
||||||
import uvicorn
|
|
||||||
port = int(os.environ.get("LABWARE_PORT", "8010"))
|
|
||||||
print(f"PRCXI 耗材管理 → http://localhost:{port}")
|
|
||||||
uvicorn.run(app, host="0.0.0.0", port=port)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1,451 +0,0 @@
|
|||||||
"""JSON → prcxi_labware.py 代码生成。
|
|
||||||
|
|
||||||
读取 labware_db.json,输出完整的 prcxi_labware.py(或 prcxi_labware_test.py)。
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import shutil
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
from unilabos.labware_manager.models import LabwareDB, LabwareItem
|
|
||||||
|
|
||||||
_TARGET_DIR = Path(__file__).resolve().parents[1] / "devices" / "liquid_handling" / "prcxi"
|
|
||||||
|
|
||||||
# ---------- 固定头部 ----------
|
|
||||||
_HEADER = '''\
|
|
||||||
from typing import Any, Callable, Dict, List, Optional, Tuple
|
|
||||||
from pylabrobot.resources import Tube, Coordinate
|
|
||||||
from pylabrobot.resources.well import Well, WellBottomType, CrossSectionType
|
|
||||||
from pylabrobot.resources.tip import Tip, TipCreator
|
|
||||||
from pylabrobot.resources.tip_rack import TipRack, TipSpot
|
|
||||||
from pylabrobot.resources.utils import create_ordered_items_2d
|
|
||||||
from pylabrobot.resources.height_volume_functions import (
|
|
||||||
compute_height_from_volume_rectangle,
|
|
||||||
compute_volume_from_height_rectangle,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .prcxi import PRCXI9300Plate, PRCXI9300TipRack, PRCXI9300Trash, PRCXI9300TubeRack, PRCXI9300PlateAdapter
|
|
||||||
|
|
||||||
def _make_tip_helper(volume: float, length: float, depth: float) -> Tip:
|
|
||||||
"""
|
|
||||||
PLR 的 Tip 类参数名为: maximal_volume, total_tip_length, fitting_depth
|
|
||||||
"""
|
|
||||||
return Tip(
|
|
||||||
has_filter=False, # 默认无滤芯
|
|
||||||
maximal_volume=volume,
|
|
||||||
total_tip_length=length,
|
|
||||||
fitting_depth=depth
|
|
||||||
)
|
|
||||||
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_plate(item: LabwareItem) -> str:
|
|
||||||
"""生成 Plate 类型的工厂函数代码。"""
|
|
||||||
lines = []
|
|
||||||
fn = item.function_name
|
|
||||||
doc = item.docstring or f"Code: {item.material_info.Code}"
|
|
||||||
|
|
||||||
has_vf = item.volume_functions is not None
|
|
||||||
|
|
||||||
if has_vf:
|
|
||||||
# 有 volume_functions 时需要 well_kwargs 方式
|
|
||||||
vf = item.volume_functions
|
|
||||||
well = item.well
|
|
||||||
grid = item.grid
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str) -> PRCXI9300Plate:')
|
|
||||||
lines.append(f' """')
|
|
||||||
for dl in doc.split('\n'):
|
|
||||||
lines.append(f' {dl}')
|
|
||||||
lines.append(f' """')
|
|
||||||
|
|
||||||
# 计算 well_size 变量
|
|
||||||
lines.append(f' well_size_x = {well.size_x}')
|
|
||||||
lines.append(f' well_size_y = {well.size_y}')
|
|
||||||
|
|
||||||
lines.append(f' well_kwargs = {{')
|
|
||||||
lines.append(f' "size_x": well_size_x,')
|
|
||||||
lines.append(f' "size_y": well_size_y,')
|
|
||||||
lines.append(f' "size_z": {well.size_z},')
|
|
||||||
lines.append(f' "bottom_type": WellBottomType.{well.bottom_type},')
|
|
||||||
if well.cross_section_type and well.cross_section_type != "CIRCLE":
|
|
||||||
lines.append(f' "cross_section_type": CrossSectionType.{well.cross_section_type},')
|
|
||||||
lines.append(f' "compute_height_from_volume": lambda liquid_volume: compute_height_from_volume_rectangle(')
|
|
||||||
lines.append(f' liquid_volume=liquid_volume, well_length=well_size_x, well_width=well_size_y')
|
|
||||||
lines.append(f' ),')
|
|
||||||
lines.append(f' "compute_volume_from_height": lambda liquid_height: compute_volume_from_height_rectangle(')
|
|
||||||
lines.append(f' liquid_height=liquid_height, well_length=well_size_x, well_width=well_size_y')
|
|
||||||
lines.append(f' ),')
|
|
||||||
if well.material_z_thickness is not None:
|
|
||||||
lines.append(f' "material_z_thickness": {well.material_z_thickness},')
|
|
||||||
lines.append(f' }}')
|
|
||||||
lines.append(f'')
|
|
||||||
lines.append(f' return PRCXI9300Plate(')
|
|
||||||
lines.append(f' name=name,')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
lines.append(f' lid=None,')
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' category="plate",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))},')
|
|
||||||
lines.append(f' ordered_items=create_ordered_items_2d(')
|
|
||||||
lines.append(f' Well,')
|
|
||||||
lines.append(f' num_items_x={grid.num_items_x},')
|
|
||||||
lines.append(f' num_items_y={grid.num_items_y},')
|
|
||||||
lines.append(f' dx={grid.dx},')
|
|
||||||
lines.append(f' dy={grid.dy},')
|
|
||||||
lines.append(f' dz={grid.dz},')
|
|
||||||
lines.append(f' item_dx={grid.item_dx},')
|
|
||||||
lines.append(f' item_dy={grid.item_dy},')
|
|
||||||
lines.append(f' **well_kwargs,')
|
|
||||||
lines.append(f' ),')
|
|
||||||
lines.append(f' )')
|
|
||||||
else:
|
|
||||||
# 普通 plate
|
|
||||||
well = item.well
|
|
||||||
grid = item.grid
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str) -> PRCXI9300Plate:')
|
|
||||||
lines.append(f' """')
|
|
||||||
for dl in doc.split('\n'):
|
|
||||||
lines.append(f' {dl}')
|
|
||||||
lines.append(f' """')
|
|
||||||
lines.append(f' return PRCXI9300Plate(')
|
|
||||||
lines.append(f' name=name,')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
if item.plate_type:
|
|
||||||
lines.append(f' plate_type="{item.plate_type}",')
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' category="plate",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))},')
|
|
||||||
if grid and well:
|
|
||||||
lines.append(f' ordered_items=create_ordered_items_2d(')
|
|
||||||
lines.append(f' Well,')
|
|
||||||
lines.append(f' num_items_x={grid.num_items_x},')
|
|
||||||
lines.append(f' num_items_y={grid.num_items_y},')
|
|
||||||
lines.append(f' dx={grid.dx},')
|
|
||||||
lines.append(f' dy={grid.dy},')
|
|
||||||
lines.append(f' dz={grid.dz},')
|
|
||||||
lines.append(f' item_dx={grid.item_dx},')
|
|
||||||
lines.append(f' item_dy={grid.item_dy},')
|
|
||||||
lines.append(f' size_x={well.size_x},')
|
|
||||||
lines.append(f' size_y={well.size_y},')
|
|
||||||
lines.append(f' size_z={well.size_z},')
|
|
||||||
if well.max_volume is not None:
|
|
||||||
lines.append(f' max_volume={well.max_volume},')
|
|
||||||
if well.material_z_thickness is not None:
|
|
||||||
lines.append(f' material_z_thickness={well.material_z_thickness},')
|
|
||||||
if well.bottom_type and well.bottom_type != "FLAT":
|
|
||||||
lines.append(f' bottom_type=WellBottomType.{well.bottom_type},')
|
|
||||||
if well.cross_section_type:
|
|
||||||
lines.append(f' cross_section_type=CrossSectionType.{well.cross_section_type},')
|
|
||||||
lines.append(f' ),')
|
|
||||||
lines.append(f' )')
|
|
||||||
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_tip_rack(item: LabwareItem) -> str:
|
|
||||||
"""生成 TipRack 工厂函数代码。"""
|
|
||||||
lines = []
|
|
||||||
fn = item.function_name
|
|
||||||
doc = item.docstring or f"Code: {item.material_info.Code}"
|
|
||||||
grid = item.grid
|
|
||||||
tip = item.tip
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str) -> PRCXI9300TipRack:')
|
|
||||||
lines.append(f' """')
|
|
||||||
for dl in doc.split('\n'):
|
|
||||||
lines.append(f' {dl}')
|
|
||||||
lines.append(f' """')
|
|
||||||
lines.append(f' return PRCXI9300TipRack(')
|
|
||||||
lines.append(f' name=name,')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))},')
|
|
||||||
if grid and tip:
|
|
||||||
lines.append(f' ordered_items=create_ordered_items_2d(')
|
|
||||||
lines.append(f' TipSpot,')
|
|
||||||
lines.append(f' num_items_x={grid.num_items_x},')
|
|
||||||
lines.append(f' num_items_y={grid.num_items_y},')
|
|
||||||
lines.append(f' dx={grid.dx},')
|
|
||||||
lines.append(f' dy={grid.dy},')
|
|
||||||
lines.append(f' dz={grid.dz},')
|
|
||||||
lines.append(f' item_dx={grid.item_dx},')
|
|
||||||
lines.append(f' item_dy={grid.item_dy},')
|
|
||||||
lines.append(f' size_x={tip.spot_size_x},')
|
|
||||||
lines.append(f' size_y={tip.spot_size_y},')
|
|
||||||
lines.append(f' size_z={tip.spot_size_z},')
|
|
||||||
lines.append(f' make_tip=lambda: _make_tip_helper(volume={tip.tip_volume}, length={tip.tip_length}, depth={tip.tip_fitting_depth})')
|
|
||||||
lines.append(f' )')
|
|
||||||
lines.append(f' )')
|
|
||||||
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_trash(item: LabwareItem) -> str:
|
|
||||||
"""生成 Trash 工厂函数代码。"""
|
|
||||||
lines = []
|
|
||||||
fn = item.function_name
|
|
||||||
doc = item.docstring or f"Code: {item.material_info.Code}"
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str = "trash") -> PRCXI9300Trash:')
|
|
||||||
lines.append(f' """')
|
|
||||||
for dl in doc.split('\n'):
|
|
||||||
lines.append(f' {dl}')
|
|
||||||
lines.append(f' """')
|
|
||||||
lines.append(f' return PRCXI9300Trash(')
|
|
||||||
lines.append(f' name="trash",')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
lines.append(f' category="trash",')
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))}')
|
|
||||||
lines.append(f' )')
|
|
||||||
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_tube_rack(item: LabwareItem) -> str:
|
|
||||||
"""生成 TubeRack 工厂函数代码。"""
|
|
||||||
lines = []
|
|
||||||
fn = item.function_name
|
|
||||||
doc = item.docstring or f"Code: {item.material_info.Code}"
|
|
||||||
grid = item.grid
|
|
||||||
tube = item.tube
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str) -> PRCXI9300TubeRack:')
|
|
||||||
lines.append(f' """')
|
|
||||||
for dl in doc.split('\n'):
|
|
||||||
lines.append(f' {dl}')
|
|
||||||
lines.append(f' """')
|
|
||||||
lines.append(f' return PRCXI9300TubeRack(')
|
|
||||||
lines.append(f' name=name,')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' category="tube_rack",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))},')
|
|
||||||
if grid and tube:
|
|
||||||
lines.append(f' ordered_items=create_ordered_items_2d(')
|
|
||||||
lines.append(f' Tube,')
|
|
||||||
lines.append(f' num_items_x={grid.num_items_x},')
|
|
||||||
lines.append(f' num_items_y={grid.num_items_y},')
|
|
||||||
lines.append(f' dx={grid.dx},')
|
|
||||||
lines.append(f' dy={grid.dy},')
|
|
||||||
lines.append(f' dz={grid.dz},')
|
|
||||||
lines.append(f' item_dx={grid.item_dx},')
|
|
||||||
lines.append(f' item_dy={grid.item_dy},')
|
|
||||||
lines.append(f' size_x={tube.size_x},')
|
|
||||||
lines.append(f' size_y={tube.size_y},')
|
|
||||||
lines.append(f' size_z={tube.size_z},')
|
|
||||||
lines.append(f' max_volume={tube.max_volume}')
|
|
||||||
lines.append(f' )')
|
|
||||||
lines.append(f' )')
|
|
||||||
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_plate_adapter(item: LabwareItem) -> str:
|
|
||||||
"""生成 PlateAdapter 工厂函数代码。"""
|
|
||||||
lines = []
|
|
||||||
fn = item.function_name
|
|
||||||
doc = item.docstring or f"Code: {item.material_info.Code}"
|
|
||||||
|
|
||||||
lines.append(f'def {fn}(name: str) -> PRCXI9300PlateAdapter:')
|
|
||||||
lines.append(f' """ {doc} """')
|
|
||||||
lines.append(f' return PRCXI9300PlateAdapter(')
|
|
||||||
lines.append(f' name=name,')
|
|
||||||
lines.append(f' size_x={item.size_x},')
|
|
||||||
lines.append(f' size_y={item.size_y},')
|
|
||||||
lines.append(f' size_z={item.size_z},')
|
|
||||||
if item.model:
|
|
||||||
lines.append(f' model="{item.model}",')
|
|
||||||
lines.append(f' material_info={_fmt_dict(item.material_info.model_dump(exclude_none=True))}')
|
|
||||||
lines.append(f' )')
|
|
||||||
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _fmt_dict(d: dict) -> str:
|
|
||||||
"""格式化字典为 Python 代码片段。"""
|
|
||||||
parts = []
|
|
||||||
for k, v in d.items():
|
|
||||||
if isinstance(v, str):
|
|
||||||
parts.append(f'"{k}": "{v}"')
|
|
||||||
elif v is None:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
parts.append(f'"{k}": {v}')
|
|
||||||
return '{' + ', '.join(parts) + '}'
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_template_factory_kinds(items: List[LabwareItem]) -> str:
|
|
||||||
"""生成 PRCXI_TEMPLATE_FACTORY_KINDS 列表。"""
|
|
||||||
lines = ['PRCXI_TEMPLATE_FACTORY_KINDS: List[Tuple[Callable[..., Any], str]] = [']
|
|
||||||
for item in items:
|
|
||||||
if item.include_in_template_matching and item.template_kind:
|
|
||||||
lines.append(f' ({item.function_name}, "{item.template_kind}"),')
|
|
||||||
lines.append(']')
|
|
||||||
return '\n'.join(lines)
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_footer() -> str:
|
|
||||||
"""生成文件尾部的模板相关代码。"""
|
|
||||||
return '''
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# 协议上传 / workflow 用:与设备端耗材字典字段对齐的模板描述(供 common 自动匹配)
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
_PRCXI_TEMPLATE_SPECS_CACHE: Optional[List[Dict[str, Any]]] = None
|
|
||||||
|
|
||||||
|
|
||||||
def _probe_prcxi_resource(factory: Callable[..., Any]) -> Any:
|
|
||||||
probe = "__unilab_template_probe__"
|
|
||||||
if factory.__name__ == "PRCXI_trash":
|
|
||||||
return factory()
|
|
||||||
return factory(probe)
|
|
||||||
|
|
||||||
|
|
||||||
def _first_child_capacity_for_match(resource: Any) -> float:
|
|
||||||
"""Well max_volume 或 Tip 的 maximal_volume,用于与设备端 Volume 类似的打分。"""
|
|
||||||
ch = getattr(resource, "children", None) or []
|
|
||||||
if not ch:
|
|
||||||
return 0.0
|
|
||||||
c0 = ch[0]
|
|
||||||
mv = getattr(c0, "max_volume", None)
|
|
||||||
if mv is not None:
|
|
||||||
return float(mv)
|
|
||||||
tip = getattr(c0, "tip", None)
|
|
||||||
if tip is not None:
|
|
||||||
mv2 = getattr(tip, "maximal_volume", None)
|
|
||||||
if mv2 is not None:
|
|
||||||
return float(mv2)
|
|
||||||
return 0.0
|
|
||||||
|
|
||||||
|
|
||||||
def get_prcxi_labware_template_specs() -> List[Dict[str, Any]]:
|
|
||||||
"""返回与 ``prcxi._match_and_create_matrix`` 中耗材字段兼容的模板列表,用于按孔数+容量打分。"""
|
|
||||||
global _PRCXI_TEMPLATE_SPECS_CACHE
|
|
||||||
if _PRCXI_TEMPLATE_SPECS_CACHE is not None:
|
|
||||||
return _PRCXI_TEMPLATE_SPECS_CACHE
|
|
||||||
|
|
||||||
out: List[Dict[str, Any]] = []
|
|
||||||
for factory, kind in PRCXI_TEMPLATE_FACTORY_KINDS:
|
|
||||||
try:
|
|
||||||
r = _probe_prcxi_resource(factory)
|
|
||||||
except Exception:
|
|
||||||
continue
|
|
||||||
nx = int(getattr(r, "num_items_x", None) or 0)
|
|
||||||
ny = int(getattr(r, "num_items_y", None) or 0)
|
|
||||||
nchild = len(getattr(r, "children", []) or [])
|
|
||||||
hole_count = nx * ny if nx > 0 and ny > 0 else nchild
|
|
||||||
hole_row = ny if nx > 0 and ny > 0 else 0
|
|
||||||
hole_col = nx if nx > 0 and ny > 0 else 0
|
|
||||||
mi = getattr(r, "material_info", None) or {}
|
|
||||||
vol = _first_child_capacity_for_match(r)
|
|
||||||
menum = mi.get("materialEnum")
|
|
||||||
if menum is None and kind == "tip_rack":
|
|
||||||
menum = 1
|
|
||||||
elif menum is None and kind == "trash":
|
|
||||||
menum = 6
|
|
||||||
out.append(
|
|
||||||
{
|
|
||||||
"class_name": factory.__name__,
|
|
||||||
"kind": kind,
|
|
||||||
"materialEnum": menum,
|
|
||||||
"HoleRow": hole_row,
|
|
||||||
"HoleColum": hole_col,
|
|
||||||
"Volume": vol,
|
|
||||||
"hole_count": hole_count,
|
|
||||||
"material_uuid": mi.get("uuid"),
|
|
||||||
"material_code": mi.get("Code"),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
_PRCXI_TEMPLATE_SPECS_CACHE = out
|
|
||||||
return out
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def generate_code(db: LabwareDB, test_mode: bool = True) -> Path:
|
|
||||||
"""生成 prcxi_labware.py (或 _test.py),返回输出文件路径。"""
|
|
||||||
suffix = "_test" if test_mode else ""
|
|
||||||
out_path = _TARGET_DIR / f"prcxi_labware{suffix}.py"
|
|
||||||
|
|
||||||
# 备份
|
|
||||||
if out_path.exists():
|
|
||||||
bak = out_path.with_suffix(".py.bak")
|
|
||||||
shutil.copy2(out_path, bak)
|
|
||||||
|
|
||||||
# 按类型分组的生成器
|
|
||||||
generators = {
|
|
||||||
"plate": _gen_plate,
|
|
||||||
"tip_rack": _gen_tip_rack,
|
|
||||||
"trash": _gen_trash,
|
|
||||||
"tube_rack": _gen_tube_rack,
|
|
||||||
"plate_adapter": _gen_plate_adapter,
|
|
||||||
}
|
|
||||||
|
|
||||||
# 按 type 分段
|
|
||||||
sections = {
|
|
||||||
"plate": [],
|
|
||||||
"tip_rack": [],
|
|
||||||
"trash": [],
|
|
||||||
"tube_rack": [],
|
|
||||||
"plate_adapter": [],
|
|
||||||
}
|
|
||||||
|
|
||||||
for item in db.items:
|
|
||||||
gen = generators.get(item.type)
|
|
||||||
if gen:
|
|
||||||
sections[item.type].append(gen(item))
|
|
||||||
|
|
||||||
# 组装完整文件
|
|
||||||
parts = [_HEADER]
|
|
||||||
|
|
||||||
section_titles = {
|
|
||||||
"plate": "# =========================================================================\n# Plates\n# =========================================================================",
|
|
||||||
"tip_rack": "# =========================================================================\n# Tip Racks\n# =========================================================================",
|
|
||||||
"trash": "# =========================================================================\n# Trash\n# =========================================================================",
|
|
||||||
"tube_rack": "# =========================================================================\n# Tube Racks\n# =========================================================================",
|
|
||||||
"plate_adapter": "# =========================================================================\n# Plate Adapters\n# =========================================================================",
|
|
||||||
}
|
|
||||||
|
|
||||||
for type_key in ["plate", "tip_rack", "trash", "tube_rack", "plate_adapter"]:
|
|
||||||
if sections[type_key]:
|
|
||||||
parts.append(section_titles[type_key])
|
|
||||||
for code in sections[type_key]:
|
|
||||||
parts.append(code)
|
|
||||||
|
|
||||||
# Template factory kinds
|
|
||||||
parts.append("")
|
|
||||||
parts.append(_gen_template_factory_kinds(db.items))
|
|
||||||
|
|
||||||
# Footer
|
|
||||||
parts.append(_gen_footer())
|
|
||||||
|
|
||||||
content = '\n'.join(parts)
|
|
||||||
out_path.write_text(content, encoding="utf-8")
|
|
||||||
return out_path
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from unilabos.labware_manager.importer import load_db
|
|
||||||
db = load_db()
|
|
||||||
if not db.items:
|
|
||||||
print("labware_db.json 为空,请先运行 importer.py")
|
|
||||||
else:
|
|
||||||
out = generate_code(db, test_mode=True)
|
|
||||||
print(f"已生成 {out} ({len(db.items)} 个工厂函数)")
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user