玩转Tello
Tips: Use the New Tello SDK. Take care the UDP PORT.
Environment
- macOS 10.14
- Python 2.7.10
控制指令 Command Script
#
# Tello Python Control Demo
#
import threading
import socket
import sys
import time
host = '192.168.10.2'
port = 9000
locaddr = (host,port)
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
tello_address = ('192.168.10.1', 8889)
sock.bind(locaddr)
def recv():
count = 0
while True:
try:
data, server = sock.recvfrom(1518)
print('Receive: ' + data.decode(encoding="utf-8"))
except:
print ('\nExit . . .\n')
break
print ('\r\n\r\nTello Python3 Demo.\r\n')
print ('Tello: command takeoff land flip forward back left right \r\n up down cw ccw speed speed?\r\n')
print ('end -- quit demo.\r\n')
#recvThread create
recvThread = threading.Thread(target=recv)
recvThread.daemon = True
recvThread.start()
while True:
try:
msg = raw_input(">> ");
if not msg:
break
if 'end' in msg:
print ('...')
sock.close()
break
# Send data
msg = msg.encode(encoding="utf-8")
sent = sock.sendto(msg, tello_address)
except:
print ('\n . . .\n')
sock.close()
break
Commands List
- command
- takeoff
- land
- streamon
- streamoff
- emergency
- up x
- down x
- left x
- right x
- forward x
- back x
- cw x
- ccw x
- flip x
- go x y z speed
- curve x1 y1 z1 x2 y2 z2 speed
- speed x
- rc a b c d
- wifi said pass
- speed?
- battery?
- time?
- height?
- temp?
- attitude?
- baro?
- acceleration?
- tof?
- wifi?
状态读取 State Script
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = '0.0.0.0'
server_port = 8890
server = (server_address, server_port)
sock.bind(server)
print("Listening on " + server_address + ":" + str(server_port))
while True:
payload, client_address = sock.recvfrom(200)
print("Echoing data back to " + str(client_address))
print(payload)
sent = sock.sendto(payload, client_address)
实时视频 Video Script
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import cv2
import time
server_address = '0.0.0.0'
server_port = 11111
addr = 'udp://' + server_address + ':' + str(server_port)
cap = cv2.VideoCapture(addr)
print(cap.isOpened())
while(cap.isOpened()):
for i in range(0,7):
ret, frame = cap.read()
if ret == True:
cv2.imshow("Flame", frame)
cv2.waitKey(1)
cap.release()
cv2.destroyAllWindows()
TODO
- Solve the Problem
[h264 @ 0x7fd3ed01a600] non-existing PPS 0 referenced
[h264 @ 0x7fd3ed01a600] non-existing PPS 0 referenced
[h264 @ 0x7fd3ed01a600] decode_slice_header error
[h264 @ 0x7fd3ed01a600] no frame!
- socket.timeout: timed out