Module examples.xodr.manual_add_of_geometries
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 add geometries with a fixed position, please note that adjust_roads_and_lanes will only take care of the lane linking in this case not any geometrical adjustmensts
This is how a road can be built up if all exact postions of the geometries are already known
Some features used:
-
PlanView
-
(PlanView).add_fixed_geometry
-
RoadMark
-
Lane
-
LaneSection
-
Lanes
-
LaneLinker
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 how to add geometries with a fixed position, please note that *adjust_roads_and_lanes* will only take care of the lane linking in this case not any geometrical adjustmensts
This is how a road can be built up if all exact postions of the geometries are already known
Some features used:
- PlanView
- (PlanView).add_fixed_geometry
- RoadMark
- Lane
- LaneSection
- Lanes
- LaneLinker
"""
import os
from scenariogeneration import xodr, xosc, esmini, prettyprint, ScenarioGenerator
class Scenario(ScenarioGenerator):
def __init__(self):
super().__init__()
def road(self, **kwargs):
planview = xodr.PlanView()
# add two geometries based on exact position
planview.add_fixed_geometry(xodr.Line(100), 0, 0, 0)
planview.add_fixed_geometry(xodr.Arc(0.01, length=100), 100, 0, 0)
# create simple lanes
lanes = xodr.Lanes()
lanesection1 = xodr.LaneSection(0, xodr.standard_lane())
lanesection1.add_left_lane(xodr.standard_lane(rm=xodr.STD_ROADMARK_SOLID))
lanesection1.add_right_lane(xodr.standard_lane(rm=xodr.STD_ROADMARK_SOLID))
lanes.add_lanesection(lanesection1)
road1 = xodr.Road(0, planview, lanes)
# create a simple second road for connection
road2 = xodr.create_road(xodr.Line(100), 1)
# connect the roads with successor/predecessor
road1.add_successor(xodr.ElementType.road, 1, xodr.ContactPoint.start)
road2.add_predecessor(xodr.ElementType.road, 0, xodr.ContactPoint.end)
odr = xodr.OpenDrive("my_road")
odr.add_road(road1)
odr.add_road(road2)
# will adjust the second road and the lanes and lane links correctly
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): planview = xodr.PlanView() # add two geometries based on exact position planview.add_fixed_geometry(xodr.Line(100), 0, 0, 0) planview.add_fixed_geometry(xodr.Arc(0.01, length=100), 100, 0, 0) # create simple lanes lanes = xodr.Lanes() lanesection1 = xodr.LaneSection(0, xodr.standard_lane()) lanesection1.add_left_lane(xodr.standard_lane(rm=xodr.STD_ROADMARK_SOLID)) lanesection1.add_right_lane(xodr.standard_lane(rm=xodr.STD_ROADMARK_SOLID)) lanes.add_lanesection(lanesection1) road1 = xodr.Road(0, planview, lanes) # create a simple second road for connection road2 = xodr.create_road(xodr.Line(100), 1) # connect the roads with successor/predecessor road1.add_successor(xodr.ElementType.road, 1, xodr.ContactPoint.start) road2.add_predecessor(xodr.ElementType.road, 0, xodr.ContactPoint.end) odr = xodr.OpenDrive("my_road") odr.add_road(road1) odr.add_road(road2) # will adjust the second road and the lanes and lane links correctly odr.adjust_roads_and_lanes() return odr
Ancestors
Inherited members