-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeyboardcontrol.py
51 lines (39 loc) · 1001 Bytes
/
keyboardcontrol.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
from djitellopy import tello
import Keypressmodule as kp
import time
import cv2
kp.init()
us = tello.Tello()
us.connect()
print(us.get_battery())
def getKeyIn():
lr, fb, up, yv = 0, 0, 0, 0
speed = 50
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"):
us.land()
if kp.getKey("e"):
us.takeoff()
if kp.getKey('z'):
cv2.imwrite(f'Resources/Images/{time.time()}.jpg')
##To aviod multiple unwanted shots
time.sleep(0.3)
return [lr, fb, up, yv ]
##Reset drone if error is found
us.takeoff()
while True:
vals = getKeyIn()
us.send_rc_control(vals[0], vals[1], vals[2], vals[3])