$npx -y skills add matlab/matlab-agentic-toolkit --skill roadrunner-import-sceneConnect to RoadRunner and import HD Map or OpenDRIVE files into a new scene using MATLAB. Use when loading driving scenes in RoadRunner or RoadRunner Scene Builder, importing RRHD, OpenDRIVE, or other RoadRunner-supported formats for simulation, or verifying Lanelet2-to-RRHD conv
| 1 | # RoadRunner Scene Import |
| 2 | |
| 3 | Connect to a running RoadRunner application and import map files into a new scene for visualization and verification. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - Importing a `.rrhd` file into RoadRunner for visual verification |
| 8 | - Importing an OpenDRIVE `.xodr` file into RoadRunner |
| 9 | - Connecting to a running RoadRunner instance from MATLAB |
| 10 | - Auto-launching RoadRunner when no instance is running |
| 11 | - Verifying converted maps after Lanelet2-to-RRHD or other conversions |
| 12 | |
| 13 | ## When NOT to Use |
| 14 | |
| 15 | - Building RRHD map content — use `roadrunner-rrhd-authoring` |
| 16 | - Converting Lanelet2 to RRHD — use `roadrunner-convert-lanelet2-to-rrhd` |
| 17 | - Looking up asset paths — use `roadrunner-asset-mapping` |
| 18 | - RoadRunner is not installed or no valid project folder exists |
| 19 | |
| 20 | ## Key Rules |
| 21 | |
| 22 | - **Always write to .m files.** Never put multi-line MATLAB code directly in `evaluate_matlab_code`. Write to a `.m` file, run with `run_matlab_file`, edit on error. |
| 23 | - **Only ONE RoadRunner instance per session.** Try `roadrunner.connect()` first; only launch if none exists. |
| 24 | - **Always copy file to project folder.** Use `status(rrApp).Project.Filename` and `copyfile()` explicitly in every import workflow — never omit or hide behind a variable. |
| 25 | - **Always set `bridgeOpts.IsEnabled = true` explicitly.** Never rely on constructor defaults for bridge auto-detection. |
| 26 | - **Run enforcement gates before `importScene`.** Connection, file location, and extension checks are mandatory. |
| 27 | - **Load before Build by default.** Use `ImportStep="Load"` unless user explicitly requests a full build. |
| 28 | |
| 29 | ## Prerequisites |
| 30 | |
| 31 | - **RoadRunner** must be installed (R2025a or later) at a standard location under `C:/Program Files/` |
| 32 | - A **RoadRunner Project folder** must exist (the skill uses the Sample Project by default) |
| 33 | - If RoadRunner is already open, the skill reuses that instance |
| 34 | - If RoadRunner is NOT open, the skill **auto-launches it** — no manual steps required |
| 35 | |
| 36 | ## Connection Strategy |
| 37 | |
| 38 | Always try `roadrunner.connect()` first to reuse an existing instance. **If no instance is running, launch one automatically** — never ask the user to open RoadRunner manually. |
| 39 | |
| 40 | **IMPORTANT: Only ONE RoadRunner instance per session.** If the conversion pipeline already called `roadrunnerHDMap` (which may launch a background instance), retry `roadrunner.connect()` with a pause before launching a new one. Never call `roadrunner(InstallationFolder=...)` without first confirming no instance exists. |
| 41 | |
| 42 | ```matlab |
| 43 | % Try connecting (with retry for recently-launched instances) |
| 44 | rrApp = []; |
| 45 | for attempt = 1:3 |
| 46 | try |
| 47 | rrApp = roadrunner.connect(); |
| 48 | fprintf('Connected to existing RoadRunner instance.\n'); |
| 49 | break; |
| 50 | catch |
| 51 | if attempt < 3 |
| 52 | pause(2); % Wait for background instance to become ready |
| 53 | end |
| 54 | end |
| 55 | end |
| 56 | |
| 57 | if isempty(rrApp) |
| 58 | % No instance running — find installation and launch |
| 59 | installPaths = { ... |
| 60 | "C:/Program Files/RoadRunner R2026a/bin/win64", ... |
| 61 | "C:/Program Files/RoadRunner R2025b/bin/win64", ... |
| 62 | "C:/Program Files/RoadRunner R2025a/bin/win64"}; |
| 63 | |
| 64 | installFolder = ""; |
| 65 | for i = 1:numel(installPaths) |
| 66 | if isfolder(installPaths{i}) |
| 67 | installFolder = installPaths{i}; |
| 68 | break; |
| 69 | end |
| 70 | end |
| 71 | if installFolder == "" |
| 72 | error('RoadRunner:NotFound', ... |
| 73 | 'No RoadRunner installation found under C:/Program Files/.'); |
| 74 | end |
| 75 | |
| 76 | % Launch ONE instance |
| 77 | rrApp = roadrunner(InstallationFolder=installFolder); |
| 78 | fprintf('Launched RoadRunner from %s\n', installFolder); |
| 79 | |
| 80 | % Open or create a project (caller provides projectFolder, or use default) |
| 81 | if ~exist('projectFolder', 'var') || projectFolder == "" |
| 82 | projectFolder = fullfile(getenv("USERPROFILE"), "RoadRunner Projects", "ImportProject"); |
| 83 | end |
| 84 | if isfolder(projectFolder) |
| 85 | openProject(rrApp, projectFolder); |
| 86 | else |
| 87 | newProject(rrApp, projectFolder); |
| 88 | end |
| 89 | fprintf('Project: %s\n', projectFolder); |
| 90 | end |
| 91 | ``` |
| 92 | |
| 93 | ### Connect with Custom Port |
| 94 | |
| 95 | ```matlab |
| 96 | rrApp = roadrunner.connect(apiPort); % default: 35707 |
| 97 | rrApp = roadrunner.connect(apiPort, cosimPort); % default cosim: 35706 |
| 98 | ``` |
| 99 | |
| 100 | ### Namespace Conflict Note |
| 101 | |
| 102 | If you get `The class roadrunner has no Constant property or Static method 'hdmap'` after connecting, this means the `roadrunner` function is shadowed by the live `rrApp` variable. Clear and reinitialize: |
| 103 | ```matlab |
| 104 | clear rrApp; |
| 105 | rrMap = roadrunnerHDMap; % reload namespace |
| 106 | rrApp = roadrunner.connect(); % reconnect |
| 107 | ``` |
| 108 | |
| 109 | ## Import Workflow |
| 110 | |
| 111 | ### Step 1: Create a Fres |