How to use beamngpy - 10 common examples

To help you get started, we’ve selected a few beamngpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BeamNG / BeamNGpy / tests / test_sensors.py View on Github external
def test_damage(beamng):
    scenario = Scenario('smallgrid', 'damage_test')
    dummy = Vehicle('dummy', model='pickup')
    scenario.add_vehicle(dummy, pos=(0, 0, 0))
    scenario.make(beamng)

    vehicle = Vehicle('test_car', model='etk800')
    damage = Damage()
    vehicle.attach_sensor('damage', damage)

    with beamng as bng:
        bng.load_scenario(scenario)
        bng.start_scenario()

        scenario.add_vehicle(vehicle, pos=(0, 0, 32), rot=(-90, 0, 0),
                             cling=False)

        bng.step(600)
github BeamNG / BeamNGpy / tests / test_vehicle.py View on Github external
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)
github BeamNG / BeamNGpy / tests / test_sensors.py View on Github external
def test_electrics(beamng):
    scenario = Scenario('smallgrid', 'electrics_test')
    vehicle = Vehicle('test_car', model='etk800')

    electrics = Electrics()
    vehicle.attach_sensor('electrics', electrics)

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

    with beamng as bng:
        bng.load_scenario(scenario)
        bng.start_scenario()
        bng.step(120)

        vehicle.control(throttle=1.0)

        bng.step(360)
github BeamNG / BeamNGpy / tests / test_scenario.py View on Github external
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)
github BeamNG / BeamNGpy / tests / test_vehicle.py View on Github external
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
github BeamNG / BeamNGpy / tests / test_sensors.py View on Github external
def test_lidar(beamng):
    scenario = Scenario('west_coast_usa', 'lidar_test')
    vehicle = Vehicle('test_car', model='etk800')

    lidar = Lidar()
    vehicle.attach_sensor('lidar', lidar)

    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)

        arr = sensors['lidar']['points']
        ref = arr[0]
        eq = arr[np.where(arr == ref)]
github BeamNG / BeamNGpy / tests / test_vehicle.py View on Github external
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()
github BeamNG / BeamNGpy / tests / test_vehicle.py View on Github external
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
github BeamNG / BeamNGpy / tests / test_sensors.py View on Github external
def test_damage(beamng):
    scenario = Scenario('smallgrid', 'damage_test')
    dummy = Vehicle('dummy', model='pickup')
    scenario.add_vehicle(dummy, pos=(0, 0, 0))
    scenario.make(beamng)

    vehicle = Vehicle('test_car', model='etk800')
    damage = Damage()
    vehicle.attach_sensor('damage', damage)

    with beamng as bng:
        bng.load_scenario(scenario)
        bng.start_scenario()

        scenario.add_vehicle(vehicle, pos=(0, 0, 32), rot=(-90, 0, 0),
                             cling=False)

        bng.step(600)
github BeamNG / BeamNGpy / tests / test_sensors.py View on Github external
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)