-
Notifications
You must be signed in to change notification settings - Fork 217
脚本添加 #5146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
脚本添加 #5146
Changes from all commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
a2648e7
无人机导航系统
725921 ce76877
Merge branch 'OpenHUTB:main' into main
725921 363d13d
Merge branch 'OpenHUTB:main' into main
725921 64752ed
无人机导航系统
725921 8c29b44
Merge branch 'main' of https://github.com/725921/nn
725921 dbbc21a
Merge branch 'OpenHUTB:main' into main
725921 a20a3d7
无人机导航
725921 e91f251
Merge branch 'main' of https://github.com/725921/nn
725921 a334652
Merge branch 'OpenHUTB:main' into main
725921 d410ad5
无人机导航系统
725921 7d0f31f
Merge branch 'main' of https://github.com/725921/nn
725921 d97b5ad
Merge branch 'OpenHUTB:main' into main
725921 720f56a
无人机导航
725921 63a680b
Merge branch 'main' of https://github.com/725921/nn
725921 37306bf
Merge branch 'OpenHUTB:main' into main
725921 3bc591a
添加注释
725921 2e14e57
Merge branch 'main' of https://github.com/725921/nn
725921 0cd357c
Merge branch 'OpenHUTB:main' into main
725921 e55f1be
添加注释
725921 ddc4ae7
Merge branch 'OpenHUTB:main' into main
725921 7ae988f
Merge branch 'main' of https://github.com/725921/nn
725921 68040a4
添加了目录文件
725921 058113f
Merge branch 'OpenHUTB:main' into main
725921 00288e9
操作键位文件补充
725921 ae3622a
Merge branch 'OpenHUTB:main' into main
725921 616d301
Merge branch 'main' of https://github.com/725921/nn
725921 424fbd0
添加了操作按键补充的文件
725921 43cfc92
Merge branch 'OpenHUTB:main' into main
725921 148c67b
Merge branch 'main' of https://github.com/725921/nn
725921 fa2917a
无人机
725921 9657503
Merge branch 'OpenHUTB:main' into main
725921 cb1a892
Merge branch 'main' of https://github.com/725921/nn
725921 b8a66b5
Merge branch 'OpenHUTB:main' into main
725921 5f75090
Merge branch 'OpenHUTB:main' into main
725921 32e285b
123
725921 3ec4990
Merge branch 'main' of https://github.com/725921/nn
725921 25cb049
Merge branch 'OpenHUTB:main' into main
725921 c005f30
readme的提交
725921 b5f9fd2
Merge branch 'main' of https://github.com/725921/nn
725921 e58934f
Merge branch 'OpenHUTB:main' into main
725921 d582955
初试测试代码
725921 d50d2f3
Merge branch 'main' of https://github.com/725921/nn
725921 01369bc
Merge branch 'OpenHUTB:main' into main
725921 55e2010
无人机运行代码
725921 b22dfba
Merge branch 'main' of https://github.com/725921/nn
725921 832105d
Merge branch 'OpenHUTB:main' into main
725921 aa4a61d
模拟器链接测试
725921 fb385db
Merge branch 'main' of https://github.com/725921/nn
725921 d34daa7
无人机起飞检查
725921 9ef94c7
Merge branch 'OpenHUTB:main' into main
725921 9b7e2d2
Merge branch 'OpenHUTB:main' into main
725921 15a833b
Merge branch 'OpenHUTB:main' into main
725921 4111606
Merge branch 'OpenHUTB:main' into main
725921 84f9e8b
改进了主代码
725921 a9a0ac4
Merge branch 'OpenHUTB:main' into main
725921 9177152
Merge branch 'OpenHUTB:main' into main
725921 eea86af
Merge branch 'OpenHUTB:main' into main
725921 5444e5b
代码添加注释
725921 ddd1987
Merge branch 'main' of https://github.com/725921/nn
725921 95d9a35
Merge branch 'OpenHUTB:main' into main
725921 d5f0b81
连接代码的优化
725921 ef0bcd5
Merge branch 'main' of https://github.com/725921/nn
725921 d779aa2
Merge branch 'OpenHUTB:main' into main
725921 d5223b1
主代码注释添加
725921 06c5812
Merge branch 'main' of https://github.com/725921/nn
725921 d77fcf0
图片捕获代码
725921 b39a20e
增加了场景分析
725921 6c22674
Merge branch 'OpenHUTB:main' into main
725921 1e271d1
Merge branch 'main' of https://github.com/725921/nn
725921 7701c32
代码优化
725921 1279516
Merge branch 'OpenHUTB:main' into main
725921 c76dd2f
readme 的更新
725921 751103b
Merge branch 'OpenHUTB:main' into main
725921 c075559
Merge branch 'main' of https://github.com/725921/nn
725921 dc70536
Merge branch 'OpenHUTB:main' into main
725921 49af4c1
Merge branch 'OpenHUTB:main' into main
725921 c4cbd9a
Merge branch 'OpenHUTB:main' into main
725921 5c122af
Merge branch 'main' of https://github.com/725921/nn
725921 424c8cd
添加注释
725921 f588d61
Merge branch 'OpenHUTB:main' into main
725921 b6a33e7
Merge branch 'main' of https://github.com/725921/nn
725921 006a689
airsim初步模拟
725921 68af3cb
起飞降落测试
725921 2889d88
配置文件示例
725921 324b14b
添加脚本
725921 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| # airsim_connection.py | ||
| import airsim | ||
| import time | ||
|
|
||
|
|
||
| class AbandonedParkSimulator: | ||
| def __init__(self): | ||
| print("连接到AbandonedPark模拟器...") | ||
|
|
||
| # 连接到本地的AbandonedPark模拟器 | ||
| self.client = airsim.MultirotorClient() | ||
| self.client.confirmConnection() | ||
|
|
||
| # 检查连接状态 | ||
| print(f"连接状态: {self.client.ping()}") | ||
|
|
||
| print("模拟器已连接!") | ||
|
|
||
| def ensure_drone_mode(self): | ||
| """确保切换到无人机模式""" | ||
| print("切换到无人机模式...") | ||
|
|
||
| # 尝试解锁无人机 | ||
| try: | ||
| self.client.enableApiControl(True) | ||
| self.client.armDisarm(True) | ||
| print("无人机已解锁") | ||
| return True | ||
| except Exception as e: | ||
| print(f"切换模式时出错: {e}") | ||
| print("请确保模拟器中已选择无人机模式") | ||
| return False | ||
|
|
||
| def takeoff_and_hover(self, altitude=10): | ||
| """起飞并悬停""" | ||
| print(f"起飞到 {altitude} 米高度...") | ||
|
|
||
| # 起飞 | ||
| self.client.takeoffAsync().join() | ||
| time.sleep(2) | ||
|
|
||
| # 移动到指定高度 | ||
| self.client.moveToZAsync(-altitude, 3).join() | ||
| time.sleep(1) | ||
|
|
||
| print(f"已在 {altitude} 米高度悬停") | ||
|
|
||
| def capture_park_image(self): | ||
| """捕获废弃公园图像""" | ||
| print("捕获图像...") | ||
|
|
||
| # 从相机获取图像 | ||
| responses = self.client.simGetImages([ | ||
| airsim.ImageRequest( | ||
| "0", # 前置摄像头 | ||
| airsim.ImageType.Scene, | ||
| False, False # 不压缩 | ||
| ) | ||
| ]) | ||
|
|
||
| if responses and len(responses) > 0: | ||
| response = responses[0] | ||
|
|
||
| # 转换为numpy数组 | ||
| import numpy as np | ||
| img1d = np.frombuffer(response.image_data_uint8, dtype=np.uint8) | ||
| img_rgb = img1d.reshape(response.height, response.width, 3) | ||
|
|
||
| # 保存图像 | ||
| import cv2 | ||
| timestamp = time.strftime("%Y%m%d_%H%M%S") | ||
| cv2.imwrite(f"park_capture_{timestamp}.jpg", img_rgb) | ||
| print(f"图像已保存: park_capture_{timestamp}.jpg") | ||
|
|
||
| return img_rgb | ||
| else: | ||
| print("未能捕获图像") | ||
| return None | ||
|
|
||
| def explore_park(self): | ||
| """探索公园的简单路径""" | ||
| print("开始探索废弃公园...") | ||
|
|
||
| # 定义探索路径(围绕公园) | ||
| waypoints = [ | ||
| (20, 0, -10), # 向前20米 | ||
| (20, 15, -10), # 向右15米 | ||
| (0, 15, -12), # 向后20米,下降2米 | ||
| (0, 0, -10), # 向左15米,回到起点 | ||
| ] | ||
|
|
||
| for x, y, z in waypoints: | ||
| print(f"飞往位置: ({x}, {y}, {z})") | ||
| self.client.moveToPositionAsync(x, y, z, 3).join() | ||
|
|
||
| # 在每个位置捕获图像 | ||
| self.capture_park_image() | ||
| time.sleep(1) | ||
|
|
||
| print("探索完成!") | ||
|
|
||
| def cleanup(self): | ||
| """清理资源""" | ||
| print("正在降落...") | ||
| self.client.landAsync().join() | ||
| self.client.armDisarm(False) | ||
| self.client.enableApiControl(False) | ||
| print("无人机已降落") | ||
|
|
||
|
|
||
| # 快速测试脚本 | ||
| if __name__ == "__main__": | ||
| print("=== AbandonedPark无人机测试 ===") | ||
|
|
||
| # 1. 确保模拟器已经运行 | ||
| input("请确保AbandonedPark.exe已运行,然后按回车继续...") | ||
|
|
||
| # 2. 连接模拟器 | ||
| simulator = AbandonedParkSimulator() | ||
|
|
||
| try: | ||
| # 3. 切换到无人机模式 | ||
| if simulator.ensure_drone_mode(): | ||
| # 4. 起飞 | ||
| simulator.takeoff_and_hover(10) | ||
|
|
||
| # 5. 捕获初始图像 | ||
| simulator.capture_park_image() | ||
|
|
||
| # 6. 简单探索 | ||
| simulator.explore_park() | ||
|
|
||
| # 7. 降落 | ||
| simulator.cleanup() | ||
| except KeyboardInterrupt: | ||
| print("用户中断") | ||
| simulator.cleanup() | ||
| except Exception as e: | ||
| print(f"发生错误: {e}") | ||
| simulator.cleanup() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| @echo off | ||
| chcp 65001 > nul REM 支持 UTF-8 中文显示 | ||
| cls | ||
|
|
||
| echo ============================================ | ||
| echo 无人机视觉导航系统启动脚本 | ||
| echo ============================================ | ||
| echo. | ||
|
|
||
| :: 检查 Python 是否可用 | ||
| python --version > nul 2>&1 | ||
| if errorlevel 1 ( | ||
| echo ❌ Python 未安装或不在 PATH 中,请安装 Python 3.8 以上版本。 | ||
| pause | ||
| exit /b 1 | ||
| ) | ||
|
|
||
| :: 检查模拟器 | ||
| echo [1/4] 检查模拟器... | ||
| tasklist | findstr /i "AbandonedPark.exe" > nul | ||
| if errorlevel 1 ( | ||
| echo ⚠️ 未检测到 AbandonedPark.exe 进程。 | ||
| echo 请手动启动模拟器,然后按任意键继续... | ||
| pause > nul | ||
| ) else ( | ||
| echo ✓ 模拟器已在运行 | ||
| ) | ||
| echo. | ||
|
|
||
| :: 处理虚拟环境 | ||
| echo [2/4] 配置 Python 虚拟环境... | ||
| if exist "venv\Scripts\activate.bat" ( | ||
| call venv\Scripts\activate.bat | ||
| echo ✓ 虚拟环境已激活 | ||
| ) else ( | ||
| echo 正在创建虚拟环境... | ||
| python -m venv venv | ||
| if errorlevel 1 ( | ||
| echo ❌ 创建虚拟环境失败 | ||
| pause | ||
| exit /b 1 | ||
| ) | ||
| call venv\Scripts\activate.bat | ||
| echo 正在安装依赖(使用 requirements.txt)... | ||
| if exist requirements.txt ( | ||
| pip install -r requirements.txt | ||
| ) else ( | ||
| pip install airsim opencv-python numpy | ||
| ) | ||
| if errorlevel 1 ( | ||
| echo ❌ 依赖安装失败 | ||
| pause | ||
| exit /b 1 | ||
| ) | ||
| echo ✓ 依赖安装完成 | ||
| ) | ||
| echo. | ||
|
|
||
| :: 检查关键依赖 | ||
| echo [3/4] 验证依赖... | ||
| python -c "import airsim, cv2, numpy" 2>nul | ||
| if errorlevel 1 ( | ||
| echo ⚠️ 部分依赖未正确安装,尝试重新安装... | ||
| pip install --upgrade airsim opencv-python numpy | ||
| ) | ||
| echo ✓ 依赖验证通过 | ||
| echo. | ||
|
|
||
| :: 启动主程序 | ||
| echo [4/4] 启动导航系统... | ||
| set MAIN_SCRIPT=drone_vision_system_en.py | ||
| if not exist %MAIN_SCRIPT% ( | ||
| echo ❌ 找不到主程序文件: %MAIN_SCRIPT% | ||
| echo 请确认当前目录下存在该文件。 | ||
| pause | ||
| exit /b 1 | ||
| ) | ||
|
|
||
| python %MAIN_SCRIPT% | ||
| if errorlevel 1 ( | ||
| echo ❌ 程序运行出错,请查看上方日志。 | ||
| ) else ( | ||
| echo ✓ 程序正常结束 | ||
| ) | ||
|
|
||
| echo. | ||
| pause |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # 无人机导航系统配置文件 | ||
| mission: | ||
| default_time: 300 # 默认任务时长(秒) | ||
| takeoff_height: 15 # 起飞高度 | ||
| max_battery: 100.0 | ||
| low_battery_warning: 20 | ||
| critical_battery: 10 | ||
|
|
||
| navigation: | ||
| speeds: | ||
| ruins: 2.0 | ||
| building: 2.0 | ||
| forest: 1.5 | ||
| road: 3.0 | ||
| sky: 4.0 | ||
| water: 2.0 | ||
| fire: 5.0 | ||
| animal: 1.0 | ||
| vehicle: 2.0 | ||
| default: 1.0 | ||
|
|
||
| classifier: | ||
| # 可覆盖默认阈值 | ||
| thresholds: | ||
| fire_red: 0.25 | ||
| fire_bright: 200 | ||
| # ... 其他阈值 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
名字命名看不出含义