同步执行状态信息

This commit is contained in:
Xuwznln
2025-06-08 15:34:16 +08:00
parent 6a14104e6b
commit aaa86314e3
2 changed files with 16 additions and 5 deletions

View File

@@ -660,8 +660,10 @@ class BaseROS2DeviceNode(Node, Generic[T]):
future = ROS2DeviceNode.run_async_func(ACTION, trace_error=False, **action_kwargs) future = ROS2DeviceNode.run_async_func(ACTION, trace_error=False, **action_kwargs)
def _handle_future_exception(fut): def _handle_future_exception(fut):
nonlocal execution_error, execution_success, action_return_value
try: try:
fut.result() action_return_value = fut.result()
execution_success = True
except Exception as e: except Exception as e:
execution_error = traceback.format_exc() execution_error = traceback.format_exc()
error(f"异步任务 {ACTION.__name__} 报错了") error(f"异步任务 {ACTION.__name__} 报错了")
@@ -676,8 +678,10 @@ class BaseROS2DeviceNode(Node, Generic[T]):
future = self._executor.submit(ACTION, **action_kwargs) future = self._executor.submit(ACTION, **action_kwargs)
def _handle_future_exception(fut): def _handle_future_exception(fut):
nonlocal execution_error, execution_success, action_return_value
try: try:
fut.result() action_return_value = fut.result()
execution_success = True
except Exception as e: except Exception as e:
execution_error = traceback.format_exc() execution_error = traceback.format_exc()
error(f"同步任务 {ACTION.__name__} 报错了") error(f"同步任务 {ACTION.__name__} 报错了")

View File

@@ -612,17 +612,23 @@ class HostNode(BaseROS2DeviceNode):
def get_result_callback(self, action_id: str, uuid_str: Optional[str], future) -> None: def get_result_callback(self, action_id: str, uuid_str: Optional[str], future) -> None:
"""获取结果回调""" """获取结果回调"""
import json
result_msg = future.result().result result_msg = future.result().result
result_data = convert_from_ros_msg(result_msg) 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().info(f"[Host Node] Result for {action_id} ({uuid_str}): success")
self.lab_logger().debug(f"[Host Node] Result data: {result_data}") self.lab_logger().debug(f"[Host Node] Result data: {result_data}")
if uuid_str: if uuid_str:
for bridge in self.bridges: for bridge in self.bridges:
if hasattr(bridge, "publish_job_status"): 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: def cancel_goal(self, goal_uuid: str) -> None:
"""取消目标""" """取消目标"""
@@ -862,6 +868,7 @@ class HostNode(BaseROS2DeviceNode):
测试网络延迟的action实现 测试网络延迟的action实现
通过5次ping-pong机制校对时间误差并计算实际延迟 通过5次ping-pong机制校对时间误差并计算实际延迟
""" """
raise ValueError("test")
import time import time
import uuid as uuid_module import uuid as uuid_module