Module examples.xodr.common_junction_creator

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 of how to create a highway entry using CommonJunctionCreator

Some features used:

  • create_road

  • add_successor/add_predecessor with and without the lane_offset option, and the direct_junction input

  • CommonJunctionCreator

Expand source code
"""
  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 of how to create a highway entry using CommonJunctionCreator

    Some features used:

    - create_road

    - add_successor/add_predecessor with and without the lane_offset option, and the direct_junction input

    - CommonJunctionCreator
"""

import os
from scenariogeneration import xodr, prettyprint, ScenarioGenerator


class Scenario(ScenarioGenerator):
    def __init__(self):
        super().__init__()

    def road(self, **kwargs):
        # initalize the junction creator
        junction_id = 100
        junction_creator = xodr.DirectJunctionCreator(
            id=junction_id, name="my direct junction"
        )

        # create 3 roads, and add the successor/predecessor junction

        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)

        # create direct junction connection to all common lanes between the main roads

        junction_creator = xodr.CommonJunctionCreator(id=100, name="my_junction")

        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"
        )

        # create the opendrive
        odr = xodr.OpenDrive("my_road")

        # add the roads
        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
        )

        odr.add_road(road1)
        odr.add_road(road2)
        odr.add_road(road3)

        # add the junction creator
        odr.add_junction_creator(junction_creator)

        # adjust the roads and lanes
        odr.adjust_roads_and_lanes()

        return odr


if __name__ == "__main__":
    sce = Scenario()
    # Print the resulting xml
    prettyprint(sce.road().get_element())

    # write the OpenDRIVE file as xosc using current script name
    sce.generate(".")

    # uncomment the following lines to display the scenario using esmini
    # from scenariogeneration import esmini
    # esmini(sce,os.path.join('esmini'))

Classes

class Scenario

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

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 of lists, or list of 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 (no parallelization)

basename (str): basename of the scenariofiles,
    Default: name of file

encoding (str): encoding of the outputs
    Default:
Expand source code
class Scenario(ScenarioGenerator):
    def __init__(self):
        super().__init__()

    def road(self, **kwargs):
        # initalize the junction creator
        junction_id = 100
        junction_creator = xodr.DirectJunctionCreator(
            id=junction_id, name="my direct junction"
        )

        # create 3 roads, and add the successor/predecessor junction

        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)

        # create direct junction connection to all common lanes between the main roads

        junction_creator = xodr.CommonJunctionCreator(id=100, name="my_junction")

        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"
        )

        # create the opendrive
        odr = xodr.OpenDrive("my_road")

        # add the roads
        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
        )

        odr.add_road(road1)
        odr.add_road(road2)
        odr.add_road(road3)

        # add the junction creator
        odr.add_junction_creator(junction_creator)

        # adjust the roads and lanes
        odr.adjust_roads_and_lanes()

        return odr

Ancestors

Inherited members