Skip to content

zrwangems/dsh-zrwang-plugin / skills/engineering/matlab/automotive/matlab-use-scenario-builder

matlab-use-scenario-builder

Verified

Generate driving scenes, scenarios, road surfaces, and 3D content from scenariobuilder.* sensor data (GPS, camera, lidar, actor tracks) using Scenario Builder for Automated Driving Toolbox. BUILD, EXPORT, or AUGMENT a virtual scenario/scene/map: ego or actor trajectories, trajectory smoothing, OpenCRG road-surface extraction, 3D asset generation, static-object placement, point-cloud georeferencing + elevation, lane-based ego localization, sensor-fusion tracking, scenario-event extraction (cut-ins, hard brakes, near-misses, ADAS disengagements), or export to RoadRunner, drivingScenario, OpenDRIVE, OpenCRG, OpenSCENARIO, or Unreal Engine. Also: log-to-scenario, scenario harvesting, accident/near-miss reconstruction, SOTIF (ISO 21448) and ISO 26262 scenario coverage, USGS-aerial-lidar augmentation, traffic-sign placement, vision-based vehicle classification for actor assets. NOT for raw-data import or multi-sensor sync/crop/offset/timestamp normalization — route those to matlab-import-driving-data.

FileKindSize
SKILL.mdskill md56.8 KB
manifest.yamlconfig704 B
references/actortrackdata-api.mdmarkdown3.3 KB
references/example-roadrunner-scenario.mdmarkdown4.3 KB
references/example-scenario-from-gps-and-tracks.mdmarkdown9.6 KB
references/execution-rules-detail.mdmarkdown16.7 KB
references/gpsdata-api.mdmarkdown2.4 KB
references/osm-flat-scene-gotchas.mdmarkdown8.8 KB
references/per-frame-detections-to-actortrackdata.mdmarkdown7.8 KB
references/python-spkg-install-troubleshooting.mdmarkdown5.8 KB
references/trajectory-api.mdmarkdown13.7 KB
references/visualization-patterns.mdmarkdown12.4 KB
references/workflow-04-roadrunner-export-detail.mdmarkdown32.6 KB
references/workflow-07-height-correction.mdmarkdown3.3 KB
references/workflow-08-lane-localization.mdmarkdown39.1 KB
references/workflow-09-static-objects.mdmarkdown9.3 KB
references/workflow-10-road-surface-opencrg.mdmarkdown4.7 KB
references/workflow-11-point-cloud-georef.mdmarkdown4.5 KB
references/workflow-12-3d-asset-generation.mdmarkdown2.0 KB
references/workflow-13-event-extraction.mdmarkdown5.3 KB
references/workflow-14-sensor-fusion-tracking.mdmarkdown6.9 KB
references/workflow-15-driving-scenario-designer.mdmarkdown7.6 KB
references/workflow-16-aerial-lidar-augmentation.mdmarkdown14.4 KB
references/workflow-17-traffic-signs-from-sensor-data.mdmarkdown12.5 KB
references/workflow-18-vehicle-classification.mdmarkdown12.8 KB
references/workflow-19-ego-lane-inference.mdmarkdown10.0 KB
scripts/buildBestCropGrid.mother5.2 KB
scripts/openFile.mother716 B
scripts/plotActorCircles.mother3.5 KB
scripts/plotBEVAndCamera.mother4.2 KB

references/workflow-10-road-surface-opencrg.md

View on GitHub
---
name: workflow-10-road-surface-opencrg
description: Extract high-resolution road surface profiles from lidar point clouds using roadSurface, export to ASAM OpenCRG (.crg) for vehicle dynamics simulation, query elevation, derive lane boundaries for RoadRunner/OpenDRIVE, and export curved-grid mesh for Unreal. Loaded when user mentions road surface, OpenCRG, vehicle dynamics from lidar, or chassis testing.
---

# Workflow 10 — Road Surface Extraction & ASAM OpenCRG Export

> **Parent skill:** [`SKILL.md`](../SKILL.md) — Loaded when user needs sub-millimeter road surface profiles for vehicle dynamics or chassis testing.
>
> **Related references:** [`workflow-11-point-cloud-georef.md`](workflow-11-point-cloud-georef.md) for upstream point cloud georeferencing and the `addElevation` vs `roadSurface` decision.

Use `roadSurface` to extract high-resolution road surface profiles from lidar point cloud data. The output supports vehicle dynamics, chassis, and kinematics testing via ASAM OpenCRG, and can also feed into RoadRunner, Unreal Engine, and Simscape workflows.

**Resolution:** Accuracy depends on lidar resolution — with high-res lidar, surface detail can reach sub-millimeter (down to ~1mm). Control via `gridResolution` parameter (lateral × longitudinal step size in meters).

## Inputs
- **Point cloud** — georeferenced `pointCloud` object (from lidar stitching/aerial scan)
- **Road reference line** — N×3 matrix, trajectory object, or ego path
- **Road width** — scalar (symmetric) or `[left, right]` from reference line
- **Grid resolution** — `[lateral, longitudinal]` in meters (e.g., `[0.01, 0.01]` for 1cm). Lower values → higher resolution surface (more detail) but longer processing time; higher values → faster but coarser

## Step 1: Create road surface object
```matlab
%% Extract road surface from georeferenced point cloud
% ptCloud: merged/stitched lidar point cloud (georeferenced)
% refLine: road centerline or ego trajectory
% width: road width from reference line [left, right] in meters
% resolution: [lateral, longitudinal] grid step in meters

rsObj = roadSurface(ptCloud, refLine, [5 5], [0.01 0.01], ...
    LocalOrigin=geoReference, ...
    InterpolationMethod="linear");

% Visualize
show(rsObj);
```

## Step 2: Export to ASAM OpenCRG (vehicle dynamics testing)
```matlab
%% Export OpenCRG file — used directly by vehicle dynamics simulators
crgFile = fullfile(dataDir, "road_surface.crg");
exportToASAMOpenCRG(rsObj, crgFile);
fprintf("OpenCRG exported: %s\n", crgFile);

% The .crg file can be used in:
% - Simscape Multibody (vehicle dynamics)
% - IPG CarMaker, VIRES VTD, dSPACE ASM
% - Any ASAM OpenCRG-compatible simulator
```

## Step 3: Query elevation at arbitrary points
```matlab
%% Use evaluate() to get elevation at specific (s, t) coordinates
% s = longitudinal distance along reference line
% t = lateral offset from reference line
sQuery = [0:0.5:100]';  % every 0.5m along road
tQuery = zeros(size(sQuery));  % at centerline
elevations = evaluate(rsObj, sQuery, tQuery);
```

## Step 4: Extract road boundaries → RoadRunner / OpenDRIVE
```matlab
%% getRoadBoundaries returns laneBoundarySegment objects
lbSegments = getRoadBoundaries(rsObj);

% Feed into RoadRunner HD Map pipeline
lbGroup = laneBoundaryGroup(lbSegments);
rrMap = getLanesInRoadRunnerHDMap(lbGroup);
write(rrMap, fullfile(tempdir, "road_from_surface.rrhd"));

% Or export to OpenDRIVE via drivingScenario → roadNetwork
```

## Step 5: Export mesh for Unreal Engine workflows
```matlab
%% Get curved grid point cloud (for mesh generation / Unreal import)
pcGrid = getCurvedGridPointCloud(rsObj);
% pcGrid is a pointCloud object representing the road surface mesh
% Can be exported as .ply/.obj for Unreal Engine terrain import
pcwrite(pcGrid, fullfile(dataDir, "road_mesh.ply"));
```

## Georeferencing with LocalOrigin
The `LocalOrigin` property (`[lat lon alt]`) anchors the road surface to geographic coordinates. This ensures alignment when combining with OSM roads, HD maps, or GPS trajectories:
```matlab
% Create with geo-reference (aligns with OSM/trajectory coordinate system)
rsObj = roadSurface(ptCloud, egoTrajectory, [6 6], [0.02 0.02], ...
    LocalOrigin=egoTrajectory.LocalOrigin);
```

## Downstream Consumers

| Output | Method | Consumer |
|--------|--------|----------|
| ASAM OpenCRG `.crg` | `exportToASAMOpenCRG` | Vehicle dynamics (Simscape, CarMaker, dSPACE) |
| Elevation query | `evaluate(rsObj, s, t)` | Custom analysis, height correction |
| Road boundaries | `getRoadBoundaries` → `laneBoundarySegment` | RoadRunner HD Map, OpenDRIVE |
| Point cloud mesh | `getCurvedGridPointCloud` | Unreal Engine, 3D visualization |
| Grid resolution update | `updateGridResolution` | Trade off detail vs file size |

----

Copyright 2026 The MathWorks, Inc.

----
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall