-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_controls.py
63 lines (47 loc) · 1.21 KB
/
key_controls.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
#!/usr/bin/env python
from djitellopy import tello
import keypress_module as kp
from time import sleep
kp.init()
drone = tello.Tello()
drone.connect()
print(drone.get_battery())
def get_keyboard_input():
# (L/R, bk/fwd, up/down, clock/counterclock-wise yaw) each in -/+100%
left_right = 0
bk_fwd = 0
down_up = 0
c_cc_yaw = 0
speed = 50
if kp.is_key_pressed('q'):
drone.land()
if kp.is_key_pressed('LEFT'):
left_right = -speed
elif kp.is_key_pressed('RIGHT'):
left_right = speed
if kp.is_key_pressed('DOWN'):
bk_fwd = -speed
elif kp.is_key_pressed('UP'):
bk_fwd = speed
if kp.is_key_pressed('s'):
down_up = -speed
elif kp.is_key_pressed('w'):
down_up = speed
if kp.is_key_pressed('d'):
c_cc_yaw = -speed
elif kp.is_key_pressed('a'):
c_cc_yaw = speed
return [left_right, bk_fwd, down_up, c_cc_yaw]
# wait for RETURN to take off
while True:
if kp.is_key_pressed('RETURN') is True:
break
drone.takeoff()
while True:
commands = get_keyboard_input()
drone.send_rc_control(
commands[0],
commands[1],
commands[2],
commands[3])
sleep(0.05)