This repository was archived by the owner on Aug 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·83 lines (66 loc) · 2.35 KB
/
main.py
File metadata and controls
executable file
·83 lines (66 loc) · 2.35 KB
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
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from __future__ import division, print_function
import json
import time
import sys
import box
import comm
import term
states = {'no_comm': 'Disconnected', 'idle': 'Idle', 'test': 'Test', 'pass': 'Pass', 'fail': 'Fail', 'arm': 'Arm', 'ignite': 'Ignite', 'burn': 'Burn', 'coast': 'Coast', 'apogee': 'Apogee', 'wait': 'Wait', 'eject': 'Eject', 'fall': 'Fall', 'recover': 'Recover'}
inited = False
try:
comm.init()
term.init()
box.init('blackbox.json')
data = {'time': 0, 'state': 'no_comm', 'sensors': None}
count = 0
while True:
try:
cmd = sys.stdin.read(1)
if cmd == 't':
comm.send({'command': 'test'})
elif cmd == 'a':
comm.send({'command': 'arm'})
elif cmd == 'd':
comm.send({'command': 'disarm'})
elif cmd == 'i':
comm.send({'command': 'ignite'})
elif cmd == 'b':
comm.send({'command': 'abort'})
elif cmd == 'p':
comm.send({'command': 'pass'})
elif cmd == 'f':
comm.send({'command': 'fail'})
else:
comm.send({'command': 'none'})
except IOError:
comm.send({'command': 'none'})
message = comm.read()
if message:
count = 0
data['time'] = message['time']
if message['type'] == 'state':
data['state'] = message['state']
elif message['type'] == 'telemetry':
data['sensors'] = message['sensors']
box.write(data)
else:
count += 1
if count > 1000:
data['state'] = 'no_comm'
if data['sensors']:
print('[{}] State: {} ∙ Acceleration: {} g ∙ Altitude: {} ft ∙ GPS: {}° {}° '.format(data['time']/1000, states[data['state']], data['sensors']['acc']['z'], data['sensors']['bar']['alt'], data['sensors']['gps']['lat'], data['sensors']['gps']['lon']), end='\r')
else:
print('[{}] State: {} '.format(data['time']/1000, states[data['state']]), end='\r')
except KeyboardInterrupt:
pass
finally:
try:
box.deinit()
except:
pass
try:
term.deinit()
except:
pass