The CommonJunctionCreator class is used to build standard OpenDRIVE junctions. This is a two-step process: adding roads to the junction and then defining connections between them.
1. Add Incoming Roads
Roads must have a predecessor or successor pointing to the junction. You can add them using add_incoming_road_cartesian_geometry or add_incoming_road_circular_geometry.
- Cartesian Geometry: Uses an
x-y-h system where h is the heading of the road into the junction. - Circular Geometry: Uses an
r-h system where r is the radius from the junction center and h is the heading from the center.
2. Add Connections
Use add_connection to link roads.
- Basic:
add_connection(road_one_id=1, road_two_id=2) creates a connecting road with the minimum equal number of lanes between the two roads. - Specific Lanes: Use
lane_one_id and lane_two_id to connect only specific lanes.
3. Finalize
Add the roads to an OpenDrive object and use add_junction_creator followed by adjust_roads_and_lanes().
from scenariogeneration import xodr
road1 = xodr.create_road(xodr.Line(100), id=1, left_lanes=2, right_lanes=2)
road2 = xodr.create_road(xodr.Line(100), id=2, left_lanes=1, right_lanes=1)
road3 = xodr.create_road(xodr.Line(100), id=3, left_lanes=2, right_lanes=2)
junction_creator = xodr.CommonJunctionCreator(id=100, name='my_junction')
# Add roads using Cartesian coordinates
junction_creator.add_incoming_road_cartesian_geometry(road1, x=0, y=0, heading=0, road_connection='successor')
junction_creator.add_incoming_road_cartesian_geometry(road2, x=50, y=50, heading=3.1415*3/2, road_connection='predecessor')
junction_creator.add_incoming_road_cartesian_geometry(road3, x=100, y=0, heading=-3.1415, road_connection='predecessor')
# Define connections
junction_creator.add_connection(road_one_id=1, road_two_id=3)
junction_creator.add_connection(road_one_id=1, road_two_id=2, lane_one_id=2, lane_two_id=1)
junction_creator.add_connection(road_one_id=2, road_two_id=3, lane_one_id=-1, lane_two_id=2)
# Finalize OpenDrive
odr = xodr.OpenDrive('myroad')
odr.add_road(road1)
odr.add_road(road2)
odr.add_road(road3)
odr.add_junction_creator(junction_creator)
odr.adjust_roads_and_lanes()