-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmanual-control.py
More file actions
59 lines (53 loc) · 1.56 KB
/
manual-control.py
File metadata and controls
59 lines (53 loc) · 1.56 KB
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
from djitellopy import Tello
import cv2
import threading
import keyboard
def main():
# set up drone
global drone
drone = Tello()
drone.connect()
#create video thread
v = threading.Thread(target=GetVideo)
v.daemon = True
v.start()
drone.takeoff()
# Do pip install keyboard
#get keyboard input
while True:
try:
if keyboard.is_pressed('esc'): # ESC
drone.emergency()
break
elif keyboard.is_pressed(' '):
drone.land()
break
elif keyboard.is_pressed('w'):
print('forward')
drone.move_forward(30)
elif keyboard.is_pressed('s'):
drone.move_back(30)
elif keyboard.is_pressed('a'):
drone.move_left(30)
elif keyboard.is_pressed('d'):
drone.move_right(30)
elif keyboard.is_pressed('e'):
drone.rotate_clockwise(30)
elif keyboard.is_pressed('q'):
drone.rotate_counter_clockwise(30)
elif keyboard.is_pressed('r'):
drone.move_up(30)
elif keyboard.is_pressed('f'):
drone.move_down(30)
except:
continue
def GetVideo():
# get video stream from drone
drone.streamon()
while True:
frame = drone.get_frame_read().frame
frame = cv2.resize(frame, (1000, 1000))
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cv2.imshow("Drone cam", frame)
cv2.waitKey(1)
main()