Beispiel #1
0
def getStrangeScenario():
    beamNGPAth = getBeamngDirectory()
    beamng = BeamNGpy(
        'localhost', 64256,
        home=beamNGPAth)  # This is the host & port used to communicate over
    wallCrashScenario = Scenario('smallgrid', 'road_test')
    wall = StaticObject(
        name="Crash_Test_Wall",
        pos=(10, 0, 0),
        rot=(0, 0, 0),
        scale=(1, 10, 1),
        shape='/levels/smallgrid/art/shapes/misc/gm_alpha_barrier.dae')
    testRoad = Road('track_editor_A_center', rid='Test_Road')
    roadNode = [(-10, 0, 0, 7), (20, 0, 62)]
    testRoad.nodes.extend(roadNode)
    testVehicle = Vehicle('Test_Vehicule',
                          model='etkc',
                          licence='LIFLAB',
                          colour='Blue')
    wallCrashScenario.add_road(testRoad)
    wallCrashScenario.add_object(wall)
    wallCrashScenario.add_vehicle(testVehicle,
                                  pos=(0, 0, 0),
                                  rot=(0, 180, -90))
    scenarioDict = {
        'beamng': beamng,
        'scenario': wallCrashScenario,
        'vehicule': testVehicle
    }
    return scenarioDict
Beispiel #2
0
def getWallCrashScenario(testName):
    beamng = BeamNGpy('localhost', 64256, home=getBeamngDirectory()
                      )  # This is the host & port used to communicate over
    wallCrashScenario = Scenario('smallgrid', str(testName))

    wall = StaticObject(
        name="Crash_Test_Wall",
        pos=(420, 0, 0),
        rot=(0, 0, 0),
        scale=(1, 10, 75),
        shape='/levels/smallgrid/art/shapes/misc/gm_alpha_barrier.dae')

    testRoad = Road('track_editor_B_center', rid='Test_Road')
    roadNode = [(-2, 0, 0, 7), (420, 0, 0, 7)]
    testRoad.nodes.extend(roadNode)

    testVehicle = Vehicle('Test_Vehicule',
                          model=SelectCar(),
                          licence='LIFLAB',
                          colour='Blue')

    # Create an Electrics sensor and attach it to the vehicle
    electrics = Electrics()
    testVehicle.attach_sensor('electrics', electrics)

    # Create a Damage sensor and attach it to the vehicle if module is selected
    damage = Damage()
    testVehicle.attach_sensor('damage', damage)

    # Create a Gforce sensor and attach it to the vehicle if module is selected
    gForce = GForces()
    testVehicle.attach_sensor('GForces', gForce)

    wallCrashScenario.add_road(testRoad)
    wallCrashScenario.add_object(wall)
    wallCrashScenario.add_vehicle(testVehicle, pos=(0, 0, 0), rot=(0, 0, -90))
    scenarioDict = {
        'beamng': beamng,
        'scenario': wallCrashScenario,
        'vehicule': testVehicle
    }

    return scenarioDict
Beispiel #3
0
def main():


    beamng = BeamNGpy('localhost', 64256,getBeamngDirectory())

    scenario = Scenario('smallgrid', 'road_test')
    vehicle = Vehicle('LIF_Mobile', model='etkc', licence='LIFLAB', colour='Blue')
    ramp = StaticObject(name='pyramp', pos=(250,0, 0), rot=(0, 0, 90), scale=(0.5, 0.5, 0.5),
                        shape='/levels/west_coast_usa/art/shapes/objects/ramp_massive.dae')
    ring = ProceduralRing(name='pyring', pos=(380, 0, 60), rot=(0, 0, 0), radius=5, thickness=2.5)

    wall= StaticObject(name="trumps_wall",pos=(420,0,0),rot=(0,0,0), scale=(1,10,75),
                       shape='/levels/smallgrid/art/shapes/misc/gm_alpha_barrier.dae')
    road_c = Road('track_editor_B_center', rid='jump_road')
    roadC_Nodes=[(-2,0,0,10),(420,0,0,7)]
    road_c.nodes.extend(roadC_Nodes)
    scenario.add_road(road_c)



    scenario.add_procedural_mesh(ring)
    scenario.add_object(ramp)
    scenario.add_object(wall)

    scenario.add_vehicle(vehicle,(0,0,0),(0,0,-90))



    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()
        input('Press enter when done...')
    finally:
        bng.close()
Beispiel #4
0
import mmap
Beispiel #5
0
def getDonutScenario():
    beamng = BeamNGpy('localhost', 64256, home=getBeamngDirectory()
                      )  # This is the host & port used to communicate over
    donutScenario = Scenario('smallgrid', 'road_test')

    concreteWallSide1 = StaticObject(
        name="Crash_Test_Wall",
        pos=(20, 10, 0),
        rot=(0, 0, 0),
        scale=(10, 1, 1),
        shape=
        '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae')

    concreteWallSide2 = StaticObject(
        name="Crash_Test_Wall2",
        pos=(35, -5, 0),
        rot=(0, 0, 90),
        scale=(10, 1, 1),
        shape=
        '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae')

    concreteWallSide3 = StaticObject(
        name="Crash_Test_Wall3",
        pos=(20, -20, 0),
        rot=(0, 0, 0),
        scale=(10, 1, 1),
        shape=
        '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae')

    concreteWallSide4 = StaticObject(
        name="Crash_Test_Wall4",
        pos=(5, -5, 0),
        rot=(0, 0, 90),
        scale=(10, 1, 1),
        shape=
        '/levels/driver_training/art/shapes/race/concrete_road_barrier_a.dae')

    testRoad = Road('track_editor_C_center', rid='Test_Road')
    roadNode = [(*(-25, 25, 0), 45), (*(15, 25, 0), 45)]
    testRoad.nodes.extend(roadNode)

    testVehicle = Vehicle('Test_Vehicule',
                          model='etkc',
                          licence='LIFLAB',
                          colour='Blue')

    # Create an Electrics sensor and attach it to the vehicle
    electrics = Electrics()
    testVehicle.attach_sensor('electrics', electrics)

    # Create a Damage sensor and attach it to the vehicle if module is selected
    damage = Damage()
    testVehicle.attach_sensor('damage', damage)

    # Create a Gforce sensor and attach it to the vehicle if module is selected
    gForce = GForces()
    testVehicle.attach_sensor('GForces', gForce)

    donutScenario.add_vehicle(testVehicle, pos=(20, 0, 0), rot=(0, 0, 0))

    donutScenario.add_object(concreteWallSide1)
    donutScenario.add_object(concreteWallSide2)
    donutScenario.add_object(concreteWallSide3)
    donutScenario.add_object(concreteWallSide4)

    donutScenario.add_road(testRoad)

    scenarioDict = {
        'beamng': beamng,
        'scenario': donutScenario,
        'vehicule': testVehicle
    }

    return scenarioDict
Beispiel #6
0
scenario = Scenario('west_coast_usa', 'fourway_intersection_w_obj')

vut = Vehicle('vut', model='coupe', licence='VUT', colour='Red')
electrics = Electrics()
damage = Damage()
vut.attach_sensor('electrics', electrics)
vut.attach_sensor('damage', damage)
scenario.add_vehicle(vut, pos=(-198.5, -164.189, 119.7), rot=(0, 0, -126.25))

obj_1 = StaticObject(
    'obj_1',
    pos=(-140, -121.233, 119.586),
    rot=(0, 0, 55),
    scale=(1, 1, 1),
    shape='/levels/west_coast_usa/art/shapes/objects/barrierfence_folk.dae')
scenario.add_object(obj_1)

scenario.make(beamng)
bng = beamng.open(launch=True)
bng.load_scenario(scenario)
bng.start_scenario()

vut.ai_set_mode('span')
vut.ai_drive_in_lane(True)

for _ in range(240):
    sleep(0.1)
    vut.update_vehicle()
    sensors = bng.poll_sensors(vut)
    dmg = sensors['damage']
Beispiel #7
0
scenario_obj = ScenarioObject(oid='roadblock',
                              name='sawhorse',
                              otype='BeamNGVehicle',
                              pos=(0, -10, 0),
                              rot=None,
                              rot_quat=(0, 0, 0, 1),
                              scale=(1, 1, 1),
                              JBeam='sawhorse',
                              datablock="default_vehicle")
scenario_obj = ScenarioObject(oid='qrblock',
                              name='qrbox',
                              otype='BeamNGVehicle',
                              pos=(0, -10, 0),
                              rot=None,
                              rot_quat=(0, 0, 0, 1),
                              scale=(1, 1, 1),
                              JBeam='qrbox2',
                              datablock="default_vehicle")
scenario.add_object(scenario_obj)

scenario.make(beamng)

bng = beamng.open()
bng.load_scenario(scenario)
bng.start_scenario()

vehicle = Vehicle('ego_vehicle3', model='etk800', color='White')
bng.spawn_vehicle(vehicle, pos=(0, -20, 0), rot=None, rot_quat=(0, 1, 0, 0))
while (True):
    bng.step(1)
beamng = BeamNGpy('localhost', 64256, home='H:/BeamNG.research.v1.7.0.1clean')

scenario = Scenario('west_coast_usa', 'object_placement')

vehicle = Vehicle('ego', model='etk800', licence='PYTHON', color='Green')
scenario.add_vehicle(vehicle,
                     pos=(-198.5, -164.189, 119.7),
                     rot=(0, 0, -126.25))

ramp = StaticObject(
    name='pyramp',
    pos=(277.5, 183.5, 118.75),
    rot=(0, 0, 55),
    scale=(1, 1, 1),
    shape='/levels/west_coast_usa/art/shapes/objects/ramp_massive.dae')
scenario.add_object(ramp)

ring = ProceduralRing(name='pyring',
                      pos=(445, 301, 218),
                      rot=(0, 0, 100),
                      radius=5,
                      thickness=2.5)
scenario.add_procedural_mesh(ring)

cam_pos = (391.5, 251, 197.8)
cam_dir = (445 - cam_pos[0], 301 - cam_pos[1], 208 - cam_pos[2])
cam = Camera(cam_pos,
             cam_dir,
             60, (2048, 2048),
             near_far=(1, 4000),
             colour=True)
Beispiel #9
0
def main():
    setup_logging()

    beamng = BeamNGpy('localhost', 64256)

    scenario = Scenario('smallgrid', 'test_quat')

    vehicle = Vehicle('ego_vehicle',
                      model='etk800',
                      color='Blue',
                      licence="angle")
    scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot=(0, 0, 0))

    vehicle = Vehicle('ego_vehicle2',
                      model='etk800',
                      color='Green',
                      license="quat")
    scenario.add_vehicle(vehicle,
                         pos=(5, 0, 0),
                         rot_quat=(-0.00333699025, -0.00218820246,
                                   -0.689169466, 0.724589229))

    rb = ScenarioObject(oid='roadblock',
                        name='sawhorse',
                        otype='BeamNGVehicle',
                        pos=(-10, -5, 0),
                        rot=(0, 0, 0),
                        scale=(1, 1, 1),
                        JBeam='sawhorse',
                        datablock="default_vehicle")
    scenario.add_object(rb)

    cn = ScenarioObject(oid='cones',
                        name='cones',
                        otype='BeamNGVehicle',
                        pos=(0, -5, 0),
                        rot=None,
                        rot_quat=(0, 0, 0, 1),
                        scale=(1, 1, 1),
                        JBeam='cones',
                        datablock="default_vehicle")
    scenario.add_object(cn)

    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()

        input('Press Enter to spawn vehicle during sim with rot and rotquat')
        vehicle = Vehicle('ego_vehicle3', model='etk800', color='White')
        bng.spawn_vehicle(vehicle, (-10, 0, 0), (0, 0, 0))

        vehicle = Vehicle('ego_vehicle4', model='pickup')
        pos = (-15, 0, 0)
        bng.spawn_vehicle(vehicle, pos, None, rot_quat=(0, 0, 0, 1))

        input('press Enter to teleport last vehicle with angle')
        bng.teleport_vehicle(vehicle, pos, rot=(0, 45, 0))

        input('press Enter to teleport last vehicle with quaternion')
        bng.teleport_vehicle(vehicle,
                             pos,
                             rot_quat=(-0.00333699025, -0.00218820246,
                                       -0.689169466, 0.724589229))

        input('press Enter to teleport roadblock with angle')
        bng.teleport_scenario_object(rb, (-10, 5, 0), rot=(-45, 0, 0))

        input('press Enter to teleport roadblock with quaternion')
        bng.teleport_scenario_object(rb, (-10, 5, 0),
                                     rot_quat=(-0.003337, -0.0021882,
                                               -0.6891695, 0.7245892))

        input('Press ENTER to exit')
    finally:
        bng.close()
Beispiel #10
0
def test_quats(beamng):
    with beamng as bng:
        setup_logging()

        scenario = Scenario('smallgrid', 'test_quat')

        blue_etk = Vehicle('ego_vehicle',
                           model='etk800',
                           color='Blue',
                           licence="angle")
        scenario.add_vehicle(blue_etk, pos=(0, 0, 0), rot=(0, 0, 0))

        blue_etk = Vehicle('ego_vehicle2',
                           model='etk800',
                           color='Green',
                           license="quat")
        rot_quat = (-0.00333699025, -0.00218820246, -0.689169466, 0.724589229)
        scenario.add_vehicle(blue_etk, pos=(5, 0, 0), rot_quat=rot_quat)

        rb = ScenarioObject(oid='roadblock',
                            name='sawhorse',
                            otype='BeamNGVehicle',
                            pos=(-10, -5, 0),
                            rot=(0, 0, 0),
                            scale=(1, 1, 1),
                            JBeam='sawhorse',
                            datablock="default_vehicle")
        scenario.add_object(rb)

        cn = ScenarioObject(oid='cones',
                            name='cones',
                            otype='BeamNGVehicle',
                            pos=(0, -5, 0),
                            rot=None,
                            rot_quat=(0, 0, 0, 1),
                            scale=(1, 1, 1),
                            JBeam='cones',
                            datablock="default_vehicle")
        scenario.add_object(cn)

        scenario.make(beamng)

        bng.load_scenario(scenario)
        bng.start_scenario()

        white_etk = Vehicle('ego_vehicle3', model='etk800', color='White')
        bng.spawn_vehicle(white_etk, (-10, 0, 0), (0, 0, 0))

        pickup = Vehicle('ego_vehicle4', model='pickup')
        pos = (-15, 0, 0)
        bng.spawn_vehicle(pickup, pos, None, rot_quat=(0, 0, 0, 1))
        resp = bng.get_current_vehicles()
        assert len(resp) == 6

        pickup.connect(bng)

        pickup.poll_sensors()
        pos_before = pickup.state['pos']
        bng.teleport_vehicle(pickup.vid, pos, rot=(0, 45, 0))
        pickup.poll_sensors()
        pos_after = pickup.state['pos']
        assert (pos_before != pos_after)

        pickup.poll_sensors()
        pos_before = pickup.state['pos']
        rot_quat = (-0.00333699025, -0.00218820246, -0.689169466, 0.724589229)
        bng.teleport_vehicle(pickup.vid, pos, rot_quat=rot_quat)
        pickup.poll_sensors()
        pos_after = pickup.state['pos']
        assert (pos_before != pos_after)

        try:
            bng.teleport_scenario_object(rb, (-10, 5, 0), rot=(-45, 0, 0))
            assert True
        except socket.timeout:
            assert False

        try:
            rot_quat = (-0.003337, -0.0021882, -0.6891695, 0.7245892)
            bng.teleport_scenario_object(rb, (-10, 5, 0), rot_quat=rot_quat)
            assert True
        except socket.timeout:
            assert False
Beispiel #11
0
from beamngpy import BeamNGpy, Scenario, Vehicle, StaticObject
import numpy as np
from time import sleep, time

beamng = BeamNGpy('localhost', 64256, home = r'C:\BeamNG_unlimited\trunk' )
vehicle = Vehicle('ego', model='etk800', licence='PYTHON', colour='Green')
scenario = Scenario('west_coast_usa', 'ai_sine')
# scenario.add_vehicle(vehicle, pos=(-198.5, -164.189, 119.7), rot=(0, 0, -126.25))
scenario.add_vehicle(vehicle, pos=(-24.8179, -37.308, 119.86), rot=(0, 0, -126.25))
# so = StaticObject('stato', pos=(-140, -121.233, 119.586), rot=(0, 0, 55), scale=(1, 1, 1), shape='/levels/west_coast_usa/art/shapes/objects/barrierfence_folk.dae')
so = StaticObject('stato', pos=(2.91697, -12.596, 119.58), rot=(0, 0, 55), scale=(1, 1, 1), shape='/levels/west_coast_usa/art/shapes/objects/barrierfence_folk.dae')
scenario.add_object(so)
scenario.make(beamng)

bng = beamng.open()
bng.load_scenario(scenario)
bng.start_scenario()

vehicle.ai_set_mode('span')
vehicle.ai_drive_in_lane(True)

# scenario.update()
dist_buffer = 0
for _ in range(240):
    sleep(0.1)
    scenario.update()
    distance = np.linalg.norm(np.array(vehicle.state['pos']) - np.array([2.91697, -12.596, 119.58]))
    vehicle.update_vehicle()
    print(distance)
#     # scenario.update()
#     vehicle.update_vehicle()
Beispiel #12
0
    def add_obstacles_to_scenario(self, scenario: Scenario) -> None:
        from beamngpy import ProceduralCone, ProceduralCube, ProceduralCylinder, ProceduralBump, StaticObject
        from dbtypes.scheme import Cone, Cube, Cylinder, Bump, Stopsign, TrafficLightSingle, TrafficLightDouble
        from random import randrange
        for obstacle in self.obstacles:
            obstacle_type = type(obstacle)
            height = obstacle.height
            pos = (obstacle.x, obstacle.y, height / 2.0)
            rot = (obstacle.x_rot, obstacle.y_rot, obstacle.z_rot)
            name = obstacle.oid
            mesh = None
            if obstacle_type is Cube:
                mesh = ProceduralCube(
                    pos,
                    rot, (obstacle.length, obstacle.width, height),
                    name=name)
            elif obstacle_type is Cylinder:
                mesh = ProceduralCylinder(pos,
                                          rot,
                                          obstacle.radius,
                                          height=height,
                                          name=name)
            elif obstacle_type is Cone:
                mesh = ProceduralCone(pos,
                                      rot,
                                      obstacle.base_radius,
                                      height,
                                      name=name)
            elif obstacle_type is Bump:
                mesh = ProceduralBump(pos,
                                      rot,
                                      obstacle.width,
                                      obstacle.length,
                                      height,
                                      obstacle.upper_length,
                                      obstacle.upper_width,
                                      name=name)
            elif obstacle_type is Stopsign:
                id_number = randrange(1000)
                name_sign = "stopsign" + str(id_number)
                stopsign = StaticObject(
                    pos=(obstacle.x, obstacle.y, 0),
                    rot=rot,
                    name=name_sign,
                    scale=(3, 3, 3),
                    shape='/levels/drivebuild/art/objects/stopsign.dae')
                scenario.add_object(stopsign)
            elif obstacle_type is TrafficLightSingle:
                id_number = randrange(1000)
                name_light = "trafficlight" + str(id_number)
                name_pole = "pole" + str(id_number)
                traffic_light = StaticObject(
                    name=name_light,
                    pos=(obstacle.x, obstacle.y, 5.32),
                    rot=rot,
                    scale=(1, 1, 1),
                    shape='/levels/drivebuild/art/objects/trafficlight1a.dae')
                scenario.add_object(traffic_light)
                pole = StaticObject(
                    name=name_pole,
                    pos=(obstacle.x, obstacle.y, 0),
                    rot=rot,
                    scale=(1, 1, 1.3),
                    shape='/levels/drivebuild/art/objects/pole_traffic1.dae')
                scenario.add_object(pole)
            elif obstacle_type is TrafficLightDouble:
                from math import radians, sin, cos
                from numpy import dot
                id_number = randrange(1000)
                name_light1 = "trafficlight" + str(id_number)
                name_light2 = "trafficlight" + str(id_number) + 'a'
                name_pole = "pole" + str(id_number)
                rad = radians(obstacle.z_rot)
                pole_coords = (obstacle.x, obstacle.y, 0)
                traffic_light1_coords = (7.5, 0.35)
                traffic_light2_coords = (3, 0.35)
                rot_matrix = [[cos(rad), sin(rad)], [-sin(rad), cos(rad)]]
                traffic_light1_coords = dot(rot_matrix, traffic_light1_coords)
                traffic_light1_coords = (traffic_light1_coords[0] +
                                         pole_coords[0],
                                         traffic_light1_coords[1] +
                                         pole_coords[1], 7.8)
                traffic_light2_coords = dot(rot_matrix, traffic_light2_coords)
                traffic_light2_coords = (traffic_light2_coords[0] +
                                         pole_coords[0],
                                         traffic_light2_coords[1] +
                                         pole_coords[1], 7.3)

                pole2 = StaticObject(
                    name=name_pole,
                    pos=pole_coords,
                    rot=rot,
                    scale=(1, 1, 1),
                    shape=
                    '/levels/drivebuild/art/objects/pole_light_signal1.dae')
                scenario.add_object(pole2)
                traffic_light1 = StaticObject(
                    name=name_light1,
                    pos=traffic_light1_coords,
                    rot=rot,
                    scale=(1, 1, 1),
                    shape='/levels/drivebuild/art/objects/trafficlight2a.dae')
                scenario.add_object(traffic_light1)
                traffic_lights2 = StaticObject(
                    name=name_light2,
                    pos=traffic_light2_coords,
                    rot=rot,
                    scale=(1, 1, 1),
                    shape='/levels/drivebuild/art/objects/trafficlight2a.dae')
                scenario.add_object(traffic_lights2)
            else:
                _logger.warning("Obstacles of type " + str(obstacle_type) +
                                " are not supported by the generation, yet.")
                mesh = None
            if mesh:
                # NOTE Procedural meshes use radians for rotation
                scenario.add_procedural_mesh(mesh)