Module examples.xosc.angle_condition_trigger

scenariogeneration https://github.com/pyoscx/scenariogeneration

Example showing how to use AngleCondition as a trigger for an event.

Classes

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

    def scenario(self, **kwargs):
        # Catalogs
        catalog = xosc.Catalog()
        catalog.add_catalog("VehicleCatalog", "../xosc/Catalogs/Vehicles")

        # Road
        road = xosc.RoadNetwork(
            roadfile="../xodr/e6mini.xodr", scenegraph="../models/e6mini.osgb"
        )

        # Parameters
        paramdec = xosc.ParameterDeclarations()

        # Entities
        egoname = "Ego"
        targetname = "Target"
        entities = xosc.Entities()
        entities.add_scenario_object(
            egoname, xosc.CatalogReference("VehicleCatalog", "car_white")
        )
        entities.add_scenario_object(
            targetname, xosc.CatalogReference("VehicleCatalog", "car_yellow")
        )

        # Init
        init = xosc.Init()
        init.add_init_action(
            egoname, xosc.TeleportAction(xosc.LanePosition(10, 0, -2, 0))
        )
        init.add_init_action(
            egoname,
            xosc.AbsoluteSpeedAction(
                20,
                xosc.TransitionDynamics(
                    xosc.DynamicsShapes.linear, xosc.DynamicsDimension.time, 1
                ),
            ),
        )
        init.add_init_action(
            targetname, xosc.TeleportAction(xosc.LanePosition(50, 0, -3, 0))
        )
        init.add_init_action(
            targetname,
            xosc.AbsoluteSpeedAction(
                10,
                xosc.TransitionDynamics(
                    xosc.DynamicsShapes.linear, xosc.DynamicsDimension.time, 1
                ),
            ),
        )

        deg = 60
        rad = math.radians(deg)
        # AngleCondition (trigger when Ego's orientation is 60 degrees with 0.1 tolerance)
        angle_condition = AngleCondition(
            angle=rad,
            angle_tolerance=0.1,
            angle_type=xosc.AngleType.heading,
            coordinate_system=xosc.CoordinateSystem.world,
        )

        # Trigger

        angle_trigger = xosc.EntityTrigger(
            "trigger", 0, xosc.ConditionEdge.none, angle_condition, egoname
        )

        # Event and Maneuver
        event = xosc.Event("angle_event", xosc.Priority.overwrite)
        event.add_trigger(angle_trigger)

        event.add_action(
            "speedup",
            xosc.AbsoluteSpeedAction(
                30,
                xosc.TransitionDynamics(
                    xosc.DynamicsShapes.linear, xosc.DynamicsDimension.time, 2
                ),
            ),
        )
        man = xosc.Maneuver("angle_maneuver")
        man.add_event(event)
        mangr = xosc.ManeuverGroup("angle_mangroup")
        mangr.add_actor("$owner")
        mangr.add_maneuver(man)

        # Act
        act = xosc.Act("angle_act", angle_trigger)
        act.add_maneuver_group(mangr)

        # Story
        storyparam = xosc.ParameterDeclarations()
        storyparam.add_parameter(
            xosc.Parameter("$owner", xosc.ParameterType.string, egoname)
        )
        story = xosc.Story("angle_story", storyparam)
        story.add_act(act)

        # Storyboard
        sb = xosc.StoryBoard(init)
        sb.add_story(story)

        # Scenario
        sce = xosc.Scenario(
            "AngleCondition_trigger_example",
            "ekelidar",
            paramdec,
            entities=entities,
            storyboard=sb,
            roadnetwork=road,
            catalog=catalog,
            osc_minor_version=self.open_scenario_version,
        )
        return sce

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
excluded_permutations : list[dict]
list of parameter dicts to exclude from generation
expand_permutations : list[dict[list]]
list of dicts where each dict has lists as values, all combinations of these lists will be expanded and combined with the other permutations

Ancestors

Inherited members