Files
Uni-Lab-OS/unilabos/devices/workstation
Xuwznln 7c440d10ab Fix/resource UUID and doc fix (#109)
* Fix ResourceTreeSet load error

* Raise error when using unsupported type to create ResourceTreeSet

* Fix children key error

* Fix children key error

* Fix workstation resource not tracking

* Fix workstation deck & children resource dupe

* Fix workstation deck & children resource dupe

* Fix multiple resource error

* Fix resource tree update

* Fix resource tree update

* Force confirm uuid

* Tip more error log

* Refactor Bioyond workstation and experiment workflow (#105)

Refactored the Bioyond workstation classes to improve parameter handling and workflow management. Updated experiment.py to use BioyondReactionStation with deck and material mappings, and enhanced workflow step parameter mapping and execution logic. Adjusted JSON experiment configs, improved workflow sequence handling, and added UUID assignment to PLR materials. Removed unused station_config and material cache logic, and added detailed docstrings and debug output for workflow methods.

* Fix resource get.
Fix resource parent not found.
Mapping uuid for all resources.

* mount parent uuid

* Add logging configuration based on BasicConfig in main function

* fix workstation node error

* fix workstation node error

* Update boot example

* temp fix for resource get

* temp fix for resource get

* provide error info when cant find plr type

* pack repo info

* fix to plr type error

* fix to plr type error

* Update regular container method

* support no size init

* fix comprehensive_station.json

* fix comprehensive_station.json

* fix type conversion

* fix state loading for regular container

* Update deploy-docs.yml

* Update deploy-docs.yml

---------

Co-authored-by: ZiWei <131428629+ZiWei09@users.noreply.github.com>
2025-10-16 17:26:07 +08:00
..
2025-10-12 23:34:26 +08:00
2025-10-12 23:34:26 +08:00
2025-10-12 23:34:26 +08:00

工作站抽象基类物料系统架构说明

设计理念

基于用户需求"请你帮我系统思考一下,工作站抽象基类的物料系统基类该如何构建",我们最终确定了一个PyLabRobot Deck为中心的简化架构。

核心原则

  1. PyLabRobot为物料管理核心使用PyLabRobot的Deck系统作为物料管理的基础利用其成熟的Resource体系
  2. Graphio转换函数集成使用graphio中的resource_ulab_to_plr等转换函数实现UniLab与PLR格式的无缝转换
  3. 关注点分离基类专注核心物料系统HTTP服务等功能在子类中实现
  4. 外部系统集成模式通过ResourceSynchronizer抽象类提供外部物料系统对接模式

架构组成

1. WorkstationBase基类

文件: workstation_base.py

核心功能

  • 使用deck_config和children通过resource_ulab_to_plr转换为PLR物料self.deck
  • 基础的资源查找和管理功能
  • 抽象的工作流执行接口
  • ResourceSynchronizer集成点

关键代码

def _initialize_material_system(self, deck_config: Dict[str, Any], children_config: Dict[str, Any] = None):
    """初始化基于PLR的物料系统"""
    # 合并deck_config和children
    complete_config = self._merge_deck_and_children_config(deck_config, children_config)
    
    # 使用graphio转换函数转换为PLR资源
    self.deck = resource_ulab_to_plr(complete_config)

2. ResourceSynchronizer外部系统集成抽象类

定义在: workstation_base.py

设计目的

  • 提供外部物料系统如Bioyond、LIMS等集成的标准接口
  • 双向同步从外部系统同步到本地deck以及将本地变更同步到外部系统
  • 处理外部系统的变更通知

核心方法

async def sync_from_external(self) -> bool:
    """从外部系统同步物料到本地deck"""
    
async def sync_to_external(self, plr_resource) -> bool:
    """将本地物料同步到外部系统"""
    
async def handle_external_change(self, change_info: Dict[str, Any]) -> bool:
    """处理外部系统的变更通知"""

3. WorkstationWithHTTP子类示例

文件: workstation_with_http_example.py

扩展功能

  • HTTP报送接收服务集成
  • 具体工作流实现(液体转移、板洗等)
  • Bioyond物料系统同步器示例
  • 外部报送处理方法

技术栈

核心依赖

  • PyLabRobot: 物料资源管理核心Deck, Resource, Coordinate
  • GraphIO转换函数: UniLab ↔ PLR格式转换
    • resource_ulab_to_plr: UniLab格式转PLR格式
    • resource_plr_to_ulab: PLR格式转UniLab格式
    • convert_resources_to_type: 通用资源类型转换
  • ROS2: 基础设备节点通信BaseROS2DeviceNode

可选依赖

  • HTTP服务: 仅在需要外部报送接收的子类中使用
  • 外部系统API: 根据具体集成需求添加

使用示例

1. 简单工作站仅PLR物料系统

from unilabos.devices.workstation.workstation_base import WorkstationBase

# Deck配置
deck_config = {
    "size_x": 1200.0,
    "size_y": 800.0,
    "size_z": 100.0
}

# 子资源配置
children_config = {
    "source_plate": {
        "name": "source_plate",
        "type": "plate",
        "position": {"x": 100, "y": 100, "z": 10},
        "config": {"size_x": 127.8, "size_y": 85.5, "size_z": 14.4}
    }
}

# 创建工作站
workstation = WorkstationBase(
    device_id="simple_workstation",
    deck_config=deck_config,
    children_config=children_config
)

# 查找资源
plate = workstation.find_resource_by_name("source_plate")

2. 带HTTP服务的工作站

from unilabos.devices.workstation.workstation_with_http_example import WorkstationWithHTTP

# HTTP服务配置
http_service_config = {
    "enabled": True,
    "host": "127.0.0.1",
    "port": 8081
}

# 创建带HTTP服务的工作站
workstation = WorkstationWithHTTP(
    device_id="http_workstation",
    deck_config=deck_config,
    children_config=children_config,
    http_service_config=http_service_config
)

# 执行工作流
success = workstation.execute_workflow("liquid_transfer", {
    "volume": 100.0,
    "source_wells": ["A1", "A2"],
    "dest_wells": ["B1", "B2"]
})

3. 外部系统集成

class BioyondResourceSynchronizer(ResourceSynchronizer):
    """Bioyond系统同步器"""
    
    async def sync_from_external(self) -> bool:
        # 从Bioyond API获取物料
        external_materials = await self._fetch_bioyong_materials()
        
        # 转换并添加到本地deck
        for material in external_materials:
            await self._add_material_to_deck(material)
        
        return True

设计优势

1. 简洁性

  • 基类只专注核心物料管理,没有冗余功能
  • 使用成熟的PyLabRobot作为物料管理基础

2. 可扩展性

  • 通过子类添加HTTP服务、特定工作流等功能
  • ResourceSynchronizer模式支持任意外部系统集成

3. 标准化

  • PLR Deck提供标准的资源管理接口
  • Graphio转换函数确保格式一致性

4. 灵活性

  • 可选择性使用HTTP服务和外部系统集成
  • 支持不同类型的工作站需求

发展历程

  1. 初始设计: 复杂的统一物料系统包含HTTP服务和多种功能
  2. PyLabRobot集成: 引入PLR Deck管理但保留了ResourceTracker复杂性
  3. Graphio转换: 使用graphio转换函数简化初始化
  4. 最终简化: 专注核心PLR物料系统HTTP服务移至子类

这个架构体现了"用PyLabRobot Deck来管理物料会更好但是要做好和外部物料系统的对接"的设计理念,以及"现在我只需要在工作站创建的时候整体使用deck_config和children一起通过resource_ulab_to_plr转换为plr物料self.deck即可"的简化要求。