Skip to content

Commit a66603e

Browse files
committed
Add set_liquid example.
1 parent ec015e1 commit a66603e

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

unilabos/registry/devices/liquid_handler.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9278,7 +9278,13 @@ liquid_handler.prcxi:
92789278
z: 0.0
92799279
sample_id: ''
92809280
type: ''
9281-
handles: {}
9281+
handles:
9282+
input:
9283+
- data_key: wells
9284+
data_source: handle
9285+
data_type: resource
9286+
handler_key: input_wells
9287+
label: InputWells
92829288
placeholder_keys:
92839289
wells: unilabos_resources
92849290
result: {}

unilabos/registry/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ def setup(self, complete_registry=False, upload_registry=False):
127127
"data_type": "resource",
128128
"label": "Labware",
129129
"data_source": "executor",
130-
"data_key": "created_resource_tree",
130+
"data_key": "created_resource_tree.@flatten",
131131
},
132132
{
133133
"handler_key": "liquid_slots",
134134
"data_type": "resource",
135135
"label": "LiquidSlots",
136136
"data_source": "executor",
137-
"data_key": "liquid_input_resource_tree",
137+
"data_key": "liquid_input_resource_tree.@flatten",
138138
},
139139
{
140140
"handler_key": "materials",

unilabos/ros/msgs/message_converter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,14 @@
159159
else Pose()
160160
),
161161
config=json.dumps(x.get("config", {})),
162-
data=json.dumps(x.get("data", {})),
162+
data=json.dumps(obtain_data_with_uuid(x)),
163163
),
164164
}
165165

166+
def obtain_data_with_uuid(x: dict):
167+
data = x.get("data", {})
168+
data["unilabos_uuid"] = x.get("uuid", None)
169+
return data
166170

167171
def json_or_yaml_loads(data: str) -> Any:
168172
try:

unilabos/ros/nodes/base_device_node.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,10 @@ async def append_resource(req: SerialCommand_Request, res: SerialCommand_Respons
430430
})
431431
tree_response: SerialCommand.Response = await client.call_async(request)
432432
uuid_maps = json.loads(tree_response.response)
433-
self.resource_tracker.loop_update_uuid(input_resources, uuid_maps)
434-
rts: ResourceTreeSet = ResourceTreeSet.from_raw_dict_list(input_resources)
433+
plr_instances = rts.to_plr_resources()
434+
for plr_instance in plr_instances:
435+
self.resource_tracker.loop_update_uuid(plr_instance, uuid_maps)
436+
rts: ResourceTreeSet = ResourceTreeSet.from_plr_resources(plr_instances)
435437
self.lab_logger().info(f"Resource tree added. UUID mapping: {len(uuid_maps)} nodes")
436438
final_response = {
437439
"created_resource_tree": rts.dump(),
@@ -461,7 +463,7 @@ async def append_resource(req: SerialCommand_Request, res: SerialCommand_Respons
461463
return res
462464
try:
463465
if len(rts.root_nodes) == 1 and parent_resource is not None:
464-
plr_instance = rts.to_plr_resources()[0]
466+
plr_instance = plr_instances[0]
465467
if isinstance(plr_instance, Plate):
466468
empty_liquid_info_in: List[Tuple[Optional[str], float]] = [(None, 0)] * plr_instance.num_items
467469
if len(ADD_LIQUID_TYPE) == 1 and len(LIQUID_VOLUME) == 1 and len(LIQUID_INPUT_SLOT) > 1:
@@ -1281,9 +1283,14 @@ def ACTION(**kwargs):
12811283
# 批量查询资源
12821284
queried_resources = []
12831285
for resource_data in resource_inputs:
1284-
plr_resource = await self.get_resource_with_dir(
1285-
resource_id=resource_data["id"], with_children=True
1286-
)
1286+
unilabos_uuid = resource_data.get("data", {}).get("unilabos_uuid")
1287+
if unilabos_uuid is None:
1288+
plr_resource = await self.get_resource_with_dir(
1289+
resource_id=resource_data["id"], with_children=True
1290+
)
1291+
else:
1292+
resource_tree = await self.get_resource([unilabos_uuid])
1293+
plr_resource = resource_tree.to_plr_resources()[0]
12871294
if "sample_id" in resource_data:
12881295
plr_resource.unilabos_extra["sample_uuid"] = resource_data["sample_id"]
12891296
queried_resources.append(plr_resource)
@@ -1423,7 +1430,7 @@ def _handle_future_exception(fut: Future):
14231430
for r in rs:
14241431
res = self.resource_tracker.parent_resource(r) # 获取 resource 对象
14251432
else:
1426-
res = self.resource_tracker.parent_resource(r)
1433+
res = self.resource_tracker.parent_resource(rs)
14271434
if id(res) not in seen:
14281435
seen.add(id(res))
14291436
unique_resources.append(res)

unilabos/ros/nodes/presets/host_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ def _resource_get_callback(self, request: SerialCommand.Request, response: Seria
12441244
data = json.loads(request.command)
12451245
if "uuid" in data and data["uuid"] is not None:
12461246
http_req = http_client.resource_tree_get([data["uuid"]], data["with_children"])
1247-
elif "id" in data and data["id"].startswith("/"):
1247+
elif "id" in data:
12481248
http_req = http_client.resource_get(data["id"], data["with_children"])
12491249
else:
12501250
raise ValueError("没有使用正确的物料 id 或 uuid")
@@ -1463,7 +1463,7 @@ def test_resource(
14631463
if resource is None:
14641464
resource = RegularContainer("test_resource传入None")
14651465
return {
1466-
"resources": ResourceTreeSet.from_plr_resources([resource, *resources]).dump(),
1466+
"resources": ResourceTreeSet.from_plr_resources([resource, *resources], known_newly_created=True).dump(),
14671467
"devices": [device, *devices],
14681468
}
14691469

0 commit comments

Comments
 (0)