Skip to content

mhered/tello-fun

Repository files navigation

Tello fun

Today I got a super present: the Tello drone. The Boost combo kit includes one drone, some spares, three batteries and a charger. The packaging is compact and effective, more functional than luxurious. The drone itself is beautifully finished, sporting a vision positioning system and onboard camera capable of 5 Mpixel shots and 720p live video streaming, as well as neat safety features such as propeller guards and a rubber landing gear. Flight time is about 13'.

I plugged the batteries to top them up. It took about 20' to see the solid green light, and I used this time to visit the official Tello website, watch some of the quickstart videos and download the documentation:

Why the Tello?

iOS app

I installed the iOS app in my iphone. User reviews were a mixed bag but it was nice to see that after 3 years it keeps receiving updates.

Press the button on the side to switch on, wait a few seconds for the LED to go flashing orange. The instructions are easy to follow: you need to connect your mobile to the Tello Wifi network and the first time activate (??) ...not sure what I was about to say...

First try the drone instead of hovering in place it slowly drifted until it bumped onto a book shelf...

I searched the pretty active community in https://tellopilots.com/ and http://protello.com/ and learned this is probably related to insufficient lighting.

Programming the Tello

That's where the real fun is. Official support is for Scratch but there are plenty of community-developed alternatives, e.g the iOS app TelloFpv, a ROS driver, or several unofficial python libraries such as TelloPy library, Tello-Python or DJITelloPy by damiafuentes, used in this video tutorial about drone programming by Murtaza.

Installations

First, it is good practice to create a virtual environment:

$ cd tello 
$ python3 -m venv myvenv
$ source myvenv/bin/activate

Note: within the virtual environment, you can use the command pip instead of pip3 and python instead of python3

Install the DJITelloPy library (pulls also numpy & opencv):

(myvenv)$ pip install djitellopy

check_battery.py - First connection

#!/usr/bin/env python

from djitellopy import tello
from time import sleep

drone = tello.Tello()
drone.connect()

# Explore library in:
# ./myvenv/lib/python3.8/site-packages/djitellopy/tello.py

print(drone.get_battery())

Switch on the Tello, connect the computer Wifi to Tello and run

Note if you get an error Exception: Did not receive a state packet from the Tello disable the ubuntu firewall:

$ sudo ufw status
$ sudo ufw disable

basic_moves.py - Moving around

#!/usr/bin/env python

from djitellopy import tello
from time import sleep

drone = tello.Tello()
drone.connect()

# Explore library in:
# ./myvenv/lib/python3.8/site-packages/djitellopy/tello.py

drone.takeoff()

# (L/R, fwd/bk, up/down, anti/clockwise yaw) each in -/+100%
drone.send_rc_control(0, 30, 0, 0)
sleep(2)

drone.send_rc_control(0, 0, 30, 0)
sleep(2)

drone.send_rc_control(0, 0, 0, 0)
sleep(1)

drone.send_rc_control(0, 0, -30, 0)
sleep(2)

drone.send_rc_control(0, -30, 0, 0)
sleep(2)

drone.send_rc_control(0, 0, 0, 0)
sleep(1)

drone.land()

camera.py - Streaming frames

key_controls.py - Controlling the drone with the computer keyboard

We will use the Pygame library:

(myvenv)$ pip install pygame

keypress_module.py - implements init() and is_key_pressed() functions using pygamelibrary

key_controls.py - includes statement import keypress_module.py as kp to use functions defined in the module.

Tested OK

Note: Why this code does not work well with ESC key for landing?

surveyor.py- stream FPV, control the drone to move around and take pictures

Combine camera.py, key_controls.py and icon_overlay.py

Add display of timestamp and battery level to streaming window

Add option to take a picture and store with unique name in ./assets/images/

Note: destination folder must exist beforehand otherwise the cv2.imwrite fails to save without giving any warning

Note: Why original version did not work? Had to make a few changes to key_controls.py

Note: Why this code does not work well with SPACE key for taking pictures?

Usage:

  1. Connect computer to the drone Wifi TELLO_EFD008,

  2. Launch $ python ./surveyor.py

  3. Wait for streaming window to show live image

  4. Click on pygame window so it gets focus and can listen to keystrokes

  5. Press RETURN to take off

  6. Press pto take a picture, store with unique name in ./assets/images/

  7. Press arrow keys to move the drone: LEFT RIGHT, forward (with UP) and backwards (with DOWN)

  8. Press w to climb and s to descend

  9. Press a to rotate counterclockwise and d to rotate clockwise

  10. Press q to land

  11. CTRL-c to stop the program

Includes process_frame()to resize and superimpose battery icon with status and a timestamp in the camera feed

face_track.py - drone detects and tracks face with altitude and yaw

Inspired loosely on project 3 of Murtaza's Drone Programming With Python video but implemented simple bang-bang control instead of PID, and chose to yaw and control height instead of distance to target to avoid having the drone moving around the room. Idea from selfie air stick project: repo and video and this thread.

Downloading haarcascade_frontalface_default.xml from opencv github: https://github.com/opencv/opencv/tree/master/data/haarcascades did not work.

Also I could not find opencv from command line:

(myvenv) mhered@mhered-laptop:~/tello$ which opencv
(myvenv) mhered@mhered-laptop:~/tello$ whereis opencv
opencv:
(myvenv) mhered@mhered-laptop:~/tello$ opencv --v
Command 'opencv' not found

However it was pulled by djitellopy, and is detected in python:

>>>import cv2
>>> print(cv2.__version__)
4.5.5
>>> print(cv2.data.haarcascades)
/home/mhered/tello/myvenv/lib/python3.8/site-packages/cv2/data/

icon_overlay.py - helper function to overlay icons on the live stream

Used in frame_process() to show the battery icon After trying unsuccessfully two approaches (this one yields jagged edges and this one multiplies intensities in the two images rather than covering the background with the overlay, I finally settled for this approach

Note: I failed to automate the conversion of svg images to png preserving the alpha channel. Either it is not proprly installed or not accessible from the virtual environment (myvenv) Check!!.

After some frustration I just repeated the conversion of svg icons to pngusing GIMP:

Open -> Set density to 90pix/cm, size to 100x100 pix.

Color-> Invert

File -> Export -> Select File Type (by Extension) -> PNG image -> Export -> Export

line_follower.py

Based on project 4 of Murtaza's Drone Programming With Python video

Rotation:

LH sensor Center sensor RH sensor Action
0 1 0 move fwd
1 1 0 slight turn left
1 0 0 strong turn left
0 1 1 slight turn right
0 0 1 strong turn right
0 0 0 stop
1 0 1 stop
1 1 1 stop

Translation: PID to keep line centered in the image

utils.py - auxiliary functions

  • countdown() - speak a countdown
  • process_frame() - show an overlay with a timestamps and battery status
  • reduce_frame() - resize. Obsolete, to be eliminated

TO DO

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published