From 5b9e13555c5067a9873b02abfcae9dfd7dc3cb89 Mon Sep 17 00:00:00 2001 From: Junhan Chang Date: Mon, 16 Jun 2025 08:03:06 +0800 Subject: [PATCH] Fix handles --- recipes/ros-humble-unilabos-msgs/recipe.yaml | 4 +- .../comprehensive_station.json | 8 +- test/experiments/mock_reactor.json | 11 +- unilabos/registry/devices/pump_and_valve.yaml | 4 +- unilabos/registry/devices/virtual_device.yaml | 125 +++++++++--------- unilabos/ros/msgs/message_converter.py | 3 +- 6 files changed, 76 insertions(+), 79 deletions(-) diff --git a/recipes/ros-humble-unilabos-msgs/recipe.yaml b/recipes/ros-humble-unilabos-msgs/recipe.yaml index 6a64f9c..ef7755d 100644 --- a/recipes/ros-humble-unilabos-msgs/recipe.yaml +++ b/recipes/ros-humble-unilabos-msgs/recipe.yaml @@ -50,12 +50,12 @@ requirements: - robostack-staging::ros-humble-rosidl-default-generators - robostack-staging::ros-humble-std-msgs - robostack-staging::ros-humble-geometry-msgs - - robostack-staging::ros2-distro-mutex=0.6.* + - robostack-staging::ros2-distro-mutex=0.5.* run: - robostack-staging::ros-humble-action-msgs - robostack-staging::ros-humble-ros-workspace - robostack-staging::ros-humble-rosidl-default-runtime - robostack-staging::ros-humble-std-msgs - robostack-staging::ros-humble-geometry-msgs - - robostack-staging::ros2-distro-mutex=0.6.* +# - robostack-staging::ros2-distro-mutex=0.6.* - sel(osx and x86_64): __osx >={{ MACOSX_DEPLOYMENT_TARGET|default('10.14') }} diff --git a/test/experiments/comprehensive_protocol/comprehensive_station.json b/test/experiments/comprehensive_protocol/comprehensive_station.json index 50894ca..e6cc20e 100644 --- a/test/experiments/comprehensive_protocol/comprehensive_station.json +++ b/test/experiments/comprehensive_protocol/comprehensive_station.json @@ -77,8 +77,7 @@ "z": 0 }, "config": { - "positions": 8, - "current_position": 1 + "positions": 8 }, "data": { "valve_state": "Ready", @@ -98,8 +97,7 @@ "z": 0 }, "config": { - "positions": 8, - "current_position": 1 + "positions": 8 }, "data": { "valve_state": "Ready", @@ -489,7 +487,7 @@ "children": [], "parent": "ComprehensiveProtocolStation", "type": "device", - "class": "gas_source.mock", + "class": "container", "position": { "x": 650, "y": 150, diff --git a/test/experiments/mock_reactor.json b/test/experiments/mock_reactor.json index b0994cd..e73ab5c 100644 --- a/test/experiments/mock_reactor.json +++ b/test/experiments/mock_reactor.json @@ -37,7 +37,10 @@ "z": 0 }, "config": { - "max_volume": 5000.0 + "max_volume": 5000.0, + "size_x": 200.0, + "size_y": 200.0, + "size_z": 200.0 }, "data": { "liquid": [ @@ -71,7 +74,7 @@ "type": "device", "class": "solenoid_valve.mock", "position": { - "x": 620.6111111111111, + "x": 780, "y": 171, "z": 0 }, @@ -89,7 +92,7 @@ "type": "device", "class": "vacuum_pump.mock", "position": { - "x": 620.6111111111111, + "x": 500, "y": 171, "z": 0 }, @@ -107,7 +110,7 @@ "type": "device", "class": "gas_source.mock", "position": { - "x": 620.6111111111111, + "x": 900, "y": 171, "z": 0 }, diff --git a/unilabos/registry/devices/pump_and_valve.yaml b/unilabos/registry/devices/pump_and_valve.yaml index 120ff45..6e264ee 100644 --- a/unilabos/registry/devices/pump_and_valve.yaml +++ b/unilabos/registry/devices/pump_and_valve.yaml @@ -48,14 +48,14 @@ solenoid_valve.mock: feedback: {} result: {} handles: - input: - handler_key: fluid-input label: Fluid Input data_type: fluid - output: + side: NORTH - handler_key: fluid-output label: Fluid Output data_type: fluid + side: SOUTH init_param_schema: type: object properties: diff --git a/unilabos/registry/devices/virtual_device.yaml b/unilabos/registry/devices/virtual_device.yaml index 4eda4f5..8960072 100644 --- a/unilabos/registry/devices/virtual_device.yaml +++ b/unilabos/registry/devices/virtual_device.yaml @@ -7,7 +7,7 @@ # 2. virtual_stirrer - 虚拟搅拌器 # 描述:机械连接设备,提供搅拌功能 -# 连接特性:1个双向连接点(bidirectional) +# 连接特性:1个双向连接点(undirected) # 数据类型:mechanical(机械连接) # 3a. virtual_valve - 虚拟八通阀门 @@ -32,12 +32,12 @@ # 6. virtual_heatchill - 虚拟加热/冷却器 # 描述:温控设备,容器直接放置在设备上进行温度控制 -# 连接特性:1个双向连接点(bidirectional) +# 连接特性:1个双向连接点(undirected) # 数据类型:mechanical(机械/物理接触连接) # 7. virtual_transfer_pump - 虚拟转移泵(注射器式) # 描述:注射器式转移泵,通过同一个口吸入和排出液体 -# 连接特性:1个双向连接点(bidirectional) +# 连接特性:1个双向连接点(undirected) # 数据类型:fluid(流体连接) # 8. virtual_column - 虚拟色谱柱 @@ -83,7 +83,6 @@ virtual_pump: success: success # 虚拟泵节点配置 - 具有多通道阀门特性,根据valve_position可连接多个容器 handles: - input: - handler_key: pump-inlet label: Pump Inlet data_type: fluid @@ -91,14 +90,6 @@ virtual_pump: data_source: handle data_key: fluid_in description: "泵的进液口,连接源容器" - output: - - handler_key: pump-outlet-1 - label: Outlet Port 1 - data_type: fluid - io_type: source - data_source: executor - data_key: fluid_out_1 - description: "阀门位置1的出液口" schema: type: object properties: @@ -148,11 +139,11 @@ virtual_stirrer: success: success # 虚拟搅拌器节点配置 - 机械连接设备,单一双向连接点 handles: - bidirectional: - handler_key: stirrer-vessel label: Vessel Connection data_type: mechanical - io_type: bidirectional + side: SOUTH + io_type: undirected data_source: handle data_key: vessel description: "搅拌器的机械连接口,直接与反应容器连接提供搅拌功能" @@ -191,7 +182,6 @@ virtual_multiway_valve: success: success # 八通阀门节点配置 - 1个输入口,8个输出口,可切换流向 handles: - input: - handler_key: multiway-valve-inlet label: Valve Inlet data_type: fluid @@ -199,59 +189,66 @@ virtual_multiway_valve: data_source: handle data_key: fluid_in description: "八通阀门进液口,接收来源流体" - output: - handler_key: multiway-valve-port-1 - label: Port 1 + label: 1 data_type: fluid + side: NORTH io_type: source data_source: executor data_key: fluid_port_1 description: "八通阀门端口1,position=1时流体从此口流出" - handler_key: multiway-valve-port-2 - label: Port 2 + label: 2 data_type: fluid + side: EAST io_type: source data_source: executor data_key: fluid_port_2 description: "八通阀门端口2,position=2时流体从此口流出" - handler_key: multiway-valve-port-3 - label: Port 3 + label: 3 data_type: fluid + side: EAST io_type: source data_source: executor data_key: fluid_port_3 description: "八通阀门端口3,position=3时流体从此口流出" - handler_key: multiway-valve-port-4 - label: Port 4 + label: 4 data_type: fluid + side: SOUTH io_type: source data_source: executor data_key: fluid_port_4 description: "八通阀门端口4,position=4时流体从此口流出" - handler_key: multiway-valve-port-5 - label: Port 5 + label: 5 data_type: fluid + side: SOUTH io_type: source data_source: executor data_key: fluid_port_5 description: "八通阀门端口5,position=5时流体从此口流出" - - handler_key: multiway-valve-port-6 - label: Port 6 - data_type: fluid - io_type: source - data_source: executor - data_key: fluid_port_6 - description: "八通阀门端口6,position=6时流体从此口流出" - handler_key: multiway-valve-port-7 - label: Port 7 + label: 7 data_type: fluid + side: WEST io_type: source data_source: executor data_key: fluid_port_7 description: "八通阀门端口7,position=7时流体从此口流出" - - handler_key: multiway-valve-port-8 - label: Port 8 + - handler_key: multiway-valve-port-6 + label: 6 data_type: fluid + side: WEST + io_type: source + data_source: executor + data_key: fluid_port_6 + description: "八通阀门端口6,position=6时流体从此口流出" + - handler_key: multiway-valve-port-8 + label: 8 + data_type: fluid + side: NORTH io_type: source data_source: executor data_key: fluid_port_8 @@ -299,11 +296,17 @@ virtual_solenoid_valve: success: success # 电磁阀门节点配置 - 双向流通的开关型阀门,流动方向由泵决定 handles: - bidirectional: - - handler_key: solenoid-valve-port - label: Valve Port + - handler_key: solenoid-valve-port-in + label: in data_type: fluid - io_type: bidirectional + io_type: undirected + data_source: handle + data_key: fluid_port + description: "电磁阀的双向流体口,开启时允许流体双向通过,关闭时完全阻断" + - handler_key: solenoid-valve-port-out + label: out + data_type: fluid + io_type: undirected data_source: handle data_key: fluid_port description: "电磁阀的双向流体口,开启时允许流体双向通过,关闭时完全阻断" @@ -354,22 +357,13 @@ virtual_centrifuge: message: message # 虚拟离心机节点配置 - 单个样品处理设备,输入输出都是同一个样品容器 handles: - input: - handler_key: centrifuge-sample - label: Sample Input - data_type: resource - io_type: target + label: Sample Input/Output + data_type: transport + io_type: undirected data_source: handle data_key: vessel description: "需要离心的样品容器" - output: - - handler_key: centrifuge-sample-out - label: Centrifuged Sample - data_type: resource - io_type: source - data_source: executor - data_key: vessel - description: "经过离心处理的样品容器" schema: type: object properties: @@ -424,25 +418,26 @@ virtual_filter: message: message # 虚拟过滤器节点配置 - 分离设备,1个输入(原始样品),2个输出(滤液和滤渣) handles: - input: - - handler_key: filter-sample-in - label: Sample Input - data_type: resource + - handler_key: filter-in + label: Input + data_type: fluid + side: NORTH io_type: target data_source: handle data_key: vessel description: "需要过滤的原始样品容器" - output: - handler_key: filter-filtrate-out - label: Filtrate Output - data_type: resource + label: Output + data_type: fluid + side: SOUTH io_type: source data_source: executor data_key: filtrate_vessel description: "过滤后的滤液容器" - handler_key: filter-residue-out - label: Filter Residue + label: Residue data_type: resource + side: WEST io_type: source data_source: executor data_key: residue_vessel @@ -502,11 +497,11 @@ virtual_heatchill: success: success # 虚拟加热/冷却器节点配置 - 温控设备,单一双向连接点用于放置容器 handles: - bidirectional: - handler_key: heatchill-vessel - label: Vessel Connection + label: Connection data_type: mechanical - io_type: bidirectional + side: NORTH + io_type: undirected data_source: handle data_key: vessel description: "加热/冷却器的物理连接口,容器直接放置在设备上进行温度控制" @@ -530,7 +525,7 @@ virtual_heatchill: virtual_transfer_pump: description: Virtual Transfer Pump for TransferProtocol Testing (Syringe-style) class: - module: unilabos.devices.virtual.virtual_transferpump:VirtualTransferPump + module: unilabos.devices.virtual.virtual_transferpump:VirtualPump type: python status_types: status: String @@ -565,11 +560,11 @@ virtual_transfer_pump: message: message # 注射器式转移泵节点配置 - 只有一个双向连接口,可吸入和排出液体 handles: - bidirectional: + undirected: - handler_key: syringe-port label: Syringe Port data_type: fluid - io_type: bidirectional + io_type: undirected data_source: handle data_key: fluid_port description: "注射器式转移泵的唯一连接口,通过阀门切换实现吸入和排出" @@ -617,18 +612,18 @@ virtual_column: message: message # 虚拟色谱柱节点配置 - 分离纯化设备,1个样品输入口,1个纯化产物输出口 handles: - input: - handler_key: column-sample-inlet label: Sample Input - data_type: resource + data_type: fluid + side: NORTH io_type: target data_source: handle data_key: from_vessel description: "需要纯化的样品输入口" - output: - handler_key: column-product-outlet label: Purified Product - data_type: resource + data_type: fluid + side: SOUTH io_type: source data_source: executor data_key: to_vessel diff --git a/unilabos/ros/msgs/message_converter.py b/unilabos/ros/msgs/message_converter.py index 62ab606..2bcaadb 100644 --- a/unilabos/ros/msgs/message_converter.py +++ b/unilabos/ros/msgs/message_converter.py @@ -100,7 +100,7 @@ _action_mapping: Dict[Type, Dict[str, Any]] = { # 添加Protocol action类型到映射 for py_msgtype in imsg.__all__: - if py_msgtype not in _action_mapping and py_msgtype.endswith("Protocol"): + if py_msgtype not in _action_mapping and (py_msgtype.endswith("Protocol") or py_msgtype.startswith("Protocol")): try: protocol_class = msg_converter_manager.get_class(f"unilabos.messages.{py_msgtype}") action_name = py_msgtype.replace("Protocol", "") @@ -117,6 +117,7 @@ for py_msgtype in imsg.__all__: "result": {k: k for k in action_type.Result().get_fields_and_field_types().keys()}, } except Exception: + traceback.print_exc() logger.debug(f"Failed to load Protocol class: {py_msgtype}") # Python到ROS消息转换器