Main Content

Build Simple Roads Programatically Using RoadRunner HD Map

RoadRunner HD Map is a road data model for representing high-definition (HD) map data in a RoadRunner scene. The model defines a simple structure to represent road layouts using lanes, lane boundaries, lane markings, and junctions. This example shows how to build simple roads using RoadRunner HD Map MATLAB® objects and functions. You can then import the roads into RoadRunner. Use these steps to construct a road and import it into a RoadRunner scene:

  • Build an HD map in MATLAB.

  • Verify the representation of lanes and lane boundaries by plotting the map in MATLAB.

  • Write the map to a RoadRunner HD Map (.rrhd) file.

  • Import the file into RoadRunner and preview the RoadRunner HD Map data.

  • Build a RoadRunner scene from the imported file.

Create Straight, Unmarked Road

To define a fixed-width road, you must specify a series of xy-coordinates for the center of the road at various points along its path. First, create a straight, unmarked road, as shown in this figure. Then, plot the road in MATLAB and save it to a binary file.

Create an empty RoadRunner HD Map as a roadrunnerHDMap object.

rrMap = roadrunnerHDMap;

Define the center of the straight road as a matrix that contains three sets of xy-coordinates specifying the center of the road. Also, define the width of the road.

roadCenters = [0 0; 0 50; 0 100];
roadWidth = 6;

Create the left and right boundaries of the road using the roadrunner.hdmap.LaneBoundary object. Specify the lane boundary information for the lane ID and the coordinates defining the lane geometry.

laneGeometryLeft = roadCenters-[roadWidth/2 0];
laneGeometryRight = roadCenters+[roadWidth/2 0];
rrMap.LaneBoundaries(1) = roadrunner.hdmap.LaneBoundary(ID="Left",Geometry=laneGeometryLeft);
rrMap.LaneBoundaries(2) = roadrunner.hdmap.LaneBoundary(ID="Right",Geometry=laneGeometryRight);

Create the road lane using the roadrunner.hdmap.Lane object. Specify the lane information for the lane ID, the coordinates defining the lane geometry, the driving direction, and the lane type.

rLane = roadrunner.hdmap.Lane(ID="Lane",Geometry=roadCenters,TravelDirection="Forward",LaneType="Driving");

Link the lane boundaries to the lane. Define the left and the right lane boundaries for the lane, and specify the alignments between the lane and lane boundaries.

leftBoundary(rLane,"Left",Alignment="Forward");
rightBoundary(rLane,"Right",Alignment="Forward");
rrMap.Lanes = rLane;

Plot the lane centers and lane boundaries to preview the lanes and lane boundaries before importing them into RoadRunner.

plot(rrMap)

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent Lane Boundaries, Lane Centers.

Write the HD map to a file using the write function.

write(rrMap,"straightRoad.rrhd")

Import HD Map File into RoadRunner

For detailed instructions on importing a RoadRunner HD Map file with the .rrhd extension into RoadRunner, previewing the map, and building the scene, see Import Custom Data Using RoadRunner HD Map (RoadRunner).

This figure shows a scene of a straight, unmarked road built using RoadRunner Scene Builder.

Add Markings to Straight Road

In this section, you add solid, white lane markings to the left and right lane boundaries of the straight road you created in the previous section. To specify a lane marking, you must use an asset in RoadRunner. In this example, you use assets that are part of the RoadRunner Asset Types (RoadRunner). Specify these assets in the map by using a relative path to the RoadRunner project folder.

Define the path to the solid, white lane marking asset using the roadrunner.hdmap.RelativeAssetPath function.

solidWhiteAsset = roadrunner.hdmap.RelativeAssetPath(AssetPath="Assets/Markings/SolidSingleWhite.rrlms");

Create a solid, white lane marking on the straight road using the roadrunner.hdmap.LaneMarking object. Specify the lane marking information for the lane marking ID and the path to the asset.

rrMap.LaneMarkings = roadrunner.hdmap.LaneMarking(ID="SolidWhite",AssetPath=solidWhiteAsset);

Create a reference for the solid, white marking using the roadrunner.hdmap.MarkingReference object. You can use this reference to apply the marking to the lane boundaries.

markingRefSW = roadrunner.hdmap.MarkingReference(MarkingID=roadrunner.hdmap.Reference(ID="SolidWhite"));

Use parametric attributes to apply this lane marking to the full length of the left and right lane boundaries.

markingSpan = [0 1];
markingAttribSW = roadrunner.hdmap.ParametricAttribution(MarkingReference=markingRefSW,Span=markingSpan);
rrMap.LaneBoundaries(1).ParametricAttributes = markingAttribSW;
rrMap.LaneBoundaries(2).ParametricAttributes = markingAttribSW;

Write the modified HD map to a file.

write(rrMap,"straightRoadWithMarkings.rrhd");

This figure shows a scene of a straight road with solid, white lane markings for the left and right boundaries built using RoadRunner Scene Builder.

Create Two-Way Road

A two-way road has two lanes with opposite driving directions. A solid yellow lane marking separates the lanes. In this section, you create a straight, two-way road, as shown in this figure, using the same road centers and road width as for the straight, unmarked road.

Create an empty RoadRunner HD Map as a roadrunnerHDMap object.

rrMap = roadrunnerHDMap;

Specify the lane and the lane boundaries. In this example, preinitialization of these values results in improved performace as the number of objects in the map increases.

rrMap.Lanes(2,1) = roadrunner.hdmap.Lane();
rrMap.LaneBoundaries(3,1) = roadrunner.hdmap.LaneBoundary();

Assign the Lane property values. Use the deal function to match up the input and the output lists.

roadCenterLeft = roadCenters-[roadWidth/4 0];
roadCenterRight = roadCenters+[roadWidth/4 0];
[rrMap.Lanes.ID] = deal("Lane1","Lane2");
[rrMap.Lanes.Geometry] = deal(roadCenterLeft,roadCenterRight);
[rrMap.Lanes.TravelDirection] = deal("Backward","Forward");
[rrMap.Lanes.LaneType] = deal("Driving");

Assign the LaneBoundaries property values. In this example, the center lane is shared between Lane1 and Lane2.

[rrMap.LaneBoundaries.ID] = deal("Left","Center","Right");
[rrMap.LaneBoundaries.Geometry] = deal(roadCenters-[roadWidth/2 0], ...
  roadCenters,roadCenters+[roadWidth/2 0]);

Link the lane boundaries to the lanes. Define the left and the right lane boundaries for each lane, and specify the alignments between the lanes and lane boundaries.

leftBoundary(rrMap.Lanes(1),"Left",Alignment="Forward");
rightBoundary(rrMap.Lanes(1),"Center",Alignment="Forward");
leftBoundary(rrMap.Lanes(2),"Center",Alignment="Forward");
rightBoundary(rrMap.Lanes(2),"Right",Alignment="Forward");

Add a solid, yellow marking, in addition to the solid, white marking to the HD map. Define the path to the solid, yellow lane marking asset using the roadrunner.hdmap.RelativeAssetPath function.

solidYellowAsset = roadrunner.hdmap.RelativeAssetPath(AssetPath="Assets/Markings/SolidSingleYellow.rrlms");

Create a solid, yellow lane marking and solid, white lane markings on the straight road using the roadrunner.hdmap.LaneMarking object. Specify the lane marking information for the lane marking IDs and the paths to the assets.

rrMap.LaneMarkings(2,1) = roadrunner.hdmap.LaneMarking();
[rrMap.LaneMarkings.ID] = deal("SolidWhite","SolidYellow");
[rrMap.LaneMarkings.AssetPath] = deal(solidWhiteAsset,solidYellowAsset);

Assign the white marking to the lane boundaries at the lane edges and the yellow marking to the center lane boundary. These markings span the entire length of the boundaries.

markingRefSY = roadrunner.hdmap.MarkingReference(MarkingID=roadrunner.hdmap.Reference(ID="SolidYellow"));
markingAttribSY = roadrunner.hdmap.ParametricAttribution(MarkingReference=markingRefSY,Span=markingSpan);
[rrMap.LaneBoundaries.ParametricAttributes] = deal(markingAttribSW,markingAttribSY,markingAttribSW);

Plot the lane centers and lane boundaries.

plot(rrMap)

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent Lane Boundaries, Lane Centers.

Write the HD map to a file.

write(rrMap,"twoWayRoad.rrhd")

This figure shows a scene of the two-way road defined in this section, built using RoadRunner Scene Builder.

Add Lane to One-Way Road

In this section, you add a lane to a one-way road. Use a dashed, white marking to separate two lanes with the same travel direction. To add a lane to a one-way road, you must split one lane into two from the left edge of the lane. You must create additional lanes and lane boundaries in the RoadRunner HD map where the lane splits. This figure shows a one-way road with an added lane on the left side:

Create an empty RoadRunner HD Map as a roadrunnerHDMap object.

rrMap = roadrunnerHDMap;

Specify the lane and the lane boundaries.

rrMap.Lanes(5,1) = roadrunner.hdmap.Lane();
rrMap.LaneBoundaries(8,1) = roadrunner.hdmap.LaneBoundary();

Specify the lane groups and the lane markings.

rrMap.LaneGroups(3,1) = roadrunner.hdmap.LaneGroup();
rrMap.LaneMarkings(3,1) = roadrunner.hdmap.LaneMarking();

Assign the Lane property values. Split Lane1 into Lane4 and Lane5, and use Lane2 and Lane3 for the transition.

[rrMap.Lanes.ID] = deal("Lane1","Lane2","Lane3","Lane4","Lane5");
[rrMap.Lanes.Geometry] = deal([0 -20;0 0;0 20;], [0 20;0 40;0 60;], [0 20;-3 40;-6 60], [-6 60;-6 80;-6 100], [0 60;0 80;0 100]);
[rrMap.Lanes.TravelDirection] = deal("Forward");
[rrMap.Lanes.LaneType] = deal("Driving");

Assign the LaneBoundaries property values. Lane3 shares its right boundary, Left2, with Lane2.

[rrMap.LaneBoundaries.ID] = deal("Left1","Right1","Left2","Right2","Left3","Left4","Center4","Right4");
[rrMap.LaneBoundaries.Geometry] = deal([-3 -20;-3 0;-3 20],[3 -20;3 0;3 20],[-3 20;-3 40;-3 60;],...
        [3 20;3 40;3 60],[-3 20;-6 40;-9 60],[-9 60;-9 80;-9 100],[-3 60;-3 80;-3 100],[3 60;3 80;3 100]);

Link the lane boundaries to the lanes. Define the left and the right lane boundaries for each lane, and specify alignment between the lanes and lane boundaries.

leftBoundary(rrMap.Lanes(1),"Left1",Alignment="Forward");
rightBoundary(rrMap.Lanes(1),"Right1",Alignment="Forward");
leftBoundary(rrMap.Lanes(2),"Left2",Alignment="Forward");
rightBoundary(rrMap.Lanes(2),"Right2",Alignment="Forward");
leftBoundary(rrMap.Lanes(3),"Left3",Alignment="Forward");
rightBoundary(rrMap.Lanes(3),"Left2",Alignment="Forward");
leftBoundary(rrMap.Lanes(4),"Left4",Alignment="Forward");
rightBoundary(rrMap.Lanes(4),"Center4",Alignment="Forward");
leftBoundary(rrMap.Lanes(5),"Center4",Alignment="Forward");
rightBoundary(rrMap.Lanes(5),"Right4",Alignment="Forward");

Specify the alignments between the lanes by defining their predecessor and successor relationships.

rrMap.Lanes(3).Successors = roadrunner.hdmap.AlignedReference(Reference=roadrunner.hdmap.Reference(ID="Lane4"));
rrMap.Lanes(3).Predecessors = roadrunner.hdmap.AlignedReference(Reference=roadrunner.hdmap.Reference(ID="Lane1"));
rrMap.Lanes(2).Successors = roadrunner.hdmap.AlignedReference(Reference=roadrunner.hdmap.Reference(ID="Lane5"));
rrMap.Lanes(2).Predecessors = roadrunner.hdmap.AlignedReference(Reference=roadrunner.hdmap.Reference(ID="Lane1"));
rrMap.Lanes(1).Successors = roadrunner.hdmap.AlignedReference(Reference=roadrunner.hdmap.Reference(ID="Lane2"));
rrMap.Lanes(4).Predecessors = roadrunner.hdmap.AlignedReference(Reference=roadrunner.hdmap.Reference(ID="Lane3"));
rrMap.Lanes(5).Predecessors = roadrunner.hdmap.AlignedReference(Reference=roadrunner.hdmap.Reference(ID="Lane2"));

Add a dashed, white marking in addition to the solid white and yellow markings, to the HD map. Define the path to the dashed, white lane marking asset using the roadrunner.hdmap.RelativeAssetPath function.

dashedWhiteAsset = roadrunner.hdmap.RelativeAssetPath(AssetPath="Assets/Markings/DashedSingleWhite.rrlms");

Create a dashed, white lane marking on the road using the roadrunner.hdmap.LaneMarking object.

rrMap.LaneMarkings(3,1) = roadrunner.hdmap.LaneMarking();
[rrMap.LaneMarkings.ID] = deal("SolidWhite","SolidYellow","DashedWhite");
[rrMap.LaneMarkings.AssetPath] = deal(solidWhiteAsset,solidYellowAsset,dashedWhiteAsset);

Assign lane markings using the parametric attributes.

markingRefDW = roadrunner.hdmap.MarkingReference(MarkingID=roadrunner.hdmap.Reference(ID="DashedWhite"));
markingAttribDW = roadrunner.hdmap.ParametricAttribution(MarkingReference=markingRefDW,Span=markingSpan);
[rrMap.LaneBoundaries.ParametricAttributes] = deal(markingAttribSY,markingAttribSW,markingAttribDW,markingAttribSW, ...
    markingAttribSY,markingAttribSY,markingAttribDW,markingAttribSW);

Plot the lane centers and lane boundaries.

plot(rrMap)

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent Lane Boundaries, Lane Centers.

Write the HD map to a file.

write(rrMap,"laneAdd.rrhd")

This figure shows a scene of the one-way road with two lanes defined in this section, built using RoadRunner Scene Builder.

See Also

|

Related Topics