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

  1. command
  2. takeoff
  3. land
  4. streamon
  5. streamoff
  6. emergency
  7. up x
  8. down x
  9. left x
  10. right x
  11. forward x
  12. back x
  13. cw x
  14. ccw x
  15. flip x
  16. go x y z speed
  17. curve x1 y1 z1 x2 y2 z2 speed
  18. speed x
  19. rc a b c d
  20. wifi said pass
  21. speed?
  22. battery?
  23. time?
  24. height?
  25. temp?
  26. attitude?
  27. baro?
  28. acceleration?
  29. tof?
  30. 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

  1. 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!
  1. socket.timeout: timed out

References

  1. Video packets
  2. pytello
  3. TelloDriver