Module examples.xodr.lane_number_change_merge

scenariogeneration https://github.com/pyoscx/scenariogeneration

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

Copyright (c) 2022 The scenariogeneration Authors.

Example how to create a road with a lanemerge.

Simple cases can automated with create_road and LaneDef, but for complex cases this example shows how to do it from scratch. This example makes use of the LaneLinker class that is not part of OpenDRIVE but a helper class for the xodr module

Some features used:

  • PlanView

  • RoadMark

  • Lane

  • LaneSection

  • Lanes

  • LaneLinker

Classes

class Scenario
Expand source code
class Scenario(ScenarioGenerator):
    def __init__(self):
        super().__init__()

    def road(self, **kwargs):
        # create the planview and the geometry
        planview = xodr.PlanView()

        planview.add_geometry(xodr.Line(500))

        # create two different roadmarkings
        rm_solid = xodr.RoadMark(xodr.RoadMarkType.solid, 0.2)
        rm_dashed = xodr.RoadMark(xodr.RoadMarkType.broken, 0.2)

        # create a centerlane (same centerlane can be used since no linking is needed for this)
        centerlane = xodr.Lane(a=2)
        centerlane.add_roadmark(rm_solid)

        # create the first lanesection with two lanes
        lanesec1 = xodr.LaneSection(0, centerlane)
        lane1 = xodr.Lane(a=3)
        lane1.add_roadmark(rm_dashed)

        lane2 = xodr.Lane(a=3)
        lane2.add_roadmark(rm_solid)

        lanesec1.add_right_lane(lane1)
        lanesec1.add_right_lane(lane2)

        # create the second lanesection with one lane merging
        lanesec2 = xodr.LaneSection(250, centerlane)
        lane3 = xodr.Lane(a=3)
        lane3.add_roadmark(rm_dashed)

        lane4 = xodr.Lane(a=3, b=-0.1)
        lane4.add_roadmark(rm_solid)

        lanesec2.add_right_lane(lane3)
        lanesec2.add_right_lane(lane4)

        # create the last lanesection with one lane
        lanesec3 = xodr.LaneSection(280, centerlane)

        lane5 = xodr.Lane(a=3)
        lane5.add_roadmark(rm_solid)

        lanesec3.add_right_lane(lane5)

        # create the lane links
        lanelinker = xodr.LaneLinker()
        lanelinker.add_link(predlane=lane1, succlane=lane3)
        lanelinker.add_link(predlane=lane2, succlane=lane4)
        lanelinker.add_link(predlane=lane3, succlane=lane5)

        # create the lanes with the correct links
        lanes = xodr.Lanes()
        lanes.add_lanesection(lanesec1, lanelinker)
        lanes.add_lanesection(lanesec2, lanelinker)
        lanes.add_lanesection(lanesec3, lanelinker)

        # create the road
        road = xodr.Road(1, planview, lanes)

        # create the opendrive
        odr = xodr.OpenDrive("myroad")
        odr.add_road(road)

        # adjust the roads and lanes
        odr.adjust_roads_and_lanes()
        return odr

ScenarioTemplate is a class that should be inherited by a Scenario class in order to generate xodr and xosc files based on the submodules xodr and xosc

Two main uses, in your generation class define self.parameters as either as: - a dict of lists, where the lists are the values you want to sweep over, all permutations of these sets will be generated - a list of dicts, where the dicts are identical and each element in the list is one scenario

Attributes

road_file : str
name of the roadfile
parameters : dict[list], list[dicts]
parameter sets to be used
naming : str
two options "numerical" or "parameter"
generate_all_roads : bool
will only generate unique roads
number_of_parallel_writings : int
parallelize the writing of the xml files, default: 1
basename : str
basename of the scenariofiles, default: name of file
encoding : str
encoding of the outputs, default: utf-8

Ancestors

Inherited members