def test_road(): roadfile = 'Databases/SampleDatabase.xodr' road = OSC.RoadNetwork(roadfile) OSC.prettyprint(road.get_element())
Some features used: Controller Properties """ import pyoscx ### create catalogs catalog = pyoscx.Catalog() catalog.add_catalog('VehicleCatalog', '../xosc/Catalogs/Vehicles') ### create road road = pyoscx.RoadNetwork(roadfile='../xodr/e6mini.xodr', scenegraph='../models/e6mini.osgb') ### create parameters paramdec = pyoscx.ParameterDeclarations() paramdec.add_parameter( pyoscx.Parameter('$HostVehicle', pyoscx.ParameterType.string, 'car_white')) paramdec.add_parameter( pyoscx.Parameter('$TargetVehicle', pyoscx.ParameterType.string, 'car_red')) ### create vehicles bb = pyoscx.BoundingBox(2, 5, 1.8, 2.0, 0, 0.9) fa = pyoscx.Axel(30, 0.8, 1.68, 2.98, 0.4) ba = pyoscx.Axel(30, 0.8, 1.68, 0, 0.4) white_veh = pyoscx.Vehicle('car_white', pyoscx.VehicleCategory.car, bb, fa, ba,
def test_scenario(): catalog = OSC.Catalog() catalog.add_catalog('VehicleCatalog', 'Catalogs/VehicleCatalogs') catalog.add_catalog('ControllerCatalog', 'Catalogs/ControllerCatalogs') roadfile = 'Databases/SampleDatabase.xodr' road = OSC.RoadNetwork(roadfile) trigcond = OSC.TimeToCollisionCondition(10, 'equalTo', True, freespace=False, position=OSC.WorldPosition()) trigger = OSC.EntityTrigger('mytesttrigger', 0.2, 'rising', trigcond, 'Target_1') event = OSC.Event('myfirstevent', 'overwrite') event.add_trigger(trigger) TD = OSC.TransitionDynamics('step', 'rate', 1) lanechangeaction = OSC.AbsoluteLaneChangeAction(1, TD) OSC.prettyprint(lanechangeaction.get_element()) speedaction = OSC.AbsoluteSpeedAction(50, TD) event.add_action('newspeed', speedaction) man = OSC.Maneuver('my maneuver') man.add_event(event) mangr = OSC.ManeuverGroup('mangroup') mangr.add_actor('Ego') mangr.add_maneuver(man) act = OSC.Act('my act', trigger) act.add_maneuver_group(mangr) story = OSC.Story('mystory') story.add_act(act) bb = OSC.BoundingBox(2, 5, 1.5, 1.5, 0, 0.2) fa = OSC.Axel(2, 2, 2, 1, 1) ba = OSC.Axel(1, 1, 2, 1, 1) veh = OSC.Vehicle('mycar', 'vehicle', bb, fa, ba, 150, 10, 10) entities = OSC.Entities() entities.add_scenario_object('Ego', veh) entities.add_scenario_object('Target_1', veh) init = OSC.Init() egospeed = OSC.AbsoluteSpeedAction(10, TD) init.add_init_action('Ego', egospeed) init.add_init_action( 'Ego', OSC.TeleportAction(OSC.WorldPosition(1, 2, 3, 0, 0, 0))) init.add_init_action('Target_1', egospeed) init.add_init_action( 'Target_1', OSC.TeleportAction(OSC.WorldPosition(1, 5, 3, 0, 0, 0))) sb = OSC.StoryBoard(init) sb.add_story(story) sce = OSC.Scenario('myscenario', 'Mandolin', OSC.ParameterDeclarations(), entities=entities, storyboard=sb, roadnetwork=road, catalog=catalog) OSC.prettyprint(sce.get_element())
def CCRm(ego_speedvalue,offset): # create empty catalog catalog = pyoscx.Catalog() # add straight road road = pyoscx.RoadNetwork(roadfile='../xodr/straight_500m.xodr',scenegraph='../models/straight_500m.osgb') # create empty paramdeclaration paramdec = pyoscx.ParameterDeclarations() egoname = 'Ego' targetname = 'Target1' ### create vehicles ego_width = 2 target_width = 1.8 bb = pyoscx.BoundingBox(ego_width,5,1.8,2.0,0,0.9) fa = pyoscx.Axel(30,0.8,1.68,2.98,0.4) ba = pyoscx.Axel(30,0.8,1.68,0,0.4) white_veh = pyoscx.Vehicle('car_white',pyoscx.VehicleCategory.car,bb,fa,ba,69,10,10) white_veh.add_property_file('../models/car_white.osgb') white_veh.add_property('control','internal') white_veh.add_property('model_id','0') bb = pyoscx.BoundingBox(target_width,4.5,1.5,1.3,0,0.8) fa = pyoscx.Axel(30,0.8,1.68,2.98,0.4) ba = pyoscx.Axel(30,0.8,1.68,0,0.4) red_veh = pyoscx.Vehicle('car_red',pyoscx.VehicleCategory.car,bb,fa,ba,69,10,10) red_veh.add_property_file('../models/car_red.osgb') red_veh.add_property('model_id','2') ## create entities entities = pyoscx.Entities() entities.add_scenario_object(egoname,white_veh) entities.add_scenario_object(targetname,red_veh) # create init (0 starting speed) init = pyoscx.Init() step_time = pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step,pyoscx.DynamicsDimension.time,1) # caluclate correct offset based on target vehicle width cal_offset = offset/100*target_width egospeed = pyoscx.AbsoluteSpeedAction(0,step_time) egostart = pyoscx.TeleportAction(pyoscx.LanePosition(25,cal_offset,-1,1)) startpos = 25 + (ego_speedvalue-20)/3.6* (acceleration_time+ttc_at_speed) targetspeed = pyoscx.AbsoluteSpeedAction(0,step_time) targetstart = pyoscx.TeleportAction(pyoscx.LanePosition(startpos,0,-1,1)) init.add_init_action(egoname,egospeed) init.add_init_action(egoname,egostart) init.add_init_action(targetname,targetspeed) init.add_init_action(targetname,targetstart) # create start trigger trigger = pyoscx.ValueTrigger('starttrigger',0,pyoscx.ConditionEdge.rising,pyoscx.SimulationTimeCondition(1,pyoscx.Rule.greaterThan)) # accelerate cars to wanted velocity eventego = pyoscx.Event('egospeedchange',pyoscx.Priority.overwrite) eventego.add_trigger(trigger) ego_action = pyoscx.AbsoluteSpeedAction(ego_speedvalue/3.6,pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.linear,pyoscx.DynamicsDimension.time,acceleration_time)) eventego.add_action('newspeed',ego_action) event_tar = pyoscx.Event('targetspeedchange',pyoscx.Priority.overwrite) event_tar.add_trigger(trigger) target_action = pyoscx.AbsoluteSpeedAction(20/3.6,pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.linear,pyoscx.DynamicsDimension.time,acceleration_time)) event_tar.add_action('targetspeed',target_action) # create maneuvers/maneuvergroups ego_man = pyoscx.Maneuver('ego man') ego_man.add_event(eventego) tar_man = pyoscx.Maneuver('target man') tar_man.add_event(event_tar) egomangr = pyoscx.ManeuverGroup('egomangr') egomangr.add_actor(egoname) egomangr.add_maneuver(ego_man) tarmangr = pyoscx.ManeuverGroup('tarmangr') tarmangr.add_actor(targetname) tarmangr.add_maneuver(tar_man) # create act act = pyoscx.Act('ccrm act',pyoscx.ValueTrigger('starttrigger',0,pyoscx.ConditionEdge.rising,pyoscx.SimulationTimeCondition(0,pyoscx.Rule.greaterThan))) act.add_maneuver_group(egomangr) act.add_maneuver_group(tarmangr) # create story story = pyoscx.Story('mystory') story.add_act(act) ## create the storyboard sb = pyoscx.StoryBoard(init,pyoscx.ValueTrigger('stop_simulation',0,pyoscx.ConditionEdge.rising,pyoscx.SimulationTimeCondition(ttc_at_speed*2+acceleration_time,pyoscx.Rule.greaterThan),'stop')) sb.add_story(story) ## create and return the scenario sce = pyoscx.Scenario('CCRm_v: ' +str(ego_speedvalue) + ', offset: ' + str(offset),'Mandolin',paramdec,entities=entities,storyboard = sb,roadnetwork=road,catalog=catalog) return sce
Example of a synchronizing two vehicles at one point Some features used: AbsoluteSynchronizeAction """ import pyoscx ### create catalogs catalog = pyoscx.Catalog() catalog.add_catalog('VehicleCatalog', '../xosc/Catalogs/Vehicles') ### create road road = pyoscx.RoadNetwork(roadfile="../xodr/e6mini.xodr", scenegraph="../models/e6mini.osgb") ### create parameters paramdec = pyoscx.ParameterDeclarations() ## create entities egoname = 'Ego' targetname = 'Target' entities = pyoscx.Entities() entities.add_scenario_object( egoname, pyoscx.CatalogReference('VehicleCatalog', 'car_red')) entities.add_scenario_object( targetname, pyoscx.CatalogReference('VehicleCatalog', 'car_blue'))
def CCRb(distance, decelleration): # create empty catalog catalog = pyoscx.Catalog() # add straight road road = pyoscx.RoadNetwork(roadfile='../xodr/straight_500m.xodr', scenegraph='../models/straight_500m.osgb') # create empty paramdeclaration paramdec = pyoscx.ParameterDeclarations() egoname = 'Ego' targetname = 'Target1' ### create vehicles ego_width = 2 target_width = 1.8 bb = pyoscx.BoundingBox(ego_width, 5, 1.8, 2.0, 0, 0.9) fa = pyoscx.Axle(0.523598775598, 0.8, 1.68, 2.98, 0.4) ba = pyoscx.Axle(0.523598775598, 0.8, 1.68, 0, 0.4) white_veh = pyoscx.Vehicle('car_white', pyoscx.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 = pyoscx.BoundingBox(target_width, 4.5, 1.5, 1.3, 0, 0.8) fa = pyoscx.Axle(0.523598775598, 0.8, 1.68, 2.98, 0.4) ba = pyoscx.Axle(0.523598775598, 0.8, 1.68, 0, 0.4) red_veh = pyoscx.Vehicle('car_red', pyoscx.VehicleCategory.car, bb, fa, ba, 69, 10, 10) red_veh.add_property_file('../models/car_red.osgb') red_veh.add_property('model_id', '2') ## create entities entities = pyoscx.Entities() entities.add_scenario_object(egoname, white_veh) entities.add_scenario_object(targetname, red_veh) # create init (0 starting speed) init = pyoscx.Init() step_time = pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step, pyoscx.DynamicsDimension.time, 1) # caluclate correct offset based on target vehicle width cal_offset = 0 egospeed = pyoscx.AbsoluteSpeedAction(0, step_time) egostart = pyoscx.TeleportAction(pyoscx.LanePosition( 25, cal_offset, -1, 1)) targetspeed = pyoscx.AbsoluteSpeedAction(0, step_time) targetstart = pyoscx.TeleportAction( pyoscx.LanePosition(25 + distance, 0, -1, 1)) init.add_init_action(egoname, egospeed) init.add_init_action(egoname, egostart) init.add_init_action(targetname, targetspeed) init.add_init_action(targetname, targetstart) # create start trigger trigger = pyoscx.ValueTrigger( 'starttrigger', 0, pyoscx.ConditionEdge.rising, pyoscx.SimulationTimeCondition(1, pyoscx.Rule.greaterThan)) # accelerate cars to wanted velocity eventego = pyoscx.Event('egospeedchange', pyoscx.Priority.overwrite) eventego.add_trigger(trigger) ego_action = pyoscx.AbsoluteSpeedAction( 50 / 3.6, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.linear, pyoscx.DynamicsDimension.time, acceleration_time)) eventego.add_action('newspeed', ego_action) event_tar = pyoscx.Event('targetspeedchange', pyoscx.Priority.overwrite) event_tar.add_trigger(trigger) target_action = pyoscx.LongitudinalDistanceAction(-distance, egoname) event_tar.add_action('targetspeed', target_action) # trigger here could be changed to speed but tested for esmini at the point where speed condition was not implemented target_slowingdown_trigger = pyoscx.ValueTrigger( 'slowingdowntrigger', 0, pyoscx.ConditionEdge.rising, pyoscx.SimulationTimeCondition(6, pyoscx.Rule.greaterThan)) target_slowingdown_action = pyoscx.AbsoluteSpeedAction( 0, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.linear, pyoscx.DynamicsDimension.rate, abs(decelleration))) event_tar_slowdown = pyoscx.Event('target slowing down', pyoscx.Priority.overwrite) event_tar_slowdown.add_trigger(target_slowingdown_trigger) event_tar_slowdown.add_action('slowdownaction', target_slowingdown_action) # create maneuvers/maneuvergroups ego_man = pyoscx.Maneuver('ego man') ego_man.add_event(eventego) tar_man = pyoscx.Maneuver('target man') tar_man.add_event(event_tar) tar_man.add_event(event_tar_slowdown) egomangr = pyoscx.ManeuverGroup('egomangr') egomangr.add_actor(egoname) egomangr.add_maneuver(ego_man) tarmangr = pyoscx.ManeuverGroup('tarmangr') tarmangr.add_actor(targetname) tarmangr.add_maneuver(tar_man) # create act act = pyoscx.Act( 'ccrm act', pyoscx.ValueTrigger( 'starttrigger', 0, pyoscx.ConditionEdge.rising, pyoscx.SimulationTimeCondition(0, pyoscx.Rule.greaterThan))) act.add_maneuver_group(egomangr) act.add_maneuver_group(tarmangr) # create story story = pyoscx.Story('mystory') story.add_act(act) ## create the storyboard sb = pyoscx.StoryBoard( init, pyoscx.ValueTrigger( 'stop_simulation', 2, pyoscx.ConditionEdge.rising, pyoscx.SimulationTimeCondition( acceleration_time + np.ceil(np.sqrt(2 * distance / abs(decelleration))) + distance / 50, pyoscx.Rule.greaterThan), 'stop')) sb.add_story(story) ## create and return the scenario sce = pyoscx.Scenario('CCRb, distance: ' + str(distance) + ', decelleration: ' + str(decelleration), 'Mandolin', paramdec, entities=entities, storyboard=sb, roadnetwork=road, catalog=catalog) return sce
Some features used: Route AssignRouteAction LanePosition """ import pyoscx ### create catalogs catalog = pyoscx.Catalog() catalog.add_catalog('VehicleCatalog','../xosc/Catalogs/Vehicles') ### create road road = pyoscx.RoadNetwork(roadfile="../xodr/fabriksgatan.xodr",scenegraph="../models/fabriksgatan.osgb") ### create parameters paramdec = pyoscx.ParameterDeclarations() ## create entities egoname = 'Ego' targetname = 'Target' entities = pyoscx.Entities() entities.add_scenario_object(egoname,pyoscx.CatalogReference('VehicleCatalog','car_red')) ### create init init = pyoscx.Init()
Some features used: multiple execusions End of road Teleport LanePosition """ import pyoscx ### create catalogs catalog = pyoscx.Catalog() catalog.add_catalog('VehicleCatalog', '../xosc/Catalogs/Vehicles') ### create road road = pyoscx.RoadNetwork(roadfile='../xodr/straight_500m.xodr', scenegraph='../models/straight_500m.osgb') ### create parameters paramdec = pyoscx.ParameterDeclarations() ## loop to create cars, init and their reset actions egoname = 'Ego' targetname = 'Target' entities = pyoscx.Entities() init = pyoscx.Init() act = pyoscx.Act('indef traffic') for i in range(20): entities.add_scenario_object(