Tello программирование на питоне

DJITelloPy

DJI Tello drone python interface using the official Tello SDK and Tello EDU SDK. This library has the following features:

  • implementation of all tello commands
  • easily retrieve a video stream
  • receive and parse state packets
  • control a swarm of drones
  • support for python >= 3.6

Install using pip

For Linux distributions with both python2 and python3 (e.g. Debian, Ubuntu, . ) you need to run

Install in developer mode

Using the commands below you can install the repository in an editable way. This allows you to modify the library and use the modified version as if you had installed it regularly.

git clone https://github.com/damiafuentes/DJITelloPy.git cd DJITelloPy pip install -e . 

Usage

API Reference

See djitellopy.readthedocs.io for a full reference of all classes and methods available.

Simple example

In the examples directory there are some code examples. Comments in the examples are mostly in both english and chinese.

Notes

  • If you are using the streamon command and the response is Unknown command means you have to update the Tello firmware. That can be done through the Tello app.
  • Mission pad detection and navigation is only supported by the Tello EDU.
  • Bright environment is necessary for successful use of mission pads.
  • Connecting to an existing wifi network is only supported by the Tello EDU.
  • When connected to an existing wifi network video streaming is not available (TODO: needs confirmation with the new SDK3 port commands)
Читайте также:  Java sdk and tools

DJITelloPy in the media and in the wild

  • >1.5 Million views Youtube: Drone Programming With Python Course
  • German magazine «Make»: «KI steuert Follow-Me-Drohne» (paywall), authors notes, github repo
  • Webinar on learn.droneblocks.io: «DJITelloPy Drone Coding», github repo
  • Universities & Schools using DJITelloPy in projects or in class:
    • Ball State University in Muncie, Indiana
    • Technical University Kaiserslautern
    • Sha Tin College, Hong Kong
    • University of São Paulo
    • add yours.

    Authors

    License

    This project is licensed under the MIT License — see the LICENSE.txt file for details

    Источник

    Saved searches

    Use saved searches to filter your results more quickly

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

    This is a collection of python modules that interact with the Ryze Tello drone.

    License

    dji-sdk/Tello-Python

    This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

    Name already in use

    A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

    Sign In Required

    Please sign in to use Codespaces.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching GitHub Desktop

    If nothing happens, download GitHub Desktop and try again.

    Launching Xcode

    If nothing happens, download Xcode and try again.

    Launching Visual Studio Code

    Your codespace will open once ready.

    There was a problem preparing your codespace, please try again.

    Latest commit

    Git stats

    Files

    Failed to load latest commit information.

    README.md

    This is a collection of python-based sample code that interact with the Ryze Tello drone.

    This toolkit contains three sample programs based on tello sdk and python2.7,including Single_Tello_Test, Tello_Video, and Tello_Video (With_Pose_Recognition). There is also a program file named tello_state.py.

    In Single_Tello_Test,You can design a series of command combinations by writing a txt script to let tello execute a series of actions you have designed. This program can also be used as a command set test tool for tello.

    In Tello_Video,You can receive the video stream data from tello, decode the video through the h264 decoding library, and display it on a GUI interface based on Tkinter and PIL. In addition, it also supports a control panel that can operate tello. This sample code provides an example of receiving and processing and getting the correct video data. The source code of the h264 decoding library is also provided in the package, which can be used for your reference.

    Tello_Video_With_Pose_Recognition is an application version modified from Tello_Video.It uses the decoded video data,and everytime extract a single frame image for pose recognition operation , and binds the specific posture and aircraft control commands to realize the pose control of Tello.This code is mainly used as an application case for utilizing the decoded video data of tello for image processing.

    Tello_state.py can read the various status data of tello, and can be used as a tool to debug and view the status of tello.

    The sample codes above are based on python2.7.There is no need to install additional third-party libraries for running Single_Tello_Test and tello_state.py.For Tello_Video and Tello_Video (With_Pose_Recognition), you need to install a series of third-party libraries. Therefore, in these two folders, a one-click installation script (based on windows32/64, linux and macos) is provided, which can facilitate you with installing all relevant dependencies.

    Specific to the content and description of each package, you can refer to the readme file in the related folder.

    If you have any questions about this sample code and the installation, please feel free to contact me. You can communicate with me by sending e-mail to sdk@ryzerobotics.com. And recently we have committed a new FAQ file under the ‘Tello-Python’.If you have any questions,you can firstly refer to it .

    Please refer to github repository https://github.com/TelloSDK/Multi-Tello-Formation. This is a python program that enable the function of multi-tello swarms.

    About

    This is a collection of python modules that interact with the Ryze Tello drone.

    Источник

    7. Python, Auto Flight Path

    The code below will use Python to fly your Tello drone on a pre-determined flight path. There are four main Python files.

    • stats.py defines the Stats object to store statistics on command request and response
    • tello.py defines the Tello object to abstract and represent the Tello drone
    • command.txt stores the commands that will be sent to the Tello drone
    • app.py is the application program, or the driver , that will be executed as an entrypoint to start sending commands

    7.1. Stats

    The Stats class is used to log command requests and responses.

     1from datetime import datetime 2 3class Stats(object): 4 def __init__(self, command, id): 5 """ 6 Constructor. 7 :param command: The command sent. 8 :param id: The identifier. 9 """ 10 self.command = command 11 self.response = None 12 self.id = id 13 14 self.start_time = datetime.now() 15 self.end_time = None 16 self.duration = None 17 18 def add_response(self, response): 19 """ 20 Adds the response. 21 :param response: Response. 22 :return: None. 23 """ 24 self.response = response 25 self.end_time = datetime.now() 26 self.duration = self.get_duration() 27 28 def get_duration(self): 29 """ 30 Gets the duration. 31 :return: Duration. 32 """ 33 diff = self.end_time - self.start_time 34 return diff.total_seconds() 35 36 def print_stats(self): 37 """ 38 Prints the statistics. 39 :return: None. 40 """ 41 print(f'\nid self.id>') 42 print(f'command: self.command>') 43 print(f'response: self.response>') 44 print(f'start_time: self.start_time>') 45 print(f'end_time: self.end_time>') 46 print(f'duration: self.duration>') 47 48 def got_response(self): 49 """ 50 Returns a boolean if a response was received. 51 :return: Boolean. 52 """ 53 54 if self.response is None: 55 return False 56 else: 57 return True 58 59 def return_stats(self): 60 """ 61 Returns the statistics. 62 :return: Statistics. 63 """ 64 str = '' 65 str += f'\nid: self.id>\n' 66 str += f'command: self.command>\n' 67 str += f'response: self.response>\n' 68 str += f'start_time: self.start_time>\n' 69 str += f'end_time: self.end_time>\n' 70 str += f'duration: self.duration>\n' 71 return str 

    7.2. Tello

    The Tello class is used to abstract the drone.

     1import socket 2import threading 3import time 4from stats import Stats 5 6class Tello(object): 7 def __init__(self): 8 """ 9 Constructor. 10 """ 11 self.local_ip = '' 12 self.local_port = 8889 13 self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 14 self.socket.bind((self.local_ip, self.local_port)) 15 16 # thread for receiving cmd ack 17 self.receive_thread = threading.Thread(target=self._receive_thread) 18 self.receive_thread.daemon = True 19 self.receive_thread.start() 20 21 self.tello_ip = '192.168.10.1' 22 self.tello_port = 8889 23 self.tello_address = (self.tello_ip, self.tello_port) 24 self.log = [] 25 26 self.MAX_TIME_OUT = 15.0 27 28 def send_command(self, command): 29 """ 30 Send a command to the ip address. Will be blocked until 31 the last command receives an 'OK'. 32 If the command fails (either b/c time out or error), 33 will try to resend the command 34 :param command: (str) the command to send 35 :param ip: (str) the ip of Tello 36 :return: The latest command response 37 """ 38 self.log.append(Stats(command, len(self.log))) 39 40 self.socket.sendto(command.encode('utf-8'), self.tello_address) 41 print(f'sending command: command> to self.tello_ip>') 42 43 start = time.time() 44 while not self.log[-1].got_response(): 45 now = time.time() 46 diff = now - start 47 if diff > self.MAX_TIME_OUT: 48 print(f'Max timeout exceeded. command command>') 49 return 50 print(f'Done. sent command: command> to self.tello_ip>') 51 52 def _receive_thread(self): 53 """ 54 Listen to responses from the Tello. 55 Runs as a thread, sets self.response to whatever the Tello last returned. 56 """ 57 while True: 58 try: 59 self.response, ip = self.socket.recvfrom(1024) 60 print(f'from ip>: self.response>') 61 62 self.log[-1].add_response(self.response) 63 except Exception as exc: 64 print(f'Caught exception socket.error : exc>') 65 66 def on_close(self): 67 """ 68 On close. 69 :returns: None. 70 """ 71 pass 72 73 def get_log(self): 74 """ 75 Gets the logs. 76 :returns: Logs. 77 """ 78 return self.log 

    7.3. Commands

    The command.txt file stores the sequence of string commands that we will send to the drone. Note how we have to put a delay in between commands? This delay gives time for the drone and your program/computer to send, receive and process the data.

     1command 2takeoff 3delay 5 4flip f 5delay 2 6flip b 7delay 2 8flip b 9delay 2 10flip f 11delay 3 12land

    7.4. Application

    The app.py file is the application program entry point.

     1from tello import Tello 2import sys 3from datetime import datetime 4import time 5import argparse 6 7 8def parse_args(args): 9 """ 10 Parses arguments. 11 :param args: Arguments. 12 :return: Parsed arguments. 13 """ 14 parser = argparse.ArgumentParser('Tello Flight Commander', 15 epilog='One-Off Coder https://www.oneoffcoder.com') 16 17 parser.add_argument('-f', '--file', help='command file', required=True) 18 return parser.parse_args(args) 19 20 21def start(file_name): 22 """ 23 Starts sending commands to Tello. 24 :param file_name: File name where commands are located. 25 :return: None. 26 """ 27 start_time = str(datetime.now()) 28 29 with open(file_name, 'r') as f: 30 commands = f.readlines() 31 32 tello = Tello() 33 for command in commands: 34 if command != '' and command != '\n': 35 command = command.rstrip() 36 37 if command.find('delay') != -1: 38 sec = float(command.partition('delay')[2]) 39 print(f'delay sec>') 40 time.sleep(sec) 41 pass 42 else: 43 tello.send_command(command) 44 45 with open(f'log/start_time>.txt', 'w') as out: 46 log = tello.get_log() 47 48 for stat in log: 49 stat.print_stats() 50 s = stat.return_stats() 51 out.write(s) 52 53 54if __name__ == '__main__': 55 args = parse_args(sys.argv[1:]) 56 file_name = args.file 57 start(file_name) 

    7.5. Running the application

    To run the program, type in the following from a terminal. The program will output the logs to the directory log/ .

    python app.py -f command.txt

    Источник

Оцените статью