Module examples.xodr.two_roads
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 showing how to create two separate roads (that are not linked), hence adjust_roads_and_lanes will not be able to set the geometries without a similar approach.
Some features used:
- PlanView
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 showing how to create two separate roads (that are not linked), hence adjust_roads_and_lanes will not be able to set the geometries without a similar approach.
Some features used:
- PlanView
"""
from scenariogeneration import xodr, prettyprint, ScenarioGenerator
import numpy as np
import os
class Scenario(ScenarioGenerator):
def __init__(self):
super().__init__()
def road(self, **kwargs):
odr = xodr.OpenDrive("myroad")
# ---------------- Road 1
planview = xodr.PlanView(0, 0, 0)
# create some geometries and add to the planview
planview.add_geometry(xodr.Line(100))
# create a solid roadmark
rm = xodr.RoadMark(xodr.RoadMarkType.solid, 0.2)
# create centerlane
centerlane_1 = xodr.Lane(a=2)
centerlane_1.add_roadmark(rm)
lanesec_1 = xodr.LaneSection(0, centerlane_1)
# add a driving lane
lane2_1 = xodr.Lane(a=3.1)
lane2_1.add_roadmark(rm)
lanesec_1.add_left_lane(lane2_1)
lane3_1 = xodr.Lane(a=3.1)
lane3_1.add_roadmark(rm)
lanesec_1.add_right_lane(lane3_1)
## finalize the road
lanes_1 = xodr.Lanes()
lanes_1.add_lanesection(lanesec_1)
road = xodr.Road(1, planview, lanes_1)
odr.add_road(road)
# ---------------- Road 2
planview2 = xodr.PlanView(x_start=0, y_start=10, h_start=np.pi / 2)
# planview2 = xodr.PlanView()
# create some geometries and add to the planview
planview2.add_geometry(xodr.Line(200))
# create a solid roadmark
rm = xodr.RoadMark(xodr.RoadMarkType.solid, 0.2)
# create centerlane
centerlane = xodr.Lane(a=2)
centerlane.add_roadmark(rm)
lanesec = xodr.LaneSection(0, centerlane)
# add a driving lane
lane2 = xodr.Lane(a=3.1)
lane2.add_roadmark(rm)
lanesec.add_left_lane(lane2)
lane3 = xodr.Lane(a=3.1)
lane3.add_roadmark(rm)
lanesec.add_right_lane(lane3)
## finalize the road
lanes = xodr.Lanes()
lanes.add_lanesection(lanesec)
road2 = xodr.Road(2, planview2, lanes)
odr.add_road(road2)
# ------------------ Finalize
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): odr = xodr.OpenDrive("myroad") # ---------------- Road 1 planview = xodr.PlanView(0, 0, 0) # create some geometries and add to the planview planview.add_geometry(xodr.Line(100)) # create a solid roadmark rm = xodr.RoadMark(xodr.RoadMarkType.solid, 0.2) # create centerlane centerlane_1 = xodr.Lane(a=2) centerlane_1.add_roadmark(rm) lanesec_1 = xodr.LaneSection(0, centerlane_1) # add a driving lane lane2_1 = xodr.Lane(a=3.1) lane2_1.add_roadmark(rm) lanesec_1.add_left_lane(lane2_1) lane3_1 = xodr.Lane(a=3.1) lane3_1.add_roadmark(rm) lanesec_1.add_right_lane(lane3_1) ## finalize the road lanes_1 = xodr.Lanes() lanes_1.add_lanesection(lanesec_1) road = xodr.Road(1, planview, lanes_1) odr.add_road(road) # ---------------- Road 2 planview2 = xodr.PlanView(x_start=0, y_start=10, h_start=np.pi / 2) # planview2 = xodr.PlanView() # create some geometries and add to the planview planview2.add_geometry(xodr.Line(200)) # create a solid roadmark rm = xodr.RoadMark(xodr.RoadMarkType.solid, 0.2) # create centerlane centerlane = xodr.Lane(a=2) centerlane.add_roadmark(rm) lanesec = xodr.LaneSection(0, centerlane) # add a driving lane lane2 = xodr.Lane(a=3.1) lane2.add_roadmark(rm) lanesec.add_left_lane(lane2) lane3 = xodr.Lane(a=3.1) lane3.add_roadmark(rm) lanesec.add_right_lane(lane3) ## finalize the road lanes = xodr.Lanes() lanes.add_lanesection(lanesec) road2 = xodr.Road(2, planview2, lanes) odr.add_road(road2) # ------------------ Finalize odr.adjust_roads_and_lanes() return odr
Ancestors
Inherited members