We are starting a new page for Drone programming by Python, Ryze Tello is a very good price drone. With their SDK, which makes it very easy to program by different platforms such as Scratch and Python. We picked this to start our journey of Drone Programming, and hope that we can achieve Face recognition and Gesture-based control as our ultimate target. Then, Swarm with Tello Edu – multiple drone control and performance.
SDK & DJITELLOPY API
Ryze Tello already provide SDK to connect the drone via a WIFI UDP port, allows users to control the drone with text command. You can refer to this link for their SDK 2.0 document and below is the example how’s the SDK working.
# Before you run this program, ensure to connect Tello with the WIFIimport socketimport time# Tello IP and portTello_IP ='192.168.10.1'Tello_PORT =8889# Create a UDP socketsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)sock.bind(('', Tello_PORT))# Function to send commands to the dronedefsend_command(command): sock.sendto(command.encode(), (Tello_IP, Tello_PORT))defreceive_response(): response, _ = sock.recvfrom(256)return response.decode()# Connect to the Tello drone via WIFIsend_command('command')receive_response()# Take off the dronesend_command('takeoff')receive_response()# Do combo action such as move up & down and rotatingsend_command('up 30')receive_response()send_command('down 30')receive_response()send_command('up 30')receive_response()send_command('down 30')receive_response()send_command('cw 30')receive_response()send_command('ccw 60')receive_response()send_command('cw 30')receive_response()# Landing the dronesend_command('land')receive_response()# Show the battery level before ending the programsend_command('battery?')print("Battery :", receive_response())# Stop the connection with the dronesend_command('End')
To make life easier and the program easy to read, there are few third parties created library to support the SDK, such as EASYTELLO, TELLOPY, and DJITELLOPY. We picked DJITELLOPY from Murtaza’s Workshop – Robotics and AI (Thank you!) for our project.
First of all, go ahead to install DJITELLOPY into your Python by using command ‘PIP install djitellopy‘ in your terminal. The latest version I can download right now is 2.50 including the following libraries, DJITELLOPY, NUMPY, OPENCV-PYTHON, AV and PILLOW.
‘Hello World’ from Tello
OK, let start our first drone programming try with the code below.
# Before you run this program, ensure to connect Tello with the WIFI# Import Tello class from djitellopy libraryfrom djitellopy import Tello# Assign tello to the Tello classtello = Tello()# Connect to the Tello drone via WIFItello.connect()# Take off the dronetello.takeoff()# Do combo action such as move up & down, rotating and flippingtello.move_up(30)tello.move_down(30)tello.move_up(30)tello.move_down(30)tello.rotate_counter_clockwise(30)tello.rotate_clockwise(60)tello.rotate_counter_clockwise(30)# Landing the dronetello.land()# Show the battery level before ending the programprint("Battery :", tello.get_battery())# Stop the connection with the dronetello.end()
It is pretty simple, right? Just import the DJITELLOPY API and you can use those command control the drone Tello. The first thing you must do is to ‘tello.connect()’ to the Tello, so that it is asked to be in SDK mode and accept different commands. Then, I just have the drone takeoff and do some combo as shown in the code. Finally, I get the battery information and display before complete the process.
Next step, we will learn how to capture video from the drone.