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
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) 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)
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())
def test_lanechange_abs(): lanechange = OSC.AbsoluteLaneChangeAction(1,TD) prettyprint(lanechange.get_element())
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))) # create two separate condition groups headway_cond_2 = xosc.TimeHeadwayCondition(speedyname,1,xosc.Rule.greaterThan) headway_trigger_2 = xosc.EntityTrigger('trigger',0,xosc.ConditionEdge.none,headway_cond_2,egoname) ttc_cond_2 = xosc.TimeToCollisionCondition(3,xosc.Rule.lessThan,entity=targetname) collision_trigger_2 = xosc.EntityTrigger('trigger',0,xosc.ConditionEdge.none,ttc_cond_2,egoname) lc_group = xosc.ConditionGroup() lc_group.add_condition(headway_trigger_2) lc_group.add_condition(collision_trigger_2) lane_change_event.add_trigger(lc_group)