Lesson: Retrieving Drone Status Information

Overview: 
Explore the first Demo program.
Objectives: 

Understand more about the Tello-SDK by examining and running the first demo program to retrieve status data from the drone.

Content: 

We are about ready to work with the first example program. But first we need to cover some concepts that you will encounter in the example.

Logging

The Tello-SDK classes and example programs use Java's built-in logging feature. Using the Logging class allows the programmer to display status, informational, error and  debugging messages to the Eclipse Console window. When any of the programs run, the console window will open and any information logged by the program will appear in that window. The programmer can set a severity level on logged messages. You  can then control the level of detail logged by setting the desired level of detail to be output. In this way, you can control the level of logging detail globally and switch when more or less detail is needed. You can learn more about Java logging here.

Singleton Classes

Singleton is a programming design pattern (convention or scheme) that creates only one instance of a class and that instance is available globally to be used at any location in your program where you need access to the class. Singleton classes have a method getInstance() that can be called at any time and returns a reference to the single global instance of the class. The first call to getInstance() creates the global instance. Why do this? In this case, it is logical to decide that there really can be only one instance of the TelloDrone class, one instance of the TelloControl class and one instance of theTelloCamera class because the Tello-SDK only supports one drone at a time. Having more than one instance of any of these classes is not needed and would not work anyway The use of the Singleton pattern in the Tello-SDK enforces single instances and makes these instances available globally.

Command Mode

By default, when the drone is turned on, it is in it's autonomous flying mode as described in the Tello User Manual. In order to be controlled by commands sent over the network, the drone must be placed into command mode. In this mode, the drone performs only limited automatic functions (like hover) and waits for commands to tell it what to do. All programs that want to control the drone must issue the "enter command mode" command right after establishing connection to the drone.

Tello-SDK

The Tello-SDK is a library of classes that wrap drone communication, commands, error handling, status information and video stream processing into a higher level abstraction. As such, you will control the drone via methods on the SDK classes. The main class is TelloControl, which has methods mapping to the commands you can send to the Tello. When you call a method on the TelloControl class, like takeOff() for example, that method will assemble a command string (with any required parameters) and call a lower level method to send that command string to the drone and wait for the ok/error status reply from the drone. This model of calling methods that correspond to drone commands makes it much simpler to get started and to program at the level of telling the drone what you want it to do without having to worry about the details of how that is done.

Tello-SDK is also the name of the Eclipse project that contains the SDK library as discussed above and includes a set of example drone "programs" that demonstrate drone programming. Each example is a self-contained block of code (a class) that is a complete drone control program (meaning a set of instructions) that stands by itself. These programs are each implemented as a single Java class. You modify the Main class to select which example class you want to execute. When you click the green run button, Eclipse compiles the SDK library, the Main class and the example classes into a single program (called Tello) which is then launched and executes as a child program of Eclipse. When this happens, the Eclipse console window will open and you will see output from  the complete program. As you can see, the word "program" has several meanings: the total Java executable run by Eclipse, and the separate examples of drone programming from which you select.

Each lesson from here will have text like what you are reading now, discussing the provided example code. The code itself will have detailed comments describing what the code is doing. Between the two forms of documentation you should be able to learn how to write your own programs to fly drone missions.

Finally, drone programing can be done by sending movement control commands, like the EV3, or you can operate the drone using a game controller much like you control Tetrix or RoboRio robots. We will work through examples of both styles.

First Example

Our first example is called Retrieving Drone Status Information. The code is included in the Tello-SDK project. A simple start, it shows connecting to the drone, setting the drone into command mode and then using the TelloControl class methods to get status information from the drone. Commands that request status information are issued and those methods wait for the status information to be sent back from the drone to your program. The information is returned by the command method and also stored for later retrieval in the TelloDrone class. 

Take a look at the Demo1 class code in Eclipse. Click on Tello-SDK in the Pacage Explorer window. This will expand the project to show all of the project folders. Click src/main/java then click tello. This will display a list of the example classes in the project. Double click Main.java to open the top most program and your starting point. Then double click Demo1.java to view the first example.

When ready to try it, turn on your drone and wait a few moments for it's access point to come up. Check your Windows network connections list. You should see a network called TELLO-xxxxxx (or the name you assigned if you change the network name of the drone). Click on it to connect. When connection is established, you can click on the green run button in Eclipse to run the program. The console window should open and display logging info showing the program connecting, retrieving the status data, displaying it and finally shutting down. The Main class is setup to run the Demo1 program (class).

Note that the code issues the command to land the drone at the end. This will result in an error returned from the drone because it is not actually flying. This is done to show what an error looks like in the console log. Later examples will use the TelloDrone.isFlying() method to determine if a land command is necessary.

Notes: If you start your program too soon after connecting to the drone, you will  see an error in the console log that is a string of nonsense characters. Just run the program again.

If the drone returns an error on the takeoff() method or when commanding a flip maneuver, this indicates the battery is too low. Drone overheating can also cause this. If you see the message "error Not joystick" returned by any command, this also indicates low battery.

If the connect command fails and the the underlying error is "cannot bind to address of socket", this means a previous execution of your program is still running in the Eclipse background. You have lost control of it and cannot terminate it. You will have to restart Eclipse to clear this condition.

 

Navigation: