base_agent/tools/uav_control.py

42 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from typing import List
from agent.device import controller
from agent.tools.base_tool import BaseTool, ToolResult
class Tool(BaseTool):
name = "uav_control"
description = (
"该工具用于对无人系统进行控制并在飞行控制中完成一系列的活动Action例如起飞、移动、悬停、照相等"
)
parameters = {
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "无人系统飞行控制命令例如arm、disarm、takeoff、rtl、goto等",
},
"params": {
"type": "object",
"description": "控制命令参数"
},
"actions": {
"type": "array",
"description": "过程中执行的一些列的动作例如pause、capture_phone、standby等"
}
},
"required": ["command"],
}
def execute(self, command: str, params: dict={}, actions: List[object]=()) -> ToolResult:
if not controller.connect():
return ToolResult(success=False, output="连接无人机失败")
try:
command_handler = getattr(controller, command)
try:
return ToolResult(success=True, output=str(command_handler(**params)))
except Exception as e:
return ToolResult(success=False, output=str(e))
finally:
controller.disconnect()