How to use the roadrunner hdmap junction in matlab?
Show older comments
Hi, I think the same question was ask in 2023 but didn't get answered yet (https://www.mathworks.com/matlabcentral/answers/1909405-how-to-write-a-junction-in-roadrunner-hdmap-using-matlab?s_tid=srchtitle).
I tried to understand the documantation (https://ww2.mathworks.cn/help/driving/ref/roadrunner.hdmap.junction.html#) and create a simple junction by myself. But the juction doesn't show up in the Roadrunner. Can you please help me diagonise which step might be wrong in my example? Thanks!
rrMap = roadrunnerHDMap;
outer1 = [0 0; 4 0; 4 4; 0 4; 0 0];
outer2 = [5 5 0; 7 5 0; 7 7 0; 5 7 0; 5 5 0];
polygon1 = roadrunner.hdmap.Polygon( ...
'ExteriorRing', outer1, ...
'InteriorRings', {} ...
);
polygon2 = roadrunner.hdmap.Polygon( ...
'ExteriorRing', outer2, ...
'InteriorRings', {} ...
);
multiPoly = roadrunner.hdmap.MultiPolygon( ...
'Polygons', [polygon1;] ...
);
rrMap.Junctions(1) = roadrunner.hdmap.Junction(ID="Junction1", Geometry=multiPoly)
Answers (1)
The junction is not visible in RoadRunner because a junction is only visible when lanes associated with them are present in the RoadRunnner HD Map. The following code snippet adds a lane alongwith a junction:
rrMap = roadrunnerHDMap;
outer1 = [0 0; 4 0; 4 4; 0 4; 0 0];
outer2 = [5 5 0; 7 5 0; 7 7 0; 5 7 0; 5 5 0];
polygon1 = roadrunner.hdmap.Polygon( ...
'ExteriorRing', outer1, ...
'InteriorRings', {} ...
);
polygon2 = roadrunner.hdmap.Polygon( ...
'ExteriorRing', outer2, ...
'InteriorRings', {} ...
);
multiPoly = roadrunner.hdmap.MultiPolygon( ...
'Polygons', [polygon1;] ...
);
rrMap.Junctions(1) = roadrunner.hdmap.Junction(ID="Junction1", Geometry=multiPoly)
rrMap.Lanes(1) = roadrunner.hdmap.Lane(ID="Lane1", Geometry=[0 0;25 0], LaneType= "Driving", TravelDirection="Forward");
rrMap.LaneBoundaries(2) = roadrunner.hdmap.LaneBoundary(ID="LaneBoundary2",Geometry=[0 2.5; 25 2.5]);
rrMap.LaneBoundaries(1) = roadrunner.hdmap.LaneBoundary(ID="LaneBoundary1",Geometry=[0 -2.5; 25 -2.5]);
rightBoundary(rrMap.Lanes(1),"LaneBoundary1",Alignment="Forward");
leftBoundary(rrMap.Lanes(1),"LaneBoundary2",Alignment="Forward");
rrMap.Junctions(1).Lanes(1) = roadrunner.hdmap.Reference(ID="Lane1");
write(rrMap, "sampleMap.rrhd")
Observe the grey rectangle in the image below which is the junction:

You can refer to the following documentation links for more information:
- https://www.mathworks.com/help/driving/ref/roadrunner.hdmap.junction.html
- https://www.mathworks.com/help/driving/ref/roadrunnerhdmap.html
Hope it helps, best!
Categories
Find more on Programmatic Scene and Scenario Management in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!