Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions docs/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ title: 效果展示
![前车切出遇静止车辆](img/scenario_cut_out.gif)
<div align="center"><i>cut_out(前车切出遇静止车辆)播放 6 秒:前车让出本车道 → 露出静止车 → 自车制动停车(红圈为静止车,黄圈为前车,10 帧;底部为口语输入与命中模板)</i></div>

![对向车借道侵入本车道](img/scenario_oncoming_intrusion.gif)
<div align="center"><i>oncoming_intrusion(对向车借道侵入本车道)播放 5 秒:对向车越线借道 → 自车制动 → 来车退回原车道(红圈为对向车,黄圈为慢车,11 帧;底部为口语输入与命中模板)</i></div>

![运行指标](img/scenario_run_metrics.gif)
<div align="center"><i>运行危险度指标:右上角实时显示自车速度、与行人距离与 TTC,末帧汇总碰撞/最小中心距/最小 TTC/最大减速度/末速</i></div>

Expand Down Expand Up @@ -104,3 +107,4 @@ title: 效果展示
| `low_overlap` | 3 | 4/4 | 0 |
| `unprotected_turn` | 3 | 4/4 | 0 |
| `cut_in` | 4 | 4/5 | 0 |
| `oncoming_intrusion` | 3 | 7/7 | 0 |
Binary file added docs/img/scenario_oncoming_intrusion.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions docs/new-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,95 @@ title: New Features

图片全部使用绝对链接。

---
## 2026-11 · 对向车借道侵入本车道场景

本版新增 `oncoming_intrusion` 模板:对向车道的来车借道超越慢车,越过中心线
迎面驶入本车道;自车制动,来车在临近时退回原车道。同时修正了播放器在
城市地图上的两处问题:变道前瞻点方向、车道识别偏移。

### 1. 用法

```text
对向车借道超车,越过中心线朝我迎面开过来
对面来车占了我的车道,只能紧急刹车
对向车跑到我车道上来了
```

语义层把 `对向车借道`、`越过中心线`、`迎面占道`、`占了我的车道`
等说法路由到该模板;与借道超车相关的输入若同时含"对向车"与"借道/占道"
额外加权,避免与自车借道超车的 `overtake_oncoming` 混淆。

```python
plan_scenario("对向车借道超车,越过中心线朝我迎面开过来")
# → {"template": "oncoming_intrusion", "confidence": 1.0, ...}
```

### 2. 场景编排

城市双向路上,自车 12 m/s,对向车道一辆 12 m/s 的来车跟在 6 m/s 慢车后方。
0.5 s 时来车越过中心线驶入本车道;自车在中心距 70 m 时线性制动,
来车在 45 m 时退回原车道并减速到 5 m/s。

| 时刻 | 事件 |
|---|---|
| 0 s | 自车 12 m/s、慢车 6 m/s、对向车 12 m/s 同时布景 |
| 0.5 s | 对向车越线借道,驶入本车道 |
| 距对向车 70 m | 自车线性制动 |
| 距对向车 45 m | 对向车退回原车道并减速 |
| 约 3.6 s | 自车停车,对向车恢复原车道行驶,无碰撞 |

参数:`s0`、`road_id`、`lane`、`ego_speed`、`slow_speed`、`slow_gap`、
`oncoming_speed`、`oncoming_gap`、`lc_delay`、`lc_time`、`brake_gap`、
`brake_time`、`abort_gap`、`abort_time`、`abort_speed`,均可通过
`params_json` 覆盖。

### 3. 城市路段

模板在 `Town03` 的 `road 67`、`s0=174` 处布景。该处向前约 136 m 为直线且
无路口,`lane -1` 与对向 `+1` 均存在:

```text
run_scenario_in_carla(template="oncoming_intrusion", map_name="Town03")
```

`+1` 与 `-1` 在 OpenDRIVE 中互为左邻车道,越线与退回都用 `delta=+1`。
退回动作必须晚于越线完成,否则车辆尚未跨过中心线,播放器会按当前车道
判定,把本车道再次当作目标车道;默认参数(`lc_delay=0.5`、`lc_time=1.2`、
`abort_gap=45`)满足该约束。

### 4. 播放器修正

- **变道前瞻方向**:新增 `look_back`。对向车向负 s 方向行驶时变道,前瞻点
必须用 `previous` 沿目标车道反向取;否则目标落在车后,纯追踪转向量恒为 0。
- **车道识别**:`Town03 road 67` 上 `get_waypoint(location)` 会把 `+1` 车道
中心识别为 `+2`,直接取它的左邻车道会指回本车道。现在按 `(road, s)` 处
各车道中心与车辆的实际距离重新判定(`_lane_at`)。

### 5. 效果

![对向车借道侵入本车道](img/scenario_oncoming_intrusion.gif)
<div align="center"><i>oncoming_intrusion:对向车越线借道 → 自车制动 → 来车退回原车道(红圈为对向车,黄圈为慢车,11 帧)</i></div>

### 6. 实测结果

| 项目 | 结果 |
|---|---|
| 离线回归(19 个模板) | 全部通过,3 实体 / 7 事件 |
| CARLA 实跑(Town03 `road 67`) | 7 个事件全部触发:0.45 s 越线、0.80 s 制动、1.70 s 退回 |
| 碰撞 | 无 |
| 最小中心距 | 3.27 m(t=4.65 s,对向车在旁车道通过) |
| 制动减速度 | 约 4.5 m/s²(10 m/s 经 2.2 s 线性刹停) |
| 自车末速 | 0.06 m/s(已停止) |
| 语义识别 | 3 条口语描述均命中 `oncoming_intrusion` |

### 7. 已知限制

- `s0=174` 与 `road_id=67` 针对 `Town03`,换地图需重新确认直线路段与车道号。
- 退回时按固定 `abort_time` 完成变道,不随相对速度自适应;
若把 `abort_gap` 调大到接近 `oncoming_gap`,退回会早于越线完成而失效。
- 城市路段不做路侧静态物的避让检查,调用方需自行避开停放车辆与路沿。

---

## 2026-11 · 前车切出遇静止车辆场景
Expand Down
51 changes: 50 additions & 1 deletion docs/scenario.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ graph LR
|---|---|---|---|
| `file_path` | string | 必填 | 待校验的 `.xosc` 文件 |

## 3. 18 个场景模板
## 3. 19 个场景模板

| 模板 | 场景含义 | 实体数 | 主要触发 |
|---|---|---|---|
Expand All @@ -54,6 +54,7 @@ graph LR
| `close_follow` | 近距跟驰(TTC 触发减速) | 2 | TTC |
| `overtake` | 超车(变道 + 相对速度) | 3 | 时间、距离、到达 |
| `overtake_oncoming` | 借道超车遇对向来车 | 3 | 时间、相对距离 |
| `oncoming_intrusion` | 对向车借道侵入本车道(需 Town03) | 3 | 时间、相对距离 |
| `evasive_swerve` | 紧急避让(轨迹跟随) | 3 | 时间 |
| `signal_phase` | 红绿灯相位(红灯等待→切绿→起步) | 2 | 信号灯、时间 |

Expand Down Expand Up @@ -158,6 +159,54 @@ run_scenario_in_carla(template="cut_out", map_name="Town10HD_Opt",
相对距离按两车中心点的直线距离计算,弯道会让"距离缩减"比沿路里程更慢,
因此城市路段应尽量平直;路段内的静态车辆、路侧停放物需要调用方自行避开。

### 3.4 对向车借道侵入本车道 `oncoming_intrusion`

城市双向路上,自车以 12 m/s 正常行驶;对向车道的来车以 12 m/s 跟在
6 m/s 的慢车后方,0.5 s 时越过中心线驶入本车道借道超车,形成迎面冲突。
自车在与来车中心距 70 m 时线性制动,来车在 45 m 时放弃借道、退回原车道
并在 2 s 内减到 5 m/s,自车停车,无碰撞。

```text
对向车借道超车,越过中心线朝我迎面开过来
对面来车占了我的车道,只能紧急刹车
对向车跑到我车道上来了
```

![对向车借道侵入本车道](img/scenario_oncoming_intrusion.gif)
<div align="center"><i>oncoming_intrusion:对向车越线借道 → 自车制动 → 来车退回原车道(红圈为对向车,黄圈为慢车,11 帧)</i></div>

| 参数 | 默认 | 说明 |
|---|---|---|
| `s0` | 174 m | 自车起点弧长(固定,对应 136 m 直线段起点) |
| `road_id` | `67` | Town03 上的城市双向路段 |
| `lane` | `-1` | 自车车道号,对向车道为 `+1` |
| `ego_speed` | 12 m/s | 自车速度 |
| `slow_speed` | 6 m/s | 对向车道慢车速度 |
| `slow_gap` | 45 m | 慢车与自车的初始距离 |
| `oncoming_speed` | 12 m/s | 借道车速度 |
| `oncoming_gap` | 95 m | 借道车与自车的初始距离 |
| `lc_delay` | 0.5 s | 借道车开始越线的时刻 |
| `lc_time` | 1.2 s | 越线变道持续时间 |
| `brake_gap` | 70 m | 自车开始制动的相对距离阈值 |
| `brake_time` | 2.5 s | 制动到停车的时间 |
| `abort_gap` | 45 m | 借道车退回原车道的相对距离阈值 |
| `abort_time` | 1.2 s | 退回变道持续时间 |
| `abort_speed` | 5 m/s | 退回后减到的速度 |

触发仍是**相对距离**:自车与 `oncoming` 的中心距小于 `brake_gap` 时自车
线性制动;小于 `abort_gap` 时 `oncoming` 退回 `+1` 车道并减速。`+1` 与 `-1`
在 OpenDRIVE 中互为左邻车道,因此越线与退回都用 `delta=+1`。退回必须晚于
越线完成(`abort_gap` 对应的时刻大于 `lc_delay + lc_time`),否则车辆尚未
跨过中心线,播放器会按当前车道判定,把本车道再次当作目标车道。

与 `overtake_oncoming` 的区别:那里借道的是自车,本模板借道的是对向车;
与 `wrong_way` 的区别:逆行是长时间占用本车道,本模板只演示借道超车时的
短时越线侵入,并带退回动作。

**城市路段**:模板在 `Town03` 的 `road 67`、`s0=174` 处布景,该处向前有
约 136 m 直线无路口,`lane -1` 与 `+1` 均存在。换用其他城市地图时需要
重新确认路段(左邻车道号、直线长度、路口位置)后覆盖 `road_id`/`s0`。

## 4. 对话示例

```text
Expand Down
Loading