Esempio n. 1
0
def test_timetocollisioncondition():
    cond = OSC.TimeToCollisionCondition(value=20,
                                        alongroute=True,
                                        rule='equalTo',
                                        entity='Ego')
    OSC.prettyprint(cond.get_element())

    cond = OSC.TimeToCollisionCondition(value=20,
                                        alongroute=True,
                                        rule='equalTo',
                                        position=OSC.WorldPosition())
    OSC.prettyprint(cond.get_element())
Esempio n. 2
0
def test_entitytrigger():
    trigcond = OSC.TimeToCollisionCondition(10,
                                            'equalTo',
                                            True,
                                            freespace=False,
                                            position=OSC.WorldPosition())

    trigger = OSC.EntityTrigger('mytesttrigger', 0.2, 'rising', trigcond,
                                'Target_1')
    OSC.prettyprint(trigger.get_element())
Esempio n. 3
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,
                                            '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())
Esempio n. 4
0
import pytest

import pyoscx as OSC

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')
Esempio n. 5
0
        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,
                                         pyoscx.ConditionEdge.none, trig_cond1,
                                         egoname)
headway_trigger = pyoscx.EntityTrigger('trigger', 0, pyoscx.ConditionEdge.none,
                                       trig_cond2, egoname)

# create two separate condition groups

col_group = pyoscx.ConditionGroup()
col_group.add_condition(collision_trigger)
        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)

collision_trigger = pyoscx.EntityTrigger('trigger', 0,
                                         pyoscx.ConditionEdge.none, ttc_cond,
                                         egoname)

#create the "and" logic
sc_group = pyoscx.ConditionGroup()
sc_group.add_condition(collision_trigger)
sc_group.add_condition(headway_trigger)