def osc_fixture(): parameters = xosc.ParameterDeclarations() parameters.add_parameter(xosc.Parameter('param1',xosc.ParameterType.string,'hej')) parameters.add_parameter(xosc.Parameter('param2',xosc.ParameterType.integer,1)) parameters.add_parameter(xosc.Parameter('param3',xosc.ParameterType.boolean,True)) catalog = xosc.Catalog() catalog.add_catalog('VehicleCatalog','Catalogs/VehicleCatalogs') catalog.add_catalog('ControllerCatalog','Catalogs/ControllerCatalogs') roadfile = 'Databases/SampleDatabase.xodr' road = xosc.RoadNetwork(roadfile) bb = xosc.BoundingBox(2,5,1.5,1.5,0,0.2) fa = xosc.Axle(2,2,2,1,1) ba = xosc.Axle(1,1,2,1,1) veh = xosc.Vehicle('mycar',xosc.VehicleCategory.car,bb,fa,ba,150,10,10) entities = xosc.Entities() entities.add_scenario_object('Ego',veh) init = xosc.Init() egospeed = xosc.AbsoluteSpeedAction(10,xosc.TransitionDynamics(xosc.DynamicsShapes.step,xosc.DynamicsDimension.distance,3)) init.add_init_action('Ego',egospeed) init.add_init_action('Ego',xosc.TeleportAction(xosc.WorldPosition(1,2,3,0,0,0))) sb = xosc.StoryBoard(init) return xosc.Scenario('myscenario','Mandolin',parameters,entities=entities,storyboard = sb,roadnetwork=road,catalog=catalog)
def test_paramdeclaration(): pardec = OSC.ParameterDeclarations() pardec.add_parameter( OSC.Parameter('myparam1', OSC.ParameterType.integer, '1')) pardec.add_parameter( OSC.Parameter('myparam1', OSC.ParameterType.double, '0.01')) prettyprint(pardec.get_element())
def test_miscobj(): bb = OSC.BoundingBox(2, 5, 1.5, 1.5, 0, 0.2) veh = OSC.MiscObject('mycar', 100, OSC.MiscObjectCategory.obstacle, bb) prettyprint(veh.get_element()) veh.add_property_file('propfile.xml') veh.add_property('myprop', '12') param = OSC.Parameter('mypar', OSC.ParameterType.integer, '1') veh.add_parameter(param) prettyprint(veh.get_element())
def test_pedestrian(): bb = OSC.BoundingBox(2, 5, 1.5, 1.5, 0, 0.2) veh = OSC.Pedestrian('myped', 'ped', 100, OSC.PedestrianCategory.pedestrian, bb) prettyprint(veh.get_element()) veh.add_property_file('propfile.xml') veh.add_property('myprop', '12') param = OSC.Parameter('mypar', OSC.ParameterType.integer, '1') veh.add_parameter(param) prettyprint(veh.get_element())
def test_vehicle(): bb = OSC.BoundingBox(2, 5, 1.5, 1.5, 0, 0.2) fa = OSC.Axle(2, 2, 2, 1, 1) ba = OSC.Axle(1, 1, 2, 1, 1) veh = OSC.Vehicle('mycar', OSC.VehicleCategory.car, bb, fa, ba, 150, 10, 10) prettyprint(veh.get_element()) veh.add_property_file('propfile.xml') veh.add_property('myprop', '12') veh.add_axle(ba) param = OSC.Parameter('mypar', OSC.ParameterType.integer, '1') veh.add_parameter(param) prettyprint(veh.get_element())
import os from scenariogeneration import xosc, prettyprint ### create catalogs catalog = xosc.Catalog() catalog.add_catalog('VehicleCatalog', '../xosc/Catalogs/Vehicles') ### create road road = xosc.RoadNetwork(roadfile='../xodr/e6mini.xodr', scenegraph='../models/e6mini.osgb') ### create parameters paramdec = xosc.ParameterDeclarations() paramdec.add_parameter( xosc.Parameter('$HostVehicle', xosc.ParameterType.string, 'car_white')) paramdec.add_parameter( xosc.Parameter('$TargetVehicle', xosc.ParameterType.string, 'car_red')) bb = xosc.BoundingBox(2, 5, 1.8, 2.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) white_veh.add_property_file('../models/car_white.osgb') white_veh.add_property('model_id', '0') bb = xosc.BoundingBox(1.8, 4.5, 1.5, 1.3, 0, 0.8) 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)
ego_man = xosc.Maneuver('ego_maneuver') ego_man.add_event(ego_start_event) ego_man.add_event(ego_event) ego_mangr = xosc.ManeuverGroup('mangroup') ego_mangr.add_actor(egoname) ego_mangr.add_maneuver(ego_man) starttrigger = xosc.ValueTrigger('starttrigger',0,xosc.ConditionEdge.rising,xosc.SimulationTimeCondition(0,xosc.Rule.greaterThan)) act = xosc.Act('my_act',starttrigger) act.add_maneuver_group(mangr) act.add_maneuver_group(ego_mangr) ## create the story storyparam = xosc.ParameterDeclarations() storyparam.add_parameter(xosc.Parameter('$owner',xosc.ParameterType.string,targetname)) story = xosc.Story('mystory',storyparam) story.add_act(act) ## create the storyboard sb = xosc.StoryBoard(init,xosc.ValueTrigger('stop_simulation',0,xosc.ConditionEdge.rising,xosc.SimulationTimeCondition(15,xosc.Rule.greaterThan),'stop')) sb.add_story(story) ## create the scenario sce = xosc.Scenario('adapt_speed_example','Mandolin',paramdec,entities=entities,storyboard = sb,roadnetwork=road,catalog=catalog) # Print the resulting xml prettyprint(sce.get_element()) # write the OpenSCENARIO file as xosc using current script name sce.write_xml(os.path.basename(__file__).replace('.py','.xosc'))
def test_parameter(): param = OSC.Parameter('stuffs', OSC.ParameterType.integer, '1') prettyprint(param.get_element())