我有DJI Tello无人机,我想从中接收视频数据。我可以将PC连接到无人机,并通过UDP连接在端口“ 8889”上通过UDP发送命令,但是我不知道如何使用端口“ 11111”从无人机的摄像头接收视频数据。

我使用无人机与PC之间的UDP连接来命令该端口(端口8889),并且运行良好:我可以发送“命令”,“起飞”或“降落”之类的命令,并且收到“确定”。但是,当我将“ streamon”发送到我的电视时,会收到“ Unknow command”(未知命令),并且端口“ 11111”上没有任何内容。

import socket
import threading
import time


class Tello:
    def __init__(self):
        self.ip = '192.168.10.1'
        self.command_port = 8889
        self.address = (self.ip, self.command_port)
        self.response = None
        self.overtime = 3

        self.lock = threading.RLock()

        self.video_port = 11111

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.video_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        self.socket.bind(('', self.command_port))

        # init command and video stream

        self.receive_thread = threading.Thread(target = self.receive_response)
        self.receive_thread.daemon = True


        self.socket.sendto(b'command', self.address)
        print('sent: command')
        last_send = time.time()

        self.receive_thread.start()

        while self.response != b'OK':
            if time.time() - last_send >= self.overtime:
                self.socket.sendto(b'command', self.address)
                print('sent: command')
                last_send = time.time()

        # video stream

        self.video_socket.bind(('', self.video_port))

        self.receive_video_thread = threading.Thread(target = self.receive_video_data)
        self.receive_video_thread.daemon = True
        self.receive_video_thread.start()

        self.socket.sendto(b'streamon', self.address)
        print('sent: streamon')



    def receive_response(self):
        while True:
            with self.lock:
                self.response, ip = self.socket.recvfrom(3000)
                if self.response:
                        print(str(self.response))

    def receive_video_data(self):
        self.video_data = None
        while True:
            with self.lock:
                data, ip = self.video_socket.recvfrom(2048)
                if data:
                    print(str(data))


    def send_command(self, command):
        self.socket.sendto(command.encode('utf-8'), self.address)

    #control command:

    def takeoff(self):
        self.send_command('takeoff')

    def land(self):
        self.send_command('land')


drone = Tello()

最佳答案

我得到了答案:Tello的固件未更新,因此无法正常工作。
如果您(像我一样)在发送'Unknow Command!'后得到'streamon'
使用您的Tello应用程序并在设置中更新固件。

关于python - 如何使用python从DJI Tello无人机和UDP服务器收集视频数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56951741/

10-12 02:38