-
Notifications
You must be signed in to change notification settings - Fork 0
/
f1demo2val.py
66 lines (50 loc) · 2.19 KB
/
f1demo2val.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
import csv
import time
import logging
import os
import datetime
from itertools import islice
import kuksa_viss_client as kuksa
KUKSAVAL_HOST = os.environ['KUKSAVAL_HOST']
KUKSAVAL_PORT = os.environ['KUKSAVAL_PORT']
def readData(client):
with open("bottas_monza21race.csv", "r", newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
signals_list = next(reader)
while True:
csvfile.seek(0)
prev_time = 0
for row in islice(reader, 1, None):
curr_time = row[1]
if prev_time != 0:
curr = datetime.datetime.strptime(curr_time, '%Y-%m-%d %H:%M:%S.%f')
prev = datetime.datetime.strptime(prev_time, '%Y-%m-%d %H:%M:%S.%f')
delta = (curr-prev).total_seconds()
else:
delta = 0
for i in range(5, 14):
if row[i] != "":
drivetime_str = row[5]
dt = datetime.datetime.strptime(drivetime_str[7:], '%H:%M:%S.%f') #strip '0 days' from front of string
drivetime_seconds = dt.second + dt.minute*60 + dt.hour*3600
### Send values to kuksa.val server
client.setValue("Vehicle.DriveTime", drivetime_seconds)
client.setValue("Vehicle.Powertrain.CombustionEngine.Engine.Speed", row[6])
client.setValue("Vehicle.OBD.Speed", row[7])
client.setValue("Vehicle.Powertrain.Transmission.Gear", row[8])
client.setValue("Vehicle.Powertrain.CombustionEngine.Engine.TPS", row[9])
client.setValue("Vehicle.Chassis.Brake.PedalPosition", row[10])
client.setValue("Vehicle.TravelledDistance", (float(row[13]) / 1000) ) # convert meters to kilometers
time.sleep(delta)
prev_time = curr_time
def main():
config = {
"ip" : KUKSAVAL_HOST,
"port" : KUKSAVAL_PORT
}
client = kuksa.KuksaClientThread(config)
client.authorize()
client.start()
readData(client)
if __name__ == "__main__":
main()