2026-06-06 08:42:07 +00:00
|
|
|
import json
|
2026-06-18 03:28:14 +00:00
|
|
|
from device import controller
|
|
|
|
|
from tools.base_tool import BaseTool, ToolResult
|
2026-06-06 08:42:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Tool(BaseTool):
|
|
|
|
|
name = "uav_get_state"
|
|
|
|
|
description = (
|
|
|
|
|
"获取无人系统当前状态, 例如当前位置等信息"
|
|
|
|
|
)
|
|
|
|
|
parameters = {
|
|
|
|
|
"type": "object",
|
|
|
|
|
"properties": {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
"required": [""],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def execute(self) -> ToolResult:
|
2026-06-16 02:54:12 +00:00
|
|
|
if not controller.is_connected:
|
|
|
|
|
if not controller.connect():
|
|
|
|
|
return ToolResult(success=False, output="连接无人机失败")
|
2026-06-06 08:42:07 +00:00
|
|
|
try:
|
|
|
|
|
telemetry = controller.get_telemetry()
|
|
|
|
|
return ToolResult(success=True, output=json.dumps(telemetry.to_dict(), ensure_ascii=True))
|
2026-06-16 02:54:12 +00:00
|
|
|
except Exception as e:
|
|
|
|
|
return ToolResult(success=False, output=str(e))
|