From 1b43c53015fab3cedeebf2b5ca2c224707e008d0 Mon Sep 17 00:00:00 2001 From: Junhan Chang Date: Fri, 17 Oct 2025 11:18:47 +0800 Subject: [PATCH] fix resource_get in action --- unilabos/ros/nodes/base_device_node.py | 2 +- unilabos/ros/nodes/presets/host_node.py | 7 ++++++- unilabos/ros/nodes/presets/workstation.py | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/unilabos/ros/nodes/base_device_node.py b/unilabos/ros/nodes/base_device_node.py index 8523a66f..289fe513 100644 --- a/unilabos/ros/nodes/base_device_node.py +++ b/unilabos/ros/nodes/base_device_node.py @@ -943,7 +943,7 @@ class BaseROS2DeviceNode(Node, Generic[T]): queried_resources = [] for resource_data in resource_inputs: r = SerialCommand.Request() - r.command = json.dumps({"id": resource_data["id"], "with_children": True}) + r.command = json.dumps({"id": resource_data["id"], "uuid": resource_data.get("uuid", None), "with_children": True}) # 发送请求并等待响应 response: SerialCommand_Response = await self._resource_clients[ "resource_get" diff --git a/unilabos/ros/nodes/presets/host_node.py b/unilabos/ros/nodes/presets/host_node.py index d265e13a..f40e0cbb 100644 --- a/unilabos/ros/nodes/presets/host_node.py +++ b/unilabos/ros/nodes/presets/host_node.py @@ -1070,7 +1070,12 @@ class HostNode(BaseROS2DeviceNode): """ try: data = json.loads(request.command) - http_req = self.bridges[-1].resource_get(data["id"], data["with_children"]) + if "uuid" in data and data["uuid"] is not None: + http_req = self.bridges[-1].resource_tree_get([data["uuid"]], data["with_children"]) + elif "id" in data and data["id"].startswith("/"): + http_req = self.bridges[-1].resource_get(data["id"], data["with_children"]) + else: + raise ValueError("没有使用正确的物料 id 或 uuid") response.response = json.dumps(http_req["data"]) return response except Exception as e: diff --git a/unilabos/ros/nodes/presets/workstation.py b/unilabos/ros/nodes/presets/workstation.py index 745ec196..dc1175d6 100644 --- a/unilabos/ros/nodes/presets/workstation.py +++ b/unilabos/ros/nodes/presets/workstation.py @@ -232,8 +232,9 @@ class ROS2WorkstationNode(BaseROS2DeviceNode): resource_id = ( protocol_kwargs[k]["id"] if v == "unilabos_msgs/Resource" else protocol_kwargs[k][0]["id"] ) + resource_uuid = protocol_kwargs[k].get("uuid", None) r = SerialCommand_Request() - r.command = json.dumps({"id": resource_id, "with_children": True}) + r.command = json.dumps({"id": resource_id, "uuid": resource_uuid, "with_children": True}) # 发送请求并等待响应 response: SerialCommand_Response = await self._resource_clients[ "resource_get"