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
def add_barriers(scenario): barrier_locations = [] with open( 'H:/GitHub/BeamNGpy-meriels-ext/examples/industrial_racetrack_barrier_locations.txt', 'r') as f: lines = f.readlines() for i, line in enumerate(lines): line = line.split(' ') pos = line[0].split(',') pos = tuple([float(i) for i in pos]) rot_quat = line[1].split(',') rot_quat = tuple([float(j) for j in rot_quat]) rot_quat = turn_90(rot_quat) # barrier_locations.append({'pos':pos, 'rot_quat':rot_quat}) # add barrier to scenario ramp = StaticObject( name='barrier{}'.format(i), pos=pos, rot=None, rot_quat=rot_quat, scale=(1, 1, 1), shape= 'levels/Industrial/art/shapes/misc/concrete_road_barrier_a.dae' ) scenario.add_object(ramp)
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()
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
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
import numpy as np from time import sleep, time beamng = BeamNGpy('localhost', 64256, home=r'C:\BeamNG_unlimited\trunk') 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()
no_of_vehicles += 1 elif 'object' in eve: no_of_static_objects += 1 lst_vehicle_objs = [] for veh in range(no_of_vehicles): vehicle = Vehicle('vehicle_' + str(veh), model='etkc', licence='THESIS') lst_vehicle_objs.append(vehicle) scenario.add_vehicle(vehicle, pos=(-820, 24, 118), rot=(45, 0, 0)) lst_static_objs = [] for stat in range(no_of_static_objects): stat_obj = StaticObject( name="statc_object_ai", pos=(0, 0, 0), rot=(45, 0, 0), scale=(0.5, 0.5, 0.5), shape= "C://Projects//BeamNG Unlimited//trunk//levels//west_coast_usa//art//shapes//objects//construction_sign_big_a.DAE" ) lst_static_objs.append(stat_obj) scenario.add_vehicle(stat_obj) print(lst_vehicle_objs[0].vid, lst_static_objs) scenario.add_vehicle(Vehicle('ai_vehicle', model='coupe', licence='THESIS')) # scenario.make(bng) # # # Launch BeamNG.research # bng.open() # # Load and start our scenario # bng.load_scenario(scenario)
from beamngpy import BeamNGpy, Vehicle, Scenario, ProceduralRing, StaticObject from beamngpy.sensors import Camera 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,
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()
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)