-
Notifications
You must be signed in to change notification settings - Fork 1
/
KeyboardControl
39 lines (28 loc) · 976 Bytes
/
KeyboardControl
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
from djitellopy import tello
from time import sleep
import KeyPressModule as kp
kp.init()
me = tello.Tello()
me.connect()
# checking the battery to check the connection
print(me.get_battery())
# writing a function to control the movements of the drone
def getKeyboardInput():
lr, fb, ud, yv = 0, 0, 0, 0
# lr-left\right; fb-forward\backwards; ud-up\down; yv-rotation
speed = 47
if kp.getKey('LEFT'): lr = -speed # writing as a negative to do the reverse action
elif kp.getKey('RIGHT'): lr = speed
if kp.getKey('UP'): fb = -speed
elif kp.getKey('DOWN'): fb = speed
if kp.getKey('w'): ud = speed
elif kp.getKey('s'): ud = -speed
if kp.getKey('a'): yv = speed
elif kp.getKey('d'): yv = -speed
if kp.getKey('q'): yv = me.land(); sleep(3)
if kp.getKey('e'): yv = me.takeoff()
return [lr, fb, ud, yv]
while True:
vals = getKeyboardInput()
me.send_rc_control(vals[0], vals[1], vals[2], vals[3])
sleep(0.05)