-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathKeyboardControl.py
More file actions
49 lines (37 loc) · 882 Bytes
/
KeyboardControl.py
File metadata and controls
49 lines (37 loc) · 882 Bytes
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
from djitellopy import tello
import KeyPressModule as kp
import ImageCapture
from time import sleep
kp.init()
me = tello.Tello()
me.connect()
batteryLvl = me.get_battery()
print("Battery Level : ", batteryLvl)
def getKeyboardInput():
lr, fb, up, yv = 0, 0, 0, 0
speed = 50
if kp.getKey("e"):
me.takeoff()
if kp.getKey("LEFT"):
lr = -speed
elif kp.getKey("RIGHT"):
lr = speed
if kp.getKey("UP"):
fb = speed
elif kp.getKey("DOWN"):
fb = -speed
if kp.getKey("w"):
up = speed
elif kp.getKey("s"):
up = -speed
if kp.getKey("a"):
yv = -speed
elif kp.getKey("d"):
yv = speed
if kp.getKey("q"):
me.land()
return [lr, fb, up, yv]
while True:
vals = getKeyboardInput()
me.send_rc_control(vals[0], vals[1], vals[2], vals[3])
sleep(0.05)