def test_conditiongroup(): condgr = OSC.ConditionGroup() trig1 = OSC.EntityTrigger('firsttrigger',1,OSC.ConditionEdge.rising,OSC.RelativeDistanceCondition(10,OSC.Rule.greaterThan,OSC.RelativeDistanceType.longitudinal,'Ego'),'Target') trig2 = OSC.EntityTrigger('secondtrigger',2,OSC.ConditionEdge.rising,OSC.SpeedCondition(2,OSC.Rule.equalTo),'Target') condgr.add_condition(trig1) condgr.add_condition(trig2) prettyprint(condgr.get_element())
def test_entitytrigger(): trigcond = OSC.TimeToCollisionCondition(10,OSC.Rule.equalTo,True,freespace=False,position=OSC.WorldPosition()) trigger = OSC.EntityTrigger('mytesttrigger',0.2,OSC.ConditionEdge.rising,trigcond,'Target_1') prettyprint(trigger.get_element())
xosc.DynamicsDimension.time, 1) init.add_init_action(egoname, xosc.AbsoluteSpeedAction(30, step_time)) init.add_init_action(egoname, xosc.TeleportAction(xosc.LanePosition(25, 0, -3, 0))) init.add_init_action(redname, xosc.AbsoluteSpeedAction(40, step_time)) init.add_init_action(redname, xosc.TeleportAction(xosc.LanePosition(15, 0, -2, 0))) init.add_init_action(yelname, xosc.AbsoluteSpeedAction(30, step_time)) init.add_init_action(yelname, xosc.TeleportAction(xosc.LanePosition(35, 0, -4, 0))) ### create an event for the red car r_trigcond = xosc.TimeHeadwayCondition(redname, 0.1, xosc.Rule.greaterThan) r_trigger = xosc.EntityTrigger('redtrigger', 0.2, xosc.ConditionEdge.rising, r_trigcond, egoname) r_event = xosc.Event('first_lane_change', xosc.Priority.overwrite) r_event.add_trigger(r_trigger) r_event.add_action( 'lane_change_red', xosc.AbsoluteLaneChangeAction( -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)
event = xosc.Event('speedchange', xosc.Priority.overwrite) event.add_action( 'speedaction', xosc.AbsoluteSpeedAction( 10, xosc.TransitionDynamics(xosc.DynamicsShapes.step, xosc.DynamicsDimension.time, 3))) # create two trigger conditions trig_cond1 = xosc.TimeToCollisionCondition(2, xosc.Rule.lessThan, entity=targetname) trig_cond2 = xosc.TimeHeadwayCondition(speedyname, 1, xosc.Rule.greaterThan) collision_trigger = xosc.EntityTrigger('trigger', 0, xosc.ConditionEdge.none, trig_cond1, egoname) headway_trigger = xosc.EntityTrigger('trigger', 0, xosc.ConditionEdge.none, trig_cond2, egoname) # create two separate condition groups col_group = xosc.ConditionGroup() col_group.add_condition(collision_trigger) head_group = xosc.ConditionGroup() head_group.add_condition(headway_trigger) # create trigger and add the two conditiongroups (or logic) trigger = xosc.Trigger() trigger.add_conditiongroup(col_group) trigger.add_conditiongroup(head_group)
egospeed = xosc.AbsoluteSpeedAction(30, step_time) egostart = xosc.TeleportAction(xosc.LanePosition(25, 0, -3, 0)) targetspeed = xosc.AbsoluteSpeedAction(40, step_time) targetstart = xosc.TeleportAction(xosc.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 = xosc.TimeHeadwayCondition(targetname, 0.4, xosc.Rule.greaterThan) trigger = xosc.EntityTrigger('mytesttrigger', 0.2, xosc.ConditionEdge.rising, trigcond, egoname) event = xosc.Event('myfirstevent', xosc.Priority.overwrite) event.add_trigger(trigger) positionlist = [] positionlist.append(xosc.RelativeLanePosition(0, 0, 0, targetname)) positionlist.append(xosc.RelativeLanePosition(20, 0.5, 0, targetname)) positionlist.append(xosc.RelativeLanePosition(40, -0.5, 0, targetname)) positionlist.append(xosc.RelativeLanePosition(60, -1, 0, targetname)) polyline = xosc.Polyline([0, 0.5, 1, 1.5], positionlist) traj = xosc.Trajectory('my_trajectory', False) traj.add_shape(polyline)
entities = xosc.Entities() init = xosc.Init() act = xosc.Act('indef traffic') for i in range(20): entities.add_scenario_object(targetname+str(i),xosc.CatalogReference('VehicleCatalog','car_yellow')) init.add_init_action(targetname+str(i),xosc.TeleportAction(xosc.LanePosition(100+i*20,0,-1,1))) init.add_init_action(targetname+str(i),xosc.AbsoluteSpeedAction(60,xosc.TransitionDynamics(xosc.DynamicsShapes.step,xosc.DynamicsDimension.time,1))) event = xosc.Event('speedchange',xosc.Priority.overwrite,maxexecution=10) event.add_action('restart',xosc.TeleportAction(xosc.LanePosition(0,0,-1,1))) 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)
egostart = xosc.TeleportAction(xosc.LanePosition(25,0,-3,0)) targetspeed = xosc.AbsoluteSpeedAction(15,step_time) targetstart = xosc.TeleportAction(xosc.RelativeRoadPosition(30,0,egoname)) 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 for target trigcond = xosc.AccelerationCondition(2.9,xosc.Rule.greaterThan) trigger = xosc.EntityTrigger('mytesttrigger',0.2,xosc.ConditionEdge.none,trigcond,egoname) event = xosc.Event('myfirstevent',xosc.Priority.overwrite) event.add_trigger(trigger) sin_time = xosc.TransitionDynamics(xosc.DynamicsShapes.linear,xosc.DynamicsDimension.time,3.9) action = xosc.AbsoluteSpeedAction(0,sin_time) 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)
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, OSC.Rule.equalTo, True, freespace=False, position=OSC.WorldPosition()) trigger = OSC.EntityTrigger('mytesttrigger', 0.2, OSC.ConditionEdge.rising, trigcond, 'Target_1') event = OSC.Event('myfirstevent', OSC.Priority.overwrite) event.add_trigger(trigger) TD = OSC.TransitionDynamics(OSC.DynamicsShapes.step, OSC.DynamicsDimension.rate, 1) lanechangeaction = OSC.AbsoluteLaneChangeAction(1, TD) 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.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) 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) prettyprint(sce.get_element())
init.add_init_action(speedyname,xosc.TeleportAction(xosc.LanePosition(10,0,-3,0))) init.add_init_action(speedyname,xosc.AbsoluteSpeedAction(speed_of_outer_car,xosc.TransitionDynamics(xosc.DynamicsShapes.step,xosc.DynamicsDimension.time,1))) init.add_init_action(targetname,xosc.TeleportAction(xosc.LanePosition(100,0,-2,0))) init.add_init_action(targetname,xosc.AbsoluteSpeedAction(10,xosc.TransitionDynamics(xosc.DynamicsShapes.step,xosc.DynamicsDimension.time,1))) ### create the "optional" slowdown event slowdown_event = xosc.Event('speedchange',xosc.Priority.overwrite) slowdown_event.add_action('speedaction',xosc.AbsoluteSpeedAction(9,xosc.TransitionDynamics(xosc.DynamicsShapes.sinusoidal,xosc.DynamicsDimension.time,1))) # create two trigger conditions ttc_cond = xosc.TimeToCollisionCondition(3,xosc.Rule.lessThan,entity=targetname) headway_cond = xosc.TimeHeadwayCondition(speedyname,1,xosc.Rule.lessThan) headway_trigger = xosc.EntityTrigger('trigger',0,xosc.ConditionEdge.none,headway_cond,egoname) collision_trigger = xosc.EntityTrigger('trigger',0,xosc.ConditionEdge.none,ttc_cond,egoname) #create the "and" logic sc_group = xosc.ConditionGroup() sc_group.add_condition(collision_trigger) sc_group.add_condition(headway_trigger) slowdown_event.add_trigger(sc_group) # create the optional lanechange event lane_change_event = xosc.Event('lanechange',xosc.Priority.overwrite) lane_change_event.add_action('lanechangeaction',xosc.AbsoluteLaneChangeAction(-3,xosc.TransitionDynamics(xosc.DynamicsShapes.sinusoidal,xosc.DynamicsDimension.time,3)))
import pytest from scenariogeneration import xosc as OSC from scenariogeneration import prettyprint TD = OSC.TransitionDynamics(OSC.DynamicsShapes.step, OSC.DynamicsDimension.rate, 1) speedaction = OSC.AbsoluteSpeedAction(50, TD) trigcond = OSC.TimeToCollisionCondition( 10, OSC.Rule.equalTo, position=OSC.WorldPosition(), freespace=False, ) trigger = OSC.EntityTrigger('mytesttrigger', 0.2, OSC.ConditionEdge.rising, trigcond, 'Target_1') def test_event(): event = OSC.Event('myfirstevent', OSC.Priority.overwrite) event.add_trigger(trigger) event.add_action('newspeed', speedaction) def test_maneuver(): event = OSC.Event('myfirstevent', OSC.Priority.overwrite) event.add_trigger(trigger) event.add_action('newspeed', speedaction) man = OSC.Maneuver('my maneuver')
xosc.AbsoluteSpeedAction( 10, xosc.TransitionDynamics(xosc.DynamicsShapes.step, xosc.DynamicsDimension.time, 1))) ## do lanechange lc_cond = xosc.ReachPositionCondition(xosc.LanePosition(40, 0, -4, 0), 1) lc_event = xosc.Event('lanechange', xosc.Priority.parallel) lc_event.add_action( 'lanechangeaction', xosc.RelativeLaneChangeAction( -1, targetname, xosc.TransitionDynamics(xosc.DynamicsShapes.sinusoidal, xosc.DynamicsDimension.time, 3))) lc_event.add_trigger( xosc.EntityTrigger('lanechangetrigger', 0, xosc.ConditionEdge.none, lc_cond, egoname)) event = xosc.Event('speedchange', xosc.Priority.parallel) event.add_action( 'speedaction', xosc.AbsoluteSpeedAction( 10, xosc.TransitionDynamics(xosc.DynamicsShapes.linear, xosc.DynamicsDimension.time, 3))) trig_cond = xosc.RelativeDistanceCondition(5, xosc.Rule.lessThan, xosc.RelativeDistanceType.lateral, targetname) event.add_trigger( xosc.EntityTrigger('trigger', 0, xosc.ConditionEdge.none, trig_cond, egoname))
xosc.DynamicsDimension.time, 8)) egostart = xosc.TeleportAction(xosc.LanePosition(25, 0, -3, 0)) targetspeed = xosc.AbsoluteSpeedAction(15, step_time) targetstart = xosc.TeleportAction(xosc.RoadPosition(30, -5, 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 = xosc.RelativeSpeedCondition(0, xosc.Rule.lessThan, egoname) trigger = xosc.EntityTrigger('mytesttrigger', 0.2, xosc.ConditionEdge.none, trigcond, targetname) event = xosc.Event('myfirstevent', xosc.Priority.overwrite) event.add_trigger(trigger) sin_time = xosc.TransitionDynamics(xosc.DynamicsShapes.linear, xosc.DynamicsDimension.time, 5) action = xosc.RelativeLaneChangeAction( -8, targetname, xosc.TransitionDynamics(xosc.DynamicsShapes.linear, xosc.DynamicsDimension.time, 6), -10) event.add_action('newspeed', action) ## create the maneuver man = xosc.Maneuver('my_maneuver') man.add_event(event)