-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfrom_keyboard.py
69 lines (63 loc) · 2.03 KB
/
from_keyboard.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
import curses
import sys
import nerf_turret
import time
screen = curses.initscr()
curses.noecho()
curses.cbreak()
screen.keypad(True)
screen.nodelay(True)
reflect = sys.argv[1]
def main_loop(rel):
global last_pressed
motion = 'n'
vel = 60
try:
while True:
char = screen.getch()
if char == ord('q'):
break
elif char == ord('u'):
if vel + 5 < 127:
vel += 5
print("Velocity at",vel)
else:
vel = 127
print("Velocity at max")
elif char == ord('d'):
if vel - 5 > 0:
vel -= 5
print("Velocity at",vel)
else:
vel = 0
print("Velocity at min")
elif char == curses.KEY_RIGHT:
last_pressed = time.time()
if motion != 'r':
nerf_turret.set_velocity(rel*vel, 0)
motion = 'r'
elif char == curses.KEY_LEFT:
last_pressed = time.time()
if motion != 'l':
nerf_turret.set_velocity(rel*-vel, 0)
motion = 'l'
elif char == curses.KEY_UP:
last_pressed = time.time()
if motion != 'u':
nerf_turret.set_velocity(0, max(vel-20,0))
motion = 'u'
elif char == curses.KEY_DOWN:
last_pressed = time.time()
if motion != 'd':
nerf_turret.set_velocity(0, min(-vel+20,0))
motion = 'd'
if motion != 'n' and time.time() - last_pressed > 0.5:
nerf_turret.set_velocity(0,0)
motion = 'n'
time.sleep(100)
finally:
nerf_turret.pan(0)
nerf_turret.tilt(0)
curses.nocbreak(); screen.keypad(0); curses.echo(); screen.nodelay(0)
curses.endwin()
main_loop(1 if reflect[0] == "n" else -1)