Module examples.xosc.trailer_example
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.
Simple example showing how one vehicle connects to a trailer
Some features used: - HitchCoupler
-
TrailerConnectAction
-
TrailerDisconnectAction
-
StoryboardElementStateCondition
Classes
class Scenario-
Expand source code
class Scenario(ScenarioGenerator): def __init__(self): super().__init__() self.open_scenario_version = 2 def scenario(self, **kwargs): ### create catalogs catalog = xosc.Catalog() ### create road road = xosc.RoadNetwork(roadfile="../xodr/straight_500m.xodr") ### create entities trailername = "trailer" bb = xosc.BoundingBox(2, 5, 1.8, 1.0, 0, 0.9) fa = xosc.Axle(0.523598775598, 0.8, 1.68, 2.98, 0.4) ba = xosc.Axle(0.523598775598, 0.8, 1.68, 0, 0.4) white_veh = xosc.Vehicle( "car_white", xosc.VehicleCategory.car, bb, fa, ba, 69, 10, 10, trailer_hitch=xosc.HitchCoupler(-1.5), ) white_veh.add_property_file("../models/car_white.osgb") bb = xosc.BoundingBox(1.8, 3, 0.5, 0, 0, 0.8) trailer = xosc.Vehicle( "car_red", xosc.VehicleCategory.trailer, bb, None, ba, 69, 10, 10, trailer_coupler=xosc.HitchCoupler(1.6), ) trailer.add_property_file("../models/car_trailer.osgb") ## create entities egoname = "Ego" entities = xosc.Entities() entities.add_scenario_object(egoname, white_veh) entities.add_scenario_object(trailername, trailer) ### create init init = xosc.Init() egostart = xosc.TeleportAction(xosc.LanePosition(25, 0, -1, 1)) targetstart = xosc.TeleportAction(xosc.LanePosition(15, 0, -1, 1)) init.add_init_action(egoname, egostart) init.add_init_action(trailername, targetstart) ### create an event ego_maneuver = xosc.Maneuver("ego pick up trailer") ego_event = xosc.Event("reverse", xosc.Priority.override) ego_event.add_trigger( xosc.ValueTrigger( "start reverse", 0.5, xosc.ConditionEdge.none, xosc.SimulationTimeCondition(0, xosc.Rule.greaterThan), ) ) ego_event.add_action( "reverse action", xosc.AbsoluteSpeedAction( -2, xosc.TransitionDynamics( xosc.DynamicsShapes.linear, xosc.DynamicsDimension.time, 0.5, ), ), ) ego_stop = xosc.Event("stop", xosc.Priority.override) ego_stop.add_trigger( xosc.EntityTrigger( "ego should stop", 0, xosc.ConditionEdge.none, xosc.RelativeDistanceCondition( 0.05, xosc.Rule.lessOrEqual, xosc.RelativeDistanceType.longitudinal, trailername, alongroute=False, ), egoname, ) ) ego_stop.add_action( "stop action", xosc.AbsoluteSpeedAction( 0, xosc.TransitionDynamics( xosc.DynamicsShapes.linear, xosc.DynamicsDimension.time, 0.1, ), ), ) ego_hitch = xosc.Event("connect", xosc.Priority.override) ego_hitch.add_trigger( xosc.EntityTrigger( "stand still", 0, xosc.ConditionEdge.none, xosc.StandStillCondition(1), egoname, ) ) ego_hitch.add_action( "connect trailer", xosc.ConnectTrailerAction(trailername) ) ego_drive = xosc.Event("start driving", xosc.Priority.override) ego_drive.add_trigger( xosc.ValueTrigger( "start driving condition", 1, xosc.ConditionEdge.none, xosc.StoryboardElementStateCondition( xosc.StoryboardElementType.event, "connect", xosc.StoryboardElementState.completeState, ), ) ) ego_drive.add_action( "drive action action", xosc.AbsoluteSpeedAction( 10, xosc.TransitionDynamics( xosc.DynamicsShapes.cubic, xosc.DynamicsDimension.time, 5 ), ), ) ego_detach = xosc.Event("disconnect", xosc.Priority.parallel) ego_detach.add_trigger( xosc.ValueTrigger( "disconnect trailer", 0, xosc.ConditionEdge.none, xosc.SimulationTimeCondition(8, xosc.Rule.greaterThan), ) ) ego_detach.add_action( "disconnect trailer", xosc.DisconnectTrailerAction() ) ego_maneuver.add_event(ego_event) ego_maneuver.add_event(ego_stop) ego_maneuver.add_event(ego_hitch) ego_maneuver.add_event(ego_drive) ego_maneuver.add_event(ego_detach) ## create the storyboard sb = xosc.StoryBoard(init) sb.add_maneuver(ego_maneuver, egoname) paramdec = xosc.ParameterDeclarations() ## create the scenario sce = xosc.Scenario( "adapt_speed_example", "Mandolin", paramdec, entities=entities, storyboard=sb, roadnetwork=road, catalog=catalog, osc_minor_version=3, ) return sceScenarioTemplate 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