示例#1
0
def test_ultrasonic(beamng):
    with beamng as bng:
        scenario = Scenario('smallgrid', 'ultrasonic_test')
        cube_dist = 4
        cube = ProceduralCube(name='cube',
                              pos=(0, -cube_dist, 5),
                              rot=None,
                              rot_quat=(0, 0, 0, 1),
                              size=(1, 20, 10))
        scenario.add_procedural_mesh(cube)

        pos = (0, 1, 2)
        rot = (0, 1, 0)
        ultrasonic = Ultrasonic(pos, rot)

        vehicle = Vehicle('test', model='pickup')
        vehicle.attach_sensor('ultrasonic', ultrasonic)

        scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot_quat=(0, 0, 0, 1))
        scenario.make(beamng)

        bng.load_scenario(scenario)
        bng.start_scenario()
        vehicle.poll_sensors()
        assert 0 < vehicle.sensors['ultrasonic'].data['distance'] < cube_dist
示例#2
0
def main():
    beamng = BeamNGpy('localhost', 64256)

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

    cylinder = ProceduralCylinder(pos=(10, -10, 0),
                                  rot=(0, 0, 0),
                                  radius=3.5,
                                  height=5)
    scenario.add_procedural_mesh(cylinder)

    cone = ProceduralCone(pos=(-10, -10, 0),
                          rot=(45, 0, 0),
                          radius=3.5,
                          height=5)
    scenario.add_procedural_mesh(cone)

    cube = ProceduralCube(pos=(0, -20, 0),
                          rot=(0, 0, 0),
                          size=(5, 2, 3))
    scenario.add_procedural_mesh(cube)

    vehicle = Vehicle('ego_vehicle', model='etk800')
    scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot=(0, 0, 0))

    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()
        input('Press enter when done...')
    finally:
        bng.close()
示例#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()
示例#4
0
def main():
    beamng = BeamNGpy('localhost', 64256)

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

    cylinder = ProceduralCylinder(name='cylinder',
                                  radius=3.5,
                                  height=5,
                                  pos=(10, -10, 0),
                                  rot=None,
                                  rot_quat=(0, 0, 0, 1))
    scenario.add_procedural_mesh(cylinder)

    bump = ProceduralBump(name='bump',
                          pos=(-10, -10, 0),
                          rot=None,
                          rot_quat=(0, 0, 0, 1),
                          width=5,
                          length=7,
                          height=2,
                          upper_length=2,
                          upper_width=2)
    scenario.add_procedural_mesh(bump)

    cone = ProceduralCone(name='cone',
                          pos=(-10, -20, 0),
                          rot=None,
                          rot_quat=(0, 0, 0, 1),
                          radius=3.5,
                          height=5)
    scenario.add_procedural_mesh(cone)

    cube = ProceduralCube(name='cube',
                          pos=(0, -20, 0),
                          rot=None,
                          rot_quat=(0, 0, 0, 1),
                          size=(5, 2, 3))
    scenario.add_procedural_mesh(cube)

    ring = ProceduralRing(name='ring',
                          pos=(10, -20, 0),
                          rot=None,
                          rot_quat=(0, 0.7071068, 0, 0.7071068),
                          radius=2,
                          thickness=1)
    scenario.add_procedural_mesh(ring)

    vehicle = Vehicle('ego_vehicle', model='etk800')
    scenario.add_vehicle(vehicle,
                         pos=(0, 0, 0),
                         rot=None,
                         rot_quat=(0, 0, 0, 1))

    scenario.make(beamng)

    bng = beamng.open(launch=True)
    try:
        bng.load_scenario(scenario)
        bng.start_scenario()
        input('Press enter when done...')
    finally:
        bng.close()
示例#5
0
                     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)
scenario.add_camera(cam, 'cam')

scenario.make(beamng)

bng = beamng.open()
bng.set_deterministic()
bng.load_scenario(scenario)
示例#6
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)