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 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_ai(beamng): with beamng as bng: bng.set_deterministic() scenario = Scenario('west_coast_usa', 'ai_test') vehicle = Vehicle('test_car', model='etk800') other = Vehicle('other', model='etk800') pos = [-717.121, 101, 118.675] scenario.add_vehicle(vehicle, pos=pos, rot=(0, 0, 45)) scenario.add_vehicle(other, pos=(-453, 700, 75), rot=(0, 0, 45)) scenario.make(bng) bng.load_scenario(scenario) bng.start_scenario() bng.pause() vehicle.ai_set_mode('span') assert_continued_movement(bng, vehicle, pos) bng.restart_scenario() bng.pause() vehicle.ai_set_waypoint('Bridge4_B') assert_continued_movement(bng, vehicle, pos) bng.restart_scenario() bng.pause() vehicle.ai_set_target('other', mode='chase') assert_continued_movement(bng, vehicle, pos) bng.restart_scenario() bng.pause() vehicle.ai_set_target('other', mode='flee') assert_continued_movement(bng, vehicle, pos) scenario.delete(beamng)
def test_vehicle_ai(beamng): with beamng as bng: bng.set_deterministic() scenario = Scenario('west_coast_usa', 'ai_test') vehicle = Vehicle('test_car', model='etk800') other = Vehicle('other', model='etk800') pos = [-717.121, 101, 118.675] scenario.add_vehicle(vehicle, pos=pos, rot=(0, 0, 45)) scenario.add_vehicle(other, pos=(-453, 700, 75), rot=(0, 0, 45)) scenario.make(bng) bng.load_scenario(scenario) bng.start_scenario() bng.pause() vehicle.ai_set_mode('span') assert_continued_movement(bng, vehicle, pos) bng.restart_scenario() bng.pause() vehicle.ai_set_waypoint('Bridge4_B') assert_continued_movement(bng, vehicle, pos) bng.restart_scenario() bng.pause() vehicle.ai_set_target('other', mode='chase') assert_continued_movement(bng, vehicle, pos) bng.restart_scenario() bng.pause() vehicle.ai_set_target('other', mode='flee') assert_continued_movement(bng, vehicle, pos) bng.restart_scenario() bng.pause() script = [ { 'x': -735, 'y': 86.7, 'z': 119, 't': 0 }, { 'x': -752, 'y': 70, 'z': 119, 't': 5 }, { 'x': -762, 'y': 60, 'z': 119, 't': 8 }, ] vehicle.ai_set_script(script) bng.step(600, wait=True) vehicle.update_vehicle() ref = [script[1]['x'], script[1]['y'], script[1]['z']] pos = vehicle.state['pos'] ref, pos = np.array(ref), np.array(pos) assert np.linalg.norm(ref - pos) < 2.5 scenario.delete(beamng)