Module examples.xodr.multiple_geometries_one_road

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.

Fundamental example how to build up a road from scratch.

This example should be seen as a developer example how roads are built up from the very basic classes in OpenDRIVE create_road will take care of this and much more, so a user is recommended to use that generator instead.

Some features used:

  • PlanView

  • Lane

  • Lanes

  • LaneSection

  • RoadMark

  • Road

Classes

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

    def road(self, **kwargs):
        ## Multiple geometries in one only road.

        ##1. Create the planview
        planview = xodr.PlanView()

        ##2. Create some geometries and add them to the planview
        line1 = xodr.Line(100)
        arc1 = xodr.Arc(0.05, angle=np.pi / 2)
        line2 = xodr.Line(100)
        cloth1 = xodr.Spiral(0.05, -0.1, 30)
        line3 = xodr.Line(100)

        planview.add_geometry(line1)
        planview.add_geometry(arc1)
        planview.add_geometry(line2)
        planview.add_geometry(cloth1)
        planview.add_geometry(line3)

        ##3. Create a solid roadmark
        rm = xodr.RoadMark(xodr.RoadMarkType.solid, 0.2)

        ##4. Create centerlane
        centerlane = xodr.Lane(a=2)
        centerlane.add_roadmark(rm)

        ##5. Create lane section form the centerlane
        lanesec = xodr.LaneSection(0, centerlane)

        ##6. Create left and right lanes
        lane2 = xodr.Lane(a=3)
        lane2.add_roadmark(rm)
        lane3 = xodr.Lane(a=3)
        lane3.add_roadmark(rm)

        ##7. Add lanes to lane section
        lanesec.add_left_lane(lane2)
        lanesec.add_right_lane(lane3)

        ##8. Add lane section to Lanes
        lanes = xodr.Lanes()
        lanes.add_lanesection(lanesec)

        ##9. Create Road from Planview and Lanes
        road = xodr.Road(1, planview, lanes)

        ##10. Create the OpenDrive class (Master class)
        odr = xodr.OpenDrive("myroad")

        ##11. Finally add roads to Opendrive
        odr.add_road(road)

        ##12. Adjust initial positions of the roads looking at succ-pred logic
        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