-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
56 lines (44 loc) · 1.76 KB
/
main.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
from com import communication
import time
import csv
import threading
# initialize serial communication
com = communication(com_port='/dev/ttyUSB0')
# initialize thread
thread = threading.Thread(target=com.transmit, daemon=True)
thread.start()
thread2 = threading.Thread(target=com.decode_telemetry, daemon=True)
thread2.start()
# disarming channels
disarm_channels = [1500, 1500, 885, 1500, 1000, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500]
com.update_data(disarm_channels)
time.sleep(2)
# arming channels
arm_channels = [1500, 1500, 885, 1500, 1800, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500]
com.update_data(arm_channels)
time.sleep(2)
# csv settings
csv_counter = 0
dicts = []
save_after = 100000 # seconds
t1 = time.time()
# Increase and decrease the throttle in a loop and save the times in a csv file
while True:
channels_pwm = [1500, 1500, 1050, 1500, 1800, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500]
com.update_data(channels_pwm)
data = {'time': time.time(), 'throttle': channels_pwm[2]}
dicts.append(data)
time.sleep(0.01)
channels_pwm = [1500, 1500, 1500, 1500, 1800, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500]
com.update_data(channels_pwm)
data = {'time': time.time(), 'throttle': channels_pwm[2]}
dicts.append(data)
time.sleep(0.01)
if (time.time()-t1) > save_after:
print("saving csv file")
com.update_data(disarm_channels)
keys = dicts[0].keys()
with open('command_data.csv', 'w', newline='') as output_file:
dict_writer = csv.DictWriter(output_file, keys)
dict_writer.writeheader()
dict_writer.writerows(dicts)