-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_control.py
96 lines (76 loc) · 2.04 KB
/
debug_control.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from controller.drive import DriveMotors
from Adafruit_BNO055.BNO055 import BNO055
import curses
import threading
import time
W = ord('w')
A = ord('a')
S = ord('s')
D = ord('d')
Q = ord('q')
E = ord('e')
imu_cont_lock = threading.Lock()
imu_cont = True
def continue_imu_data():
imu_cont_lock.acquire()
status = imu_cont
imu_cont_lock.release()
return status
def set_imu_cont(val):
global imu_cont
imu_cont_lock.acquire()
imu_cont = val
imu_cont_lock.release()
def display_iterable(scr, iterable, start, x=10, name=None):
sy, sx = curses.getsyx()
if name:
curses.setsyx(start, x)
scr.clrtoeol()
scr.addstr(start, x, name)
start += 1
for i in iterable:
curses.setsyx(start, x)
scr.clrtoeol()
scr.addstr(start, x, str(round(i,2)))
start += 1
curses.setsyx(sy, sx)
scr.refresh()
def display_imu_data(scr, bno, startline=4):
while continue_imu_data():
start = startline
for i in (('Euler', bno.read_euler()),
('Gyroscope', bno.read_gyroscope()),
('Accelerometer', bno.read_accelerometer())):
display_iterable(scr, i[1], start, name=i[0])
start += len(i[1]) + 2
time.sleep(0.25)
def main():
scr = curses.initscr()
curses.cbreak()
curses.setsyx(-1, -1)
# scr.keypad(1)
dm = DriveMotors()
bno = BNO055()
bno.begin()
scr.addstr(0, 10, 'debug_control.py: the ultimate boxbot controller')
scr.addstr(2, 10, 'Press Q to exit.')
scr.refresh()
tdisp = threading.Thread(target=display_imu_data, args=(scr, bno))
tdisp.start()
while True:
key = scr.getch()
if key == Q:
dm.stop()
break
{
W: dm.forward,
S: dm.backward,
A: dm.turnleft,
D: dm.turnright,
E: dm.stop,
}.get(key, dm.stop)()
set_imu_cont(False)
tdisp.join()
curses.endwin()
if __name__ == '__main__':
main()