-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
71 lines (58 loc) · 1.71 KB
/
controller.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
from evdev import InputDevice, categorize, ecodes
from motor import Controller
controller = Controller()
gamepad = InputDevice('/dev/input/event2')
print(gamepad)
x_dir = 0
y_dir = 0
for event in gamepad.read_loop():
#print(categorize(event))
#print(str(event.code) + " / " + str(event.value))
if event.code == 16:
# links
if event.value == -1:
if y_dir == 0:
controller.spin_l()
elif y_dir == -1:
controller.turn_l()
x_dir = -1
# rechts
elif event.value == 1:
if y_dir == 0:
controller.spin_r()
elif y_dir == -1:
controller.turn_r()
x_dir = 1
# losgelassen
elif event.value == 0:
controller.idle()
x_dir = 0
elif event.code == 17:
# oben
if event.value == -1:
if x_dir == 0:
controller.forward()
elif x_dir == -1:
controller.turn_l()
elif x_dir == 1:
controller.turn_r()
y_dir = -1
# unten
elif event.value == 1:
controller.backward()
y_dir = 1
# losgelassen
elif event.value == 0:
controller.idle()
y_dir = 0
elif event.code == 9 or event.code == 10:
# gedrueckt
if event.value > 0:
if event.code == 9:
mode = -1
else:
mode = 1
controller.shoot(True, mode)
# losgelassen
elif event.value == 0:
controller.shoot(False)