Module examples.xodr.road_with_custom_lanes

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 roads with custom lanes to the left and right

Some features used

  • PlanView

  • LaneSection

Classes

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

    def road(self, **kwargs):
        # create a simple planview
        planview = xodr.PlanView()
        planview.add_geometry(xodr.Line(500))

        # create the customized lanes
        centerlane = xodr.Lane(lane_type=xodr.LaneType.median)
        lanesection = xodr.LaneSection(0, centerlane)

        # add the median to the center
        lanesection.add_left_lane(
            xodr.Lane(lane_type=xodr.LaneType.median, a=0.3)
        )
        lanesection.add_right_lane(
            xodr.Lane(lane_type=xodr.LaneType.median, a=0.3)
        )

        # add a curb
        lanesection.add_left_lane(
            xodr.Lane(lane_type=xodr.LaneType.curb, a=0.1)
        )
        lanesection.add_right_lane(
            xodr.Lane(lane_type=xodr.LaneType.curb, a=0.1)
        )

        # add driving lanes with roadmarks
        left_lane_with_roadmark = xodr.Lane(a=4)
        left_lane_with_roadmark.add_roadmark(xodr.std_roadmark_solid())
        lanesection.add_left_lane(left_lane_with_roadmark)

        right_lane_with_roadmark = xodr.Lane(a=4)
        right_lane_with_roadmark.add_roadmark(xodr.std_roadmark_solid())
        lanesection.add_right_lane(right_lane_with_roadmark)

        # add driving lanes to end in border
        lanesection.add_left_lane(xodr.Lane(a=4))
        lanesection.add_right_lane(xodr.Lane(a=4))

        # add a border

        lanesection.add_left_lane(
            xodr.Lane(lane_type=xodr.LaneType.border, a=0.2)
        )
        lanesection.add_right_lane(
            xodr.Lane(lane_type=xodr.LaneType.border, a=0.2)
        )

        # add a final curb
        lanesection.add_left_lane(
            xodr.Lane(lane_type=xodr.LaneType.curb, a=0.1)
        )
        lanesection.add_right_lane(
            xodr.Lane(lane_type=xodr.LaneType.curb, a=0.1)
        )

        # add a bikingroad on one side
        lanesection.add_right_lane(
            xodr.Lane(lane_type=xodr.LaneType.biking, a=2)
        )

        # create the lanes and add the lanesection
        lanes = xodr.Lanes()
        lanes.add_lanesection(lanesection)

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

        # create the opendrive and add the road
        odr = xodr.OpenDrive("road with custom lanes")
        odr.add_road(road)

        # adjust the road
        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