Clay Hinskie
Keshia Poedjiono
UPH
2023
Tangerang
ABSTRACT
ABSTRAK
Drone atau yang disebut juga sebagai unmanned aerial vehicle (UAV) adalah pesawat
yang tidak memiliki penerbang manusia di dalamnya, oleh karena itu drone dinamai 'tak
berawak'. Drone dikendalikan melalui pengendali berbasis darat yang dibangun melalui
program komputerisasi. Dalam hal ini, program dapat dibentuk dengan berbagai metode.
Sesuai dengan modul ini, metode yang digunakan untuk mengendalikan drone yang dibangun
oleh program rakitan mencakup peran Python sebagai cara untuk mengartikulasikan visi
pengguna terhadap drone. Python sebagai bahasa pemrograman, adalah metode yang
sederhana namun efisien yang dapat mendukung tujuan penerapan modul. Modul ini disusun
oleh instruksi yang jelas dan tutorial yang dipandu untuk mengantarkan pembaca/pengguna
menuju tujuan yang sama. Terlepas dari hal tersebut, modul yang dirancang telah melalui uji
coba untuk memastikan pengguna dapat menerima hasil terbaik dalam mencapai tujuan yang
sesuai dari pemrograman drone.
ABSTRACT / ABSTRAK
CHAPTER I
INSTALLATION
1.1 Python
1.1.1 Definition of Python
1.1.2 How to Install Python
1.2 Github
1.2.1 Definition of Github
1.2.2 How to Create Github Account
1.3 Copilot
1.3.1 Definition of Copilot
1.3.2 How to get Copilot for Student
1.4 Visual Studio Code (VSC)
1.4.1 How to Download Visual Studio Code
1.5 Connect Python to Visual Studio Code
1.5.1 Download Python Extension
1.5.2 Test Python in Visual Studio Code
1.6 How to Install PIP for DJI Tello
1.6.1 How to install DJI Tello using pip
1.7 Connect Github Copilot into Visual Studio Code
CHAPTER II
SIMPLE COMMAND
2.1 Library and Object
2.2 Connect
2.3 Take-off & Landing
2.4 Simple Movements
2.5 Rotation
2.6 Battery Monitoring
2.7 DJI Tello User Guide and All Commands
CHAPTER III
FLYING PATH
3.10 Control the Drone using Keyboard and Take Picture using Camera
3.12 Tips for Making a Flying Path and Play with the Drone
CHAPTER IV
SENSORS
4.1 Camera
CHAPTER V
ARTIFICIAL INTELLIGENCE
CHAPTER VI
MACHINE LEARNING
CHAPTER VII
SIMULATION PROJECT
7.2.1 DJI Tello Drone’s Program for Search and Rescue Simulation Project
BIBLIOGRAPHY
ATTACHMENT
CHAPTER I
INSTALLATION
1.1 Python
2. Click the “download” section and choose the Operating System (OS) for
Windows or macOS
3. Select and Download Python Executable Installer
For Windows, you can click the name of the Python version. We highly
recommend downloading the latest version. Click “Python 3.10.11 - April 5,
2023”
For macOS, you can also download the latest version of Python. Click,
“Latest Python 3 Release - Python 3.11.3”
4. Run Executable Installer
After you have downloaded the installer then just run the installer. Make sure
to select both the checkboxes at the bottom and then click “Install Now”
On clicking the “Install Now”, the installation process will start. The
installation process will take a few minutes to complete.
3. The version of the python which you have installed will be displayed if
the python is successfully installed on your windows.
1.2 Github
1.3 Copilot
4. Click on add an email address and click on the blue highlighted text to add
your personal school email. (Skip if you don’t have school email)
5. Go back to the page before and refresh. Click your school email and fill in the
name of your school, and how you plan to use Github.
6. If your school isn’t registered, select your school below the map and fill in
details of your school. (Skip if you can find your school on the “What is the
name of your school” answer tab).
7. Take a picture of your student ID using your phone and select Student ID on
the proof type. You can also upload an image of your Student ID (Not
Recommended). You can also use other types of proof according to the options
given below.
8. You might be able to get access to the student package or get a 1-3 days notice
after submitting the proof.
9. After you have successfully gained the student developer package, go back to
https://github.com/
10. Click on your profile on the top right corner of the screen and click settings.
3. As the Download finishes, VSC Setup will appear in the downloads folder.
5. As the Installer opens, Visual Studio Code will ask you to accept the terms and
conditions of the software. Select ‘I Accept the agreement’ and continue by selecting
the Next button.
6. Choose the location data to run Visual Studio Code. The program will ask you to
browse for a file location, then select the Next button.
7. VSC will then ask to begin the Installation process, select the Install button.
8. After the installation has finished, you can select the Finish button and run the
software to start writing your very own program.
3. Search “Python” in the search bar, like the image given below. Download the Python
extension by Microsoft by clicking install in that extension.
1.5.2 Test Python in Visual Studio Code
1. Create a new folder anywhere in your computer or laptop and name it “Python”, you
can freely give a name to the folder.
2. Open Visual Studio Code and then use this shortcut Ctrl + K + Ctrl + O to open New
Folder
3. Search the folder that you have created and it will look like this:
4. Then click the folder and create a new file, you can give any name to the file but, you
MUST put “.py” at the end of the file name. Ex: “Tutorial.py”
5. You can test if Python is already connected to the Visual Studio Code or not, by
giving a very simple command, “Print(“hello world!”)”
6. Then run the code by clicking this button or use a shortcut, “Ctrl + Alt + N”
7. Python has connected to the Visual Studio Code if it outputs, “hello world!”, like the
image given below
1.6 PIP DJI Tello
DJI Tello is a mini-drone which will be developed and programmed through python in
accordance with this module. The drone will be programmed by installing the library into
Python. The following is a guide to integrate the drone into python using pip.
5. If you have not previously authorised Visual Studio Code in your GitHub account,
you will be prompted to sign in to GitHub in Visual Studio Code.
6. In your browser, GitHub will request the necessary permissions for GitHub Copilot.
To approve these permissions, click Authorise Visual Studio Code.
7. To confirm the authentication, in Visual Studio Code, in the "Visual Studio Code"
dialog box, click Open.
8. After the Github Copilot connects to the Visual Studio Code, you can use the
extension in the VSC.
CHAPTER II
SIMPLE COMMANDS
After we import the library to our code, we should define an object that we will use in
the coding. An object is simply a collection of data or variables and methods or functions. In
our coding, we can define an object as simple as we declare a variable, but this is an object.
We can give any name to our object and this is the code to define an object:
Variable names can be anything you want to define your Tello drone in a set of commands.
2.2 Connect
Before the drone is available to be programmed, the device must first be connected
with the drone using simple codes available from the python library. The Tello drone could be
connected with the user’s device through a connection enabled with WiFi.
To connect the drone with the user’s device, the user must first connect the device
with the drone in accordance with the drone’s network name through WiFi. After turning on
the drone, connect the drone with the user’s device. After the device has been connected with
the drone, there are a few simple commands to continue on the program to be able to access
the drone.
You can use the commands consecutively to make a simple flight path. Here is a
simple example of the commands:
2.5 Rotation
The Tello drone can do left, right, or full rotation simply by using single commands.
This enables the drone to make movements in any direction. We can also adjust the rotation
degree.
To rotate left, use the command:
tello.rotate_counter_clockwise(90) # this command will rotate the drone 90 degree in a
counter clockwise direction
Battery Status: print(tello.get_battery()) # display the information of the battery status in the
output section.
You can access the user guide by clicking or copying this link:
https://dl-cdn.ryzerobotics.com/downloads/Tello/Tello%20SDK%202.0%20User%20Guide.p
df
CHAPTER III
FLYING PATH
# Take off
tello.takeoff()
# Fly
tello.move_forward(50) # Moves 50cm Forward
tello.rotate_clockwise(90) # Rotates 90° Clockwise
tello.move_forward(50) # Movies 50cm Forward
tello.rotate_clockwise(90) # Rotates 90° Clockwise
# Land Tello
tello.land()
tello.takeoff()
tello.land()
You can also make use of the for command to make loops so that your code can be more
efficient, like this:
tello.takeoff()
for i in range(2):
tello.land()
To make a square flying path, you can use the following code:
tello = Tello()
tello.connect()
tello.takeoff()
tello.move_forward(30) # Move forward 30 cm
tello.rotate_clockwise(90) # Rotate 90 degrees clockwise
tello.move_forward(30) # Move forward 30 cm
tello.rotate_clockwise(90) # Rotate 90 degrees clockwise
tello.move_forward(30) # Move forward 30 cm
tello.rotate_clockwise(90) # Rotate 90 degrees clockwise
tello.move_forward(30) # Move forward 30 cm
tello.rotate_clockwise(90) # Rotate 90 degrees clockwise
tello.land()
You can also make use of the for command to make loops so that your code can be more
efficient, as shown below:
tello = Tello()
tello.connect()
tello.takeoff()
for i in range(4):
tello.move_forward(30) # Move forward 30 cm
tello.rotate_clockwise(90) # Rotate 90 degrees clockwise
tello.land()
tello.takeoff()
tello.rotate_clockwise(45)
tello.move_forward(50)
tello.rotate_clockwise(90)
tello.move_forward(50)
tello.rotate_clockwise(135)
tello.move_forward(71)
tello.rotate_clockwise(90)
tello.land()
tello = Tello()
tello.connect()
tello.takeoff()
tello.rotate_clockwise(45)
tello.move_forward(50)
tello.rotate_counter_clockwise(90)
tello.move_forward(50)
tello.rotate_clockwise(90)
tello.move_forward(50)
tello.rotate_counter_clockwise(90)
tello.move_forward(50)
tello.land()
tello = Tello()
tello.connect()
tello.takeoff()
tello.move_up(20)
tello.send_rc_control(0,0,0,0)
time.sleep(0.1)
# Turns motors on:
tello.send_rc_control(-100,-100,-100,100)
time.sleep(2)
tello.send_rc_control(0,10,20,0)
time.sleep(3)
tello.send_rc_control(0,0,0,0)
time.sleep(2)
v_up = 0
for i in range(4):
tello.send_rc_control(40, -5, v_up, -35)
time.sleep(4)
tello.send_rc_control(0,0,0,0)
time.sleep(0.5)
tello.land()
tello.land()
tello = Tello()
tello.connect()
tello.takeoff()
tello.move_up(heightUp)
tello.land()
tello = Tello()
tello.connect()
tello.takeoff()
for i in range(3):
tello.move_forward(100)
tello.land()
tello.takeoff()
tello.move_up(70)
tello.land()
tello.end()
tello.takeoff()
tello.land()
tello.end()
3.10 Control the Drone using Keyboard and Take Pictures using Camera
The DJI Tello Drone holds the ability to be controlled with the user’s device
(preferably laptop/computer) through the keyboard as programmed in Python. Controlling the
mini-drone using the keyboard enables the user to control the drone in accordance with how
the user has intended for. With this being said, the drone can be controlled according to the
various commands that Python offers. Which in this case, range from moving forward &
backwards, moving left & right, and also moving up & down. Besides that, in this section, we
also use the camera sensor within the Tello, we can see a picture using the camera while the
drone is under our control, and we also can take a picture when the camera position is stable
according to the drone’s position by pressing ‘p’ key. The picture will automatically be saved
to the same folder with your code’s folder.
Below is an example of a program constructed to control the Tello drone with the
keyboard and take pictures using the camera. Although the example is programmed in a
certain way by the input of selected keys, the user can rescript the program according to what
fits the user’s liking.
tello = Tello()
tello.connect()
tello.streamon()
frame_read = tello.get_frame_read()
tello.takeoff()
while True:
img = frame_read.frame
cv2.imshow("drone", img)
tello.end()
tello.land()
# import libraries
tello = Tello()
tello.connect()
# camera setup
keepRecording = True
tello.streamon()
frame_read = tello.get_frame_read()
def videoRecorder():
video.release()
recorder = Thread(target=videoRecorder)
recorder.start()
# normal commands
tello.takeoff()
# these are the movement, you can change it whatever you want
tello.move_up(100)
tello.rotate_counter_clockwise(360)
# ends
tello.land()
keepRecording = False
recorder.join()
3.12 Tips for Making a Flying Path and Play with the Drone
To make a flying path, we need a creative mind to make it an amazing path. You can
also search for inspiration or find a resource on what flying path to make. Just think
creatively and outside the box that the flying path you make is different from the common
path. After you have an idea what flying path to make, you need to think and code it how the
drone will follow and fly according to that flying path. You can also find resources from
anywhere to help you get the logic to code a flying path that you have imagined. Just make
your freestyle move and any flying path that you want and imagine and code it, because there
is no wrong or true in making a flying path, just make it amazing.
CHAPTER IV
SENSORS
4.1 Camera
4.1.1 Definition of Camera
From the Merriam Webster Dictionary, camera is a device that consists of a
lightproof chamber with an aperture fitted with a lens and a shutter through which the
image of an object is projected onto a surface for recording (as on a photosensitive
film or an electronic sensor) or for translation into electrical impulses (as for
television broadcast). A camera is an optical instrument to capture still images or to
record moving images, which are stored in a physical medium such as in a digital
system or on photographic film. A camera consists of a lens which focuses light from
the scene, and a camera body which holds the image capture mechanism. Apart from
that, in this drone, DJI Tello also has a camera that can be used like any camera, but
the camera resolution is just 720p (720 pixel). However, this camera sensor has a
great impact and function for DJI Tello, which is we can use this camera sensor to
detect something, take photos, take video, use the camera to avoid obstacles in front
of the drone, and others.
import cv2
‘’’
this is a MUST library to use the camera.
you can learn more from this article:
https://www.topcoder.com/thrive/articles/what-is-the-opencv-libra
ry-and-why-do-we-need-to-know-about-it#:~:text=Capturing%20video%
20using%20OpenCV,really%20useful%20for%20video%20analysis.
‘’’
tello.streamon()
frame_read = tello.get_frame_read()
# this command to make a variable to get the frame that will show
the picture capture by Tello’s camera
while True:
img = frame_read.frame
cv2.imshow("drone", img)
while True:
img = frame_read.frame
cv2.imwrite("drone", img)
You can try this simple example of controlling the camera sensor to show an image to
our screen and press the “p” key to take a screenshot of the image captured by Tello’s
drone.
tello = Tello()
tello.connect()
tello.streamon()
frame_read = tello.get_frame_read()
#tello.takeoff()
#you can take off the drone or not
while True:
img = frame_read.frame
cv2.imshow("drone", img)
tello.end()
#tello.land()
#if you take off the drone, make sure to land it also
For another example, you can go back to the 3.8 section which is Chapter Flying Path
about “Controlling the Drone using Keyboard and Take Pictures using Camera.”
height = tello.get_distance_tof()
tello.takeoff()
height = tello.get_distance_tof()
print(height)
print(height)
tello.land()
tello.end()
4.3 Proximity Sensor
4.3.1 Definition of Proximity Sensor
Proximity sensor is a device that can detect the approach or presence of nearby
objects without physical contact. It has many applications, such as measurement,
gauging the thickness of metal, detecting surface irregularities, and angular speed
measurement. Proximity sensors use different technologies such as ultrasonic,
LiDAR, or infrared to detect obstacles and provide information. For drones,
specifically, a proximity sensor system used to scan the area near the drone and send
that information to the drone so it can avoid unexpected contacts and collision risks.
With the help of proximity sensors, drones will navigate safely in complex
environments such as indoors and outdoors.
height = tello.get_distance_tof()
tello.takeoff()
# variables
height = 0
newHeight = 0
sameHeight = True
while sameHeight:
height = tello.get_distance_tof()
tello.move_forward(100)
time.sleep(2)
newHeight = tello.get_distance_tof()
if newHeight == height:
tello.move_forward(100)
else:
tello.move_up(50)
sameHeight = False
break
tello.land()
tello.end()
CHAPTER V
ARTIFICIAL INTELLIGENCE
Machine Learning is a very interesting field we can learn and in the next chapter we
will provide many things that can be learned about Machine Learning. We will tell you about
Haar Cascade, make or search dataset using Roboflow and Kaggle, and introduction to
Google Colaboratory, Jupyter Notebook, and YOLOv5. We will also make an object
detection project that we can apply in real life about Machine Learning.
CHAPTER VI
MACHINE LEARNING
5. To input the Haar Cascade file into your program use the following code to
call the Haar Cascade classifier.
faceCascade = cv2.CascadeClassifier('folder
name/haarcascade_frontalface_default.xml')
For further comprehension and involvement in programs see the examples below.
tello = Tello()
tello.connect()
print(tello.get_battery())
tello.streamon()
frame_read = tello.get_frame_read()
tello.takeoff()
def findFace(img):
faceCascade = cv2.CascadeClassifier('folder
name/haarcascade_frontalface_default.xml')
imGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(imGray, 1.1, 4)
myFaceListC = []
myFaceListArea = []
while True:
img = frame_read.frame
cv2.imshow("drone", img)
img = tello.get_frame_read().frame
img, info = findFace(img)
cv2.imshow("Face Tracking", img)
tello.land()
Control Face Detection and Movement with Keyboard Output:
#PARAMETERS
width = 200
height = 100
startCounter = 1
tello = Tello()
tello.connect()
print(tello.get_battery())
tello.streamoff()
tello.streamon()
def findFace(img):
faceCascade = cv2.CascadeClassifier('folder
name/haarcascade_frontalface_default.xml')
imGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(imGray, 1.1, 4)
myFaceListC = []
myFaceListArea = []
while True:
frame_read = tello.get_frame_read()
myFrame = frame_read.frame
img = cv2.resize(myFrame, (width, height))
if startCounter == 0:
tello.takeoff()
tello.move_forward(20)
startCounter = 1
img = tello.get_frame_read().frame
img, info = findFace(img)
cv2.imshow("Face Tracking", img)
if cv2.waitKey(1) == ord('q'):
tello.land()
break
import cv2
import numpy as np
from djitellopy import tello
import time
tello = tello.Tello()
tello.connect()
tello.takeoff()
tello.streamon()
tello.send_rc_control(0, 0, 25, 0)
time.sleep(0.5)
w, h = 800, 600
fbRange = [6200, 6800]
pid = [0.4, 0.4, 0]
pError = 0
def findFace(img):
faceCascade = cv2.CascadeClassifier('folder
name/haarcascade_frontalface_default.xml')
imGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(imGray, 1.1, 4)
myFaceListC = []
myFaceListArea = []
error = x - w // 2
speed = pid[0] * error + pid[1] * (error - pError)
speed = int(np.clip(speed, -100, 100))
if x == 0:
speed = 0
error = 0
print(speed, fb)
while True:
img = tello.get_frame_read().frame
img = cv2.resize(img, (w, h))
img, info = findFace(img)
pError = trackFace(info, w, pid, pError)
cv2.imshow("Face Tracking", img)
if cv2.waitKey(1) == ord('q'):
tello.land()
break
6.3 Roboflow
Roboflow empowers developers to build their own computer vision applications, no
matter their skillset or experience. They provide all of the tools needed to convert raw images
into a custom trained computer vision model and deploy it for use in applications. This is the
overview of roboflow from the official website, https://roboflow.com/
2. Sign up or register if you don’t have an account, then sign in to the roboflow.
3. For the first time, you can watch the video tutorial provided by Roboflow on
the website in the Quick Tips section or Resources section.
4. Then, you must create a workspace and name it whatever you want.
7. You can make your own custom dataset using your own images or videos.
However, you can also search for images that you want to detect and upload it
on the upload section.
8. After you’ve done upload all the images you want to use as data training for
the Machine Learning, then assign all the images on the assign section.
9. After that, go to the annotation section and go annotate all of the things in the
images that you want to detect. Just use the Bounding box tool or just press ‘b’
on the keyboard to use that tool. Then, annotate the thing that you want to
detect, like this (if you want to train the machine learning to detect a mask):
10. After you have done annotating all of the images you want to use, then add the
images to the dataset. (By default the system will divide the images to 3
categories, which is test, train, and valid. We just use the default method of
that dividing).
11. Then you will find this on the annotating section and click the “Generate New
Version”
12. After you click “Generate New Version”, you will be on this page and you can
make a detail before
13. If you already make a detail whatever you want to the data training, just click
generate and wait for the machine learning to learn the dataset we gave.
14. After the loading is done, then you will find this page and just export the
dataset and choose the format as “YOLO v5 PyTorch”, then download zip to
the computer.
15. After the download is completed, congratulations you have made a custom
dataset by yourself. After that, you can use that dataset on the YOLOv5 using
Google Colab Environment in the next section (5.6.3 Google Colab
Environment).
You will find this page and you can explore the website to find the dataset that is
suitable for you and you love the best. After you have found the best dataset, just
download it and learn how to use that on the YOLOv5 Google Colab Environment
Section (5.6.3).
Remember:
Roboflow is just one platform to make and find a dataset, however, in the next
section, we will provide another platform where you can find more dataset, which is
on https://www.kaggle.com/
6.4 Kaggle
From the official website of Kaggle, this is the overview of what Kaggle is. Kaggle is
a platform that allows users to find datasets they want to use in building AI and Machine
Learning models, publish datasets, work with other data scientists and machine learning
engineers, and enter competitions to solve data science challenges. Therefore, this is the right
place for us to find a dataset, because there are many types of dataset we can get and use on
Kaggle.
This is the guide on what we can find, search, and use on Kaggle:
4. On the main page, go to the “Datasets” section. There, you can search any
datasets that have been provided by others in the search bar.
5. For the example, we use this datasets, from:
https://www.kaggle.com/datasets/aditya276/face-mask-dataset-yolo-format
6. Remember to download a dataset with YOLO Format and then just click the
download button to download the dataset.
7. After the download is completed, the file will be in your folder and you can go
to the next section, how to use that dataset on Google Colab.
6.5 YOLOv5
6.5.1 What is YOLOv5?
YOLOv5 is the world's most loved vision AI, representing Ultralytics
open-source research into future vision AI methods, incorporating lessons learned and
best practices evolved over thousands of hours of research and development. Besides
that, YOLOv5 is a family of compound-scaled object detection models trained on the
COCO dataset, and includes simple functionality for Test Time Augmentation (TTA),
model ensembling, hyperparameter evolution, and export to ONNX, CoreML and
TFLite. To make it easier to understand, we can call YOLOv5 as a library and helper
we can use to train our dataset, so the machine can understand what we want to detect
by using machine learning.
2. There, you can find a quick start and guide about YoloV5, you can read it carefully, so
that you know well about what YOLOV5 is YOLOv5.
3. First thing you should download ZIP of the Github and store in your own folder
4. After that, you should install all packages that you need to use YOLOv5 according to
the documentation below:
6. After you have already set up all of the requirements that needed to use YOLOv5, you
are ready to go and you can go to the next section, which is use the YOLOV5 on the
Google Colab Environment.
7. This is another guide to know more about YOLOv5 and also a simple manual on how
to use YOLOv5 in another way:
PyTorch: https://pytorch.org/hub/ultralytics_yolov5/
Ultralytics: https://ultralytics.com/yolov5
Thing to remember, this is just one way of many other ways that can be used for
training and using Machine Learning. You can also explore YOLOv5 by yourself or
other platforms and libraries for well learned about machine learning and AI.
As we mentioned before about Google Colab, so right now we will be using Google
Colaboratory as an environment for YOLOv5. This is the step by step you can follow
to use Google Colab:
2. After you go to the Google Colab for YOLOv5, you will be on this page
3. After that, you should connect first to the Google Colab by pressing connect at
the top of the page
4. Then, we can set up the notebook by going to the “Edit” menu, then go to the
“Notebook settings”, and after that select the hardware accelerator as “GPU”,
then just click save.
5. After that, you can go to the setup section on the Google Colab (YOLOv5)
and run the code to clone the GitHub Repository.
(Important: you must already download all packages needed for YOLOv5
from the YOLOv5 section).
Then, you can run the setup code and clone the GitHub.
6. After it’s completed, you can go to the files menu at the left section and the
YOLO master file will appear on our Google Colab Environment like this:
8. After the upload completed, we will find our folder in the Google Colab like
this:
9. Then, you can scroll down in the Google Colab Environment to the “Train”
section, right here:
10. On there, we can extract our dataset ZIP folder, by using this command:
11. After we extract all the files, we can refresh the files section and we can find
our ZIP folder has been extracted.
12. Then, we still in the “Train” section and we can change the available code like
the image below:
We change the number of epochs to 100 and change the file name of
“coco128.yaml” to “/content/data.yaml” which is the path of our
“data.yaml” file. You can copy the path of the “data.yaml” file in the files
section, if you have already extracted the ZIP, it should be there.
Notes:
An epoch is when all the training data is used at once and is defined as the
total number of iterations of all the training data in one cycle for training the
machine learning model.
13. After your code is like the image above, you can run that code
After that, just wait until the code finishes running (it will take a few minutes
or long enough).
14. After the code is finished running, then we can go to our files section
Then open the “yolov5” folder like the image below:
../yolov5/runs/train/exp/weights/best.pt (download the “best.pt” file)
Another meaning:
Open yolov5 → open runs folder → open train folder → open exp folder →
open weights folder → download the “best.pt” file
15. “best.pt” is our machine learning model file that has been learned from our
dataset and we will use that file to make a program that detects something we
already put to the machine to learn, which is to detect people wearing a mask.
1. Open Visual Studio Code and go to the extensions panel on the left bar. Search
“Jupyter”
2. Click the “install” button to install the extension.
3. Now we are ready to launch the Jupyter Notebook. Go to the command palette by
pressing Ctrl + Shift + P on a windows or Cmd + Shift + P on a mac. After that type
“jupyter notebook”. Choose “Create: New Jupyter Notebook”.
However, you also can just make a new file on VSCode, but give the file name
extension as “.ipynb” This extension file will automatically create a Jupyter Notebook
file, like this:
4. Select kernel on the top right. Make sure you set it to python
5. Everything is already set up. If you want to add a new code box, simply click on the
“+ Code” button on the left. Besides that, by using Jupyter Notebook, you also can
add a text box, by clicking on the “+ Markdown.”
6. One of the special features of the Jupyter Notebook is you can execute your code box
by box. To execute a specific box, click the run button on the left side of the box. You
can also run all programs at once by pressing the “Run All” button.
1. Open your Visual Studio Code and make a new file, you can name it anything,
however use a Jupyter Notebook extension as what you have learned before like this:
2. Remember that the Jupyter Notebook file extension is “.ipynb” and you also should
put the “best.pt” file in the same folder as our Jupyter Notebook file.
3. As we know, we can divide our code in our Notebook, so we are making 2 parts of
code, the first part, we can run by using WIFI and the second part, we run it by
connecting to the DJI Tello drone first.
# import libraries
import cv2
import torch
import numpy as np
from djitellopy import Tello
import time
Not just libraries, we also call the YOLOv5 and our best.pt model, so that we can use
it as our model to learn and detect people wearing a mask.
# external packages
Remember: the “path” variable is according to where you store your best.pt file in
your own folder, so don’t copy it, but change it
Notes:
We run the import libraries first, then the external “packages” we should use which is
the YOLOv5 and our best.pt file
def mask_detect(frame):
mask_count = 0
results = model(frame)
frame = np.squeeze(results.render())
labels, cord = results.xyxyn[0][:, -1], results.xyxyn[0][:,
:-1]
n = len(labels)
x_shape, y_shape = frame.shape[1], frame.shape[0]
for i in range(n):
row = cord[i]
if row[4] >= 0.30:
x1, y1, x2, y2 = int(row[0] * x_shape), int(row[1] *
y_shape), int(row[2] * x_shape), int(row[3] * y_shape)
mask_count += 1
This is the first part of the second part of the code, which is making the method to
detect a mask. You can just copy it to your Jupyter Notebook in VSCode.
tello = Tello()
tello.connect()
print(tello.get_battery())
tello.streamon()
# shows frame
while True:
frame = tello.get_frame_read().frame
This is the second part of the second part of the code, which is the DJI Tello code and
shows the frame on our screen
So, this is the second part of the code, which is we must connect to the DJI Tello
Drone first:
You can copy the codes above or just write this by your own
6. Finally, this is the complete code, however you should run it part by part, the first
part run it by using WIFI and second part run it by connecting to the DJI Tello Drone:
# import libraries
import cv2
import torch
import numpy as np
from djitellopy import Tello
import time
# external packages
def mask_detect(frame):
mask_count = 0
results = model(frame)
frame = np.squeeze(results.render())
labels, cord = results.xyxyn[0][:, -1], results.xyxyn[0][:,
:-1]
n = len(labels)
x_shape, y_shape = frame.shape[1], frame.shape[0]
for i in range(n):
row = cord[i]
if row[4] >= 0.30:
x1, y1, x2, y2 = int(row[0] * x_shape), int(row[1] *
y_shape), int(row[2] * x_shape), int(row[3] * y_shape)
mask_count += 1
tello = Tello()
tello.connect()
print(tello.get_battery())
tello.streamon()
# shows frame
while True:
frame = tello.get_frame_read().frame
frame = cv2.resize(frame, (480, 360))
mask_count, frame = mask_detect(frame)
font = cv2.FONT_HERSHEY_COMPLEX_SMALL
cv2.putText(frame,"Mask Count: " + str(mask_count), (10, 50),
font, 1, (255, 0, 0), 3)
cv2.imshow("Mask Detection", frame)
time.sleep(0.05)
cv2.waitKey(1)
Notes:
Run it part by part by using Jupyter Notebook
Running the first part of the code while connected to the WIFI:
Running the second part of the code while connected to the DJI Tello Drone:
After you run all the parts of the code correctly, then you will find the frame screen
appear in your windows and just open it.
8. To close the frame window, you should stop the last code from running, just click the
part of the last code, which is the DJI Tello Drone and shows the frame.
After that, close the frame windows and close the program like this:
This graphic shows the accuracy and efficiency using the YOLOv5 Machine Learning Model
and this is the notes about the details:
➢ COCO AP val denotes mAP@0.5:0.95 metric measured on the 5000-image COCO
val2017 dataset over various inference sizes from 256 to 1536.
➢ GPU Speed measures average inference time per image on COCO val2017 dataset
using a AWS p3.2xlarge V100 instance at batch-size 32.
➢ EfficientDet data from google/automl at batch size 8.
This table shows more detailed information for each YOLOv5 model that we can use.
So, if we don’t want to make a custom dataset and just want to try simple machine
learning. We can use the YOLOv5 model and choose what model we want to use. However,
if we use the YOLOv5 model, we can’t detect a thing that we want, our camera will detect
any object that the model has been training for. For example, the YOLOv5 model will detect
bottle, person, tie, mouse, etc and all of the things that the model has learned will be detected
by our DJI Tello drone’s camera. For more details you can try this code by your own, which
is detect objects using YOLOv5 model and for this example we use “yolov5x” model:
# import libraries
import cv2
import torch
import numpy as np
from djitellopy import Tello
import time
# YOLOv5 Packages
model = torch.hub.load("ultralytics/yolov5","yolov5x")
def object_detect(frame):
object_count = 0
results = model(frame)
frame = np.squeeze(results.render())
labels, cord = results.xyxyn[0][:, -1], results.xyxyn[0][:, :-1]
n = len(labels)
x_shape, y_shape = frame.shape[1], frame.shape[0]
for i in range(n):
row = cord[i]
if row[4] >= 0.30:
x1, y1, x2, y2 = int(row[0] * x_shape), int(row[1] *
y_shape), int(row[2] * x_shape), int(row[3] * y_shape)
object_count += 1
return object_count, frame
tello = Tello()
tello.connect()
print(tello.get_battery())
tello.streamon()
# shows frame
while True:
frame = tello.get_frame_read().frame
Actually this code is very similar to the previous code, which is mask detection. But, in this
case we didn’t use a custom dataset but we used the YOLOv5 model provided from the
COCO dataset. So, the major difference between this code with the mask detection code are:
➢ We didn’t make and use custom data, but we use the YOLOv5 model.
➢ We cannot detect things that we want, but our camera will detect anything that the
YOLOv5 has been training for.
➢ In the code, we just change the external packages section, which is if we use a custom
dataset, we need to put our path of the “best.pt” file. However, if we use the YOLOv5
model, we don't need a custom path, because we just connect it to the YOLOv5
model.
This is what the code looks like if we run it (Object Detection Using YOLOv5):
So this is the output difference between using custom dataset and COCO dataset. However,
this is the end of the Machine Learning Chapter, but you can learn more in the next chapter,
so just read it more. Congratulations on your improvement skill on drone programming so
far!
CHAPTER VII
SIMULATION PROJECT
7.2.1 DJI Tello Drone’s Program for Search and Rescue Simulation Project
Developing a program for the drone to autonomously search, identify, and
land on objects is a more intricate task compared to what we have accomplished so
far. It necessitates us to comprehend application of the knowledge and skills we have
acquired throughout this module. We must combine our code we have learnt, ranging
from fundamental functionalities such as takeoff, to more sophisticated processes like
object recognition and precise manoeuvring.
To know how to code for the simulation project, we should know what the
flying path and the simulation based on real life look like. So that, this is the scenario
picture of Search and Rescue Program:
In this Search and Rescue Project, we will use a ball that represents a human being in
real life. So, this is the step by step of our project will look like:
1. We will make a custom dataset about balls that we will use in the project
2. We will train a machine learning model using YOLOv5 with Google Colab
Environment to learn our ball custom dataset, so that the DJI Tello Drone will
detect the ball using the camera’s sensor.
3. We will code the drone to detect the ball that represents humans in this case
and will go forward the ball, then landing to represent that the drone fetch the
human and then take off again to Search and Rescue all the balls (human).
4. Finally after the drone has gone and picked up all the balls (human), the drone
will go back to the first place where the drone has taken off to represent that it
is the safe place.
So, this is what we will do and code about the Search and Rescue Simulation Project
and let’s make it:
1. First step, make a custom dataset about balls. In this case, we will use Roboflow as
our platform to make the custom dataset.
First, we take a 2 - 3 minutes video to record the ball that we will use in the
simulation project and then upload the video to the Roboflow object detection project
with 5 - 6 frames per second.
After we have enough images to make a custom dataset, then we annotate the ball in
all images that we use.
After we’ve done annotating all the images, then assigning all the images to the
dataset and then still in the annotate section, click “Generate new version.”
Clik, “Generate New Version.” and you will be in this page shown below:
In the augmentation section, add rotation and blur to the augmentation step and then
just generate it.
Generate with the maximum version size for free (3x from total images), then click
Generate.
After that, export the dataset with YOLOv5 PyTorch format and download the ZIP to
the computer.
2. Train a machine learning model using YOLOv5 with Google Colab Environment
Actually, this step is the same as what we explain and give as an example in the
previous chapter, about Machine Learning. So that, you can go back and learn how to
use YOLOv5 to train a machine learning model with Google Colab as Environment
on Chapter 6 (6.6.2). However, surely the ZIP file and the custom dataset is different
from the example, because in this case we will use a custom dataset that we have been
exporting from Roboflow that will detect a ball. But, for the step by step, you can
follow from the “6.6.2 lesson”
3. Finally, this is the final step of our Simulation Project which is to code the DJI Tello
Drone to follow the Search and Rescue Program as what we wanted before. However,
in this part we will not make the code the same as what we wanted before, because we
will give you a challenge to make the code on your own. But, we will give a basic
example that approaches the Search and Rescue Program. The code:
…
BIBLIOGRAPHY
https://www.simplilearn.com/tutorials/machine-learning-tutorial/machine-learning-ste
ps
Damiafuentes. (2023, April 7). damiafuentes/DJITelloPy: DJI Tello drone python interface
https://github.com/damiafuentes/DJITelloPy
https://www.springboard.com/blog/data-science/is-ai-hard-to-learn/
https://doi.org/10.5281/zenodo.3908559
https://dl-cdn.ryzerobotics.com/downloads/Tello/Tello%20SDK%202.0%20User%20
Guide.pdf
Singh, P. (2022.). How to use Google Colab for Machine Learning Projects.
https://www.shiksha.com/online-courses/articles/how-to-use-google-colab-for-machin
e-learning-projects/
Coursera. (2023). What Is Python Used For? A Beginner’s Guide.
https://www.coursera.org/articles/what-is-python-used-for-a-beginners-guide-to-using
-python
ATTACHMENT
Besides the manual module that we had provided, in this attachment we also provide the
GitHub repository link, so you can easily clone the module and every code in it, and use it on
your own.
https://github.com/StyNW7/UPH_DJITello.git