#1 [overview, commands] Control the Tello drone! Node.js | TypeScript | JavaScript

Do you like drones? Did you hear about Node.js? Tello? TypeScript? How about… put it all together? If you want to learn how to control a drone in an unconventional way, You are in the right place!

Tello, TypeScript, Node.js

This is the first part of a series about Tello drone programming. You will learn about the basic theoretical and practical things needed to control the drone via its commands. In future articles, we will discuss reading the drone state, presenting a drone video stream, and maybe... write the whole control application! So... stay tuned!

But at the beginning, I would like to thank PGS Software for organizing a great event — Angular Week — in which I had the pleasure to participate and win the described drone! Keep it up, guys. 👌 💪

#1 — Tello

Coming back to the point. The Tello drone because everything will happen with it. In this section, we will learn the basic information about the drone.

Overview

According to the User Manual: “Tello is a small quadcopter that features a Vision Positioning System and an onboard camera”.

The drone can be controlled in two ways: 1) using the official application 2) using your OWN script/application. And of course, we will choose option number two.

For more technical information, please refer to the official documentation— User Manual section.

Connection

The device interface provides a connection via WiFi while sending and commands receiving messages takes place via the UDP (User Datagram Protocol) protocol. The scenario is simple: we connect to the drone via WiFi, then send a command via the UDP protocol, and… we hope that everything will go well. 😆

Few words about UDP…

There is no need to discuss the UDP protocol in detail, for detailed information I recommend you look for information on the Internet (especially the difference between UDP and TCP). In this article, we only need to know that UDP is a protocol used for data transmission between the client and the server. UDP does not have a flow control and retransmission mechanisms — this means that we can’t be certain that the sent data will reach the destination (in our case, that the command will be correctly sent and received by the drone).

Connection summarizing:

  1. The drone provides the WiFi network to which we connect. Tello WiFi is usually named like TELLO-xyz where xyz is a unique string.
  2. We send the commands to the drone IP host and a specific port. All information is described in SDK (next chapter).
  3. And... observe the actual drone’s reactions!✈️

SDK

RyzeRobotics — producer of the described drone provides the SDK (Software development kit), which contains all the information you need, including a description of the software architecture, connection method, and the command interface. So… every needed information like drone port or commands we will get from the SDK.

IMPORTANT! Different software may be used on different version of the drone — as a result the commands may differ.

The version of the drone used in this article is Tello and the software is 04/01/92.01. The version of the installed software can be checked in the official application by going to: settings ➡️ more ➡️ button ➡️ ️️️Firmware Version.

UDP host and ports

For communication, we need an IP address and the port on which the drone listens for messages. According to the SDK, the shared IP address is http://192.168.10.1/, while the shared services depend on the port:

  • UDP port 8889 — sending and receiving messages 👈👈👈 (will be discussed in THIS article),
  • UDP server 0.0.0.0 port 8890 — receiving the drone status (will be discussed in the next articles),
  • UDP server 0.0.0.0 port 11111 — receiving video stream (will be discussed in the next articles).

Commands

The commands are divided into three types:

  • Control — used for controlling the drone. Returns ok if the command is executed successfully and error or an informative result code if unsuccessful.
  • Read — used for reading information about the drone. Returns the current value of the sub-parameter(s).
  • Set — used for setting a new sub-parameter value. Returns ok if the command is executed successfully and error or an informative result code if unsuccessful.

Example commands [command — type — description]:

  • commandcontrol entry SDK mode,
  • takeoffcontrol Tello auto takeoff,
  • landcontrol Tello auto land,
  • battery?readget current battery percentage,
  • height?read get current height [dm],
  • up xsetfly up by x [cm].

All available commands are described in the SDK in the Tello Command section.

Enough for theory, let’s move on to the practice! 😍👇

#2 — Implementation

Ok time to implement! This article covers communication with the drone. For this, we will create three classes: (1) UdpSocket — sending messages to actual UDP Socket (2) DroneIO — communication with the drone, (3) DroneConsole — getting commands from the user. Combining these three we will have transparent communication between objects and will be able to easily control the drone.

Requirements

Everything will be implemented in an object-oriented approach using TypeScript (used v4.2.4) — which is a JS superset — and Node.js (used v10.19.0) as a run environment. For communication, we will create a UDP datagram socket through which we will send commands and receive messages. To do it, we will use the dgram library (which is a default in node).

IMPORTANT! Make sure your system DOES NOT block UDP port you wish to access. If the port is blocked, you wont be able to communicate with the drone and you wont get any error!

UDP Socket

The first step is to make contact through the UPD. Let’s create a simple class called UdpSocket that will be responsible for it. In the case of UDP, the port is required, but the host is not (the default is 0.0.0.0). We pass these parameters to the constructor. The class also holds references to the socket object (_socket), which is initialized in the constructor and listens for the appropriate port.

To make the class more independent and transparent, we will create universal methods in it:

  • addSocketListener — the function takes the name of the event and the callback that reacts to it. Thanks to this, different things can listen to different events!
  • close — closing the socket connection,
  • send — sending a message to our socket instance. So, this is where we will send our drone commands. 💻

And that’s it for the UDP connection itself. When creating an instance of the object, we specify which port and host we should listen to. The attached methods allow to listen for events, close the connection and send a message to the server (socket).

The whole class looks like this:

Drone IO

Ok… socket connection is done. Time for the class that is responsible for controlling the drone — through the class created earlier. In the constructor, we create an object of the previously created class (UdpSocket), and add listeners for two events (error and message) with appropriate callback functions. We only need one method to complete the set — send — which is responsible for sending the command to the drone via the socket.

AND THAT’S IT! 😃

Command mode

IMPORTANT! The first step you need to take is to switch the drone mode to the command mode. To do this, send command as the first command. All available commands are described in Tello SDK.

For example:

Console — TelloCopter

At this moment, we have two most important pieces of the puzzle: 1) a class to communicate via the socket and 2) a class to send commands to the drone (control it). By combining these two, you can easily send a command to the drone from the console.

However, we will go a step further and create a console for sending commands. The user will be able to enter subsequent commands in the console. The code is simple — we retrieve commands from the user keyboard and send it to the drone (to this work is important that the command is correct). The command quit exits the program.

Run

You already have all the parts — now just create the DroneConsole object! Let’s create index.ts the file and do it there. To see the Tello Copter Console, just run the created file from your computer console. For more instructions see the Example of use section below.

Classes for UDP socket, drone IO and drone console

#3 — Example of use

Putting it all together, the steps you need to follow to control the drone using our console application:

  1. Turn on the Tello drone.
  2. Connect your laptop/pc/whatever-your-script-is to its WiFi. Tello WiFi is usually named like TELLO-xyz where xyz is unique string.
  3. From your console run index.ts file. (See Run script section below)
  4. Write valid drone commands on the console. (See example below)
  5. Observe the drone reactions! 😍

NOTE. “If Tello does not receive any command input for 15 seconds, it will land automatically”.

Run script

To automate the script execution a little I wrote a simple start script in package.json.

..."scripts": {
...
"start": "tsc --outDir dist index.ts && cd dist && node index.js"
},
...

It does two things: (1) transpile TypeScript code to JavaScript and places the resulting files in a dist folder, (2) go to the folder and runs transpiled script.

Now from your console, you can just run npm run start to see our app.

Example command sequence:

  1. command — set the drone to receive commands mode,
  2. battery?— check and display the drone’s battery level,
  3. takeoff—take off the drone ✈️,
  4. height?—check and display the current height,
  5. up 20—fly up by 20 cm,
  6. height?—check and display the current height again,
  7. down 20—fly down by 20 cm,
  8. height?—check and display the current height again,
  9. land—land (hope so 😅),
  10. quit — Enough flying for today!
Example command sequence

I strongly recommend trying others commands from the SDK, especially flip commands, it really works!

#4 — Conclusions

As you can see, connecting and controlling the drone with Node.js & TypeScript is quite simple! We learned the basic information about the Tello drone: how it works, how to connect to it and control it through commands. In the next article of this series we will read the status of the drone, so stay tuned! 😎

Thanks for reading and making it to the end! 💪💪

About the author

Passionate about programming and technology, especially related to Web Development. I’m currently working as a Web Software Engineer in Teleste Video Network.

Repository link

All of the presented code is available in my repository (link below). The code may be slightly different, but the idea stays the same.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store