create-scenario
Skill này làm gì
Skill viết một kịch bản kiểm thử lái xe mới cho simulator CARLA, gồm các actor, hành vi và tiêu chí đạt. Skill dành cho lập trình viên xây dựng bài kiểm thử riêng cho phần mềm lái xe tự động.
Khi nào nên dùng
- ✓Khi bạn muốn một bài kiểm thử mới trong đó một xe phải xử lý một tình huống đường cụ thể.
- ✓Khi bạn cần một file kịch bản mà trình chạy kiểm thử có thể tìm và chạy theo tên.
- ✓Khi bạn muốn kịch bản mới được kiểm tra lỗi trước khi chạy trên simulator.
Liên kết skill
https://github.com/carla-simulator/carla/blob/ue58-dev/Skills/scenario-runner/create-scenario/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể viết một bài kiểm thử CARLA mới, trong đó một xe khác đột ngột cắt ngang trước xe của tôi, rồi kiểm tra xem nó có nạp đúng không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tạo một file khởi đầu với cấu trúc bắt buộc, điền các actor, hành vi và kiểm tra, rồi chạy một kiểm tra nhanh ngoại tuyến. Tên file phải khớp với tên kịch bản, nếu không trình chạy kiểm thử sẽ không tìm thấy.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
Câu hỏi thường gặp
Có cần simulator để kiểm tra kịch bản mới không?
Không. Kiểm tra đầu tiên chạy mà không cần nó, nên bạn bắt được lỗi file và tên sớm.
Vì sao tên phải khớp chính xác?
Trình chạy kiểm thử tìm kịch bản theo tên trong file cấu hình, nên gõ sai sẽ gây lỗi “không được hỗ trợ”.
Tôi có thể thêm kịch bản vào cả một tuyến không?
Có. Nó có thể được thêm vào một tuyến bằng một tùy chọn kịch bản thêm.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 15k
- Vị trí xếp hạng
- #11109
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
create-leaderboard-route
15kGiúp agent của bạn tạo file tuyến đường CARLA Leaderboard bằng cách đặt các điểm waypoint và trigger kịch bản từ camera của simulator, rồi kiểm tra và sắp xếp chúng.
package-leaderboard-agent
15kGiúp agent của bạn đóng gói một agent lái xe thành image Docker để nộp lên CARLA Leaderboard, kiểm tra cấu trúc thư mục và thử rằng image nạp được agent.
read-leaderboard-results
15kGiúp agent của bạn đọc file kết quả CARLA Leaderboard, giải thích điểm và vi phạm của từng tuyến, và chấm lại một lần chạy theo phiên bản luật khác.
run-leaderboard-evaluation
15kGiúp agent của bạn chạy bộ đánh giá CARLA Leaderboard trên một tập tuyến với agent lái xe, kiểm tra thiết lập trước và lưu checkpoint để có thể tiếp tục.
Skill tương tự
test-driven-development
311kDạy agent của bạn viết kiểm thử thất bại trước, xem nó thất bại, rồi viết đoạn mã ngắn nhất để vượt qua trước khi làm bất kỳ tính năng hay bản sửa nào.
verification-before-completion
311kDạy agent của bạn chạy kiểm tra thực tế và đọc kết quả đầu ra trước khi khẳng định một việc, bản sửa hoặc bản build đã hoàn thành hay vượt qua.
migrate-to-shoehorn
310kThay các ép kiểu rủi ro trong tệp kiểm thử bằng thư viện shoehorn, để các bài kiểm thử dùng dữ liệu một phần vẫn qua được kiểm tra kiểu.