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)
    prettyprint(man.get_element())

    mangr = OSC.ManeuverGroup('mangroup')
    mangr.add_actor('Ego')
    mangr.add_maneuver(man)
    prettyprint(mangr.get_element())

    act = OSC.Act('my act', trigger)
    act.add_maneuver_group(mangr)
    prettyprint(act.get_element())

    story = OSC.Story('mystory')
    story.add_act(act)
    prettyprint(story.get_element())
def test_storyboard_story_input():
    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)))
    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)
    prettyprint(man.get_element())

    mangr = OSC.ManeuverGroup('mangroup')
    mangr.add_actor('Ego')
    mangr.add_maneuver(man)
    prettyprint(mangr.get_element())

    act = OSC.Act('my act', trigger)
    act.add_maneuver_group(mangr)
    prettyprint(act.get_element())

    story = OSC.Story('mystory')
    story.add_act(act)
    prettyprint(story.get_element())

    sb = OSC.StoryBoard(init)
    sb.add_story(story)
    prettyprint(sb.get_element())
## create the act for the yellow car
y_man = xosc.Maneuver('yellow_maneuver')
y_man.add_event(y_event)

y_mangr = xosc.ManeuverGroup('yellow_mangroup')
y_mangr.add_actor(yelname)
y_mangr.add_maneuver(y_man)
y_starttrigger = xosc.ValueTrigger(
    'starttrigger', 0, xosc.ConditionEdge.rising,
    xosc.SimulationTimeCondition(0, xosc.Rule.greaterThan))
# y_act = xosc.Act('my_act',y_starttrigger)
act.add_maneuver_group(y_mangr)

## create the story

story = xosc.Story('mystory')
story.add_act(act)
# story.add_act(y_act)

## create the storyboard
sb = xosc.StoryBoard(
    init,
    xosc.ValueTrigger('stop_simulation', 0, xosc.ConditionEdge.rising,
                      xosc.SimulationTimeCondition(10, xosc.Rule.greaterThan),
                      'stop'))
sb.add_story(story)

## create the scenario
sce = xosc.Scenario('adaptspeed_example',
                    'Mandolin',
                    paramdec,
Exemplo n.º 4
0
man.add_event(event)

mangr = xosc.ManeuverGroup('mangroup')
mangr.add_actor('$owner')
mangr.add_maneuver(man)
starttrigger = xosc.ValueTrigger(
    'starttrigger', 0, xosc.ConditionEdge.rising,
    xosc.SimulationTimeCondition(0, xosc.Rule.greaterThan))
act = xosc.Act('my_act', starttrigger)
act.add_maneuver_group(mangr)

## create the story
storyparam = xosc.ParameterDeclarations()
storyparam.add_parameter(
    xosc.Parameter('$owner', xosc.ParameterType.string, targetname))
story = xosc.Story('mystory', storyparam)
story.add_act(act)

## create the storyboard
sb = xosc.StoryBoard(init)
sb.add_story(story)

## create the scenario
sce = xosc.Scenario('trajectory_example',
                    'Mandolin',
                    paramdec,
                    entities=entities,
                    storyboard=sb,
                    roadnetwork=road,
                    catalog=catalog)
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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())