def test_camera_control(beamng): with beamng as bng: scenario = Scenario('smallgrid', 'camera_control_test') ego = Vehicle('ego', model='etk800') other = Vehicle('other', model='etk800') scenario.add_vehicle(ego, pos=(0, 0, 0)) scenario.add_vehicle(other, pos=(5, 5, 0)) scenario.make(bng) bng.load_scenario(scenario) bng.start_scenario() camera_configs = bng.get_player_camera_modes(ego.vid) for camera in camera_configs.keys(): bng.set_player_camera_mode(ego.vid, camera, {}) time.sleep(5) current_camera = bng.get_player_camera_modes(ego.vid) assert current_camera[camera]['focused'] time.sleep(10) assert 'orbit' in camera_configs bng.set_player_camera_mode(ego.vid, 'orbit', {'distance': 50}) time.sleep(5) current_camera = bng.get_player_camera_modes(ego.vid) assert current_camera['orbit']['focused'] assert abs(current_camera['orbit']['camDist'] - 50) < 0.5
def test_gforces(beamng): with beamng as bng: scenario = Scenario('west_coast_usa', 'gforce_test') vehicle = Vehicle('test_car', model='etk800') gforces = GForces() vehicle.attach_sensor('gforces', gforces) scenario.add_vehicle(vehicle, pos=(-717.121, 101, 118.675), rot=(0, 0, 45)) scenario.make(beamng) gx = [] gy = [] bng.load_scenario(scenario) bng.start_scenario() bng.step(120) vehicle.ai_set_aggression(2) vehicle.ai_set_mode('span') for _ in range(64): bng.step(30) vehicle.poll_sensors() gx.append(gforces.data['gx']) gy.append(gforces.data['gy']) assert np.var(gx) > 1 and np.var(gy) > 1
def main(): beamng = BeamNGpy('localhost', 64256) scenario = Scenario('GridMap', 'road_test') road_a = Road('track_editor_C_center', looped=True) nodes = [ (-25, 300, 0, 5), (25, 300, 0, 6), (25, 350, 0, 4), (-25, 350, 0, 5), ] road_a.nodes.extend(nodes) scenario.add_road(road_a) road_b = Road('track_editor_C_center') nodes = [ (0, 325, 0, 5), (50, 375, 0, 5), ] road_b.nodes.extend(nodes) scenario.add_road(road_b) 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 test_noise(beamng): scenario = Scenario('west_coast_usa', 'camera_test') vehicle = Vehicle('test_car', model='etk800') pos = (-0.3, 1, 1.0) direction = (0, 1, 0) fov = 120 resolution = (64, 64) reference_camera = Camera(pos, direction, fov, resolution, colour=True) vehicle.attach_sensor('reference_camera', reference_camera) noise_camera = Camera(pos, direction, fov, resolution, colour=True) noise_camera = WhiteGaussianRGBNoise(noise_camera, .5, 0) vehicle.attach_sensor('noise_cam', noise_camera) scenario.add_vehicle(vehicle, pos=(-717.121, 101, 118.675), rot=(0, 0, 45)) scenario.make(beamng) with beamng as bng: bng.load_scenario(scenario) bng.step(120) vehicle.poll_sensors() noise_img = np.asarray(noise_camera.data['colour']) reference_img = np.asarray(reference_camera.data['colour']) # since this is based on two different renders this will always be different assert (not (np.array_equal(noise_img, reference_img)))
def setup_BeamNG(self): # Create a scenario in test map scenario = Scenario('cruise-control', 'example') # Create an ETK800 with the licence plate 'PID' self.vehicle = Vehicle('ego_vehicle', model='etk800', licence='PID') electrics = Electrics() self.vehicle.attach_sensor('electrics', electrics) # Cars electric system # Add it to our scenario at this position and rotation scenario.add_vehicle(self.vehicle, pos=(406.787, 1115.518, 0), rot=(0, 0, 0)) # Place files defining our scenario for the simulator to read scenario.make(self.bng) # Launch BeamNG.research self.bng.open() # Load and start our scenario self.bng.load_scenario(scenario) self.bng.start_scenario()
def test_camera(beamng): scenario = Scenario('west_coast_usa', 'camera_test') vehicle = Vehicle('test_car', model='etk800') pos = (-0.3, 1, 1.0) direction = (0, 1, 0) fov = 120 resolution = (64, 64) front_camera = Camera(pos, direction, fov, resolution, colour=True, depth=True, annotation=True) vehicle.attach_sensor('front_cam', front_camera) scenario.add_vehicle(vehicle, pos=(-717.121, 101, 118.675), rot=(0, 0, 45)) scenario.make(beamng) with beamng as bng: bng.load_scenario(scenario) bng.step(120) sensors = bng.poll_sensors(vehicle) assert_image_different(sensors['front_cam']['colour']) assert_image_different(sensors['front_cam']['depth']) assert_image_different(sensors['front_cam']['annotation'])
def main(): beamng = BeamNGpy('localhost', 64256, home='F:\Softwares\BeamNG_Research_SVN') scenario = Scenario('GridMap', 'road_test') road_a = Road('custom_track_center', looped=False) nodes = [ (0, 0, 0, 4), (0, 400, 0, 4), ] road_a.nodes.extend(nodes) scenario.add_road(road_a) vehicle = Vehicle('ego', model='etk800', licence='PYTHON', colour='Black') scenario.add_vehicle(vehicle, pos = ( 0, 0, 0.163609) , rot=(0,0,180)) # 0.163609 , scenario.make(beamng) script = list() node0 = { 'x': 0, 'y': 2, 'z': 0.163609, 't': 0.01, } node1 = { 'x': 0, 'y': 3, 'z': 0.163609, 't': 0.01, } node2 = { 'x': 0, 'y': 350, 'z': 0.163609, 't': 15, } node3 = { 'x': 0, 'y': 400, 'z': 0.163609, 't': 5, } script.append(node0) script.append(node1) script.append(node2) script.append(node3) bng = beamng.open(launch=True) try: bng.load_scenario(scenario) bng.start_scenario() vehicle.ai_set_script(script) input('Press enter when done...') finally: bng.close()
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
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()
def main(): random.seed(1703) setup_logging() beamng = BeamNGpy('localhost', 64256) scenario = Scenario('west_coast_usa', 'lidar_demo', description='Spanning the map with a lidar sensor') vehicle = Vehicle('ego_vehicle', model='etk800', licence='RED', color='Red') lidar = Lidar(offset=(0, 0, 1.6)) vehicle.attach_sensor('lidar', lidar) scenario.add_vehicle(vehicle, pos=(-717.121, 101, 118.675), rot=(0, 0, 45)) scenario.make(beamng) bng = beamng.open(launch=True) try: bng.set_deterministic() # Set simulator to be deterministic bng.set_steps_per_second(60) # With 60hz temporal resolution bng.load_scenario(scenario) bng.hide_hud() bng.start_scenario() vehicle.ai_set_mode('span') print('Driving around for 60 seconds...') sleep(60) finally: bng.close()
def main(): bng_home = os.environ['BEAMNG_HOME'] road = TrainingRoad(ASFAULT_PREFAB) road.calculate_road_line(back=True) bng = BeamNGpy('localhost', 64256, home=bng_home) scenario = Scenario('smallgrid', 'train') scenario.add_road(road.asphalt) scenario.add_road(road.mid_line) scenario.add_road(road.left_line) scenario.add_road(road.right_line) vehicle = Vehicle('ego_vehicle', model='etk800', licence='PYTHON') front_camera = Camera(pos=(0, 1.4, 1.8), direction=(0, 1, -0.23), fov=FOV, resolution=(CAMERA_WIDTH, CAMERA_HEIGHT), colour=True, depth=False, annotation=False) vehicle.attach_sensor("front_camera", front_camera) # Add it to our scenario at this position and rotation spawn_point = road.spawn_point() scenario.add_vehicle(vehicle, pos=spawn_point.pos(), rot=spawn_point.rot()) # Place files defining our scenario for the simulator to read scenario.make(bng) prefab_path = scenario.get_prefab_path() update_prefab(prefab_path) bng.open() bng.set_nondeterministic() bng.set_steps_per_second(60) # Load and start our scenario bng.load_scenario(scenario) bng.start_scenario() vehicle.ai_set_mode('span') vehicle.ai_set_speed(5) vehicle.ai_set_line([{ 'pos': node.pos(), 'speed': 10 } for node in road.road_line]) number_of_images = 0 while number_of_images < 9000: bng.poll_sensors(vehicle) number_of_images += 1 #print(number_of_images) bng.step(1) sensors = bng.poll_sensors(vehicle) image = sensors['front_camera']['colour'].convert('RGB') image = np.array(image) image = image[:, :, ::-1] dist = road.dist_to_center(vehicle.state['pos']) cv2.imwrite('datasets\\{}.jpg'.format(number_of_images), image) bng.close()
def test_noise(beamng): with beamng as bng: scenario = Scenario('west_coast_usa', 'camera_test') vehicle = Vehicle('test_car', model='etk800') pos = (-0.3, 1, 1.0) direction = (0, 1, 0) fov = 120 resolution = (64, 64) cam = Camera(pos, direction, fov, resolution, colour=True, depth=True) noise_cam = RandomImageNoise(cam) vehicle.attach_sensor('noise_cam', noise_cam) lidar = Lidar() noise_lidar = RandomLIDARNoise(lidar, mean=0, var=.5) vehicle.attach_sensor('noise_lidar', noise_lidar) scenario.add_vehicle(vehicle, pos=(-717.121, 101, 118.675), rot=(0, 0, 45)) scenario.make(beamng) bng.load_scenario(scenario) bng.step(120) time.sleep(20) vehicle.poll_sensors() reference_img = np.array(noise_cam._sensor.data['colour']) noise_img = np.array(noise_cam.data['colour']) assert (not (np.array_equal(noise_img, reference_img))) ref_pc = lidar.data['points'] noise_pc = noise_lidar.data['points'] assert (not (np.array_equal(ref_pc, noise_pc)))
def main(): beamng = BeamNGpy('localhost', 64256, home='C:/Users/merie/Documents/BeamNG.research.v1.7.0.0') scenario = Scenario('GridMap', 'road_test') road_a = Road('track_editor_C_center', rid='circle_road', looped=True) nodes = [ (-25, 300, 0, 5), (25, 300, 0, 6), (25, 350, 0, 4), (-25, 350, 0, 5), ] road_a.nodes.extend(nodes) scenario.add_road(road_a) road_b = Road('track_editor_C_center', rid='center_road') nodes = [ (0, 325, 0, 5), (50, 375, 0, 5), ] road_b.nodes.extend(nodes) scenario.add_road(road_b) 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 setup_beamng(vehicle_model='etk800', camera_pos=(-0.5, 0.38, 1.3), camera_direction=(0, 1.0, 0), pitch_euler=0.0): global base_filename, default_color, default_scenario, default_spawnpoint, steps_per_sec global integral, prev_error, setpoint integral = 0.0 prev_error = 0.0 # version==keras # sm = DAVE2Model() # model = sm.define_dual_model_BeamNG() # model = sm.load_weights("BeamNGmodel-racetrackdual-comparison100K-PIDcontrolset-2.h5") # model = sm.load_weights("BeamNGmodel-racetrackdual-comparison100K-PIDcontrolset-3-sanitycheckretraining-model.h5") # version==pytorch # model = torch.load("C:/Users/merie/Downloads/dave/test_model_20.pt", map_location=torch.device('cpu')).eval() # model = torch.load("F:/MODELS-FOR-MERIEL/models/model-100000D-1000B-100E-1p000000e-04LR-100.pt.pt", map_location=torch.device('cpu')).eval() # model = torch.load("F:/MODELS-FOR-MERIEL/models/model-292757D-1000B-100E-1p000000e-04LR-100.pt", map_location=torch.device('cpu')).eval() model = torch.load( "H:/GitHub/DAVE2-Keras/test7-trad-50epochs-64batch-1e4lr-ORIGDATASET-singleoutput-model.pt", map_location=torch.device('cpu')).eval() random.seed(1703) setup_logging() beamng = BeamNGpy('localhost', 64256, home='H:/BeamNG.research.v1.7.0.1clean', user='******') scenario = Scenario(default_scenario, 'research_test') vehicle = Vehicle('ego_vehicle', model=vehicle_model, licence='EGO', color=default_color) vehicle = setup_sensors(vehicle, pos=camera_pos, direction=camera_direction) spawn = spawn_point(default_scenario, default_spawnpoint) scenario.add_vehicle( vehicle, pos=spawn['pos'], rot=None, rot_quat=spawn['rot_quat']) #, partConfig=parts_config) add_barriers(scenario) add_qr_cubes(scenario) # Compile the scenario and place it in BeamNG's map folder scenario.make(beamng) # Start BeamNG and enter the main loop bng = beamng.open(launch=True) #bng.hide_hud() bng.set_deterministic() # Set simulator to be deterministic bng.set_steps_per_second(steps_per_sec) # With 60hz temporal resolution bng.load_scenario(scenario) bng.start_scenario() # Put simulator in pause awaiting further inputs bng.pause() assert vehicle.skt # bng.resume() # find_width_of_road(bng) return vehicle, bng, model
def main(): setup_logging() beamng = BeamNGpy('localhost', 64256, home='C:/Users/merie/Documents/BeamNG.research.v1.7.0.1') #beamng.change_setting('research', True) scenario = Scenario('west_coast_usa', 'lidar_tour', description='Tour through the west coast gathering ' 'Lidar data') vehicle = Vehicle('ego_vehicle', model='etk800', licence='LIDAR') lidar = Lidar() vehicle.attach_sensor('lidar', lidar) #beamng.open_lidar('lidar', vehicle, 'shmem', 8000) scenario.add_vehicle(vehicle, pos=(-717.121, 101, 118.675), rot=None, rot_quat=(0, 0, 0.3826834, 0.9238795)) scenario.make(beamng) bng = beamng.open(launch=True) #bng.open_lidar('lidar', vehicle, 'shmem', 8000) #lidar.connect(bng, vehicle) try: bng.load_scenario(scenario) # this is where the error happens window = open_window(SIZE, SIZE) lidar_vis = LidarVisualiser(Lidar.max_points) lidar_vis.open(SIZE, SIZE) bng.set_steps_per_second(60) bng.set_deterministic() bng.hide_hud() bng.start_scenario() bng.pause() vehicle.ai_set_mode('span') def update(): sensors = bng.poll_sensors(vehicle) points = sensors['lidar']['points'] bng.step(3, wait=False) lidar_vis.update_points(points, vehicle.state) glutPostRedisplay() glutReshapeFunc(lidar_resize) glutIdleFunc(update) glutMainLoop() except Exception as e: print(e) finally: bng.close()
class BeamNGBrewer: def __init__(self, beamng_home=None, road_nodes: List4DTuple = None): self.beamng = BeamNGpy('localhost', 64256, home=beamng_home) self.vehicle: Vehicle = None self.camera: BeamNGCamera = None if road_nodes: self.setup_road_nodes(road_nodes) steps = 5 self.params = SimulationParams(beamng_steps=steps, delay_msec=int(steps * 0.05 * 1000)) self.vehicle_start_pose = BeamNGPose() def setup_road_nodes(self, road_nodes): self.road_nodes = road_nodes self.decal_road: DecalRoad = DecalRoad('street_1').add_4d_points( road_nodes) self.road_points = RoadPoints().add_middle_nodes(road_nodes) def setup_vehicle(self) -> Vehicle: assert self.vehicle is None self.vehicle = Vehicle('ego_vehicle', model='etk800', licence='TIG', color='Red') return self.vehicle def setup_scenario_camera(self, resolution=(1280, 1280), fov=120) -> BeamNGCamera: assert self.camera is None self.camera = BeamNGCamera(self.beamng, 'brewer_camera') return self.camera def bring_up(self): self.scenario = Scenario('tig', 'tigscenario') if self.vehicle: self.scenario.add_vehicle(self.vehicle, pos=self.vehicle_start_pose.pos, rot=self.vehicle_start_pose.rot) if self.camera: self.scenario.add_camera(self.camera.camera, self.camera.name) self.scenario.make(self.beamng) if not self.beamng.server: self.beamng.open() self.beamng.pause() self.beamng.set_deterministic() self.beamng.load_scenario(self.scenario) self.beamng.start_scenario() def __del__(self): if self.beamng: try: self.beamng.close() except: pass
def _start_simulation(self, test_case: TestCase) -> Tuple[Scenario, ExtThread]: from threading import Thread from config import BEAMNG_LEVEL_NAME from beamngpy.beamngcommon import BNGValueError Simulation._start_simulation.lock.acquire() while not Simulation._is_port_available( Simulation._start_simulation.port): Simulation._start_simulation.port += 200 # Make sure to not interfere with previously started simulations self._bng_instance = DBBeamNGpy('localhost', Simulation._start_simulation.port) authors = ", ".join(test_case.authors) bng_scenario = Scenario(BEAMNG_LEVEL_NAME, self._sim_name, authors=authors) test_case.scenario.add_all(bng_scenario) bng_scenario.make(self._bng_instance) # Make manual changes to the scenario files self._make_lanes_visible() self._annotate_objects() self._add_waypoints_to_scenario(test_case.scenario.participants) self._enable_participant_movements(test_case.scenario.participants) waypoints = set() for wps in [p.movement for p in test_case.scenario.participants]: for wp in wps: if wp.id is not None: # FIXME Waypoints are added in wrong order waypoints.add(wp.id) # self._add_lap_config(waypoints) try: self._bng_instance.open(launch=True) self._bng_instance.load_scenario(bng_scenario) self._bng_instance.set_steps_per_second(test_case.stepsPerSecond) self._bng_instance.set_deterministic() test_case.scenario.set_time_of_day_to(self._bng_instance) self._bng_instance.hide_hud() self._bng_instance.start_scenario() self._bng_instance.pause() except OSError: _logger.exception("The start of a BeamNG instance failed (Port: " + str(Simulation._start_simulation.port) + ").") except BNGValueError: _logger.exception( "Sending to or receiving from BeamNGpy failed and may corrupt the socket" ) Simulation._start_simulation.lock.release() runtime_thread = Thread(target=Simulation._run_runtime_verification, args=(self, test_case.aiFrequency)) runtime_thread.daemon = True runtime_thread.start() while not runtime_thread.ident: # Wait for the Thread to get an ID pass return bng_scenario, ExtThread(runtime_thread.ident)
def test_get_available_vehicles(beamng): with beamng as bng: scenario = Scenario('smallgrid', 'spawn_test') vehicle = Vehicle('irrelevant', model='pickup') scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot=(0, 0, 0)) scenario.make(beamng) bng.load_scenario(scenario) bng.start_scenario() resp = bng.get_available_vehicles() assert len(resp) > 0
def setup_beamng(traffic=2): global sp, beamng_home, beamng_user setup_logging() beamng = BeamNGpy('localhost', 64256, home=beamng_home, user=beamng_user) scenario = Scenario( 'west_coast_usa', 'lidar_tour', description= 'Tour through highway with variable traffic vehicles gathering ' 'Lidar data') # setup vehicle vehicle = Vehicle('ego_vehicle', model='etk800', licence='LIDAR', color='Red') vehicle = setup_sensors(vehicle) # setup vehicle poses lane = random.choice([1, 2, 3, 4]) ego_sp = spawn_point(sp, lane) ego_pos = ego_sp['pos'] ego_rot_quat = ego_sp['rot_quat'] lane = ego_sp['lane'] # add vehicles to scenario # print("adding vehicle to scenario...") scenario.add_vehicle(vehicle, pos=ego_pos, rot=None, rot_quat=ego_rot_quat) tvs = traffic_vehicles(traffic) ps = generate_vehicle_positions(ego_pos, ego_rot_quat, lane, tvs) for i in range(len(tvs)): print("adding vehicle {}...".format(i)) scenario.add_vehicle(tvs[i], pos=ps[i], rot_quat=ego_rot_quat) print("making scenario...") scenario.make(beamng) print("opening beamNG...") bng = beamng.open(launch=True) st = time.time() print("loading scenario...") bng.load_scenario(scenario) bng.set_steps_per_second(60) bng.set_deterministic() #print("Bounding box: {}".format(vehicle.get_bbox())) bng.hide_hud() print("starting scenario...") bng.start_scenario() vehicle.ai_set_mode('traffic') #"DecalRoad31765_8" vehicle.ai_drive_in_lane(False) vehicle.ai_set_aggression(2.0) bng.start_traffic(tvs) bng.switch_vehicle(vehicle) bng.pause() return vehicle, bng
def __init__(self, host='localhost', port=64256): self.steps = WCARaceGeometry.sps // WCARaceGeometry.rate self.host = host self.port = port self.action_space = self._action_space() self.observation_space = self._observation_space() self.episode_steps = 0 self.spine = None self.l_edge = None self.r_edge = None self.polygon = None front_factor = WCARaceGeometry.front_dist / WCARaceGeometry.front_step trail_factor = WCARaceGeometry.trail_dist / WCARaceGeometry.trail_step self.front = lambda step: +front_factor * step self.trail = lambda step: -trail_factor * step self.bng = BeamNGpy(self.host, self.port) self.vehicle = Vehicle('racecar', model='sunburst', licence='BEAMNG', colour='red', partConfig='vehicles/sunburst/hillclimb.pc') electrics = Electrics() damage = Damage() self.vehicle.attach_sensor('electrics', electrics) self.vehicle.attach_sensor('damage', damage) scenario = Scenario('west_coast_usa', 'wca_race_geometry_v0') scenario.add_vehicle(self.vehicle, pos=(394.5, -247.925, 145.25), rot=(0, 0, 90)) scenario.make(self.bng) self.bng.open(launch=True) self.bng.set_deterministic() self.bng.set_steps_per_second(WCARaceGeometry.sps) self.bng.load_scenario(scenario) self._build_racetrack() self.observation = None self.last_observation = None self.last_spine_proj = None self.bng.start_scenario() self.bng.pause()
def test_dynamic_vehicle_spawn(beamng): with beamng as bng: scenario = Scenario('smallgrid', 'dynamic spawn test') unique_vehicle_name = 'unique' vehicle = Vehicle(unique_vehicle_name, model='pickup') scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot=(0, 0, 0)) scenario.make(beamng) bng.load_scenario(scenario) bng.start_scenario() duplicate = Vehicle(unique_vehicle_name, model="etk800") assert not bng.spawn_vehicle(duplicate, (0, 10, 0), None)
def test_bboxes(beamng): with beamng as bng: scenario = Scenario('west_coast_usa', 'bbox_test') ego = Vehicle('ego', model='etk800', color='White') scenario.add_vehicle(ego, pos=(-725.365, 92.4684, 118.437), rot_quat=(-0.006, -0.0076, 0.921, -0.389)) camera = Camera((-0.3, 1, 1), (0, 1, 0), 75, (1024, 1024), colour=True, depth=True, annotation=True, instance=True) ego.attach_sensor('camera', camera) car1 = Vehicle('car1', model='etk800', color='Green') scenario.add_vehicle(car1, pos=(-710.76, 101.50, 118.56), rot_quat=(-0.006, -0.0076, 0.921, -0.389)) car2 = Vehicle('car2', model='etk800', color='Red') scenario.add_vehicle(car2, pos=(-715.83, 96.69, 118.53), rot_quat=(-0.006, -0.0076, 0.921, -0.389)) car3 = Vehicle('car3', model='etki', color='Blue') scenario.add_vehicle(car3, pos=(-696.96, 126.9, 118.44), rot_quat=(0.0181, -0.0065, 0.3816, 0.924)) car4 = Vehicle('car4', model='miramar', color='Black') scenario.add_vehicle(car4, pos=(-708.58203, 115.326, 118.60), rot_quat=(0.0181, -0.00645, 0.3818, 0.9240)) scenario.make(beamng) bng.load_scenario(scenario) bng.step(120) time.sleep(5) ego.poll_sensors() classes = bng.get_annotation_classes(bng.get_annotations()) annotation = ego.sensors['camera'].data['annotation'] instance = ego.sensors['camera'].data['instance'] bboxes = Camera.extract_bboxes(annotation, instance, classes) bboxes = [b for b in bboxes if b['class'] == 'CAR'] assert len(bboxes) == 5
def test_new_scenario(beamng): with beamng as bng: scenario = Scenario('smallgrid', 'test_scenario') vehicle = Vehicle('test_car', model='etk800') scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot=(0, 0, 0)) scenario.make(bng) bng.load_scenario(scenario) assert bng.get_scenario_name() == 'test_scenario' scenario.delete(beamng) with beamng as bng: with pytest.raises(BNGValueError): bng.load_scenario(scenario)
def main(): setup_logging() beamng = BeamNGpy('localhost', 64256) scenario = Scenario('west_coast_usa', 'lidar_tour', description='Tour through the west coast gathering ' 'Lidar data') vehicle = Vehicle('ego_vehicle', model='etk800', licence='LIDAR') lidar = Lidar() vehicle.attach_sensor('lidar', lidar) scenario.add_vehicle(vehicle, pos=(-717.121, 101, 118.675), rot=None, rot_quat=(0, 0, 0.3826834, 0.9238795)) scenario.make(beamng) bng = beamng.open(launch=True) try: bng.load_scenario(scenario) window = open_window(SIZE, SIZE) lidar_vis = LidarVisualiser(Lidar.max_points) lidar_vis.open(SIZE, SIZE) bng.set_steps_per_second(60) bng.set_deterministic() bng.hide_hud() bng.start_scenario() bng.pause() vehicle.ai_set_mode('span') def update(): sensors = bng.poll_sensors(vehicle) points = sensors['lidar']['points'] bng.step(3, wait=False) lidar_vis.update_points(points, vehicle.state) glutPostRedisplay() glutReshapeFunc(lidar_resize) glutIdleFunc(update) glutMainLoop() finally: bng.close()
def test_get_scenetree(beamng): with beamng as bng: scenario = Scenario('gridmap_v2', 'test_scenario') vehicle = Vehicle('egoVehicle', model='etk800') scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot=(0, 0, 0)) scenario.make(bng) bng.load_scenario(scenario) bng.start_scenario() scenario.sync_scene() assert scenario.scene is not None assert scenario.scene.type == 'SimGroup' prefab = find_object_name(scenario.scene, 'test_scenario') assert prefab is not None
def test_vehicle_move(beamng): with beamng as bng: bng.set_steps_per_second(50) bng.set_deterministic() scenario = Scenario('smallgrid', 'move_test') vehicle = Vehicle('test_car', model='etk800') scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot=(0, 0, 0)) scenario.make(bng) bng.load_scenario(scenario) bng.start_scenario() bng.pause() vehicle.control(throttle=1) bng.step(120, wait=True) vehicle.poll_sensors() assert np.linalg.norm(vehicle.sensors['state'].data['pos']) > 1 scenario.delete(beamng)
def test_vehicle_move(beamng): with beamng as bng: bng.set_deterministic() scenario = Scenario('smallgrid', 'move_test') vehicle = Vehicle('test_car', model='etk800') scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot=(0, 0, 0)) scenario.make(bng) bng.load_scenario(scenario) bng.start_scenario() bng.pause() vehicle.control(throttle=1) bng.step(120) vehicle.update_vehicle() assert np.linalg.norm(vehicle.state['pos']) > 1 scenario.delete(beamng)
def test_vehicle_spawn(beamng): scenario = Scenario('smallgrid', 'spawn_test') vehicle = Vehicle('irrelevant', model='pickup') scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot=(0, 0, 0)) scenario.make(beamng) with beamng as bng: bng.load_scenario(scenario) bng.start_scenario() other = Vehicle('relevant', model='etk800') scenario.add_vehicle(other, pos=(10, 10, 0), rot=(0, 0, 0)) other.update_vehicle() assert 'pos' in other.state bng.step(120) scenario.remove_vehicle(other) bng.step(600) assert other.state is None
def test_state(beamng): with beamng as bng: scenario = Scenario('smallgrid', 'vehicle_state_test') vehicle = Vehicle('test_car', model='pickup') state = State() vehicle.attach_sensor('newstate', state) scenario.add_vehicle(vehicle, pos=(0, 0, 0)) scenario.make(beamng) bng.load_scenario(scenario) bng.start_scenario() bng.step(20) vehicle.poll_sensors() assert state.data['pos'][0] < 0.1
def createBeamNGLanes(): beamng = BeamNGpy('localhost', 64256, home='F:\Softwares\BeamNG_Research_SVN') scenario = Scenario('GridMap', 'road_test') graph_edges = graph.edges for sample in graph_edges: road_a = Road('track_editor_C_border', looped=False) road_b = Road('track_editor_C_border', looped=False) point1 = list(beamng_dict[sample[0]]) point2 = list(beamng_dict[sample[1]]) lane_marking_points = getRoadEndLaneMarking(point1, point2, 4) nodes0 = [ (lane_marking_points[0], lane_marking_points[1], -0.05, 0.05), (lane_marking_points[4], lane_marking_points[5], -0.05, 0.05) ] nodes1 = [ (lane_marking_points[2], lane_marking_points[3], -0.05, 0.05), (lane_marking_points[6], lane_marking_points[7], -0.05, 0.05) ] road_a.nodes.extend(nodes0) road_b.nodes.extend(nodes1) scenario.add_road(road_a) scenario.add_road(road_b) scenario.make(beamng) bng = beamng.open(launch=True) try: bng.load_scenario(scenario) bng.start_scenario() input('Press enter when done...') finally: bng.close()