Repository navigation
提交选题 #3549
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
Closed
Closed
提交选题 #3549
Changes from all commits
Commits
Show all changes
441 commits
Select commit
Hold shift + click to select a range
7d511fe
Merge branch 'main' of https://github.com/haoliuaa/nn
haoliuaa 394e9de
Update maze.py
explorer1009 85e5948
Merge branch 'drone_233' of https://github.com/explorer1009/nn233 int…
explorer1009 786d740
Merge branch 'OpenHUTB:main' into main
is-leplus da0e96f
Merge branch 'main' into drone_233
explorer1009 74878c0
新增了 ROSManager 类,将 ROS 功能封装为独立模块
Vortex444 191005d
新增了 ROSManager 类,将 ROS 功能封装为独立模块
Vortex444 90117c5
Merge branch 'OpenHUTB:main' into mujoco
Vortex444 7c45df1
Merge branch 'mujoco' of https://github.com/Vortex444/nn into mujoco
Vortex444 bd0818a
Update README.md
explorer1009 5926a64
Merge branch 'drone_233' of https://github.com/explorer1009/nn233 int…
explorer1009 39b6d3e
修改main.py:添加了ppo算法初试机器人行走
blank885 62cb187
解决main.py合并冲突
blank885 e5e9900
提交感知模块和控制模块ros封装
Vortex444 dc20865
Merge branch 'OpenHUTB:main' into mujoco
Vortex444 6bfa5b9
update
blank885 be42974
Merge branch 'OpenHUTB:main' into main
blank885 7cf2818
Merge branch 'OpenHUTB:main' into main
blank885 c1d0623
Merge branch 'OpenHUTB:main' into mujoco
Vortex444 8f1bc5d
添加 mujoco_ros 相关启动/脚本文件,添加控制和感知模块
Vortex444 3d0450d
Merge branch 'mujoco' of https://github.com/Vortex444/nn into mujoco
Vortex444 a96c786
提交选题
fcb6f3b
Merge branch 'OpenHUTB:main' into main
joe-justin369 a8473e2
feat: 优化ROS关节状态发布逻辑,支持多自由度关节
Vortex444 4f39239
Merge branch 'OpenHUTB:main' into main
is-leplus 3456741
删除提交的感知模块的临时文件
Vortex444 ab47944
Merge branch 'mujoco' of https://github.com/Vortex444/nn into mujoco
Vortex444 eb7efb1
删除提交的感知模块的临时文件
Vortex444 b11f752
feat: 优化ROS关节状态发布逻辑,支持多自由度关节
Vortex444 989791c
Add files via upload
is-leplus a9fdf8d
Merge branch 'OpenHUTB:main' into main
Liu-Kui111 c3a15c3
Merge branch 'OpenHUTB:main' into main
yishikaka 4efe171
Merge branch 'OpenHUTB:main' into main
haoliuaa e57010e
打开摄像头,录入并保存人脸及名字,放入数据集
e904f6d
Merge branch 'OpenHUTB:main' into main
Liu-Kui111 d7bd135
第一次运行成功
wuuu0236 d0ffb7a
改进无人机寻路策略
explorer1009 3c881c1
Merge branch 'OpenHUTB:main' into main
is-leplus 547ad3f
Merge branch 'OpenHUTB:main' into main
haoliuaa 3d6ed72
更新README.md文件
haoliuaa fb1f551
Merge branch 'main' of https://github.com/haoliuaa/nn
haoliuaa 09aeed3
Add files via upload
is-leplus 895adb5
Merge branch 'OpenHUTB:main' into main
is-leplus 7dd7143
Merge branch 'OpenHUTB:main' into main
is-leplus 54e1843
Merge branch 'OpenHUTB:main' into main
is-leplus a6e98a0
Merge branch 'main' into drone_233
explorer1009 556825a
Add files via upload
is-leplus bf06da2
新增ros感知模块和控制模块文件
Vortex444 01141b6
Merge branch 'OpenHUTB:main' into main
haoliuaa fb36a8d
解决行人避障问题,同时保持车辆沿道路行驶
joe-justin369 1552a88
添加了语音功能,实现了五个功能
896cece
Merge branch 'OpenHUTB:main' into main
Liu-Kui111 1e4a806
Merge branch 'OpenHUTB:main' into main
is-leplus e5faaee
Delete src/image_object_detection/main.py
is-leplus cbe3f1f
Delete src/image_object_detection/requirements.txt
is-leplus 4408689
优化visualize命令模型路径处理+通用化参数提示
Vortex444 3aa92a6
Merge branch 'main' into mujoco
Vortex444 de9a2d2
Add files via upload
is-leplus fa4bcfb
Merge branch 'OpenHUTB:main' into main
is-leplus 0c432cd
Delete src/image_object_detection/requirements.txt
is-leplus d46dbef
Add files via upload
is-leplus 7baa719
Add files via upload
is-leplus e2c38ed
Update detection_engine.py
is-leplus 43271ab
Update image_detector.py
is-leplus 13fa00c
Create camera_detector.py
is-leplus eb731ee
Update README.md
explorer1009 d58bb2c
Merge branch 'drone_233' of https://github.com/explorer1009/nn233 int…
explorer1009 661dd1f
Merge branch 'OpenHUTB:main' into main
joe-justin369 7c9a687
新增 DoubleDQN 训练与评估脚本
GODDDDD22311 ac4480a
算法优化:新增Dueling DQN架构和优先经验回放
joe-justin369 7aece60
Unitree h1模型文件
blank885 b9b614a
Merge branch 'OpenHUTB:main' into main
yishikaka 8588830
Merge branch 'OpenHUTB:main' into main
yishikaka c136006
增加自动查找路径模型功能
joe-justin369 f12fb41
Merge branch 'OpenHUTB:main' into main
is-leplus b4b5c8c
Merge branch 'OpenHUTB:main' into main
blank885 a7a3d2e
更换了模型,修改代码对应模型
yishikaka 3b751b6
新增强化学习策略控制功能到MuJoCo可视化工具
Vortex444 e4221ba
Merge branch 'OpenHUTB:main' into main
joe-justin369 15ce163
新增强化学习策略控制功能到MuJoCo可视化工具
Vortex444 77de327
课程学习增强、模仿学习预训练和多目标优化
joe-justin369 2f9b8c3
Merge branch 'main' into mujoco
Vortex444 aa62abc
Merge branch 'OpenHUTB:main' into main
haoliuaa 9a3a122
Merge branch 'OpenHUTB:main' into main
joe-justin369 249cca9
修改了README.md文件,新增一些修改过的内容
Vortex444 472169b
Merge branch 'mujoco' of https://github.com/Vortex444/nn into mujoco
Vortex444 03d529a
将模型调用路径,全更改为相对路径
joe-justin369 20fd735
Merge branch 'OpenHUTB:main' into mujoco
Vortex444 06b2e2c
添加了double_action文件,实现Unitree h1的'walk+squrt'结合
blank885 e5ebbf5
Merge branch 'OpenHUTB:main' into main
yishikaka aa5b42a
Merge branch 'OpenHUTB:main' into main
is-leplus a85a0bd
Update camera_detector.py
is-leplus 4391724
Merge branch 'OpenHUTB:main' into main
yishikaka 99db513
增加了简单步行的代码。附带g1所需的环境建模文件
yishikaka 8122294
添加一个重要注释在策略指令映射的核心行
Vortex444 ab7ac5d
Merge branch 'mujoco' of https://github.com/Vortex444/nn into mujoco
Vortex444 230d011
Merge branch 'OpenHUTB:main' into mujoco
Vortex444 b2ee661
Merge branch 'OpenHUTB:main' into main
is-leplus 4ec40e1
Update main.py
is-leplus 93f4da1
Update image_detector.py
is-leplus 2e4d4a8
Update camera_detector.py
is-leplus 950cf9f
Update ui_handler.py
is-leplus 3518c7d
Merge branch 'OpenHUTB:main' into main
joe-justin369 ab496dc
Merge branch 'OpenHUTB:main' into mujoco
Vortex444 3c130a4
代码结构调整
joe-justin369 bdbb63b
Merge branch 'OpenHUTB:main' into main
is-leplus b243166
优化策略推理性能和修复可视化缩进冲突
Vortex444 5787d09
Merge branch 'mujoco' of https://github.com/Vortex444/nn into mujoco
Vortex444 6265431
Merge branch 'main' into mujoco
Vortex444 5f1dd55
Merge branch 'OpenHUTB:main' into main
is-leplus 17e7d7e
Update ui_handler.py
is-leplus bb78522
Update config.py
is-leplus 379a04e
深度强化学习无人机迷宫寻路系统
explorer1009 c685984
更新README文件
explorer1009 90f333c
Merge branch 'main' into drone_233
explorer1009 6555093
Merge branch 'OpenHUTB:main' into main
joe-justin369 21f7ed8
Merge branch 'OpenHUTB:main' into main
is-leplus 2b95981
Update requirements.txt
is-leplus 6d50853
Update README.md
is-leplus 7b84c37
Merge branch 'OpenHUTB:main' into main
is-leplus f20ce24
Merge branch 'OpenHUTB:main' into main
Liu-Kui111 bb4498c
Merge branch 'OpenHUTB:main' into main
is-leplus b18cb55
实现了无人机“视频帧 + 半透明地图 + 位置标记” 的可视化效果
4b9fb1d
Update main.py
is-leplus ba25df3
Merge branch 'OpenHUTB:main' into main
joe-justin369 2887a46
代码优化改进
joe-justin369 ee4088e
Merge branch 'OpenHUTB:main' into main
blank885 726566c
优化test_speed内存占用
Vortex444 809388a
Merge branch 'OpenHUTB:main' into mujoco
Vortex444 e243bf6
Merge branch 'mujoco' of https://github.com/Vortex444/nn into mujoco
Vortex444 07e62b7
新增 DQN vs Double DQN 回报对比绘图脚本
GODDDDD22311 9b86796
Merge branch 'OpenHUTB:main' into main
wuuu0236 d1a6894
实现了无人机模拟以及相关功能
e9793a1
写了一个README.md
dacun922 2ac1cf8
增加迷宫终点判定
explorer1009 e4d985d
Merge branch 'main' into drone_233
explorer1009 f2d238f
fix(main.py): 修复common模块导入问题,适配绝对路径
dacun922 24d1be7
Add files via upload
wuuu0236 b4e3547
Update carla_env_multi_obs.py
wuuu0236 aeb39d0
Merge branch 'OpenHUTB:main' into main
Liu-Kui111 e60416b
Merge branch 'OpenHUTB:main' into main
is-leplus 45fee93
Update ui_handler.py
is-leplus eed7876
Merge branch 'OpenHUTB:main' into main
is-leplus cef07c1
无人机检测模块
7ca8da5
Merge branch 'OpenHUTB:main' into main
Liu-Kui111 74fa0ec
Merge branch 'OpenHUTB:main' into main
is-leplus 664ed4b
Merge branch 'OpenHUTB:main' into main
yishikaka e39a431
Merge branch 'OpenHUTB:main' into main
joe-justin369 af37d64
Merge branch 'OpenHUTB:main' into main
yishikaka f31ffea
优化了机器人的稳定性
yishikaka f61d2bb
Merge branch 'OpenHUTB:main' into main
joe-justin369 9b53a4b
提高小车对障碍物和行人的反应速度
joe-justin369 697f301
创建调参工具tuner.py
abc123335 5bc6c57
Merge branch 'main' of https://github.com/abc123335/nn
abc123335 37e4246
Merge branch 'OpenHUTB:main' into main
haoliuaa 7f1b657
优化脚本文件,增添其他元素
haoliuaa b770dc6
Merge branch 'main' of https://github.com/haoliuaa/nn
haoliuaa fabe028
补充学校仓库根目录缺失文件
haoliuaa 93cb346
Merge pull request #3462 from haoliuaa/main
William4861 dbe9086
Revert "更新README.md并修复文件位置错放问题"
William4861 2d62e96
Merge branch 'OpenHUTB:main' into main
yishikaka 998adfe
Merge pull request #3463 from OpenHUTB/revert-3451-main
timetravler123 37a687d
Merge branch 'OpenHUTB:main' into main
abc123335 cb4b241
Merge pull request #3466 from abc123335/main
timetravler123 61c73da
feat: 提交仿人手臂MuJoCo仿真模型
HuangJinjie2887 946cb45
增加计算服务脚本
haoliuaa 4ab01bb
Merge branch 'main' of https://github.com/haoliuaa/nn
haoliuaa 0ca829e
Merge branch 'OpenHUTB:main' into main
haoliuaa 83e571d
Merge remote-tracking branch 'upstream/main'
HuangJinjie2887 2123767
DQN 与 DoubleDQN 的评估与对比脚本(支持录制评估视频)
GODDDDD22311 645434c
Merge branch 'OpenHUTB:main' into main
blank885 3df2817
路径更改e
GODDDDD22311 6649dba
Merge pull request #3467 from haoliuaa/main
William4861 159c3f3
Merge branch 'OpenHUTB:main' into main
Liu-Kui111 5c4b152
Merge pull request #3470 from HuangJinjie2887/main
William4861 113aefa
Merge branch 'OpenHUTB:main' into main
Liu-Kui111 0b31c76
Merge pull request #3471 from GODDDDD22311/main
William4861 3d82d97
Merge pull request #3408 from wuuu0236/main
timetravler123 b2d619c
Merge branch 'OpenHUTB:main' into main
Liu-Kui111 1d9c562
Merge pull request #3420 from explorer1009/drone_233
timetravler123 f173b62
Merge pull request #3421 from dacun922/fix-main-py-import
timetravler123 10d4acf
Merge branch 'OpenHUTB:main' into main
blank885 15e3c28
Merge branch 'OpenHUTB:main' into LiuKui222
Liu-Kui111 415c8c3
更新了double_action文件效果并附上运行视频
blank885 7951d99
Merge pull request #3449 from yishikaka/main
timetravler123 a8ac78c
Merge pull request #3472 from Liu-Kui111/LiuKui222
William4861 9c43812
提交选题:机械臂
f813eaf
Merge pull request #3473 from blank885/main
timetravler123 31a78fb
添加配置文件 (#3410)
lbxlb 886ef79
requirements修改
joe-justin369 bafae9b
optimize(main.py): 轻量化优化+友好提示+资源安全释放
dacun922 cbb9cb5
Merge pull request #3477 from joe-justin369/main
timetravler123 0ce7c8a
Merge pull request #3475 from lijinghan12/main
timetravler123 fa889f7
更新脚本文件
haoliuaa c66342d
Merge branch 'main' of https://github.com/haoliuaa/nn
haoliuaa 2c616bf
Merge branch 'OpenHUTB:main' into main
haoliuaa d3a08b3
Merge pull request #3414 from Vortex444/mujoco
timetravler123 ec9c6d9
Merge pull request #3479 from haoliuaa/main
timetravler123 2190b76
在环境中加入了不同的天气 (#3411)
timetravler123 451fee1
图像分割 (#3422)
MKHQ07 54fd893
Merge pull request #3478 from dacun922/optimize-main-py-lightweight
timetravler123 dea7f5d
554455 (#3423)
shengzhanpeng 6d2a048
优化 plan_path_cb 方法,提升可维护性 (#3424)
dream1112221 31a0bda
添加 MoBL ARMS 上肢模型 (#3426)
Xinyue-cao df09b5b
update ros2 node (#3427)
Heyh003 17a7b33
更新requirement (#3428)
ly28266 3674870
为ui_handler模块完善注释说明交互逻辑 (#3430)
is-leplus f109c36
向readme文件中添加了从天地图获取高精度卫星图作为底图来辅助roadrunner建图的方法 (#3431)
2382613701lzy-netizen 50a61df
Merge branch 'OpenHUTB:main' into main
is-leplus 377407b
README (#3432)
yuboyyy bf60306
Update config.py
is-leplus db60325
Merge branch 'OpenHUTB:main' into main
is-leplus 01f4950
新增配置管理模块和日志模块 进行模块化重构 (#3435)
Z-w-7799 f159124
Merge branch 'OpenHUTB:main' into main
is-leplus 3a382bb
删除大写文件夹 (#3436)
pppzzz222 94b0f14
Merge branch 'OpenHUTB:main' into main
is-leplus 0b00622
车辆检测 (#3437)
aasdar 8214298
新添了分类模块,以及初步训练程序 (#3439)
Arrebol01 c3f67a5
将 BeatSVR 双手协同评估流程统一至单一入口脚本 main.py,同时修正了之前视频打不开的问题 (#3440)
sda-57 35e81fd
实现主车辆沿道路行驶、生成 NPC 车辆互动及相机图像显示功能 (#3441)
YDY027 74735b5
车辆检测(添加模型训练代码) (#3443)
aasdar 018e8e3
无人机导航系统 (#3444)
725921 34077ef
Merge pull request #3486 from is-leplus/main
William4861 adc6172
适配虚拟机环境,提升鲁棒性 (#3480)
dacun922 2e5d020
无人机追踪检测识别人脸及人体 (#3481)
Liu-Kui111 ecebb6d
抓取动作的实现 (#3482)
longzhongliang 518af9d
增添检查文件 (#3483)
haoliuaa 63ff91d
为locomujoco项目创建随机环境 (#3487)
Heyh003 cce3b3b
Update image_detector.py (#3495)
is-leplus 57e3e2b
车辆检测 (#3497)
aasdar 924257b
更新main.py文件错误处理增强 + 配置常量化 (#3500)
ly28266 1978aca
代码所需要的所有依赖 (#3501)
GODDDDD22311 fb7e680
更改了文件结构,使目录更清晰 (#3502)
manayume 18e5b41
Update train_agent.py (#3503)
wuuu0236 fbdc417
添加了double_action.py第2版,实现‘squat+dance’结合 (#3504)
blank885 5680670
优化小车被npc卡住问题 (#3507)
cljrobot 2db6873
detection_engine模块注释完善与静默推理说明 (#3508)
is-leplus c991f98
为locomujoco环境添加观测空间 (#3509)
Heyh003 52d8440
新添学习增强的手势识别程序,并修改了主程序 (#3512)
Arrebol01 0ea5212
添加模型文件 (#3513)
lbxlb 90dfafa
无人机导航系统 (#3514)
725921 4bfc277
每次运行代码,清除前段代码产生的汽车 (#3517)
wuuu0236 75abb4c
camera_detector模块注释完善与实时检测逻辑说明 (#3518)
is-leplus 71f51c6
修复了无法生成行人的错误 (#3519)
manayume 761a97b
删除了重复的 apply_obstacle_avoidance 方法定义 (#3520)
cljrobot 1a5bde7
项目配置工具核心检测等模块 (#3521)
heeyusike 2308a3d
新增了自动标注系统和数据验证系统 (#3522)
Z-w-7799 3f1eac9
小车落点位置优化 (#3526)
wutong88yuyu 09d91f7
提交选题
liuxudong12 3f51174
Merge pull request #1 from liuxudong12/car
liuxudong12 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,48 @@ | ||
| # 神经网络实现代理 | ||
|
|
||
| 利用神经网络/ROS 实现 Carla(车辆、行人的感知、规划、控制)、AirSim、Mujoco 中人和载具的代理。 | ||
|
|
||
| ## 环境配置 | ||
|
|
||
| * 平台:Windows 10/11,Ubuntu 20.04/22.04 | ||
| * 软件:Python 3.7-3.12(需支持3.7)、Pytorch(尽量不使用Tensorflow) | ||
| * 相关软件下载 [链接](https://pan.baidu.com/s/1IFhCd8X9lI24oeYQm5-Edw?pwd=hutb) | ||
|
|
||
|
|
||
| ## 贡献指南 | ||
|
|
||
| 准备提交代码之前,请阅读 [贡献指南](https://github.com/OpenHUTB/.github/blob/master/CONTRIBUTING.md) 。 | ||
| 代码的优化包括:注释、[PEP 8 风格调整](https://peps.pythonlang.cn/pep-0008/) 、将神经网络应用到Carla模拟器中、撰写对应 [文档](https://openhutb.github.io/nn/) 、添加 [源代码对应的自动化测试](https://docs.github.com/zh/actions/use-cases-and-examples/building-and-testing/building-and-testing-python) 等(从Carla场景中获取神经网络所需数据或将神经网络的结果输出到场景中)。 | ||
|
|
||
| ### 约定 | ||
|
|
||
| * 每个模块位于`src/{模块名}`目录下,`模块名`需要用2-3个单词表示,首字母不需要大写,下划线`_`分隔,不能宽泛,越具体越好 | ||
| * 每个模块的入口须为`main.`开头,比如:main.py、main.cpp、main.bat、main.sh等,提供的ROS功能以`main.launch`文件作为启动配置文件 | ||
| * 每次pull request都需要保证能够通过main脚本直接运行整个模块,在提交信息中提供运行动图或截图;Pull Request的标题不能随意,需要概括具体的修改内容;README.md文档中提供运行环境和运行步骤的说明 | ||
| * 仓库尽量保存文本文件,二进制文件需要慎重,如运行需要示例数据,可以保存少量数据,大量数据可以通过提供网盘链接并说明下载链接和运行说明 | ||
|
|
||
|
|
||
| ### 文档生成 | ||
|
|
||
| 测试生成的文档: | ||
| 1. 安装python 3.11,并使用以下命令安装`mkdocs`和相关依赖: | ||
| ```shell | ||
| pip install mkdocs -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com | ||
| pip install -r requirements.txt | ||
| ``` | ||
| (可选)安装完成后使用`mkdocs --version`查看是否安装成功。 | ||
|
|
||
| 2. 在命令行中进入`nn`目录下,运行: | ||
| ```shell | ||
| mkdocs build | ||
| mkdocs serve | ||
| ``` | ||
| 然后使用浏览器打开 [http://127.0.0.1:8000](http://127.0.0.1:8000),查看文档页面能否正常显示。 | ||
|
|
||
| ## 参考 | ||
|
|
||
| * [代理模拟器文档](https://openhutb.github.io) | ||
| * 已有相关 [无人车](https://openhutb.github.io/doc/used_by/) 、[无人机](https://openhutb.github.io/air_doc/third/used_by/) 、[具身人](https://openhutb.github.io/doc/pedestrian/humanoid/) 的实现 | ||
| * [神经网络原理](https://github.com/OpenHUTB/neuro) | ||
|
|
||
|
|
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,5 @@ | ||
| python-markdown-math | ||
| imageio | ||
| numpy | ||
| matplotlib | ||
| tensorflow |
258 changes: 258 additions & 0 deletions
258
src/AI_Drone_Face_Recognition_Human_Tracking/detection_module.py
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,258 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| 无人机检测模块 | ||
| 功能: | ||
| 1. 独立运行:模拟检测无人机状态、环境障碍物 | ||
| 2. 被主程序导入:提供检测接口,返回预警信息 | ||
| """ | ||
| import numpy as np | ||
| import random | ||
| from enum import Enum | ||
| import time | ||
|
|
||
|
|
||
| # ===================== 检测类型枚举(便于主程序调用) ===================== | ||
| class DetectionType(Enum): | ||
| OBSTACLE = "障碍物检测" | ||
| BATTERY = "电量检测" | ||
| POSITION = "位置检测" | ||
| COLLISION = "碰撞预警" | ||
| STATE = "状态检测" | ||
|
|
||
|
|
||
| # ===================== 核心检测类 ===================== | ||
| class DroneDetection: | ||
| def __init__(self, drone=None): | ||
| """ | ||
| 初始化检测模块 | ||
| :param drone: 可选,传入虚拟无人机对象(主程序调用时传) | ||
| """ | ||
| self.drone = drone # 关联无人机对象 | ||
| self.obstacle_list = self._generate_obstacles() # 生成模拟障碍物 | ||
| self.warning_threshold = { | ||
| "battery": 20.0, # 电量预警阈值(%) | ||
| "height": 0.5, # 高度过低预警阈值(m) | ||
| "distance": 1.0 # 障碍物距离预警阈值(m) | ||
| } | ||
|
|
||
| def _generate_obstacles(self): | ||
| """生成模拟环境障碍物(随机坐标)""" | ||
| obstacles = [] | ||
| for _ in range(10): # 生成10个随机障碍物 | ||
| x = random.uniform(-10, 10) | ||
| y = random.uniform(-10, 10) | ||
| z = random.uniform(0, 8) | ||
| obstacles.append(np.array([x, y, z])) | ||
| return obstacles | ||
|
|
||
| def detect_obstacle(self): | ||
| """ | ||
| 障碍物检测:计算无人机与最近障碍物的距离 | ||
| :return: dict - 检测结果(距离、是否预警、最近障碍物坐标) | ||
| """ | ||
| if self.drone is None: | ||
| return { | ||
| "type": DetectionType.OBSTACLE.value, | ||
| "status": "未关联无人机", | ||
| "distance": None, | ||
| "warning": False, | ||
| "nearest_obstacle": None | ||
| } | ||
|
|
||
| # 计算无人机与每个障碍物的欧氏距离 | ||
| drone_pos = self.drone.position | ||
| distances = [np.linalg.norm(drone_pos - obs) for obs in self.obstacle_list] | ||
| min_distance = min(distances) | ||
| nearest_idx = np.argmin(distances) | ||
| nearest_obs = self.obstacle_list[nearest_idx] | ||
|
|
||
| # 判断是否触发预警 | ||
| warning = min_distance < self.warning_threshold["distance"] | ||
|
|
||
| return { | ||
| "type": DetectionType.OBSTACLE.value, | ||
| "status": "检测完成", | ||
| "distance": round(min_distance, 2), | ||
| "warning": warning, | ||
| "nearest_obstacle": nearest_obs.round(2), | ||
| "message": f"⚠️ 距离障碍物仅{min_distance:.2f}m,请注意避让!" if warning else "✅ 无障碍物风险" | ||
| } | ||
|
|
||
| def detect_battery(self): | ||
| """ | ||
| 电量检测:判断是否低于预警阈值 | ||
| :return: dict - 检测结果 | ||
| """ | ||
| if self.drone is None: | ||
| return { | ||
| "type": DetectionType.BATTERY.value, | ||
| "status": "未关联无人机", | ||
| "battery": None, | ||
| "warning": False, | ||
| "message": "未关联无人机,无法检测电量" | ||
| } | ||
|
|
||
| battery = self.drone.battery | ||
| warning = battery < self.warning_threshold["battery"] | ||
|
|
||
| return { | ||
| "type": DetectionType.BATTERY.value, | ||
| "status": "检测完成", | ||
| "battery": round(battery, 2), | ||
| "warning": warning, | ||
| "message": f"⚠️ 电量低({battery:.1f}%),请尽快返航!" if warning else f"✅ 电量充足({battery:.1f}%)" | ||
| } | ||
|
|
||
| def detect_position(self): | ||
| """ | ||
| 位置检测:判断高度是否过低/超出边界 | ||
| :return: dict - 检测结果 | ||
| """ | ||
| if self.drone is None: | ||
| return { | ||
| "type": DetectionType.POSITION.value, | ||
| "status": "未关联无人机", | ||
| "position": None, | ||
| "warning": False, | ||
| "message": "未关联无人机,无法检测位置" | ||
| } | ||
|
|
||
| pos = self.drone.position | ||
| # 兼容主程序枚举状态和独立运行字符串状态 | ||
| drone_state = self.drone.state.value if hasattr(self.drone.state, "value") else self.drone.state | ||
| height_warning = pos[2] < self.warning_threshold["height"] and drone_state == "FLYING" | ||
| boundary_warning = abs(pos[0]) > 15 or abs(pos[1]) > 15 # 水平边界±15m | ||
|
|
||
| warning = height_warning or boundary_warning | ||
| messages = [] | ||
| if height_warning: | ||
| messages.append(f"⚠️ 飞行高度过低({pos[2]:.1f}m),请注意!") | ||
| if boundary_warning: | ||
| messages.append(f"⚠️ 超出安全边界(坐标:{pos[:2].round(1)}),请返航!") | ||
| if not warning: | ||
| messages.append(f"✅ 位置正常({pos.round(1)})") | ||
|
|
||
| return { | ||
| "type": DetectionType.POSITION.value, | ||
| "status": "检测完成", | ||
| "position": pos.round(2), | ||
| "warning": warning, | ||
| "message": " | ".join(messages) | ||
| } | ||
|
|
||
| def detect_collision(self): | ||
| """ | ||
| 碰撞预警:预测未来1秒是否有碰撞风险 | ||
| :return: dict - 检测结果 | ||
| """ | ||
| if self.drone is None: | ||
| return { | ||
| "type": DetectionType.COLLISION.value, | ||
| "status": "未关联无人机", | ||
| "risk": False, | ||
| "message": "未关联无人机,无法预测碰撞风险" | ||
| } | ||
|
|
||
| # 预测1秒后无人机位置(基于当前速度) | ||
| future_pos = self.drone.position + self.drone.velocity * 1.0 | ||
| # 计算与障碍物的距离 | ||
| distances = [np.linalg.norm(future_pos - obs) for obs in self.obstacle_list] | ||
| min_future_dist = min(distances) | ||
| risk = min_future_dist < 0.5 # 距离<0.5m判定为碰撞风险 | ||
|
|
||
| return { | ||
| "type": DetectionType.COLLISION.value, | ||
| "status": "检测完成", | ||
| "risk": risk, | ||
| "future_position": future_pos.round(2), | ||
| "message": "🚨 1秒后有碰撞风险!请立即调整方向!" if risk else "✅ 无碰撞风险" | ||
| } | ||
|
|
||
| def detect_state(self): | ||
| """ | ||
| 状态检测:判断无人机当前状态是否正常 | ||
| :return: dict - 检测结果 | ||
| """ | ||
| if self.drone is None: | ||
| return { | ||
| "type": DetectionType.STATE.value, | ||
| "status": "未关联无人机", | ||
| "drone_state": None, | ||
| "message": "未关联无人机,无法检测状态" | ||
| } | ||
|
|
||
| # 兼容主程序枚举状态(DroneState)和独立运行字符串状态 | ||
| state = self.drone.state.value if hasattr(self.drone.state, "value") else self.drone.state | ||
| if state == "LANDED": | ||
| message = "✅ 无人机处于落地状态,状态正常" | ||
| elif state == "FLYING" and self.drone.battery > 10: | ||
| message = "✅ 无人机处于飞行状态,状态正常" | ||
| else: | ||
| message = f"⚠️ 无人机飞行状态异常(电量{self.drone.battery:.1f}%)" | ||
|
|
||
| return { | ||
| "type": DetectionType.STATE.value, | ||
| "status": "检测完成", | ||
| "drone_state": state, | ||
| "warning": state == "FLYING" and self.drone.battery <= 10, | ||
| "message": message | ||
| } | ||
|
|
||
| def full_detection(self): | ||
| """ | ||
| 全量检测:执行所有检测项 | ||
| :return: list - 所有检测结果 | ||
| """ | ||
| results = [ | ||
| self.detect_state(), | ||
| self.detect_battery(), | ||
| self.detect_position(), | ||
| self.detect_obstacle(), | ||
| self.detect_collision() | ||
| ] | ||
| return results | ||
|
|
||
|
|
||
| # ===================== 独立运行测试代码 ===================== | ||
| def main(): | ||
| """模块独立运行时的测试逻辑""" | ||
| print("=" * 60) | ||
| print("📊 无人机检测模块 - 独立测试模式") | ||
| print("=" * 60) | ||
|
|
||
| # 模拟无人机对象(独立运行时使用,简化状态为字符串,避免枚举类错误) | ||
| class MockDrone: | ||
| def __init__(self): | ||
| self.position = np.array([2.0, 1.5, 1.0]) # 模拟位置 | ||
| self.velocity = np.array([0.8, 0.5, 0.0]) # 模拟速度 | ||
| self.state = "FLYING" # 直接用字符串标识状态,替代枚举类 | ||
| self.battery = 18.5 # 模拟电量 | ||
|
|
||
| # 初始化检测模块 | ||
| mock_drone = MockDrone() | ||
| detector = DroneDetection(drone=mock_drone) | ||
|
|
||
| # 循环检测(模拟实时监测) | ||
| try: | ||
| while True: | ||
| print(f"\n⏰ 检测时间:{time.strftime('%Y-%m-%d %H:%M:%S')}") | ||
| # 执行全量检测 | ||
| all_results = detector.full_detection() | ||
| for res in all_results: | ||
| print(f"[{res['type']}] {res['message']}") | ||
|
|
||
| # 模拟无人机位置变化 | ||
| mock_drone.position += mock_drone.velocity * 0.5 | ||
| mock_drone.battery -= 0.5 # 模拟电量消耗 | ||
| # 模拟飞行状态切换(每10秒落地一次) | ||
| if mock_drone.battery < 10: | ||
| mock_drone.state = "LANDED" | ||
| time.sleep(2) # 每2秒检测一次 | ||
|
|
||
| except KeyboardInterrupt: | ||
| print("\n\n🛑 检测模块独立测试已停止") | ||
|
|
||
|
|
||
| # 仅当模块独立运行时执行测试 | ||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
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.
该文件不在模块内