def test_maneuver(): event = OSC.Event('myfirstevent', OSC.Priority.overwrite) event.add_trigger(trigger) event.add_action('newspeed', speedaction) man = OSC.Maneuver('my maneuver') man.add_event(event) OSC.prettyprint(man.get_element())
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) OSC.prettyprint(sb.get_element())
def test_maneuvergroup(): event = OSC.Event('myfirstevent', 'overwrite') event.add_trigger(trigger) event.add_action('newspeed', speedaction) man = OSC.Maneuver('my maneuver') man.add_event(event) OSC.prettyprint(man.get_element()) mangr = OSC.ManeuverGroup('mangroup') mangr.add_actor('Ego') mangr.add_maneuver(man) OSC.prettyprint(mangr.get_element())
def test_actandstory(): event = OSC.Event('myfirstevent', OSC.Priority.overwrite) event.add_trigger(trigger) event.add_action('newspeed', speedaction) man = OSC.Maneuver('my maneuver') man.add_event(event) OSC.prettyprint(man.get_element()) mangr = OSC.ManeuverGroup('mangroup') mangr.add_actor('Ego') mangr.add_maneuver(man) OSC.prettyprint(mangr.get_element()) act = OSC.Act('my act', trigger) act.add_maneuver_group(mangr) OSC.prettyprint(act.get_element()) story = OSC.Story('mystory') story.add_act(act) OSC.prettyprint(story.get_element())
def test_storyboard(): init = OSC.Init() TD = OSC.TransitionDynamics(OSC.DynamicsShapes.step, OSC.DynamicsDimension.rate, 1) 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))) init.add_init_action('Target_2', egospeed) init.add_init_action( 'Target_2', OSC.TeleportAction(OSC.WorldPosition(10, 2, 3, 0, 0, 0))) OSC.prettyprint(init.get_element()) event = OSC.Event('myfirstevent', OSC.Priority.overwrite) event.add_trigger(trigger) event.add_action('newspeed', speedaction) man = OSC.Maneuver('my maneuver') man.add_event(event) OSC.prettyprint(man.get_element()) mangr = OSC.ManeuverGroup('mangroup') mangr.add_actor('Ego') mangr.add_maneuver(man) OSC.prettyprint(mangr.get_element()) act = OSC.Act('my act', trigger) act.add_maneuver_group(mangr) OSC.prettyprint(act.get_element()) story = OSC.Story('mystory') story.add_act(act) OSC.prettyprint(story.get_element()) sb = OSC.StoryBoard(init) sb.add_story(story) OSC.prettyprint(sb.get_element())
30, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step, pyoscx.DynamicsDimension.time, 1))) init.add_init_action(targetname, pyoscx.TeleportAction(pyoscx.LanePosition(100, 0, -2, 0))) init.add_init_action( targetname, pyoscx.AbsoluteSpeedAction( 10, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step, pyoscx.DynamicsDimension.time, 1))) ### create the action event = pyoscx.Event('speedchange', pyoscx.Priority.overwrite) event.add_action( 'speedaction', pyoscx.AbsoluteSpeedAction( 10, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step, pyoscx.DynamicsDimension.time, 3))) # create two trigger conditions trig_cond1 = pyoscx.TimeToCollisionCondition(2, pyoscx.Rule.lessThan, entity=targetname) trig_cond2 = pyoscx.TimeHeadwayCondition(speedyname, 1, pyoscx.Rule.greaterThan) collision_trigger = pyoscx.EntityTrigger('trigger', 0,
init.add_init_action(egoname,pyoscx.TeleportAction(pyoscx.LanePosition(50,0,1,0))) init.add_init_action(egoname,pyoscx.AbsoluteSpeedAction(10,pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step,pyoscx.DynamicsDimension.time,1))) # create a router ego_route = pyoscx.Route('ego_route') ego_route.add_waypoint(pyoscx.LanePosition(30,0,1,0),pyoscx.RouteStrategy.fastest) ego_route.add_waypoint(pyoscx.LanePosition(10,0,-1,1),pyoscx.RouteStrategy.fastest) # create action ego_action = pyoscx.AssignRouteAction(ego_route) ego_event = pyoscx.Event('ego_event',pyoscx.Priority.overwrite) ego_event.add_action('ego_route',ego_action) ego_event.add_trigger(pyoscx.ValueTrigger('target_start',0,pyoscx.ConditionEdge.none,pyoscx.SimulationTimeCondition(1,pyoscx.Rule.greaterThan))) ## create the storyboard ego_man = pyoscx.Maneuver('ego_man') ego_man.add_event(ego_event) sb = pyoscx.StoryBoard(init,pyoscx.ValueTrigger('stop_simulation',0,pyoscx.ConditionEdge.rising,pyoscx.SimulationTimeCondition(10,pyoscx.Rule.greaterThan),'stop')) sb.add_maneuver(ego_man,egoname) ## create the scenario sce = pyoscx.Scenario('adaptspeed_example','User',paramdec,entities=entities,storyboard = sb,roadnetwork=road,catalog=catalog) # display the scenario
entities.add_scenario_object( targetname + str(i), pyoscx.CatalogReference('VehicleCatalog', 'car_yellow')) init.add_init_action( targetname + str(i), pyoscx.TeleportAction(pyoscx.LanePosition(100 + i * 20, 0, -1, 1))) init.add_init_action( targetname + str(i), pyoscx.AbsoluteSpeedAction( 60, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step, pyoscx.DynamicsDimension.time, 1))) event = pyoscx.Event('speedchange', pyoscx.Priority.overwrite, maxexecution=10) event.add_action('restart', pyoscx.TeleportAction(pyoscx.LanePosition(0, 0, -1, 1))) trig_cond = pyoscx.EndOfRoadCondition(0) event.add_trigger( pyoscx.EntityTrigger('trigger', 0, pyoscx.ConditionEdge.rising, trig_cond, targetname + str(i))) man = pyoscx.Maneuver('mymaneuver') man.add_event(event) mangr = pyoscx.ManeuverGroup('mangr', maxexecution=3) mangr.add_maneuver(man)
init.add_init_action(egoname, pyoscx.TeleportAction(pyoscx.LanePosition(25, 0, -3, 0))) init.add_init_action(redname, pyoscx.AbsoluteSpeedAction(40, step_time)) init.add_init_action(redname, pyoscx.TeleportAction(pyoscx.LanePosition(15, 0, -2, 0))) init.add_init_action(yelname, pyoscx.AbsoluteSpeedAction(30, step_time)) init.add_init_action(yelname, pyoscx.TeleportAction(pyoscx.LanePosition(35, 0, -4, 0))) ### create an event for the red car r_trigcond = pyoscx.TimeHeadwayCondition(redname, 0.1, pyoscx.Rule.greaterThan) r_trigger = pyoscx.EntityTrigger('redtrigger', 0.2, pyoscx.ConditionEdge.rising, r_trigcond, egoname) r_event = pyoscx.Event('first_lane_change', pyoscx.Priority.overwrite) r_event.add_trigger(r_trigger) r_event.add_action( 'lane_change_red', pyoscx.AbsoluteLaneChangeAction( -4, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.sinusoidal, pyoscx.DynamicsDimension.time, 4))) ## create the act for the red car r_man = pyoscx.Maneuver('red_maneuver') r_man.add_event(r_event) r_mangr = pyoscx.ManeuverGroup('mangroup_red') r_mangr.add_actor(redname) r_mangr.add_maneuver(r_man)
def test_event(): event = OSC.Event('myfirstevent', OSC.Priority.overwrite) event.add_trigger(trigger) event.add_action('newspeed', speedaction)
targetspeed = pyoscx.AbsoluteSpeedAction(40,step_time) targetstart = pyoscx.TeleportAction(pyoscx.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 = pyoscx.TimeHeadwayCondition(targetname,0.4,pyoscx.Rule.greaterThan) trigger = pyoscx.EntityTrigger('mytesttrigger',0.2,pyoscx.ConditionEdge.rising,trigcond,egoname) event = pyoscx.Event('myfirstevent',pyoscx.Priority.overwrite) event.add_trigger(trigger) positionlist = [] positionlist.append(pyoscx.RelativeLanePosition(0,0,0,targetname)) positionlist.append(pyoscx.RelativeLanePosition(20,0.5,0,targetname)) positionlist.append(pyoscx.RelativeLanePosition(40,-0.5,0,targetname)) positionlist.append(pyoscx.RelativeLanePosition(60,-1,0,targetname)) polyline = pyoscx.Polyline([0,0.5,1,1.5],positionlist) traj = pyoscx.Trajectory('my_trajectory',False) traj.add_shape(polyline)
init.add_init_action(targetname, pyoscx.TeleportAction(pyoscx.LanePosition(30, 0, -3, 0))) init.add_init_action( targetname, pyoscx.AbsoluteSpeedAction( 20, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step, pyoscx.DynamicsDimension.time, 1))) ## target action tar_action = pyoscx.AbsoluteSynchronizeAction( egoname, pyoscx.LanePosition(200, 0, -1, 0), pyoscx.LanePosition(200, 0, -2, 0), 10) tar_event = pyoscx.Event('target_event', pyoscx.Priority.overwrite) tar_event.add_trigger( pyoscx.ValueTrigger( 'ego_start', 0, pyoscx.ConditionEdge.none, pyoscx.SimulationTimeCondition(3, pyoscx.Rule.greaterThan))) tar_event.add_action('tar_action', tar_action) tar_man = pyoscx.Maneuver('target_man') tar_man.add_event(tar_event) tar_man_gr = pyoscx.ManeuverGroup('target_man_gr') tar_man_gr.add_maneuver(tar_man) tar_man_gr.add_actor(targetname) ## act act = pyoscx.Act(
init = pyoscx.Init() step_time = pyoscx.TransitionDynamics('step','time',1) init.add_init_action(egoname,pyoscx.AbsoluteSpeedAction(30,step_time)) init.add_init_action(egoname,pyoscx.TeleportAction(pyoscx.LanePosition(25,0,-3,0))) init.add_init_action(redname,pyoscx.AbsoluteSpeedAction(40,step_time)) init.add_init_action(redname,pyoscx.TeleportAction(pyoscx.LanePosition(15,0,-2,0))) init.add_init_action(yelname,pyoscx.AbsoluteSpeedAction(30,step_time)) init.add_init_action(yelname,pyoscx.TeleportAction(pyoscx.LanePosition(35,0,-4,0))) ### create an event for the red car r_trigcond = pyoscx.TimeHeadwayCondition(redname,0.1,'greaterThan') r_trigger = pyoscx.EntityTrigger('redtrigger',0.2,'rising',r_trigcond,egoname) r_event = pyoscx.Event('first_lane_change','overwrite') r_event.add_trigger(r_trigger) r_event.add_action('lane_change_red',pyoscx.AbsoluteLaneChangeAction(-4,pyoscx.TransitionDynamics('sinusoidal','time',4))) ## create the act for the red car r_man = pyoscx.Maneuver('red_maneuver') r_man.add_event(r_event) r_mangr = pyoscx.ManeuverGroup('mangroup_red') r_mangr.add_actor(redname) r_mangr.add_maneuver(r_man) act = pyoscx.Act('red_act',pyoscx.ValueTrigger('starttrigger',0,'rising',pyoscx.SimulationTimeCondition(0,'greaterThan'))) act.add_maneuver_group(r_mangr)
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
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
speed_of_outer_car, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step, pyoscx.DynamicsDimension.time, 1))) init.add_init_action(targetname, pyoscx.TeleportAction(pyoscx.LanePosition(100, 0, -2, 0))) init.add_init_action( targetname, pyoscx.AbsoluteSpeedAction( 10, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step, pyoscx.DynamicsDimension.time, 1))) ### create the "optional" slowdown event slowdown_event = pyoscx.Event('speedchange', pyoscx.Priority.overwrite) slowdown_event.add_action( 'speedaction', pyoscx.AbsoluteSpeedAction( 9, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.sinusoidal, pyoscx.DynamicsDimension.time, 1))) # create two trigger conditions ttc_cond = pyoscx.TimeToCollisionCondition(3, pyoscx.Rule.lessThan, entity=targetname) headway_cond = pyoscx.TimeHeadwayCondition(speedyname, 1, pyoscx.Rule.lessThan) headway_trigger = pyoscx.EntityTrigger('trigger', 0, pyoscx.ConditionEdge.none, headway_cond, egoname)
targetspeed = pyoscx.AbsoluteSpeedAction(40, step_time) targetstart = pyoscx.TeleportAction(pyoscx.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 = pyoscx.TimeHeadwayCondition(targetname, 0.1, 'greaterThan') trigger = pyoscx.EntityTrigger('mytesttrigger', 0.2, 'rising', trigcond, egoname) event = pyoscx.Event('myfirstevent', 'overwrite') event.add_trigger(trigger) sin_time = pyoscx.TransitionDynamics('linear', 'time', 3) action = pyoscx.LongitudinalDistanceAction(-4, egoname, max_deceleration=3, max_speed=50) event.add_action('newspeed', action) ## create the act, man = pyoscx.Maneuver('my_maneuver') man.add_event(event) mangr = pyoscx.ManeuverGroup('mangroup') mangr.add_actor('$owner')
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())
20, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step, pyoscx.DynamicsDimension.time, 1))) init.add_init_action(targetname, pyoscx.TeleportAction(pyoscx.LanePosition(50, 0, -2, 0))) init.add_init_action( targetname, pyoscx.AbsoluteSpeedAction( 10, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step, pyoscx.DynamicsDimension.time, 1))) ## do lanechange lc_cond = pyoscx.ReachPositionCondition(pyoscx.LanePosition(40, 0, -4, 0), 1) lc_event = pyoscx.Event('lanechange', pyoscx.Priority.parallel) lc_event.add_action( 'lanechangeaction', pyoscx.RelativeLaneChangeAction( -1, targetname, pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.sinusoidal, pyoscx.DynamicsDimension.time, 3))) lc_event.add_trigger( pyoscx.EntityTrigger('lanechangetrigger', 0, pyoscx.ConditionEdge.none, lc_cond, egoname)) event = pyoscx.Event('speedchange', pyoscx.Priority.parallel) event.add_action( 'speedaction', pyoscx.AbsoluteSpeedAction( 10,