Created
November 17, 2020 06:01
-
-
Save sei0o/022be1aa0567e5c2bb44e19d35bac12e to your computer and use it in GitHub Desktop.
CLI-based controllers for Tello
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from easytello import tello | |
import cv2 | |
import numpy as np | |
import time | |
# TELLO = False | |
TELLO = True | |
STEP = 50 | |
d = tello.Tello() | |
d.takeoff() | |
time.sleep(2) | |
# d.up(400) | |
# time.sleep(2) | |
# Do NOT use streamon() because it automatically takes control of the video stream (look at the source code) | |
# d.streamon() | |
d.send_command('streamon') | |
time.sleep(2) | |
stop_thres = 0.30 | |
cap = cv2.VideoCapture('udp://0.0.0.0:11111') | |
cv2.namedWindow("square") | |
fw = cap.get(cv2.CAP_PROP_FRAME_WIDTH) | |
fh = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) | |
print(fw, fh) | |
while True: | |
ret, frame = cap.read() | |
if not ret: | |
print('empty frame') | |
continue | |
cv2.imshow('frame', frame) | |
key = cv2.waitKey(0) & 0xff | |
if key == ord('q'): | |
d.land() | |
break | |
if key == ord('w'): | |
d.forward(STEP) | |
if key == ord('a'): | |
d.left(STEP) | |
if key == ord('s'): | |
d.back(STEP) | |
if key == ord('d'): | |
d.right(STEP) | |
if key == ord('e'): | |
d.ccw(45) | |
if key == ord('r'): | |
d.cw(45) | |
cap.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
端末ではなく、OpenCVのウィンドウを選択した状態でキーを打たないとダメっぽい