-
Notifications
You must be signed in to change notification settings - Fork 0
/
ayncIO.py
42 lines (35 loc) · 1.06 KB
/
ayncIO.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
import asyncio
from threading import Thread
import cv2 # requires python-opencv
from tello_asyncio import Tello, VIDEO_URL
import time
##############################################################################
# drone control in worker thread
def fly():
async def main():
drone = Tello()
try:
await drone.connect()
await drone.start_video()
#await drone.takeoff()
#await drone.turn_clockwise(360)
#await drone.land()
time.sleep(20)
finally:
await drone.stop_video()
await drone.disconnect()
asyncio.run(main())
fly_thread = Thread(target=fly, daemon=True)
fly_thread.start()
##############################################################################
# Video capture and GUI in main thread
capture = cv2.VideoCapture(VIDEO_URL)
capture.open(VIDEO_URL)
while True:
grabbed, frame = capture.read()
if grabbed:
cv2.imshow('tello-asyncio', frame)
if cv2.waitKey(1) != -1:
break
capture.release()
cv2.destroyAllWindows()