-
Notifications
You must be signed in to change notification settings - Fork 0
/
gather_manual_data.py
54 lines (47 loc) · 1.52 KB
/
gather_manual_data.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
import pickle
import time
import zlib
from math import fabs
from config import telemetry_data, host, port
from donkey_client import DonkeyClient
from manual_input import ManualInput
def test_clients():
manual_input = ManualInput()
client = DonkeyClient(address=(host, port))
client.collecting = False
client.hardReset()
client.initCar()
client.reset()
client.collecting = True
client.telemetrie = []
while len(client.telemetrie) < 10:
time.sleep(0.1)
last_printed_index = 0
while True:
if manual_input.q == 1:
client.collecting = False
break
current_telemetrie = client.telemetrie[len(client.telemetrie) - 1]
manual_input.loop(current_telemetrie.img)
if (len(client.telemetrie) % 20 == 0):
index = len(client.telemetrie)
if last_printed_index != index:
print(current_telemetrie.pos_x, ",", current_telemetrie.pos_y, ",", current_telemetrie.pos_z)
last_printed_index = index
if manual_input.e == 1:
th1 = 0.8
if fabs(current_telemetrie.cte) > 0.5:
th1 = 0.2
elif fabs(current_telemetrie.cte) > 1:
th1 = 0.5
elif fabs(current_telemetrie.cte) > 2:
th1 = 0.3
client.send_controls(-current_telemetrie.cte / 2.0, th1)
else:
client.send_controls(manual_input.st, manual_input.th)
with open(telemetry_data + str(time.time_ns()) + '.pk', 'wb') as episode_file:
episode_file.write(zlib.compress(pickle.dumps(client.telemetrie)))
time.sleep(1.0)
client.stop()
if __name__ == "__main__":
test_clients()