def test_storyboard_act_input(): egoname = "Ego" targetname = "target" init = OSC.Init() step_time = OSC.TransitionDynamics(OSC.DynamicsShapes.step, OSC.DynamicsDimension.time, 1) egospeed = OSC.AbsoluteSpeedAction(0, step_time) egostart = OSC.TeleportAction(OSC.LanePosition(25, 0, -3, 0)) targetspeed = OSC.AbsoluteSpeedAction(0, step_time) targetstart = OSC.TeleportAction(OSC.LanePosition(15, 0, -2, 0)) 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 an event # trigcond = OSC.TimeHeadwayCondition(targetname,0.1,OSC.Rule.greaterThan) # trigger = OSC.EntityTrigger('mytesttrigger',0.2,OSC.ConditionEdge.rising,trigcond,egoname) trigger = OSC.ValueTrigger( 'starttrigger', 0, OSC.ConditionEdge.rising, OSC.SimulationTimeCondition(3, OSC.Rule.greaterThan)) event = OSC.Event('myfirstevent', OSC.Priority.overwrite) event.add_trigger(trigger) # sin_time = OSC.TransitionDynamics(OSC.DynamicsShapes.linear,OSC.DynamicsDimension.time,3) action = OSC.LongitudinalDistanceAction(-4, egoname, max_deceleration=3, max_speed=50) event.add_action('newspeed', action) ## create the act, man = OSC.Maneuver('my_maneuver') man.add_event(event) mangr = OSC.ManeuverGroup('mangroup') mangr.add_actor(targetname) mangr.add_maneuver(man) starttrigger = OSC.ValueTrigger( 'starttrigger', 0, OSC.ConditionEdge.rising, OSC.SimulationTimeCondition(0, OSC.Rule.greaterThan)) act = OSC.Act('my_act', starttrigger) act.add_maneuver_group(mangr) ## create the storyboard sb = OSC.StoryBoard(init) sb.add_act(act) prettyprint(sb.get_element())
def scenario(self, **kwargs): road = xosc.RoadNetwork(self.road_file) egoname = 'Ego' entities = xosc.Entities() entities.add_scenario_object( egoname, xosc.CatalogReference('VehicleCatalog', 'car_white')) catalog = xosc.Catalog() catalog.add_catalog('VehicleCatalog', '../xosc/Catalogs/Vehicles') init = xosc.Init() init.add_init_action( egoname, xosc.TeleportAction(xosc.LanePosition(50, 0, -2, 0))) init.add_init_action( egoname, xosc.AbsoluteSpeedAction( kwargs['speed'], xosc.TransitionDynamics(xosc.DynamicsShapes.step, xosc.DynamicsDimension.time, 1))) event = xosc.Event('my event', xosc.Priority.overwrite) event.add_action( 'lane change', xosc.AbsoluteLaneChangeAction( -1, xosc.TransitionDynamics(xosc.DynamicsShapes.sinusoidal, xosc.DynamicsDimension.time, 4))) event.add_trigger( xosc.ValueTrigger( 'start_trigger ', 0, xosc.ConditionEdge.none, xosc.SimulationTimeCondition(4, xosc.Rule.greaterThan))) man = xosc.Maneuver('maneuver') man.add_event(event) sb = xosc.StoryBoard(init, stoptrigger=xosc.ValueTrigger( 'start_trigger ', 0, xosc.ConditionEdge.none, xosc.SimulationTimeCondition( 13, xosc.Rule.greaterThan), 'stop')) sb.add_maneuver(man, egoname) sce = xosc.Scenario('my scenario', 'Mandolin', xosc.ParameterDeclarations(), entities, sb, road, catalog) return sce
def test_simulationtimecondition(): cond = OSC.SimulationTimeCondition(1.2,OSC.Rule.greaterThan) prettyprint(cond.get_element())
-4, xosc.TransitionDynamics(xosc.DynamicsShapes.sinusoidal, xosc.DynamicsDimension.time, 4))) ## create the act for the red car r_man = xosc.Maneuver('red_maneuver') r_man.add_event(r_event) r_mangr = xosc.ManeuverGroup('mangroup_red') r_mangr.add_actor(redname) r_mangr.add_maneuver(r_man) act = xosc.Act( 'red_act', xosc.ValueTrigger('starttrigger', 0, xosc.ConditionEdge.rising, xosc.SimulationTimeCondition(0, xosc.Rule.greaterThan))) act.add_maneuver_group(r_mangr) ## create an event for the yellow car y_trigcond = xosc.TimeHeadwayCondition(redname, 0.5, xosc.Rule.greaterThan) y_trigger = xosc.EntityTrigger('yellow_trigger', 0, xosc.ConditionEdge.rising, y_trigcond, yelname) y_event = xosc.Event('yellow_lanechange', xosc.Priority.overwrite) y_event.add_trigger(y_trigger) y_event.add_action( 'lane_change_yellow', xosc.AbsoluteLaneChangeAction( -3,
def CCRm(ego_speedvalue, offset): # create empty catalog catalog = xosc.Catalog() # add straight road road = xosc.RoadNetwork(roadfile='../xodr/straight_500m.xodr', scenegraph='../models/straight_500m.osgb') # create empty paramdeclaration paramdec = xosc.ParameterDeclarations() egoname = 'Ego' targetname = 'Target1' ### create vehicles ego_width = 2 target_width = 1.8 bb = xosc.BoundingBox(ego_width, 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(target_width, 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) red_veh = xosc.Vehicle('car_red', xosc.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 = xosc.Entities() entities.add_scenario_object(egoname, white_veh) entities.add_scenario_object(targetname, red_veh) # create init (0 starting speed) init = xosc.Init() step_time = xosc.TransitionDynamics(xosc.DynamicsShapes.step, xosc.DynamicsDimension.time, 1) # caluclate correct offset based on target vehicle width cal_offset = offset / 100 * target_width egospeed = xosc.AbsoluteSpeedAction(0, step_time) egostart = xosc.TeleportAction(xosc.LanePosition(25, cal_offset, -1, 1)) startpos = 25 + (ego_speedvalue - 20) / 3.6 * (acceleration_time + ttc_at_speed) targetspeed = xosc.AbsoluteSpeedAction(0, step_time) targetstart = xosc.TeleportAction(xosc.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 = xosc.ValueTrigger( 'starttrigger', 0, xosc.ConditionEdge.rising, xosc.SimulationTimeCondition(1, xosc.Rule.greaterThan)) # accelerate cars to wanted velocity eventego = xosc.Event('egospeedchange', xosc.Priority.overwrite) eventego.add_trigger(trigger) ego_action = xosc.AbsoluteSpeedAction( ego_speedvalue / 3.6, xosc.TransitionDynamics(xosc.DynamicsShapes.linear, xosc.DynamicsDimension.time, acceleration_time)) eventego.add_action('newspeed', ego_action) event_tar = xosc.Event('targetspeedchange', xosc.Priority.overwrite) event_tar.add_trigger(trigger) target_action = xosc.AbsoluteSpeedAction( 20 / 3.6, xosc.TransitionDynamics(xosc.DynamicsShapes.linear, xosc.DynamicsDimension.time, acceleration_time)) event_tar.add_action('targetspeed', target_action) # create maneuvers/maneuvergroups ego_man = xosc.Maneuver('ego man') ego_man.add_event(eventego) tar_man = xosc.Maneuver('target man') tar_man.add_event(event_tar) egomangr = xosc.ManeuverGroup('egomangr') egomangr.add_actor(egoname) egomangr.add_maneuver(ego_man) tarmangr = xosc.ManeuverGroup('tarmangr') tarmangr.add_actor(targetname) tarmangr.add_maneuver(tar_man) # create act act = xosc.Act( 'ccrm act', xosc.ValueTrigger( 'starttrigger', 0, xosc.ConditionEdge.rising, xosc.SimulationTimeCondition(0, xosc.Rule.greaterThan))) act.add_maneuver_group(egomangr) act.add_maneuver_group(tarmangr) # create story story = xosc.Story('mystory') story.add_act(act) ## create the storyboard sb = xosc.StoryBoard( init, xosc.ValueTrigger( 'stop_simulation', 0, xosc.ConditionEdge.rising, xosc.SimulationTimeCondition(ttc_at_speed * 2 + acceleration_time, xosc.Rule.greaterThan), 'stop')) sb.add_story(story) ## create and return the scenario sce = xosc.Scenario('CCRm_v: ' + str(ego_speedvalue) + ', offset: ' + str(offset), 'Mandolin', paramdec, entities=entities, storyboard=sb, roadnetwork=road, catalog=catalog) return sce
# create trigger and add the two conditiongroups (or logic) trigger = xosc.Trigger() trigger.add_conditiongroup(col_group) trigger.add_conditiongroup(head_group) event.add_trigger(trigger) ## create the storyboard man = xosc.Maneuver('mymaneuver') man.add_event(event) sb = xosc.StoryBoard( init, xosc.ValueTrigger('stop_simulation', 0, xosc.ConditionEdge.rising, xosc.SimulationTimeCondition(20, xosc.Rule.greaterThan), 'stop')) sb.add_maneuver(man, egoname) ## create the scenario sce = xosc.Scenario('adaptspeed_example', 'User', paramdec, entities=entities, storyboard=sb, roadnetwork=road, catalog=catalog) # Print the resulting xml prettyprint(sce.get_element())
event.add_action('newspeed',action) ## create the maneuver man = xosc.Maneuver('my_maneuver') man.add_event(event) mangr = xosc.ManeuverGroup('mangroup') mangr.add_actor(targetname) mangr.add_maneuver(man) ### create an event for the ego start_trig = xosc.ValueTrigger('ego_acc',0,xosc.ConditionEdge.none,xosc.SimulationTimeCondition(0.5,xosc.Rule.greaterThan)) start_action = xosc.AbsoluteSpeedAction(30,xosc.TransitionDynamics(xosc.DynamicsShapes.sinusoidal,xosc.DynamicsDimension.rate,3)) ego_start_event = xosc.Event('startevent',xosc.Priority.overwrite) ego_start_event.add_trigger(start_trig) ego_start_event.add_action('start_action',start_action) trigcond = xosc.StandStillCondition(0.5) standstill_trigger = xosc.EntityTrigger('standstill trigger',0.1,xosc.ConditionEdge.none,trigcond,targetname) stop_action = xosc.AbsoluteSpeedAction(0,xosc.TransitionDynamics(xosc.DynamicsShapes.linear,xosc.DynamicsDimension.rate,10)) ego_event = xosc.Event('stopevent',xosc.Priority.overwrite) ego_event.add_trigger(standstill_trigger) ego_event.add_action('stop_action',stop_action)
init = xosc.Init() init.add_init_action(egoname,xosc.TeleportAction(xosc.LanePosition(50,0,-2,0))) init.add_init_action(egoname,xosc.AbsoluteSpeedAction(10,xosc.TransitionDynamics(xosc.DynamicsShapes.step,xosc.DynamicsDimension.time,1))) init.add_init_action(targetname,xosc.TeleportAction(xosc.LanePosition(30,0,-3,0))) init.add_init_action(targetname,xosc.AbsoluteSpeedAction(20,xosc.TransitionDynamics(xosc.DynamicsShapes.step,xosc.DynamicsDimension.time,1))) ## target action tar_action = xosc.AbsoluteSynchronizeAction(egoname,xosc.LanePosition(200,0,-1,0),xosc.LanePosition(200,0,-2,0),10,target_tolerance_master=1,target_tolerance=1) tar_event = xosc.Event('target_event',xosc.Priority.overwrite) tar_event.add_trigger(xosc.ValueTrigger('ego_start',0,xosc.ConditionEdge.none,xosc.SimulationTimeCondition(3,xosc.Rule.greaterThan))) tar_event.add_action('tar_action',tar_action) tar_man = xosc.Maneuver('target_man') tar_man.add_event(tar_event) tar_man_gr = xosc.ManeuverGroup('target_man_gr') tar_man_gr.add_maneuver(tar_man) tar_man_gr.add_actor(targetname) ## act act = xosc.Act('myact',xosc.ValueTrigger('start',0,xosc.ConditionEdge.none,xosc.SimulationTimeCondition(0,xosc.Rule.greaterThan))) act.add_maneuver_group(tar_man_gr) ## create the storyboard
trig_cond = xosc.EndOfRoadCondition(0) event.add_trigger(xosc.EntityTrigger('trigger',0,xosc.ConditionEdge.rising,trig_cond,targetname+str(i))) man = xosc.Maneuver('mymaneuver') man.add_event(event) mangr = xosc.ManeuverGroup('mangr',maxexecution=3) mangr.add_maneuver(man) mangr.add_actor(targetname+str(i)) act.add_maneuver_group(mangr) ## create the storyboard sb = xosc.StoryBoard(init,xosc.ValueTrigger('stop_simulation',0,xosc.ConditionEdge.rising,xosc.SimulationTimeCondition(100,xosc.Rule.greaterThan),'stop')) sb.add_act(act) ## create the scenario sce = xosc.Scenario('adaptspeed_example','User',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')) # uncomment the following lines to display the scenario using esmini # from scenariogeneration import esmini # esmini(sce,os.path.join('esmini'))