From aaa86314e376d75e6d137190d87b48fb60f67ee4 Mon Sep 17 00:00:00 2001 From: Xuwznln <18435084+Xuwznln@users.noreply.github.com> Date: Sun, 8 Jun 2025 15:34:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=89=A7=E8=A1=8C=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unilabos/ros/nodes/base_device_node.py | 8 ++++++-- unilabos/ros/nodes/presets/host_node.py | 13 ++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/unilabos/ros/nodes/base_device_node.py b/unilabos/ros/nodes/base_device_node.py index 95e3f0c7..67cdb6f9 100644 --- a/unilabos/ros/nodes/base_device_node.py +++ b/unilabos/ros/nodes/base_device_node.py @@ -660,8 +660,10 @@ class BaseROS2DeviceNode(Node, Generic[T]): future = ROS2DeviceNode.run_async_func(ACTION, trace_error=False, **action_kwargs) def _handle_future_exception(fut): + nonlocal execution_error, execution_success, action_return_value try: - fut.result() + action_return_value = fut.result() + execution_success = True except Exception as e: execution_error = traceback.format_exc() error(f"异步任务 {ACTION.__name__} 报错了") @@ -676,8 +678,10 @@ class BaseROS2DeviceNode(Node, Generic[T]): future = self._executor.submit(ACTION, **action_kwargs) def _handle_future_exception(fut): + nonlocal execution_error, execution_success, action_return_value try: - fut.result() + action_return_value = fut.result() + execution_success = True except Exception as e: execution_error = traceback.format_exc() error(f"同步任务 {ACTION.__name__} 报错了") diff --git a/unilabos/ros/nodes/presets/host_node.py b/unilabos/ros/nodes/presets/host_node.py index 91a9fa5a..be9c9779 100644 --- a/unilabos/ros/nodes/presets/host_node.py +++ b/unilabos/ros/nodes/presets/host_node.py @@ -612,17 +612,23 @@ class HostNode(BaseROS2DeviceNode): def get_result_callback(self, action_id: str, uuid_str: Optional[str], future) -> None: """获取结果回调""" - import json - result_msg = future.result().result result_data = convert_from_ros_msg(result_msg) + status = "success" + try: + ret = json.loads(result_data.get("return_info", "{}")) # 确保返回信息是有效的JSON + suc = ret.get("suc", False) + if not suc: + status = "failed" + except json.JSONDecodeError: + status = "failed" self.lab_logger().info(f"[Host Node] Result for {action_id} ({uuid_str}): success") self.lab_logger().debug(f"[Host Node] Result data: {result_data}") if uuid_str: for bridge in self.bridges: if hasattr(bridge, "publish_job_status"): - bridge.publish_job_status(result_data, uuid_str, "success", result_data.get("return_info", "{}")) + bridge.publish_job_status(result_data, uuid_str, status, result_data.get("return_info", "{}")) def cancel_goal(self, goal_uuid: str) -> None: """取消目标""" @@ -862,6 +868,7 @@ class HostNode(BaseROS2DeviceNode): 测试网络延迟的action实现 通过5次ping-pong机制校对时间误差并计算实际延迟 """ + raise ValueError("test") import time import uuid as uuid_module