Skip to content

Commit 55efc49

Browse files
authored
优化小车行为 (#5216)
* 完成选题,并提交readme文件 * 添加最小示例 * 将实例文件中的注释翻译成中文,方便他人学习 * 注册 Gym 环境 * 把CarlaEnv暴露出来,方便导入 * 初始化环境 * 依赖 * 安装脚本 * 优化小车动作 * 提供更为详细的说明
1 parent ea30a84 commit 55efc49

2 files changed

Lines changed: 31 additions & 16 deletions

File tree

src/carla_ad_gym_rl/easycarla_demo.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,9 @@
3535

3636
# 定义一个简单的动作策略
3737
def get_action(env, obs):
38-
"""随机选择简单的手动动作或自动驾驶动作。"""
39-
p = random.random()
40-
if p < 0.5:
41-
# 使用自动驾驶(专家模式)
42-
env.ego.set_autopilot(True)
43-
control = env.ego.get_control()
44-
action = [control.throttle, control.steer, control.brake]
45-
else:
46-
# 使用随机动作(新手模式)
47-
env.ego.set_autopilot(False)
48-
throttle = random.uniform(0.0, 1.0)
49-
steer = random.uniform(-0.6, 0.6)
50-
brake = random.uniform(0.0, 0.3)
51-
action = [throttle, steer, brake]
52-
return action
38+
env.ego.set_autopilot(True)
39+
control = env.ego.get_control()
40+
return [control.throttle, control.steer, control.brake]
5341

5442
# 与环境交互
5543
for episode in range(5): # 运行 5 个 episode

src/carla_ad_gym_rl/readme.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
本项目旨在为 CARLA 模拟器提供了一个轻便易用的兼容 Gym 的界面,专为强化学习(RL)应用量身定制。它集成了激光雷达扫描、车辆状态、附近车辆信息和航点等关键观察组件。环境支持安全意识学习,包括奖励和成本信号、路标可视化以及可定制参数,包括交通设置、车辆数量和传感器范围。
1+
本项目旨在为 CARLA 模拟器提供了一个轻便易用的兼容 Gym 的界面,专为强化学习(RL)应用量身定制。它集成了激光雷达扫描、车辆状态、附近车辆信息和航点等关键观察组件。环境支持安全意识学习,包括奖励和成本信号、路标可视化以及可定制参数,包括交通设置、车辆数量和传感器范围。
2+
3+
安装所需依赖:
4+
5+
```bash
6+
pip install -r requirements.txt
7+
```
8+
9+
将本项目作为本地 Python 包安装:
10+
11+
```bash
12+
pip install -e .
13+
```
14+
15+
## 快速开始
16+
17+
运行一个简单的演示,与环境进行交互:
18+
19+
```bash
20+
python easycarla_demo.py
21+
```
22+
23+
该脚本演示了如何:
24+
- 创建并重置环境
25+
- 选择自动驾驶动作
26+
- 在环境中逐步执行,并获取观测、奖励、代价以及结束信号
27+
28+
在运行该演示之前,请确保你的 CARLA 服务端已经启动。

0 commit comments

Comments
 (0)