diff --git a/template/parsing_error.py b/template/parsing_error.py index bfaefad..b959017 100644 --- a/template/parsing_error.py +++ b/template/parsing_error.py @@ -15,6 +15,6 @@ REMINDER - Action Input must be valid JSON: - For multiple parameters: {{"drone_id": "drone-001", "altitude": 15.0}} - Numbers WITHOUT quotes, strings WITH quotes - We put your answer to langchain, so if you want to return {{ or }}, return double of the characters. -- When the task is done, simply output "Final Answer:\n[TASK DONE]" +- When the task is done, IMMEDIATELY output ONLY "Final Answer:\n[TASK DONE]" and nothing else after that. Please try again with proper JSON format.""" diff --git a/uav_langchain_tools.py b/uav_langchain_tools.py index cb2433c..a29aa65 100644 --- a/uav_langchain_tools.py +++ b/uav_langchain_tools.py @@ -1203,10 +1203,36 @@ def create_uav_tools(client: UAVAPIClient) -> list: return "Error: Target area is too small or invalid geometry found." # 3.4 执行探索 - + # 初始化覆盖率为0,防止在没有执行任何移动时变量未定义 + current_coverage = 0.0 + first_warning = 0 for idx, wp in enumerate(final_path): if idx < tool_states.explored_count: continue + + # 检查无人机电池电量 + drone_status = client.get_drone_status(drone_id) + battery_level = drone_status.get('battery_level', 100.0) + + # 如果电量低于30%,则前往最近的充电站 + + if battery_level < 30.0: + # 查找最近的充电站 + try: + waypoints = client.get_all_waypoints() + charging_stations = [wp for wp in waypoints if wp.get('charge_amount', 0) > 0] + + if charging_stations: + #返回后交给充电工具处理, 充电完成后会再继续执行 + return f" {drone_id} is low on battery ({battery_level:.1f}%)! Please charge at the nearest station. Then continue auto exploring." + + else: + if first_warning == 0: + print("Warning: Low battery but no charging stations found!") + first_warning = 1 + except Exception as e: + print(f"Error during charging process: {str(e)}") + # 移动无人机 client.move_to(drone_id, wp['x'], wp['y'], current_z)