-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeamng.py
61 lines (46 loc) · 1.69 KB
/
beamng.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from beamngpy import BeamNGpy, Scenario, Vehicle
import time
# Instantiate BeamNGpy instance running the simulator from the given path,
# communicating over localhost:25252
bng = BeamNGpy('localhost', 25252, home='C:\Program Files (x86)\Steam\steamapps\common\BeamNG.drive',
user='/path/to/bng/tech/userfolder')
# Launch BeamNG.tech
bng.open()
# Create a scenario in automation_test_track called 'example'
scenario = Scenario('automation_test_track', 'example')
# Create an ETK800 with the licence plate 'PYTHON'
vehicle = Vehicle('ego_vehicle', model='etk800', license='PYTHON')
# # Add it to our scenario at this position and rotation
# scenario.add_vehicle(vehicle, pos=(-717, 101, 118),
# rot_quat=(0, 0, 0.3826834, 0.9238795))
# # Place files defining our scenario for the simulator to read
# scenario.make(bng)
# # Load and start our scenario
# bng.scenario.load(scenario)
# bng.scenario.start()
# # Make the vehicle's AI span the map
# vehicle.ai.set_mode('traffic')
# input('Hit Enter when done...')
# # Disconnect BeamNG
# bng.disconnect()
# # Or close the simulator
# # bng.close()
scenario.add_vehicle(vehicle, pos=(
493.4843837138369, 178.14530187901983, 131.96188901015057), rot_quat=(0, 0, -0.7071, 0.7071))
# Start BeamNG and load the scenario
scenario.make(bng)
bng.scenario.load(scenario)
bng.scenario.start()
# Poll vehicle position
try:
while True:
# Retrieve vehicle state
state = vehicle.state
scenario.update()
# Access the position
position = state['pos']
direction = state['dir']
print(f"Vehicle Position: {position}, Direction: {direction}")
time.sleep(1)
finally:
bng.close()