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())
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) act = pyoscx.Act( 'red_act', pyoscx.ValueTrigger( 'starttrigger', 0, pyoscx.ConditionEdge.rising, pyoscx.SimulationTimeCondition(0, pyoscx.Rule.greaterThan)))
step_time = pyoscx.TransitionDynamics(pyoscx.DynamicsShapes.step,pyoscx.DynamicsDimension.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,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) act = pyoscx.Act('red_act',pyoscx.ValueTrigger('starttrigger',0,pyoscx.ConditionEdge.rising,pyoscx.SimulationTimeCondition(0,pyoscx.Rule.greaterThan))) act.add_maneuver_group(r_mangr) ## create an event for the yellow car
def test_lanechange_abs(): lanechange = OSC.AbsoluteLaneChangeAction(1,TD) OSC.prettyprint(lanechange.get_element())
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) ## create an event for the yellow car