roadrunner-scenario-authoring
>
git clone --depth 1 https://github.com/matlab/matlab-agentic-toolkit /tmp/roadrunner-scenario-authoring && cp -r /tmp/roadrunner-scenario-authoring/skills-catalog/automotive/roadrunner-scenario-authoring ~/.claude/skills/roadrunner-scenario-authoringSKILL.md
# RoadRunner Scenario Authoring
Programmatically create RoadRunner scenarios from MATLAB: actors, routes, phase logic, and validation — all via `roadrunnerAPI`.
## When to Use
- Adding actors (vehicles, pedestrians, objects) to a RoadRunner scenario
- Creating routes and waypoints for actors
- Building scenario logic: phases, conditions, actions
- Authoring common patterns: cut-in, pedestrian crossing, lead-follow, emergency brake
- Placing actors on roads using anchor-based or HD Map positioning
- Validating scenario structure before simulation
## When NOT to Use
- Connecting to or launching RoadRunner → use `roadrunner-core`
- Building scenarios from recorded sensor data → use `matlab-use-scenario-builder`
- Authoring road geometry (lanes, junctions) → use `roadrunner-rrhd-authoring`
- Importing maps or scenes → use `roadrunner-import-scene`
- Simulating or exporting scenarios → use `roadrunner-scenario-simulating`
## Workflow
### 1. Ensure Session
Verify `rrApp` exists. If not, ensure RoadRunner is connected first (e.g., via `roadrunner-core` or manually).
```matlab
if ~exist('rrApp', 'var') || ~isvalid(rrApp)
error("No active RoadRunner session. Use the roadrunner-core skill.");
end
```
**Path setup:** Before calling helper functions, ensure the scripts directory is on the MATLAB path:
```matlab
addpath('<path-to-skill>/scripts');
```
### 2. Initialize Scenario
```matlab
openScene(rrApp, sceneName);
newScenario(rrApp);
rrApi = roadrunnerAPI(rrApp);
rrs = rrApi.Scenario;
phaseLogic = rrs.PhaseLogic;
rrprj = rrApi.Project;
```
### 3. Scene Awareness
Before placing actors, survey the scene to find valid lane positions. Use the `helperSceneAwareness` script for automated analysis, or query manually via HD Map export:
```matlab
sceneInfo = helperSceneAwareness(rrApp, NumActors=2, ScenarioType="cut-in");
```
See `references/scene-awareness.md` for manual HD Map query patterns when the helper is unavailable.
### 4. Add Actors
**Option A — Batch placement** (recommended for 2+ actors):
```matlab
actorSpecs(1) = struct(Name="Ego", AssetPath="Vehicles/Sedan.fbx", ...
AssetType="VehicleAsset", LaneIndex=1, Fraction=0.1, Speed=15);
[actors, report] = helperPlaceActors(rrs, rrprj, phaseLogic, sceneInfo.HDMap, actorSpecs);
ego = actors{1}; % cell array — use curly braces
```
**Option B — Manual placement:**
```matlab
vehicleAsset = getAsset(rrprj, "Vehicles/Sedan.fbx", "VehicleAsset");
actor = addActor(rrs, vehicleAsset, position);
actor.Name = "Ego";
autoAnchor(actor.InitialPoint); % Snaps to nearest road
```
**Post-placement check:** Verify `actor.InitialPoint.WorldPosition` is NOT `[0 0 0]`.
See `references/asset-catalog.md` for available vehicle/character paths.
### 5. Position Actors (Anchoring)
**Option A — Scene anchors available:**
```matlab
anchors = getAnchors(rrApp);
% Use remapAnchor for cross-scene portability (not findSceneAnchor)
anchorPt = findSceneAnchor(rrs, anchors(1).Name);
anchorToPoint(actor.InitialPoint, anchorPt);
actor.InitialPoint.ForwardOffset = 20;
actor.InitialPoint.LaneOffset = 1;
```
**Option B — No scene anchors (use autoAnchor):**
```matlab
actor = addActor(rrs, asset, approximatePosition);
autoAnchor(actor.InitialPoint); % Must be within 5m of road
```
**Option C — Relative to another actor:**
```matlab
anchorToPoint(target.InitialPoint, ego.InitialPoint);
target.InitialPoint.ForwardOffset = 30;
target.InitialPoint.LaneOffset = 1;
```
### 6. Create Routes (When Needed)
Routes put actors in **path-following mode**. Actors without routes drive in **lane-following mode** along their anchored lane.
```matlab
route = actor.InitialPoint.Route;
fwdPt = addPoint(route, actor.InitialPoint.WorldPosition + [20 0 0]);
autoAnchor(fwdPt);
% For vehicles: disable freeform so route follows road surface
% (Do NOT do this for pedestrians — they need freeform to cross roads)
for i = 1:numel(route.Segments)
route.Segments(i).Freeform = false;
end
```
**When to add routes:**
- Character/pedestrian actors — ALWAYS required (validation fails without them)
- Vehicles that follow a specific path (e.g., ego driving straight)
- Vehicles that do NOT need `ChangeLaneAction`
**When NOT to add routes:**
- Vehicles that need `ChangeLaneAction` — they MUST be in lane-following mode (no routes)
- Vehicles that need `ChangeLateralOffsetAction` — same requirement
**Route point rules:**
- Always use `autoAnchor` for route points — position must be within 5m of road
- Do NOT use `anchorToPoint` + `ForwardOffset` on route points — causes validation failure
- Keep route offset small (20m) to stay on the road
- For junction turns: use multiple waypoints (pre-junction, post-junction, exit) for smooth path
- After adding route points, set `seg.Freeform = false` on each segment to follow road geometry (freeform routes ignore road surface and may float above/below the road)
### 7. Build Phase Logic
See `references/actions-and-conditions.md` for the complete catalog.
```matlab
% Get actor's initial phase (auto-created with addActor)
initPhase = initialPhaseForActor(phaseLogic, actor);
% Modify default speed (initial phase already has ChangeSpeedAction)
initPhase.Actions(1).Speed = 20;
% Add sequential phase
nextPhase = addPhaseInSerial(phaseLogic, initPhase, "ActorActionPhase");
nextPhase.Actor = actor; % REQUIRED — never omit
% Set trigger condition on initial phase
cond = setEndCondition(initPhase, "LongitudinalDistanceToActorCondition");
cond.Actor = actor; % REQUIRED
cond.ReferenceActor = otherActor;
cond.Distance = 10;
% Add action to next phase
action = addAction(nextPhase, "ChangeLaneAction");
action.Direction = "left";
```
**Multi-actor phase logic:** Each actor's phase chain is independent. Any phase that has a subsequent phase MUST have an end condition — without one, the phase runs indefinitely and subsequent phases never execute. For multi-actor scenarios, ensure EVERY phase with a successor has an appropriate end condition set via>
Analyze AMS waveform data using Mixed-Signal Blockset utilities: phase noise measurement, clock jitter, anti-aliased resampling, timing measurements, lock time, INL/DNL, ADC/DAC calibration, HSpice import. Use when analyzing time-domain voltage from PLL/VCO/clock simulations, measuring phase noise from variable-step solver output, computing jitter, or resampling non-uniform data.
Analyze data using MATLAB. Use when the task involves tables, timetables, time-series data, numeric arrays, sensor matrices, or gridded data — including but not limited to exploring, filtering, sorting, cleaning, transforming, aggregating, smoothing, padding, trimming, and answering questions about data. MATLAB provides extensive, easy-to-use built-in functions for these workflows with no additional products required.
Analyze the effective toolbox file set to produce a Dependency Manifest — classify all transitive dependencies as included, product, add-on, or external-unresolved, then present resolution options with tradeoffs. Use after matlab-define-toolbox-api when the spec is approved.
S-parameters, insertion loss, fields, currents, mesh control, and solver selection for RF PCB performance validation. TRIGGER: user asks to compute S-parameters, analyze insertion/return loss, extract fields or currents, compare MoM vs FEM, or control mesh for any RF PCB component. Invoke BEFORE writing sparameters() or solver code — API is non-obvious. SKIP: designing or creating components (use the specific matlab-design-pcb-* skill), material/stackup setup only (use matlab-manage-pcb-material), optimization sweeps (use matlab-optimize-pcb-design), PDN/IR-drop analysis (use matlab-analyze-pcb-pdn).
Analyze antennas installed on electrically large conducting platforms using MATLAB Antenna Toolbox. Loads platform geometry from STL/STEP/IGES, installs antenna elements, selects electromagnetic solvers (MoM-PO, FMM, MoM), and computes patterns, impedance, coupling, and efficiency. Use when the user wants to model an antenna on a vehicle, aircraft, ship, satellite, or other large structure.
PDN DC voltage/current analysis, IR drop, design rule checking, and multi-net batch analysis on imported PCB layouts. TRIGGER: user asks about power integrity, PDN analysis, IR drop, voltage distribution, current density, power nets, or design rule checking on a PCB. Invoke BEFORE writing code — the PDN API chain is specialized and non-obvious. SKIP: importing a PCB file (use matlab-read-pcb-layout), EM field/S-parameter extraction (use matlab-analyze-em), material/stackup setup only (use matlab-manage-pcb-material), transmission line design (use matlab-design-pcb-txline).
Calculate and visualize monostatic and bistatic radar cross section (RCS) using MATLAB Antenna Toolbox. Computes RCS of platforms, antennas, and arrays with PO, MoM, and FMM solvers, supporting HH/VV/HV/VH polarization, GPU acceleration, and near-field observation. Use when the user wants to compute, plot, or analyze radar cross section.