forked from Gernby/OpenPilot_Dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashfile.py
72 lines (61 loc) · 2.45 KB
/
dashfile.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
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
import csv
import zmq
import time
import numpy as np
import selfdrive.messaging as messaging
from selfdrive.services import service_list
from common.realtime import set_realtime_priority, Ratekeeper
import os, os.path
# Polling rate should be twice the data rate to prevent aliasing
def main(rate=200):
set_realtime_priority(3)
context = zmq.Context()
poller = zmq.Poller()
live100 = messaging.sub_sock(context, service_list['live100'].port, conflate=True, poller=poller)
vEgo = 0.0
_live100 = None
frame_count = 0
skipped_count = 0
rk = Ratekeeper(rate, print_delay_threshold=np.inf)
# simple version for working with CWD
#print len([name for name in os.listdir('.') if os.path.isfile(name)])
# path joining version for other paths
DIR = '/sdcard/tuning'
filenumber = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
print("start")
with open(DIR + '/dashboard_file_%d.csv' % filenumber, mode='w') as dash_file:
print("opened")
dash_writer = csv.writer(dash_file, delimiter=',', quotechar='', quoting=csv.QUOTE_NONE)
print("initialized")
dash_writer.writerow(['angleSteersDes','angleSteers','vEgo','steerOverride','upSteer','uiSteer','ufSteer','time'])
print("first row")
while 1:
receiveTime = int(time.time() * 1000)
for socket, event in poller.poll(0):
if socket is live100:
_live100 = messaging.recv_one(socket)
vEgo = _live100.live100.vEgo
if vEgo >= 0:
frame_count += 1
dash_writer.writerow([str(round(_live100.live100.angleSteersDes, 2)),
str(round(_live100.live100.angleSteers, 2)),
str(round(_live100.live100.vEgo, 1)),
1 if _live100.live100.steerOverride else 0,
str(round(_live100.live100.upSteer, 4)),
str(round(_live100.live100.uiSteer, 4)),
str(round(_live100.live100.ufSteer, 4)),
str(receiveTime)])
else:
skipped_count += 1
else:
skipped_count += 1
if frame_count % 200 == 0:
print("captured = %d" % frame_count)
frame_count += 1
if skipped_count % 200 == 0:
print("skipped = %d" % skipped_count)
skipped_count += 1
rk.keep_time()
if __name__ == "__main__":
main()