Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/automotive/roadrunner-build-rrhd-map

roadrunner-build-rrhd-map

Verified

Build, convert, and import RoadRunner HD Maps (.rrhd) in MATLAB. Author lanes, lane boundaries, markings, junctions, signs, barriers, and speed limits with roadrunnerHDMap; convert Lanelet2 (.osm, Autoware) maps to RRHD; resolve RoadRunner road asset paths for markings, crosswalks, signs, signals, and barriers; and import or build .rrhd or OpenDRIVE (.xodr) files into a RoadRunner scene. Use when creating road networks for driving simulation, converting Lanelet2 or other HD map sources to RRHD, looking up road asset paths, or loading and verifying a map in RoadRunner or RoadRunner Scene Builder. Not for building scenes from recorded sensor data, running simulations, or recreating OpenSCENARIO (.xosc) scenarios.

FileKindSize
SKILL.mdskill md15.5 KB
manifest.yamlconfig557 B
references/assets/assetCatalog.mdmarkdown7.4 KB
references/assets/barriers.mdmarkdown3.6 KB
references/assets/laneMarkings.mdmarkdown5.8 KB
references/assets/laneTypes.mdmarkdown2.2 KB
references/assets/signs.mdmarkdown5.0 KB
references/assets/staticObjects.mdmarkdown5.1 KB
references/authoring/alignmentRules.mdmarkdown10.3 KB
references/authoring/apiReference.mdmarkdown9.0 KB
references/authoring/authoringWorkflow.mdmarkdown20.4 KB
references/authoring/deduplicateBoundaries.mdmarkdown4.9 KB
references/authoring/junctionPolygon.mdmarkdown6.8 KB
references/authoring/leftGapFilter.mdmarkdown6.5 KB
references/authoring/orthogonalSplit.mdmarkdown7.7 KB
references/authoring/resolveHeights.mdmarkdown2.4 KB
references/authoring/snapEndpoints.mdmarkdown4.0 KB
references/authoring/splitClosedGeometry.mdmarkdown3.8 KB
references/authoring/synthesizeCenterLine.mdmarkdown4.6 KB
references/authoring/validateMap.mdmarkdown1.1 KB
references/import/buildOptions.mdmarkdown4.0 KB
references/import/importScene.mdmarkdown12.9 KB
references/lanelet2/buildRRHD.mdmarkdown14.2 KB
references/lanelet2/conversionPipeline.mdmarkdown13.3 KB
references/lanelet2/coordinates.mdmarkdown4.9 KB
references/lanelet2/discoverRelations.mdmarkdown2.4 KB
references/lanelet2/enforcementGate.mdmarkdown3.3 KB
references/lanelet2/extractGeometry.mdmarkdown3.4 KB
references/lanelet2/extractJunctions.mdmarkdown5.0 KB
references/lanelet2/extractLanelets.mdmarkdown2.6 KB
references/lanelet2/extractNonLaneElements.mdmarkdown14.4 KB
references/lanelet2/extractSemantics.mdmarkdown4.4 KB
references/lanelet2/extractTopology.mdmarkdown5.4 KB
references/lanelet2/placedObjects.mdmarkdown4.4 KB
references/lanelet2/readOSM.mdmarkdown4.0 KB
references/lanelet2/splitClosedRoads.mdmarkdown3.0 KB
scripts/detectAlignment.mother3.3 KB
scripts/detectClosedLoop.mother5.8 KB
scripts/detectJunctions.mother12.4 KB
scripts/discoverWayTypes.mother4.8 KB
scripts/parseOSM.mother4.0 KB
scripts/resolveHeightConflicts.mother6.8 KB
scripts/resolveSignAsset.mother7.2 KB
scripts/snapConnectedEndpoints.mother4.0 KB
scripts/validateRRHD.mother6.3 KB

scripts/detectClosedLoop.m

View on GitHub
function [hasClosedLoop, info] = detectClosedLoop(rrMap, options)
%detectClosedLoop Detect closed-loop (track-style) road networks in an HD map.
%   [hasClosedLoop, info] = detectClosedLoop(rrMap) returns true when the
%   map contains a cycle of non-junction lanes (following Successors) whose
%   total center-line length is at least 100 m — e.g. an oval test track.
%   Use it to decide DetectAsphaltSurfaces: asphalt detection fills the
%   interior of such loops.
%
%   A roundabout ring is also a closed loop: a strongly connected group of
%   at least 3 lanes in which every lane has exactly one successor and one
%   predecessor inside the group (a simple ring), with total length of at
%   least MinRingLength (default 30 m). Its lanes may be junction lanes.
%
%   A map is also treated as a closed loop when one strongly connected
%   group of lanes holds at least 90% of all lane length (a track whose
%   ring passes through junction lanes, e.g. at a pit entry).
%
%   Street grids are not closed loops even though their topology contains
%   cycles: every cycle passes through junction lanes and no single cycle
%   group dominates. Short cycles of a few lanes (degenerate topology) are
%   ignored by the length threshold.
%
%   [...] = detectClosedLoop(rrMap, MinLoopLength=len) uses a custom
%   minimum loop length in meters; MinRingLength=len sets the minimum
%   simple-ring (roundabout) length.
%
%   Inputs:
%     rrMap          - roadrunnerHDMap object
%     MinLoopLength  - Minimum total lane length of a loop (default 100 m)
%     MinRingLength  - Minimum length of a simple ring / roundabout (default 30 m)
%
%   Outputs:
%     hasClosedLoop  - true if a qualifying loop exists
%     info           - Struct: nLanes, nJunctionLanes, nLanesOnAnyCycle,
%                      loopLanes (string IDs of the longest qualifying loop),
%                      loopLength (m), nRings (simple rings found), reason (text for logs)
%
%   Example:
%     m = roadrunnerHDMap; read(m, "track.rrhd");
%     [tf, info] = detectClosedLoop(m); disp(info.reason)

% Copyright 2026 The MathWorks, Inc.

    arguments
        rrMap (1,1) roadrunnerHDMap
        options.MinLoopLength (1,1) double {mustBePositive} = 100
        options.MinRingLength (1,1) double {mustBePositive} = 30
    end

    lanes = rrMap.Lanes;
    n = numel(lanes);
    info = struct('nLanes', n, 'nJunctionLanes', 0, 'nLanesOnAnyCycle', 0, ...
        'loopLanes', strings(1, 0), 'loopLength', 0, 'nRings', 0, 'reason', "");
    hasClosedLoop = false;
    if n == 0
        info.reason = "No lanes";
        if nargout == 0, clear hasClosedLoop info; end
        return
    end

    ids = arrayfun(@(l) string(l.ID), lanes);
    ids = ids(:);
    idx = containers.Map(cellstr(ids), num2cell(1:n));
    src = zeros(0, 1); dst = zeros(0, 1);
    for i = 1:n
        for k = 1:numel(lanes(i).Successors)
            sid = char(string(lanes(i).Successors(k).Reference.ID));
            if isKey(idx, sid)
                src(end + 1, 1) = i; %#ok<AGROW>
                dst(end + 1, 1) = idx(sid); %#ok<AGROW>
            end
        end
    end
    len = arrayfun(@(l) sum(vecnorm(diff(l.Geometry(:, 1:2)), 2, 2)), lanes);
    len = len(:);

    junctionIDs = strings(0, 1);
    for j = 1:numel(rrMap.Junctions)
        refs = rrMap.Junctions(j).Lanes;
        junctionIDs = [junctionIDs; arrayfun(@(r) string(r.ID), refs(:))]; %#ok<AGROW>
    end
    isJunction = ismember(ids, junctionIDs);
    info.nJunctionLanes = nnz(isJunction);

    allBins = conncomp(digraph(src, dst, [], n), 'Type', 'strong');
    allBins = allBins(:);
    allCount = accumarray(allBins, 1);
    info.nLanesOnAnyCycle = nnz(allCount(allBins) > 1);
    allLen = accumarray(allBins, len);
    [domLen, dom] = max(allLen .* (allCount > 1));

    % Simple rings (roundabouts): in/out degree exactly 1 inside the group
    ringGroups = zeros(0, 1);
    for g = find(allCount >= 3)'
        inG = allBins == g;
        e = inG(src) & inG(dst);
        outDeg = accumarray(src(e), 1, [n 1]); inDeg = accumarray(dst(e), 1, [n 1]);
        if all(outDeg(inG) == 1) && all(inDeg(inG) == 1) && allLen(g) >= options.MinRingLength
            ringGroups(end + 1, 1) = g; %#ok<AGROW>
        end
    end
    info.nRings = numel(ringGroups);

    keep = ~isJunction(src) & ~isJunction(dst);
    bins = conncomp(digraph(src(keep), dst(keep), [], n), 'Type', 'strong');
    bins = bins(:);
    count = accumarray(bins, 1);
    loopLen = accumarray(bins, len);
    selfLoop = false(numel(count), 1);
    selfLoop(bins(src(keep & src == dst))) = true;
    candidate = (count > 1 | selfLoop) & loopLen >= options.MinLoopLength;
    if ~isempty(ringGroups)
        [info.loopLength, k] = max(allLen(ringGroups));
        info.loopLanes = ids(allBins == ringGroups(k))';
        hasClosedLoop = true;
        info.reason = sprintf("Closed loop: %d simple ring(s) (roundabout); largest has %d lanes, %.0f m", ...
            numel(ringGroups), numel(info.loopLanes), info.loopLength);
    elseif any(candidate)
        [info.loopLength, best] = max(loopLen .* candidate);
        info.loopLanes = ids(bins == best)';
        hasClosedLoop = true;
        info.reason = sprintf("Closed loop: %d non-junction lanes form a %.0f m cycle", ...
            numel(info.loopLanes), info.loopLength);
    elseif domLen >= options.MinLoopLength && domLen >= 0.9 * sum(len)
        info.loopLength = domLen;
        info.loopLanes = ids(allBins == dom)';
        hasClosedLoop = true;
        info.reason = sprintf("Closed loop: one cycle group of %d lanes holds %.0f%% of lane length (%.0f m)", ...
            numel(info.loopLanes), 100 * domLen / sum(len), domLen);
    else
        info.reason = sprintf("No closed loop: %d of %d lanes lie on topology cycles, but none form a junction-free cycle >= %.0f m", ...
            info.nLanesOnAnyCycle, n, options.MinLoopLength);
    end

    if nargout == 0, clear hasClosedLoop info; end
end
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall