Ejemplo n.º 1
0
def test_trafficdefinition():
    prop = OSC.Properties()
    prop.add_file('mycontrollerfile.xml')
    controller = OSC.Controller('mycontroller', prop)

    traffic = OSC.TrafficDefinition('my traffic')
    traffic.add_controller(controller, 0.5)
    traffic.add_controller(
        OSC.CatalogReference('ControllerCatalog', 'my controller'), 0.5)

    traffic.add_vehicle(OSC.VehicleCategory.car, 0.9)
    traffic.add_vehicle(OSC.VehicleCategory.bicycle, 0.1)

    prettyprint(traffic.get_element())
def test_trafficsinkaction():
    
    prop = OSC.Properties()
    prop.add_file('mycontrollerfile.xml')
    controller = OSC.Controller('mycontroller',prop)

    traffic = OSC.TrafficDefinition('my traffic')
    traffic.add_controller(controller,0.5)
    traffic.add_controller(OSC.CatalogReference('ControllerCatalog','my controller'),0.5)

    traffic.add_vehicle(OSC.VehicleCategory.car,0.9)
    traffic.add_vehicle(OSC.VehicleCategory.bicycle,0.1)

    sink_action = OSC.TrafficSinkAction(10,10,OSC.WorldPosition(),traffic)
    prettyprint(sink_action.get_element())
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
def test_catalog_reader_pedestrian(tmpdir):
    
    tmpcatalog = os.path.join(tmpdir,'my_catalog.xosc')
    cf = xosc.CatalogFile()
    cf.create_catalog(tmpcatalog,'PedestrianCatalog','My first vehicle catalog','Mandolin')

    bb = xosc.BoundingBox(2,5,1.8,2.0,0,0.9)

    peddler = xosc.Pedestrian('dude','dude-model',80,xosc.PedestrianCategory.pedestrian,bb)

    peddler.add_property_file('../models/car_white.osgb')
    cf.add_to_catalog(peddler)
    cf.dump()
    ped = xosc.CatalogReader(xosc.CatalogReference('my_catalog','dude'),tmpdir)

    assert ped.boundingbox.boundingbox.height == peddler.boundingbox.boundingbox.height
    assert ped.boundingbox.center.x == peddler.boundingbox.center.x
    assert ped.mass == peddler.mass
    assert ped.name == peddler.name
Ejemplo n.º 5
0
def test_catalog_reader_vehicle(tmpdir):
    
    tmpcatalog = os.path.join(tmpdir,'my_catalog.xosc')
    cf = xosc.CatalogFile()
    cf.create_catalog(tmpcatalog,'VehicleCatalog','My first vehicle catalog','Mandolin')

    bb = xosc.BoundingBox(2,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('control','internal')
    white_veh.add_property('model_id','0')
    cf.add_to_catalog(white_veh)
    cf.dump()
    veh = xosc.CatalogReader(xosc.CatalogReference('my_catalog','car_white'),tmpdir)

    assert veh.boundingbox.boundingbox.height == white_veh.boundingbox.boundingbox.height
    assert veh.boundingbox.center.x == white_veh.boundingbox.center.x
    assert veh.name == white_veh.name
### create road
road = xosc.RoadNetwork(roadfile='../xodr/e6mini.xodr',
                        scenegraph='../models/e6mini.osgb')

### create parameters
paramdec = xosc.ParameterDeclarations()

## create entities

egoname = 'Ego'
redname = 'Target1'
yelname = 'Target2'

entities = xosc.Entities()
entities.add_scenario_object(
    egoname, xosc.CatalogReference('VehicleCatalog', 'car_white'))
entities.add_scenario_object(
    redname, xosc.CatalogReference('VehicleCatalog', 'car_red'))
entities.add_scenario_object(
    yelname, xosc.CatalogReference('VehicleCatalog', 'car_yellow'))

### create init

init = xosc.Init()
step_time = xosc.TransitionDynamics(xosc.DynamicsShapes.step,
                                    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))
### create road
road = xosc.RoadNetwork(roadfile='../xodr/e6mini.xodr',
                        scenegraph='../models/e6mini.osgb')

### create parameters
paramdec = xosc.ParameterDeclarations()

## create entities

egoname = 'Ego'
speedyname = 'speedy_gonzales'
targetname = 'Target'
entities = xosc.Entities()
entities.add_scenario_object(
    egoname, xosc.CatalogReference('VehicleCatalog', 'car_white'))
entities.add_scenario_object(
    speedyname, xosc.CatalogReference('VehicleCatalog', 'car_blue'))
entities.add_scenario_object(
    targetname, xosc.CatalogReference('VehicleCatalog', 'car_yellow'))

### create init

init = xosc.Init()

init.add_init_action(egoname,
                     xosc.TeleportAction(xosc.LanePosition(50, 0, -2, 0)))
init.add_init_action(
    egoname,
    xosc.AbsoluteSpeedAction(
        15,
Ejemplo n.º 8
0
catalog = xosc.Catalog()
catalog.add_catalog('VehicleCatalog','../xosc/Catalogs/Vehicles')

### create road
road = xosc.RoadNetwork(roadfile="../xodr/e6mini.xodr",scenegraph="../models/e6mini.osgb")

### create parameters
paramdec = xosc.ParameterDeclarations()

## create entities

egoname = 'Ego'
targetname = 'Target'

entities = xosc.Entities()
entities.add_scenario_object(egoname,xosc.CatalogReference('VehicleCatalog','car_red'))
entities.add_scenario_object(targetname,xosc.CatalogReference('VehicleCatalog','car_blue'))

### create init

init = xosc.Init()

init.add_init_action(egoname,xosc.TeleportAction(xosc.LanePosition(50,0,-2,0)))
init.add_init_action(egoname,xosc.AbsoluteSpeedAction(10,xosc.TransitionDynamics(xosc.DynamicsShapes.step,xosc.DynamicsDimension.time,1)))

init.add_init_action(targetname,xosc.TeleportAction(xosc.LanePosition(30,0,-3,0)))
init.add_init_action(targetname,xosc.AbsoluteSpeedAction(20,xosc.TransitionDynamics(xosc.DynamicsShapes.step,xosc.DynamicsDimension.time,1)))


## target action
Ejemplo n.º 9
0
road = xosc.RoadNetwork(roadfile='../xodr/straight_500m.xodr',scenegraph='../models/straight_500m.osgb')

### create parameters
paramdec = xosc.ParameterDeclarations()

## loop to create cars, init and their reset actions

egoname = 'Ego'

targetname = 'Target'
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)

Ejemplo n.º 10
0
catalog = xosc.Catalog()
catalog.add_catalog('VehicleCatalog','../xosc/Catalogs/Vehicles')

### create road
road = xosc.RoadNetwork(roadfile='../xodr/e6mini.xodr',scenegraph='../models/e6mini.osgb')

### create parameters
paramdec = xosc.ParameterDeclarations()

## create entities

egoname = 'Ego'
speedyname = 'speedy_gonzales'
targetname = 'Target'
entities = xosc.Entities()
entities.add_scenario_object(egoname,xosc.CatalogReference('VehicleCatalog','car_white'))
entities.add_scenario_object(speedyname,xosc.CatalogReference('VehicleCatalog','car_blue'))
entities.add_scenario_object(targetname,xosc.CatalogReference('VehicleCatalog','car_yellow'))

### create init




init = xosc.Init()

init.add_init_action(egoname,xosc.TeleportAction(xosc.LanePosition(50,0,-2,0)))
init.add_init_action(egoname,xosc.AbsoluteSpeedAction(15,xosc.TransitionDynamics(xosc.DynamicsShapes.step,xosc.DynamicsDimension.time,1)))

# change speed of this to have different outcome
init.add_init_action(speedyname,xosc.TeleportAction(xosc.LanePosition(10,0,-3,0)))
Ejemplo n.º 11
0
def test_catalogreference():
    catref = OSC.CatalogReference('VehicleCatalog', 'S60')
    prettyprint(catref.get_element())
    catref.add_parameter_assignment('stuffs', 1)
    prettyprint(catref.get_element())
Ejemplo n.º 12
0
### create road
road = xosc.RoadNetwork(roadfile="../xodr/fabriksgatan.xodr",
                        scenegraph="../models/fabriksgatan.osgb")

### create parameters
paramdec = xosc.ParameterDeclarations()

## create entities

egoname = 'Ego'
targetname = 'Target'

entities = xosc.Entities()
entities.add_scenario_object(
    egoname, xosc.CatalogReference('VehicleCatalog', 'car_red'))

### create init

init = xosc.Init()

init.add_init_action(egoname,
                     xosc.TeleportAction(xosc.LanePosition(50, 0, 1, 0)))
init.add_init_action(
    egoname,
    xosc.AbsoluteSpeedAction(
        10,
        xosc.TransitionDynamics(xosc.DynamicsShapes.step,
                                xosc.DynamicsDimension.time, 1)))

# create a router