Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3b871c6
使用DQN和PPO进行自动驾驶汽车导航
Sep 22, 2025
dfbad9d
Merge branch 'OpenHUTB:main' into main
Pan-j-l Oct 24, 2025
a12a0f6
上传我的主函数
Oct 24, 2025
212bda5
上传主函数
Oct 26, 2025
de3cd95
Merge branch 'OpenHUTB:main' into main
Pan-j-l Nov 11, 2025
6f77ded
写好了我的REANME
Nov 11, 2025
f9113fd
完成了本次作业,修改了些许代码中的错误
Nov 17, 2025
6f9f826
为黑白棋RL训练代码添加详细中文注释
Nov 24, 2025
db0de3c
Merge branch 'main' into main
Pan-j-l Nov 24, 2025
8a9642c
基于CARLA的多模态注意力DRL导航仿真
Nov 25, 2025
9385ab4
Merge branch 'OpenHUTB:main' into main
Pan-j-l Nov 25, 2025
0519aee
Merge branch 'main' of https://github.com/Pan-j-l/nn
Nov 25, 2025
7dedf5f
为主函数添加详细中文注释
Nov 26, 2025
abda7b9
修复车辆不动及轮胎晃动问题,优化图像处理
Nov 27, 2025
5fcecfa
Merge branch 'main' into main
Pan-j-l Nov 27, 2025
c7f2991
修复车辆不动及轮胎晃动问题,优化图像处理
Nov 28, 2025
ef62ae6
优化障碍物检测
Nov 29, 2025
455c84d
修复维度不匹配
Nov 30, 2025
76be5d1
实现镜头固定车辆正后方5m+上方2m实时跟随
Dec 1, 2025
e9a381d
优化自动驾驶避障与控制策略
Dec 4, 2025
f838a37
Merge branch 'main' into main
Pan-j-l Dec 4, 2025
cba166e
Merge branch 'OpenHUTB:main' into main
Pan-j-l Dec 10, 2025
e70d638
修复车辆生成位置固定问题,新增随机选点策略
Dec 10, 2025
28b7f05
Merge branch 'OpenHUTB:main' into main
Pan-j-l Dec 11, 2025
77b10db
Merge branch 'OpenHUTB:main' into main
Pan-j-l Dec 11, 2025
955d3ae
修复小车偏离车道/驶入草地问题,适配CARLA 0.9.11并优化控制逻辑
Dec 11, 2025
fa711ec
Merge branch 'OpenHUTB:main' into main
Pan-j-l Dec 12, 2025
23b0472
清除 CARLA 地图默认在车道上的静态车辆
Dec 12, 2025
1ba022b
Merge branch 'OpenHUTB:main' into main
Pan-j-l Dec 12, 2025
124def8
增加自动驾驶 NPC 车辆,提升自动驾驶场景难度
Dec 12, 2025
a14a67f
Merge branch 'OpenHUTB:main' into main
Pan-j-l Dec 14, 2025
30e96eb
增加环境难度(NPC 数量增至 60 辆)+ 提高主车辆行驶速度
Dec 14, 2025
3a255d2
Merge branch 'OpenHUTB:main' into main
Pan-j-l Dec 16, 2025
276ec63
优化镜头平滑跟随逻辑,消除抖动现象
Dec 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/self_driving_car_navigation/carla_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,13 @@ def _clear_all_non_ego_actors(self):
print(f"[清理] 车辆{cleared_count['vehicle']} | 自行车{cleared_count['bicycle']} | 静态车辆{cleared_count['static_vehicle']}")

def process_image(self, image):
"""处理摄像头数据"""
"""处理摄像头数据 - 修复frame属性访问问题"""
try:
# 检查是否为有效的图像对象
if not hasattr(image, 'raw_data') or not hasattr(image, 'height') or not hasattr(image, 'width'):
print("[图像处理错误] 无效的图像数据")
return

array = np.frombuffer(image.raw_data, dtype=np.uint8).reshape((image.height, image.width, 4))[:, :, :3]
array = array[:, :, ::-1].copy()
if self.image_queue.full():
Expand All @@ -231,8 +236,13 @@ def process_image(self, image):
print(f"[图像处理错误] {str(e)}")

def process_lidar(self, data):
"""处理激光雷达数据"""
"""处理激光雷达数据 - 修复frame属性访问问题"""
try:
# 检查是否为有效的激光雷达数据
if not hasattr(data, 'raw_data'):
print("[激光雷达处理错误] 无效的激光雷达数据")
return

points = np.frombuffer(data.raw_data, dtype=np.dtype('f4')).reshape(-1, 4)[:, :3]
distances = np.linalg.norm(points, axis=1)
angles = np.arctan2(points[:, 1], points[:, 0]) * 180 / np.pi
Expand All @@ -251,8 +261,13 @@ def process_lidar(self, data):
print(f"[激光雷达处理错误] {str(e)}")

def process_imu(self, data):
"""处理IMU数据"""
"""处理IMU数据 - 修复frame属性访问问题"""
try:
# 检查是否为有效的IMU数据
if not hasattr(data, 'accelerometer') or not hasattr(data, 'gyroscope'):
print("[IMU处理错误] 无效的IMU数据")
return

imu_data = np.array([
data.accelerometer.x, data.accelerometer.y, data.accelerometer.z,
data.gyroscope.x, data.gyroscope.y, data.gyroscope.z
Expand Down
17 changes: 16 additions & 1 deletion src/self_driving_car_navigation/run_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import sys
import pygame
import carla
import os
import sys

# 添加当前目录到Python路径,确保可以导入_agent模块
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

# 修正导入路径:适配_agent子目录下的carla_environment.py
# 从_agent子目录导入CarlaEnvironment
from _agent.carla_environment import CarlaEnvironment

print("="*60)
Expand Down Expand Up @@ -46,6 +51,9 @@ def lerp(a, b, t):
return smooth_tf

def run_simulation():
# 初始化pygame
pygame.init()

env = None
try:
print("\n[CARLA连接] 创建环境...")
Expand All @@ -71,6 +79,11 @@ def run_simulation():
# 持续运行仿真(不限制步数)
step = 0
while True:
# 处理pygame事件
for event in pygame.event.get():
if event.type == pygame.QUIT:
raise KeyboardInterrupt

# 同步CARLA帧(关键优化:保证控制时序稳定)
env.world.tick()

Expand Down Expand Up @@ -100,6 +113,8 @@ def run_simulation():
if env is not None:
print("\n[资源清理] 销毁资源...")
env.close()
# 退出pygame
pygame.quit()
print("\n[程序退出]")

if __name__ == "__main__":
Expand Down
Loading