From 83abf877b53d9c19bea0c54f7cff202e8efd49e8 Mon Sep 17 00:00:00 2001 From: wznln <18435084+Xuwznln@users.noreply.github.com> Date: Wed, 7 May 2025 02:36:53 +0800 Subject: [PATCH] fix: multi channel --- unilabos/ros/nodes/base_device_node.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/unilabos/ros/nodes/base_device_node.py b/unilabos/ros/nodes/base_device_node.py index 45daf454..078cb470 100644 --- a/unilabos/ros/nodes/base_device_node.py +++ b/unilabos/ros/nodes/base_device_node.py @@ -514,20 +514,30 @@ class BaseROS2DeviceNode(Node, Generic[T]): for k, v in goal.get_fields_and_field_types().items(): if v in ["unilabos_msgs/Resource", "sequence"]: self.lab_logger().info(f"查询资源状态: Key: {k} Type: {v}") + current_resources = [] try: - r = ResourceGet.Request() - r.id = action_kwargs[k]["id"] if v == "unilabos_msgs/Resource" else action_kwargs[k][0]["id"] - r.with_children = True - response = await self._resource_clients["resource_get"].call_async(r) + if len(action_kwargs[k]) > 1: + for i in action_kwargs[k]: + r = ResourceGet.Request() + r.id = i["id"] + r.with_children = True + response = await self._resource_clients["resource_get"].call_async(r) + current_resources.extend(response.resources) + else: + r = ResourceGet.Request() + r.id = action_kwargs[k]["id"] if v == "unilabos_msgs/Resource" else action_kwargs[k][0]["id"] + r.with_children = True + response = await self._resource_clients["resource_get"].call_async(r) + current_resources.extend(response.resources) except Exception: logger.error(f"资源查询失败,默认使用本地资源") # 删除对response.resources的检查,因为它总是存在 - resources_list = [convert_from_ros_msg(rs) for rs in response.resources] # type: ignore # FIXME + resources_list = [convert_from_ros_msg(rs) for rs in current_resources] # type: ignore # FIXME self.lab_logger().debug(f"资源查询结果: {len(resources_list)} 个资源") type_hint = action_paramtypes[k] final_type = get_type_class(type_hint) # 判断 ACTION 是否需要特殊的物料类型如 pylabrobot.resources.Resource,并做转换 - final_resource = convert_resources_to_type(resources_list, final_type) + final_resource = [convert_resources_to_type([i], final_type)[0] for i in resources_list] action_kwargs[k] = self.resource_tracker.figure_resource(final_resource) self.lab_logger().info(f"准备执行: {action_kwargs}, 函数: {ACTION.__name__}")