gpt4 book ai didi

python - 无法读取UDP数据包

转载 作者:行者123 更新时间:2023-12-02 17:58:15 26 4
gpt4 key购买 nike

关于与无人机通信的python脚本,我有一个小问题。我的程序运行正常,但是将命令“streamon”发送到无人机后,我应该会收到无人机的视频流。但是我什么都没得到。为了缩小问题的范围,我将代码发送给 friend ,以便他可以尝试。他可以接收视频,我用无人机在他的电脑上尝试了它,它也可以正常工作。所以我想问题出在我的电脑上。我尝试了一切,从更新python,从终端调试到在虚拟linux机器上尝试...。您知道问题可能是什么吗?
这是我的python脚本:

# Communication script with tello drone, connected via TELLO wifi network

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 :


try :
ret, frame = drone_videostream.read()
except Exception :
print(Exception)
if ret :
cv2.imshow("LiveStream", frame)
if cv2.waitKey(25) & 0xFF == ord('q') :
break


cap.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

receiveStreamThread = threading.Thread(target=receiveStream)

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()


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)

最好

最佳答案

在运行程序时,尝试运行wireshark。这样,您可以准确查看正在发送和接收的流量。您的 friend 可以做同样的事情,您可以比较输出以尝试找出失败的地方。
该问题可能是由您计算机的网络设置引起的。您是否正在运行阻止无人机流量的防火墙?

关于python - 无法读取UDP数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64191692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com