create-scenario
它能做什么
这项技能为 CARLA 模拟器编写新的驾驶测试场景,包括其中的角色、行为和通过标准。适合为自动驾驶软件构建自定义测试的开发者。
适用场景
- ✓当你想设计一个测试,让汽车处理特定的道路情况时。
- ✓当你需要一个测试运行器能按名称找到并运行的场景文件时。
- ✓当你想在模拟器上运行之前,检查新场景是否有错误时。
技能链接
https://github.com/carla-simulator/carla/blob/ue58-dev/Skills/scenario-runner/create-scenario/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能编写一个新的 CARLA 测试,让另一辆车突然从我车前切入,并检查它能否正确加载吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会先创建带有所需结构的起始文件,然后填写角色、行为和检查项,最后运行一次快速的离线检查。文件名必须与场景名称一致,否则测试运行器将找不到它。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Create a scenario
Paths.
scripts/…andreferences/…below are relative to the directory holding this SKILL.md. Your working directory is the user's project, not that directory, so prefix them with its absolute path or the command is not found.
A scenario is two files:
srunner/scenarios/my_scenario.py the class: actors + behaviour tree + criteria
srunner/examples/MyScenario.xml the config: town, ego spawn, parameters
ScenarioRunner finds the class by globbing $SCENARIO_RUNNER_ROOT/srunner/scenarios/*.py
and matching the config's type attribute against class names in those modules.
There is no registration list — dropping the two files in is the whole
install. The corollary is that the type in the XML must match the class name
exactly, and a typo produces Scenario 'X' not supported.
Instructions
Progress:
- [ ] Step 1: Check prerequisites (bash scripts/check_env.sh)
- [ ] Step 2: Generate the skeleton (scaffold), or copy the closest existing scenario
- [ ] Step 3: Fill in _initialize_actors, _create_behavior, _create_test_criteria
- [ ] Step 4: Validate offline (validate) — imports, class/type match, tree shape
- [ ] Step 5: Run it (run-scenario), iterate with DEBUG=1
Step 2: Scaffold
source scripts/env.sh
# a standalone scenario with a config, in the checkout
python3 scripts/scaffold_scenario.py --name MyCutIn --town Town04 \
--template follow_leading_vehicle
# somewhere else, to keep the checkout clean (use --additionalScenario to run it)
python3 scripts/scaffold_scenario.py --name MyCutIn --town Town04 --out ~/my_scenarios
python3 scripts/scaffold_scenario.py --list-templates
The scaffold writes both files with the four methods stubbed, the imports that
actually exist in this branch, and a CollisionTest criterion so the run reports
something. Then edit.
Step 3: The four methods
class MyCutIn(BasicScenario):
def __init__(self, world, ego_vehicles, config, randomize=False,
debug_mode=False, criteria_enable=True, timeout=60):
self.timeout = timeout
self._map = CarlaDataProvider.get_map()
self._reference_waypoint = self._map.get_waypoint(config.trigger_points[0].location)
# scenario parameters come from the XML, via config.other_parameters
self._distance = 50
if "distance" in config.other_parameters:
self._distance = float(config.other_parameters["distance"]["value"])
super().__init__("MyCutIn", ego_vehicles, config, world, debug_mode, criteria_enable=criteria_enable)
def _initialize_actors(self, config):
"""Spawn everything the scenario needs. Use CarlaDataProvider, never world.spawn_actor."""
wp = self._reference_waypoint.next(self._distance)[0]
actor = CarlaDataProvider.request_new_actor("vehicle.tesla.model3", wp.transform)
self.other_actors.append(actor)
def _create_behavior(self):
"""Return the py_trees tree. Composites: Sequence, Parallel; leaves: atomics."""
root = py_trees.composites.Sequence("MyCutIn")
root.add_child(InTriggerDistanceToVehicle(self.other_actors[0], self.ego_vehicles[0], 30))
root.add_child(LaneChange(self.other_actors[0], speed=10, distance_other_lane=30))
root.add_child(ActorDestroy(self.other_actors[0]))
return root
def _create_test_criteria(self):
"""Return a list of criteria. These decide pass/fail."""
return [CollisionTest(self.ego_vehicles[0])]
Rules that are not obvious and cost the most time:
- Spawn through
CarlaDataProvider.request_new_actor, notworld.spawn_actor. Only the provider registers the actor for velocity/transform caching and for cleanup; direct spawns leak between runs and read asnot foundin atomics. - Append to
self.other_actorsor the actor is never destroyed. _create_behaviormust return a tree that terminates. ASequencewhose last child never succeeds hangs until the timeout — which is what an apparently stuck scenario usually is.config.other_parametersis a dict of{name: {attr: value}}built from the XML child elements, and every value is a string. Cast it.self.timeoutmust be set beforesuper().__init__, because the base class reads it while building the tree.- Criteria are attached in parallel with the behaviour and run to the end. An
optional=Truecriterion reports but does not fail the scena
常见问题
检查新场景需要模拟器吗?
不需要。第一项检查无需模拟器即可运行,因此你可以及早发现文件和命名错误。
为什么名称必须完全一致?
测试运行器通过配置文件中的名称查找场景,拼写错误会导致“不支持”的错误。
我可以把场景添加到整条路线中吗?
可以。可以通过额外的场景选项将其添加到路线中。
详情
作者的原始描述
Writes a new ScenarioRunner scenario — a Python class deriving from BasicScenario with its behaviour tree assembled from srunner atomic behaviours and criteria, plus the XML config that gives it a town, ego spawn and parameters — and registers it so `--scenario MyScenario_1` works. Also covers adding a scenario to a route via --additionalScenario. Generates a working skeleton and validates it without a simulator. Use when the user asks to "create/write a new scenario", "add a custom scenario", "make my own traffic situation", or wants to extend the scenario library.
repo: carla-simulator/carla
热度
- GitHub 星标
- 15k
- 排名
- #11109
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
create-leaderboard-route
15k帮你的智能体通过在模拟器视角中放置路径点和场景触发器,构建 CARLA Leaderboard 路线文件,并对其进行检查和排序。
package-leaderboard-agent
15k帮你的智能体把驾驶智能体打包成 Docker 镜像,用于提交 CARLA Leaderboard,并检查文件夹结构,测试镜像能否加载它。
read-leaderboard-results
15k帮你的智能体阅读 CARLA Leaderboard 结果文件,解释每条路线的得分和违规情况,并按另一规则版本重新计分。
run-leaderboard-evaluation
15k帮你的智能体用你的驾驶智能体在一组路线上运行 CARLA Leaderboard 评估器,先检查设置,并保存可以恢复的检查点。