【发布时间】:2020-10-01 17:24:04
【问题描述】:
我正在扭动一个 python 脚本,以便通过 wifi 与我的 Tello 无人机通信。 与无人机连接后,我可以发送 UDP 数据包来发送命令(这非常好)。 我想通过 UDP 数据包在端口 11111 上到达我的 udp 服务器接收来自无人机的视频流。这在 SDK 文档中进行了描述,“https://dl-cdn.ryzerobotics.com/downloads/tello/20180910/Tello %20SDK%20Documentation%20EN_1.3.pdf"。
print ('\r\n\r\nTello drone communication tool\r\n')
print("...importing modules...")
import threading
import socket
import sys
import time
import platform
import cv2
print("Modules imported")
print("...Initialiasing UDP server to get video stream....")
drone_videostream = cv2.VideoCapture('udp://@0.0.0.0:11111')
print("Server initialised")
# my local adress to receive UDP packets from tello DRONE
host = ''
port = 9000
locaddr = (host,port)
print("...creation of UDP socket...")
# Create a UDP socket (UDP Portocol to receive and send UDP packets from/to drone)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Got drone port and ip adress from network (explained in official SDK documentation)
tello_address = ('192.168.10.1', 8889)
print("UDP socket created")
sock.bind(locaddr)
width = 320
height = 240
def receiveStream() :
print("...receiving stream...")
while True :
ret, frame = drone_videostream.read()
img = cv2.resize(frame, (width, height))
cv2.imshow("LiveStream", frame)
cv2.waitKey(1)
drone_videostream.release()
cv2.destroyAllWindows()
def receiving():
while True:
try:
data, server = sock.recvfrom(1518)
print(data.decode(encoding="utf-8"))
except Exception:
print ('\nExit . . .\n')
break
print ("...initialiazing connection with tello drone...")
message = "command"
message = message.encode(encoding="utf-8")
sent = sock.sendto(message, tello_address)
print("Connection established")
#create a thread that will excute the receiving() function
receiveThread = threading.Thread(target=receiving)
receiveThread.start()
receiveStreamThread = threading.Thread(target=receiveStream)
while True :
message = input(str("Enter a command :\r\n"))
if message == "streamon" :
message = message.encode(encoding="utf-8")
sent = sock.sendto(message, tello_address)
receiveStreamThread.start()
else :
message = message.encode(encoding="utf-8")
sent = sock.sendto(message, tello_address)
当我向无人机发送“streamon”命令时,我无法读取发送的 UDP 数据包。我收到以下错误:
error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
这意味着帧是空的,因此没有接收到图像。
你知道我为什么没有收到吗?
非常感谢您提前提供的帮助, 最好的:)
【问题讨论】:
-
您需要缩小代码范围以了解发生了什么。可能不是您收到的所有数据包都包含您期望的数据,因此您可能不得不丢弃它们
-
删除网络防火墙解决了问题。
标签: python sockets udp dji-sdk tello-drone