A Simple Guide to Code using a Drone

John R. Ballesteros
3 min readOct 21, 2023

--

When learning how to code, I realized that one practical and sucessful way to do it is by using drones. This is also confirmed after years of training students in how to code. Why? perhaps, because we can physically see and confirm the result of our code, right immediately after writting commands. This relationship between a programing language functions and the real physical actions is probably the key to the way brain stores knowledge.

To do a practical example of learning code by playing, a Tello Drone is going to be used, a full description of this drone can be found in this link:

The Tello drone can be programmed using two different languages, Swift and Python, but also, using simple, block-based visual programming like Scratch. The most important aspect in a safe manner.

Coding in Python with a Drone

A simple example of coding with the Tello drone consists of the following steps:

Install Python in your computer, create an environment and install jupyter notebook and the main library to base the code on, the “djitellopy”. See the detailed instructions in one of my previous stories linked here:

Import the library, instantiate it, and connect the drone to the computer.

# import the main library
from djitellopy import Tello

# instantiate the library, this enters SDK mode.
# call this before any of the control functions.
tello = Tello()

# connecting the drone
# your PC's wifi should be activated and connected to the Tello
tello.connect()

After this, the drone can receive the “takeoff” command to make it fly, the drone will start flying after 1 to 3 seconds.

# make it fly
tello.takeoff()

The drone can perform a mission, a set of actions like: rotate, fly higher, make a curve, move in any direction and many others. Fortunately, all the methods are called quite the same. See an example:

# rotate the drone 90 degrees in reverse clockwise direction
tello.rotate_counter_clockwise(90)

# move the drone left 200 cm, there is the possibility to use imperial units as well
tello.move_left(200)

After some actions, the drone can be land by this command:

# landing the drone
tello.land()

Landing the drone does not finish the mission, make sure to disconnect the drone, be aware that failing to do that avoids to perform a new mission.

# disconnect the drone
tello.end()

You can make a lot more, like taking a picture or video, or display variables of the drone in flight parameters. Read all the library documentation here:

Conclusion

Runing one command at a time and watching the actions performed by the drone gives an understanding of what a function is in Python, changing values in functions indicates what a parameter of a function is.

This experimentation will give insights about programming, especially for novice programmers.

Support me

Enjoying my work? Show your support with Buy me a coffee, a simple way for you to encourage me and others to write. If you feel like it, just click the next link and I will enjoy a cup of coffee!

--

--

John R. Ballesteros

Ph.D Informatics, Assoc. Professor of the UN, Med. Colombia. GenAi, Consultant & Researcher AI & GIS, Serial Interpreneur Navione Drone Services Co, Gisco Maps