Professional Documents
Culture Documents
KUMASI, GHANA
COLLEGE OF ENGINEERING
YEAR: 2022/2023
PROJECT REPORT:
1
GROUP MEMBERS INDEX NO SIGNATURE
2
DECLARATION
We hereby declare that this project report titled "Redesign and Implementation of the Flight
Control System of a Quadcopter" is based on our final year project work completed during our
studies under the supervision of Dr. A. Anthony Agyeman. elsewhere. We assert that our
research produced the statements made and the conclusions reached. Any external sources of
information used in this report have been duly cited and acknowledged. The contributions of
other individuals or organizations to this project have also been appropriately recognized. We
take full responsibility for the accuracy, completeness, and originality of the content presented
in this report. In instances where the work of others has been used or referred to, it has been
done so with proper attribution and in compliance with intellectual property rights.
3
ABSTRACT
This project focuses on the improvement and advancement of the flight control system for an
unmanned quadcopter, building upon the groundwork laid by the previous year group. The
primary objectives of this study were to achieve stable flight and implement an efficient GPS
tracking system to enhance the quadcopter's capabilities. The initial flight control system faced
challenges with instability during test flights, and the GPS tracking system remained
Through a series of iterative improvements and rigorous test flights, we successfully achieved
stable flight and optimized the quadcopter's overall performance. Additionally, we developed
custom software for a ground station to implement GPS tracking, enabling real-time location
showcases the significance of building upon prior research to enhance unmanned aerial
4
ACKNOWLEDGEMENT
We would like to take this opportunity to express our profound gratitude to all the individuals
who have supported and contributed to the successful completion of our project.
We begin by acknowledging the Almighty God for His blessings, guidance, and unwavering
support throughout this project. His divine presence has been a constant source of strength and
We would like to extend our heartfelt appreciation to our project supervisor, Dr. A. Anthony
Agyeman, for his time, guidance, mentorship, and supervision in this project.
We are also immensely thankful to all the individuals who contributed financially to this
project, especially our parents/guardians. Their unwavering belief in our academic pursuits
and their generous financial support have made this project successful.
Furthermore, we extend our appreciation to Mr. Ernest Adomako for his assistance and
cooperation during the experimentation phase. His technical expertise and willingness to lend
Lastly, we want to express our gratitude to to our predecessors who worked on this project
before us. Their efforts and contributions laid the foundation for our work and provided
Thank you for believing in us and for making this project a reality.
5
Table of Contents
DECLARATION...........................................................................................................................
ACKNOWLEDGEMENT............................................................................................................
LIST OF FIGURES.......................................................................................................................
LIST OF TABLES.........................................................................................................................
LIST OF ABBREVIATIONS AND ACRONYMS...................................................................10
CHAPTER ONE..........................................................................................................................11
INTRODUCTION....................................................................................................................11
1.0 DESCRIPTION OF A QUADCOPTER...................................................................11
1.1 PROBLEM STATEMENT......................................................................................12
1.2 AIM................................................................................................................................12
1.3 OBJECTIVES...............................................................................................................12
1.4 ESSENCE OF THE PROJECT...................................................................................12
1.5 A SUMMARY OF THE METHODS TO BE USED:..................................................13
1.6 SUGGESTED SOLUTIONS FOR IDENTIFIED PROBLEMS................................14
CHAPTER TWO.........................................................................................................................15
2.0 LITERATURE REVIEW..............................................................................................15
2.1 DISCUSSION ON SIMILAR PROJECTS..................................................................19
2.2 UNDERSTANDING OF EMBEDDED SYSTEMS.....................................................20
2.3 IMPLEMENTING ARDUINO PROGRAMMING......................................................23
2.4 HOW A FLIGHT CONTROLLER WORKS................................................................24
2.5 QUADCOPTER STABILITY AND CONTROL...........................................................25
2.6 GPS TRACKING...........................................................................................................29
2.7 CONCLUSION..............................................................................................................30
CHAPTER THREE.....................................................................................................................31
METHODOLOGY...................................................................................................................31
3.0 INTRODUCTION..........................................................................................................31
3.1 PLANNING...................................................................................................................31
3.2 IMPLEMENTATION....................................................................................................34
3.3 TESTING AND CHECKING........................................................................................34
3.4 ANALYSIS AND CONCLUSION................................................................................35
CHAPTER FOUR.......................................................................................................................37
DETAILED DESIGN AND RESULTS..................................................................................37
6
4.0 COMPONENTS DESCRIPTION................................................................................37
4.1 ARDUINO LIBRARIES USED FOR CODING THE FLIGHT CONTROLLER
SYTEM.....................................................................................................................................46
4.2 ARDUINO FLIGHT CONTROLLER DESIGN CONCEPT.......................................49
4.3 THE GPS SYSTEM DESIGN CONCEPT.................................................................53
4.4 OTHER IMAGES FROM PROJRCT WORK..........................................................57
CHAPTER FIVE.........................................................................................................................62
CONCLUSION.........................................................................................................................62
REFERENCES............................................................................................................................63
APPENDIX A (FLIGHT CONTROLLER CODES)...............................................................66
APPENDIX B (GPS CODES).....................................................................................................82
APPENDIX C (LIST OF ITEMS ORDERED).........................................................................89
7
LIST OF FIGURES
8
LIST OF TABLES
Table 2.1 Summary of the effects of increasing different parameters to the system...................23
Table 4.1 Technical specifications of some components used in the study…………………...37
Table 4.2 Description of the pins……………………………………………………………...41
Table 4.3 Technical specifications of the Transmission module……………………………...43
9
LIST OF ABBREVIATIONS AND ACRONYMS
AI - Artificial Intelligence.
PID - Proportional-Integral-Derivative.
10
CHAPTER ONE
INTRODUCTION
and the other two in a counterclockwise direction. Each rotor produces torque and lift. In
Unmanned Aerial Vehicle (UAV) research, quadcopters have gained much popularity.
Electric motors drive quadcopters and the direction in which the propellers spin is determined
by the direction of the motor's rotation. Control systems and sensors provide stabilization of
quadcopters' flight. Because of how the center of gravity and aerodynamic center are arranged,
they are more stable than helicopters, with the positioning of four propellers.
The quadcopter typically consists primarily of seven sections: Four motors, four electronic
speed controllers (E.S.C.), four propellers, an R.C. transmitter and receiver, a battery, a flight
controller, and the frame. A quadcopter's main structure, or skeleton, is the frame to which the
other parts will be attached. The quadcopter can fly because the motors drive the propellers.
For the motors to function effectively, the E.S.C. is a device that interprets flight controller
signals to determine the speed and direction of the motor. By spinning and creating an airflow,
the propellers give the drone lift. An R.C. transmitter-and-receiver is a wireless electronic
device that uses radio signals to transmit and receive signals. The battery optimally balances
the drone's performance and flight time. The quadcopter's brain is the flight controller. It
serves as a user interface for incorporating human input into the drone's flight pattern. It is a
small circuit board of varying complexity that directs the speed of each motor in response to
input.
11
1.1 PROBLEM STATEMENT
The Mechanical Engineering Department lacks a good Aerial Vehicle for Surveillance.
The Department’s quadcopter assigned to the team is unstable, and its Global
Upon further examination of the previous work we identified that the deisgned flight
controller was not stable due to the lack of extensive PID tuning resulting in noise and
vibration on the mount affecting the sensor operations. Also, the GPS antenna was not
1.2 AIM
This project aims to redesign and implement a flight control system using an Arduino
1.3 OBJECTIVES
The specific objectives of the study are to:
1. Design the setup for the flight controller components of the quadcopter.
2. Develop Arduino program codes to run the flight controller on the quadcopter.
or points, preplanned and configured into the drone remote control navigational
software.
12
This gives the drone directions for where to fly, how high to fly, what speed to fly at,
and whether or not to hover at each waypoint. It is a drone's route and destination
planner.
Latitude, longitude, elevation, and compass direction may frequently be obtained from a
single device using a G.P.S. module that integrates a magnetometer and G.P.S. receiver.
For waypoint navigation and many other autonomous flight modes, G.P.S. is a crucial
prerequisite.
The suitable areas of a place can be surveyed using Waypoint G.P.S. navigation. The
pilot on the ground focuses on controlling the camera to shoot aerial pictures or videos
while the drone can fly directly to each designated destination. Additionally, the drone
travels the shortest distance to each waypoint to conserve battery life and video
recording.
Even more cutting-edge waypoint technology will be crucial for developing drones for
package delivery. Hiring a pilot for each drone that delivers packages would be
expensive. However, if drones are pre-configured to deliver packages with their target
waypoints, they can travel directly to the destination and then to the next place using the
quickest route.
gadgets enable augmented reality games and capture stunning aerial photographs.
• The previously constructed drone was put through a flight test before being examined
13
• Concept generation, design, and evaluation - Several conceptual designs were created
• Development of the flight control system - A suitable flight controller and all
necessary avionics parts were selected. A flight controller with open-source firmware
was employed to enable capabilities like a return to home, remote telemetry, and
autonomous flight.
3. Perform basic tuning which involves adjusting the PID values fro roll, pitch, and
5. Test after each tuning adjustment an iterate settings until stability is achieved.
14
CHAPTER TWO
The earliest invention of the quadcopter dates back to 1907 when Louis Breguet invented and
flew the first quadrotor helicopter. The drones were then used mainly by the U.S. army for
military purposes. The literal introduction of the quadcopter was in this century when
capable of flying a UAV. Furthermore, several sensors were incorporated into the flight
controller to increase the stability of the quadcopter. These sensors were the accelerometer,
gyroscope, and magnetometer. This resulted in the popularity of quadcopters for small UAVs.
With their smaller dimension and maneuverability, the quadcopters were used for indoor and
outdoor applications. But in the preliminary phases, these quadcopters lacked essential
stability and controllability. Thus, new designs were incorporated into the quadcopters using
more stable sensors. These sensors increased the strength and allowed it to hover at a
predefined altitude. At this stage, the microcontrollers used were complex, and flight control
was also difficult due to errors from the controller output in basic stability and controllability.
The addition of sophisticated and reliable sensors contributed to the drone's increased hovering
stability. The P.I.D. controller design, which uses a microcontroller, was used to regulate
hovering. This increased the need for drones in agriculture to monitor crops in a particular area
(Leong et al., 2012). However, the drones were still not advanced enough to carry out specific
15
Thus, to increase the drones' productivity in their missions, scientists included a few additional
sensors such as tilt sensors, infrared sensors, etc. The infrared sensor distinguishes the object
of interest from other objects based on differences in body radiation, while the tilt sensor
tracks the drone's pitch (Mustaffa, 2012). The drones were still less effective since it was
difficult to control them remotely, and they lacked sensors to track their whereabouts as they
flew. Later, scientists installed a Global Positioning System(G.P.S.) module that determined
the location of the area in which it was flying and transmitted that information to the remote
controller. WiFi, rather than conventional radio waves, is currently being used to connect the
quadcopter and remote controller. As a result, the controller's range was multiplied and could
now be remotely controlled. At this point, the quadcopter might fly a predetermined path
stored in the controller's memory (Mustaffa, 2012; Jiinec, 2011). Low wind speeds made it
comfortable to fly the drones inside. But because of the strong wind flow outside, it was
subject to aerodynamic drag forces. The sensors utilized lost stability since they couldn't
withstand the outdoor wind forces, and the drone eventually drifted away in the direction of
the wind flow (Jiinec, 2011). The sensors were improved in order to stabilize the flying.
However, the used outdated microcontrollers were incompatible with the sophisticated
sensors. As a result, in the last ten years, new microcontrollers have been developed that
supply the necessary output to the sensors and stabilize flight. The Arduino microcontroller is
the one that has been used the most up to this point since it is so simple to use and program
16
2.03 RECENT DEVELOPMENTS
Several advancements have been achieved in the field of quadcopters over the last decade as
they have evolved in design as well as in-flight controllability. This is due to the fact that
better microcontrollers are being used along with better sensors attached. The introduction of
the BME 280 (temperature, pressure as well as altitude) sensor along with the gyroscope
helped the drone in altitude hold control predetermined by the microcontroller. At this stage,
the G.U.I. at the remote station was improved to give the user a nice flight experience. The
drones proved useful in the military in remote package delivery missions. With the passage of
time, Arduino became a popular microcontroller for making drones because of its flexibility in
programming. Besides that, additional sensors like a camera; and ultrasonic sensors can be
attached to the drones. This helped the drones in calculating the distance from the ground,
which previously were unable to achieve. This revolutionary addition increased its popularity
several times. The drones could now be used in waypoint navigation systems. The coordinates
of the waypoints for predetermined flights are fed to the microcontroller. An algorithm is used
to calculate the distance between the present G.P.S. position to the first waypoint and the
heading angle of the present position with respect to the geographical north. In this process,
succeeding waypoints are calculated, and the quadrotor altitude control is done by the
controller-generated pulse width modulated (P.W.M.) signal, which can be used for security
surveillance, fire suppression, and for terrain mapping (Rengarajan & Anitha, 2013; Mane et
al., 2017). Also, similar other models are made using FY90 microcontrollers and are used in
coast guard surveillance and rescue missions ( Mahen et al., 2014). Infrared sensors attached
to the drones could search for live targets in rescue missions (Qetkeaw & Vechian, 2012). The
other demand for these drones is in the field of agriculture, where it is used for crop
17
surveillance, fertilizer spraying, and in precision agriculture. The infrared sensor attached to
the drones could identify healthy crops from infected ones. These drones reduced human
efforts and increased the monitoring quality of the crops (Emmanuel et al., 2017; Ononiwu et
al., 2016; Patel et al., 2013; Ipate et al., 2015). Another field where it can be useful is during
natural calamities to warn people of the situation and inform them about the safety measures
reconnaissance. Here, for this additional security purposes, we need several components like a
microphone, pistol with immobilizing darts, heat-resistant frame, small medical devices, mini-
size quadcopter, and recognition devices (Ortiz-Rivera et al., 2012). The developments with
these drones are plenty. Previously, drones could follow a predetermined path. But the drone
was vulnerable to collisions. Lately, quadcopters are being designed which have the
technology of obstacle detection and collision avoidance. The quadcopters use a number of
ultrasonic sensors in coordination to detect objects around them and avoid them by using
simple algorithms. The signals from the sensors are controlled by an Arduino microcontroller.
Here, the signals from the sensors are integrated to give a collision avoidance display on the
remote controller, which can be used to control the quadcopter precisely. But then again, the
quadcopter could not provide the location to where it was traveling. This was eliminated when
a G.P.S. module was introduced in the system, which allows the quadcopter to fly between
delivering systems and thus avoided collisions on the way (Salaskar et al., 2014; Camacho et
al., 2015). Latest developments have been made where the quadcopters are being controlled by
voice commands of the user or by simple hand gestures. These developments are still in the
initial stages but are soon to become a reality (Amar, 2016; Gaur et al., 2015). Others are
being controlled by voice commands of the user or by simple hand gestures. These
developments are still in the initial stages but are soon to become a reality (Amar, 2016; Gaur
18
et al., 2015). The designed system is based on programming the quadcopter using an Arduino
Uno R3 microcontroller. Also, there are several sensors embedded with the microcontroller for
atmospheric condition monitoring and finding its altitude, as well as magnetometer and gyro
cum accelerometer sensors for finding out the exact position of a quadcopter. The sensors are
automatically transmit the sensor details as and when required. So, remote monitoring is easily
achievable. The developed system is designed keeping in mind that the circuitry becomes less
complex and the cost remains low. Also, there will be a one-touch return button designed such
that it may return to its base location by pressing a single button. So, the quadcopter can never
be lost. This type of system can find its application for remote real-time atmospheric condition
monitoring of several areas specifically for crop production and irrigation without installing
the sensors at each and every location (Ghosh et al., 2018). Also, if a camera is installed, then
Arduino website with the default code. Similar initiatives in the past have been successful. The
majority of them have posted their designs on numerous websites.Do It Yourself (D.I.Y.)
Electronic Lovers, Instructables, and droneLab are a few of them. The sensor used to identify
the quadcopters' orientation is the one thing that remains constant across all of these designs.
An Arduino Nano can be used, according to the Arduino community. The Nano can perform
tasks that other Arduino microcontrollers can. Our design makes use of an Arduino Uno,
19
which is frequently utilized in several projects across the globe. There is no specific
justification for this. The designer will choose one of the two based on their personal tastes.
With the addition of G.P.S., quadcopters have advanced to the point where they can now be
tracked, navigate using predefined paths, and return to their launch location in the case that
Typically, G.P.S. is fitted, and other functions that fully utilize its capabilities are found on
medium-sized drones like the DJI Phantom or Parrot Bebop. The addition of G.P.S. has
changed how quadcopters travel, making it safer to use and simpler to find them. The
quadcopter's location's coordinates are provided via the project's G.P.S. system. Similar
microcontroller and intended to carry out specific tasks within a broader mechanical or
an Integrated Circuit (I.C.) device that controls other components of an electronic system,
often through memory, peripherals, and a microprocessor unit (M.P.U.). These gadgets are
designed for embedded applications that need both computing power and quick, accurate
utilized in products and equipment that are automatically controlled because they may be built
for and used in embedded systems. As previously said, this functionality is produced by
combining a digital processor and memory with additional hardware that is specially made to
facilitate communication between the microcontroller and other parts. A central processing
unit (CPU), memory (volatile and nonvolatile), peripherals, and support circuitry make up a
20
microcontroller. Arduino Nano and Uno were used as the microcontrollers in the flight
controller design.
The Central Processing Unit (CPU) carries out mathematical operations, controls data flow,
and produces control signals in line with the programmer's set of instructions. The designer
cannot see the incredibly intricate circuitry needed for CPU functioning.
Memory:
The program for the microcontroller—a list of machine-language instructions that specify to
the Central Processing Unit (CPU) what to do—is stored in nonvolatile memory. Instead of
nonvolatile data storage. Temporary data is stored in volatile memory, often known as
Random Access Memory (RAM). When the power to the microcontroller is removed, data in
Peripherals:
external system. Data converters, clock generation, timing, analog signal processing,
input/output, and serial communication are some of the hardware components that make up
this group.
Support Circuitry:
Because their main role is not to operate, monitor, or connect with external components,
peripherals. Nevertheless, they are crucial for supporting the device's internal operations,
21
• Debugging circuitry enables firmware performance optimization by enabling the designer to
hardware-based events that are either internal or external and trigger the processor to respond
clock signal for the CPU and peripherals, a clock-generation module might be regarded as a
peripheral if it is designed to provide signals that will be used outside the device.
networks, it becomes more complicated. Depending on the task for which it is created, an
Programmable Gate Arrays, Graphics Processing Unit Technology, and gate arrays are used to
control embedded systems. These processing systems have integrated parts for handling
Firmware for embedded systems, also known as software for the embedded system, is stored
in read-only memory or flash memory chips and operates with constrained computer hardware
Different types of microprocessors and controllers are used in Arduino board designs. The
boards have a variety of extension boards (called "shields"), breadboards (for prototyping),
and other circuits that can be interfaced to the sets of digital and analog input/output (I/O) pins
on the boards. The boards have serial communications interfaces, some of which support USB
(Universal Serial Bus), which are also used to load programs. The C and C++ programming
languages, as well as a common Application Programming Interface (API) often known as the
22
Arduino language, can be used to program microcontrollers. Figures 2.1 shows a drone with
of electronic components
board can receive inputs, such as light on a sensor or pressure on a button, and convert them
into outputs such as starting a motor or turning on a light-emitting diode (L.E.D.). The
Arduino Boards can be used to carry out the desired activities after being programmed using
Each quadcopter can typically move in three different directions: roll, yaw, and pitch. The
thrust that each rotor generates governs each of these actions. In order to release the necessary
23
power for flight and to which rotor at any given time, the controller must be programmed at
some time.
Every quadcopter comes equipped with a microcontroller board, in this example, the Arduino
board, which has sensors on it. The motors are controlled by this board and the components
that were selected. The components chosen depend on how autonomous the quadcopter should
be. In order for the quadcopter to be able to recognize and avoid objects that are in the course
of a flight, one may alternatively use only a few simple components, such as the gyroscope, or
a variety of other, more sophisticated sensors, such as the barometer, a G.P.S. module, or even
a sonar module.
You may see with your own eyes and examine the log of sensor data utilized for each
coordinates on three axes. The frame and certain components are already attached to the
building because this is a continuation of a project started by our forebears. With a pre-
programmed flight controller, the quadcopter was put through a variety of flying test
board with a range of complexity that includes Arduino Uno, Nano, Mega, G.P.S., a compass,
In a quadcopter, the flight controller precisely regulates the four motors' rotational speeds at
the same time to maintain the aircraft's balance while in flight. The remote control's radio
transmitter in the remote sends radio signals to the drone's receiver when the pedal stick is
24
depressed. Input signals from the receiver are processed by the flight controller, which then
generates commands to control each motor's revolution per minute(rpm) speed. The electronic
speed controller is provided in this order to adjust the motors in accordance with the desired
movement of the quadcopter Gyroscopes are used by the flight controller to detect its
orientation, while barometers are used to maintain altitude automatically in order to aid in
computations.
Figure 2.2 depicts the general shape of a quadcopter and its constituent parts.
Figure 2.2
3.2 A typical outline of a quadcopter with its essential components, respectively
Different controller types are employed in ordinary tasks, lab work, and industry. On/off,
Proportional-Integral-Differential (P.I.D.), fuzzy logic, and neural are a few of the often
employed controllers. The latter two are rather more complicated and make use of Artificial
25
Intelligence (A.I.) ideas. It is also possible to distinguish between "feedforward" and
"feedback" controllers. The feedback controller functions by providing an observed result that
modifies the processing value of the subsequent step, whereas the feedforward controller
provides a result based on the anticipation of the subsequent step. Proportional Integral and
Derivative is referred to as P.I.D. The P.I.D. algorithm-based feedback control system is the
is widely used in the robotics and automation industry. The first evolution of the P.I.D.
controller was developed in 1911 by Elmer Sperry. However, it was not until 1933 that the
Taylor Instrumental Company (T.I.C.) introduced the first pneumatic controller with a fully
tunable proportional control. A few years later, control engineers eliminated the steady state
error found in proportional controllers by resetting the point to some artificial value as long as
the error was not zero. This resetting integrated the error and became known as the
Proportional-Integral controller. Then, in 1940, T.I.C. developed the first P.I.D. pneumatic
controller with a derivative action, which reduced overshooting issues. However, it was not
until 1942, when Ziegler and Nichols' tuning rules were introduced, that engineers were able
to find and set the appropriate parameters of P.I.D. controllers. By the mid-1950s, automatic
Not until 1942, when Ziegler and Nichols tuning rules were introduced, that engineers were
able to find and set the appropriate parameters of P.I.D. controllers. By the mid-1950s,
automatic P.I.D. controllers were widely adopted for industrial use (O.E., 1996).
The P.I.D. control algorithm has been considered and implemented to control the hover
altitude of the quadcopter. The P.I.D. algorithm is popularly used mainly because:
26
It has a simple structure
It can be tuned even if the specific model of the controlled plant or system is not
available
desired set point, a P.I.D. controller calculates the error or difference between the two
and makes adjustments to the system control inputs to reduce the computed error.
The error and an adjustable factor are the only components of the proportional term
(P). The algorithm can reduce the difference between the actual and desired values by
adjusting the factor. This indicates that when the error is at its peak, the proportionate
term has the biggest impact. The impact of the actual value approaching the desired
value of the proportionate term begins to decrease. The proportional term's drawback is
inaccuracy. Because of the way proportional control operates, the steady-state error is a
by-product; if the error is eliminated, the signal produced will likewise be eliminated.
As a result, although the actual value eventually comes near the intended number, it
never does.
The accumulated inaccuracy over time as the drone progresses to the intended state is taken
into account by the integral term (I). The integral term has a factor that the controller
continuously adjusts as the drone flies, much like the proportional term does. The integral term
considers the accumulated error, which can be either negative or positive. This translates to a
27
decreasing impact of the integral term as the actual value fluctuates between negative and
positive error margins. The integral term resolves the steady-state error issue by delaying the
initial attempt at zeroing out the correction. This indicates that as the actual value approaches
the target value, the controller continues to operate. It is noted that the integral term doesn't
While this feature addresses one issue, it also raises a new one because the quadcopter can
take a very long time to stabilize as it is continually exceeding the desired number.
The derivative term (D) responds to the error's rate of progression. The differential term takes
into account how quickly the inaccuracy in the signal changes over time. As the actual value
becomes closer to the desired value, the differential term decreases the rate of correction the
controller applies. As a result, the rate of approach to the intended value is slowed down,
which reduces the overshoot that results. The differential term aids a controller in achieving
the intended value faster by resolving a limitation brought on by the integral term.
Figure 2.3 depicts a condensed block diagram of a system having a P.I.D. controller. The
results of altering these parameters in the system are also summarized in Table 2.1.
The equation below gives the discrete-time P.I.D. algorithm's mathematical expression.
k
de
. u ( k ) =K P e ( k ) + K i ∑ e (i)+ K p ( ) …………………Equation 2.1
i=0 dt
Kp = proportional gain
Ki = integral gain
dt = change in time
28
Table 2.1 Summary of the effects of increasing different parameters to the system
Closed Loop Response Rise Time Overshoot Settling Time Steady-State Error Stability
Increasing K p Decrease Increase Small Increase Decrease Degrade
Increasing K i Small Decrease Increase Increase Large Decrease Degrade
Increasing K d Small Decrease Decrease Decrease Minor Change Improve
military and intelligence applications. The global positioning system (G.P.S.), which took its
cue from the Soviet spacecraft Sputnik in 1957, consists of a network of satellites circling the
earth at fixed positions above the planet and beaming signals down to everyone on earth using
G.P.S. Navigation was used. Waypoints are coordinate sets that specify a location in actual
space. Waypoints are becoming more abstract and frequently have no evident connection to
any distinguishing characteristics of the outside world. These waypoints are used to define
navigational invisible routing pathways. The pilot can customize this to tell the drone where to
29
fly, at what height, and at what speed. It may be described as a drone route and destination
planner.
Latitude, longitude, elevation, and compass direction may frequently be obtained from a single
device using a G.P.S. module that integrates a magnetometer and G.P.S. receiver. For
waypoint navigation and many other autonomous flight modes, G.P.S. is a crucial prerequisite.
The right areas of a place can be surveyed using Waypoint G.P.S. navigation. The pilot on the
ground focuses on operating the camera to take aerial pictures or videos, while a drone can be
pre-configured to fly directly to each designated destination. Additionally, the drone travels
the quickest path to each waypoint to conserve power and video recording.
2.7 CONCLUSION
The purpose of the literature study was to provide the reader with a comprehensive overview
of the numerous processes that come together to form the project, as well as a description and
various developments.
30
CHAPTER THREE
METHODOLOGY
3.0 INTRODUCTION
The goal of this project is to create a GPS-tracking flight control system for quadcopters. The
project’s initial step was to determine whether Arduino could operate and stabilize a
quadcopter. Analogous endeavors were looked into. The approaches that were employed to
accomplish the project’s goals will be thoroughly explained in this chapter. Four important
phases were taken in order to evaluate this project: planning, implementing, testing and
analysis.
3.1 PLANNING
Planning must be done correctly in order to identify all the data and requirements, including
hardware and software. Data gathering and hardware and software requirements are the two
key components of the planning phase. To visualize the design in simpler formats, the project
required discovering and learning how to utilize the Arduino IDE, proteus, and a few graphic
For a quadcopter to stay in the air, certain conditions must be met. These include:
Altitude: The flight controller system measures the altitude of the quadcopter
using a barometer, which senses the changes in air pressure, The barometer
31
Airspeed: Some flight controller systems measure airspeed using a pitot tube.
The pitot tube senses the difference in air pressure between the front and back
Wind speed and direction: Some flight controller systems measure wind speed and
direction using a anemometer. Wind speed and direction are important to consider
Temperature and humidity: Some flight controllers systems measure temperature and
humidity using sensors. Temperature and humidity can affect the quadcopter’s flight
Attitude and orientation; The flight controller system measures the quadcopter’s
attitude and orientation using sensors such as accelerometers and gyroscopes. This data
can is used to maintain stability and control the quadcopter’s movement during flight.
GPS data: The flight controller system uses GPS data to determine the quadcopter’s
position and altitude. This information is used to maintain stability and control the
The necessary components was chosen based on the quadcopter flight-related parameters.
Without the transfer of data to and from the quadcopter, control and stability of the device
would not be possible. The necessary component must allow quick and simple data transfer,
which is necessary for the quadcopter to respond quickly. The project’s plan was influenced
by these parameters.
32
The hardware that is listed in this part was all purchased, proved to be useful, and was
required for the project. How quickly the components are bought will determine when the
project will be finished. All of these are taken into account in the project plan.
Adriuno Uno R3
Spark 9Dof
Jumper wires
Pin headers
Arduino Nano
1 A Diode 1N4001
There are two fundamental needs for the project. These are to perform sustained flight and
GPS location transmission to a base station. The following specifications for the
• The components must be able to communicate with the microcontroller and receive
Whether a circuit is formed using wires on a porous board or a printed circuit board
33
(PCB), the software needed to design it relies on the circuit's architecture. Using Proteus
software, the circuit's schematic diagram was created. The Arduino IDE is by far the best-
codes. Lastly, using graphic design software like Illustrator, it was simple to create the
In any field of study, data collecting is a necessary step. At this point, the project's
resources and requirements, literature reviews, etc. were prepared. All of the necessary
information was acquired from journals. books. and research papers located online and in
libraries. The emphasis in the first few weeks of the semester was on learning the basics
of the project. The extensive resources available on the internet were mostly used for this
Other professionals who worked on related projects were found after carefully reviewing
and analyzing every component of the project. This provided the team with detailed
information on what was necessary to complete the project successfully and paved the
path for choosing the right components. Overall, extreme precautions were made to make
sure that every component was purchased in time for the project's early start.
3.2 IMPLEMENTATION
All of the planning phase's procedures or stages had been implemented by this point. To verify
the correct operation of sensors and other components, all purchased components were
calibrated, and the telemetry of the quadcopter was checked and tested. The microcontroller
was created and programmed with the necessary programming codes for controlling the
34
quadcopter. Programmed scripts were also used to create the quadcopter's GPS system.
Outcomes of the aforementioned scripts were acquired following system testing and analysis.
the circuit's track was examined. This task was making sure that the circuit will function
properly. The multimeter was the device used to check the continuity and various electrical
properties of each circuit track before soldering. While testing, it warns the user of a failed
significant PID code problems, therefore dampening of sensors is crucial once all connections
have been verified. Each element has undergone testing. The principal tests performed consist
of:
1. Motor Testing
The quadcopter also needed to go through a series of flight tests to verify if the dampening
of the main sensors was done correctly. Calibration is the most crucial factor that guarantees
CALIBRATION
The inertial measurement unit's (IMU) gyro or compass needed to be calibrated before the
drone was first flown outside. This entails comparing the measurement produced by the
sensors to a known measurement, which is standard. The flight controller, IMU, and gyro
stabilization are crucial for the quadcopter to fly successfully. At the starting position, the
pilot's commands are based on the standard established by the sensors' measurements on the
35
ground. Performance significantly changes when the quadcopter is calibrated at the
appropriate time. Calibration should be performed if there are any anomalies following any
crashing.
step in our methodology. Initially, it was dependent on the operation and output of the flight
controller system. Finding the results based on the test flight and making modifications as
36
CHAPTER FOUR
The project encompasses two distinct systems, each serving a specific purpose:
ARDUINO UNO
digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz
ceramic resonator, a USB connection, a power jack, an ICSP header and a reset button. Figure
4.1 shows an Arduino UNO Pinout, Specifications, Board Layout, and Pin Description. Table
4.1 gives the technical specifications of some components used in the study.
37
Microcontroller ATmega328P
Operating Voltage 5V
SRAM 2 KB (ATmega328P)
EEPROM 1 KB (ATmega328P)
LED_BUILTIN 13
Length 68.6 mm
Width 53.4 mm
Weight 25 g
Figure 4.1 Arduino UNO Pinout, Specifications, Board Layout, and Pin Description
MPU 6050
component solution, it eliminates the problem of axis difference when combining the
gyroscope and accelerator and reduces a lot of packaging space. MPU-6050 integrates a 3-axis
gyroscope, a 3-axis accelerometer, and includes a digital motion processor, which processes
38
complex 6-axis MotionFusion algorithms. The device can access external magnetometers or
other sensors through an auxiliary master I²C bus, allowing the devices to gather a full set of
sensor data without intervention from the system processor. The devices are offered in a 4 mm
that enables manufacturers to eliminate the costly and complex selection, qualification, and
sensor fusion algorithms and calibration procedures deliver optimal performance for
consumers.
For precision tracking of both fast and slow motions, the parts feature a user-programmable
gyro full-scale range of ±250, ±500, ±1000, and ±2000 °/sec (dps), and a user-programmable
Additional features include an embedded temperature sensor and an on-chip oscillator with
±1% variation over the operating temperature range. MPU-6050 can work under different
Below is Figure 4.2, which shows a Pin Out Diagram for MPU- 6050 with a 4.0 x 4.0 x 0.9
mm QFN whilst Figure 4.3 shows an MPU-6050 with its typical operation circuits.
Figure 4.2 Pin Out Diagram for MPU- 6050 with a 4.0 x 4.0 x 0.9 mm QFN
39
Figure 4.3 MPU-6050 with its typical operation circuits
ARDUINO NANO
The Arduino Nano is a small, complete microcontroller, and breadboard-friendly board based
on the ATmega328, which processes all instructions and swiftly carries out all mathematical
and logical operations. It lacks only a DC power jack and works with a Mini-B USB cable
instead of a standard one. It is part of the GPS System. The Arduino Nano operates with a very
small voltage of 5V. It has 14 digital input-output pins of which six provides Pulse Width
It has 32 kB of flash memory, which helps in easy storage of data and efficient processing of
signals. Essential features, which make the board very efficient, are its lightweight and small
dimensions.
overcoming the complexity of assembly level coding. Arduino Nano comes with a very useful
serial library software, which enables easy serial communication on any of the digital pins of
40
Figure 4.4 Arduino
The NEO-6M V2 is a GPS (Global Positioning System) module and is used for navigation.
The module simply checks its location on earth and provides output data, which is longitude
and latitude of its position. The module has four output pins and the function of each pin will
be discussed. The powering of module and communication interface is done through these
four pins. Figure 4.5 shows a Neo-6m V2 GPS module. Table 4.2 gives the description of the
pins.
41
GND Ground
Anti-jamming technology
UART Interface at the output pins (Can use SPI, I2C and USB by soldering pins to the
chip core)
GAGAN)
Time-To-First fix: For Cold Start 32s, For Warm Start 23s, For Hot Start <1s
42
Figure 4.5 Neo-6m V2 GPS module
The NRF24L01+ transceiver module is designed to operate in 2.4 GHz worldwide ISM
(industrial, scientific and medical) frequency band and uses GFSK (Gaussian Frequency Shift
Keying) modulation for data transmission. The data transfer rate can be one of 250kbps,
1Mbps and 2Mbps. This module would be employed for telemetry purposes. Figure 4.6 shows
an NRF24L01+ PA LNA Wireless Transceiver Module with External Antenna. Table 4.3
43
Figure 4.6 NRF24L01+ PA LNA Wireless Transceiver Module with External Antenna
Radio transmitters use radio signals to remotely control quadcopters in a wireless manner. The
commands given by transmitter are received by a radio receiver via a flight controller. The
number of channels in the transmitter determine the actions that can be controlled by the pilot.
A minimum of four channels are needed to control a quadcopter (which includes pitch, roll,
The stick control on radio transmitter is known as gimbal. The RC receiver used, operates on
2.4 GHz of radio frequency (unless you do not have any specific need for a different
frequency). A typical transmitter has about 4 to 6 channels with at least four of them being
proportional, which means the controlled surfaces or devices will move proportionally to the
movements of the control sticks. Additional channels may function like a switch, which could
Figure 4.8 shows the final design of the flight controller system with GPS tracking.
44
Figure 4.7 R/C Transmitter and Receiver
Figure 4.8 final design of the flight controller system with GPS tracking
45
Figure 4.9 An image of some purchased components.
CONTROLLER SYTEM
WIRE.h LIBRARY
EEPROM.h LIBRARY
This library enables storage of information onto the EEPROM (electrically erasable
46
NRF24L01 LIBRARY
This library was created to simplify the use of the widely available nrf24l01+ radio module
with the PIC32 microcontroller. It provides a relatively short set of functions that allow the
user to take advantage of all the major functionality of the nrf24l01+ without needing to worry
TINYGPS++ LIBRARY
For the Arduino GPS tracker, the GY-NEO6MV2 GPS module was used. To use the GPS
module with the Arduino, the GPS library must be downloaded. The GPS library used for the
aforementioned GPS module is TinyGPS++. TinyGPS++ is a new Arduino library for parsing
NMEA (National Marine Electronics Association) data streams provided by GPS modules.
This library provides compact and easy-to-use methods for extracting position, date, time,
altitude, speed, and course from consumer GPS devices. The new library can extract arbitrary
data from any of the myriad NMEA sentences out there, even proprietary ones.
The library was then added to the Arduino libraries by following the steps below:
2. Open the zip folder and move the TinyGps++ folder to the desktop.
47
7. Open any folder on your computer and then paste the sketchbook location there.
10. Open the Arduino IDE, go to sketch, select include library. It will be added to the
library.
The software serial library was also used in writing the code for the GPS tracker. The Arduino
hardware has built-in support for serial communication on pins 0 and 1 (which also goes to the
computer via the USB connection). The native serial support happens via a piece of hardware
(built into the chip) called a UART (universal asynchronous receiver-transmitter). This
hardware allows the Atmega chip to receive serial communication even while working on
The SoftwareSerial library has been developed to allow serial communication on other digital
pins of the Arduino, using software to replicate the functionality (hence the name
115200 bps. A parameter enables inverted signaling for devices which require that protocol.
Limitations
If multiple software serial ports are used, only one can receive data at a time.
48
Not all pins on the Mega and Mega 2560 support change interrupts, so only the
following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63),
A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).
Not all pins on the Leonardo and Micro support change interrupts, so only the
following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
library. AltSoftSerial overcomes a number of other issues with the core SoftwareSerial, but
has its own limitations. Figure 4.13 shows a setup of the Arduino Neo 6M GPS model with the
Arduino Nano before transmission whilst Figure 4.14 shows the data (latitude, longitude and
altitude) from the Arduino Neo 6M GPS module in sync with the Arduino Nano during
DESCRIPTION
The flight controller runs on the Arduino Uno. This is responsible for calculating the
quadcopter’s current angle, and stabilize it from there. Additionally, it takes the remote
controller's input so that the pilot can control the quadcopter. This is done via the receiver
49
The Electronic speed controllers and receiver channels are connected to the Arduino Uno via
digital pins for transfer of signals. The Uno is supplied with power tapped from the battery
through the sensor shield for voltage regulation. The Esc signal connectors are all grounded
via the receiver. The inertial measurement unit (sensors) are connected to the Arduino Uno. It
Here are the Schematic connections for the flight controller board:
ESC Connections:
RECEIVER Connections:
50
GND << GND BATTERY
In a systematic procedure of what should occur for the flight controller to achieve its function,
1. The R/C transmitter bonded to the receiver communicates with the quadcopter by
giving a command.
2. The receiver communicates with the flight controller system by sending a signal.
3. The MPU provides the control with real-time orientation of the quadcopter.
4. The PID controller, which is the Arduino Uno, compares the set point signals values
5. The error is used to adjust motor speeds in order to obtain the required maneuver
The components were synchronized to provide data for the operation and control of the
quadcopter (QUAD 4). These components were calibrated on ground and programmed in the
Arduino IDE to build the flight control system, which is the brain of the quadcopter. The flight
51
controller controls the stability and movement of the QUAD4. Figure 4.1 shows the schematic
of the flight controller system and Figure 4.2 shows an image of the quadcopter with its flight
52
Figure 4.11 An image of the quadcopter with its flight controller after a flight test at Paa
Joe Stadium
The GPS system consists of components such as the GPS module, the NRF transmitter,
Arduino Nano and the ground station. The ground station is made up of the laptop, Arduino
Uno and the receiver. The GPS data is transferred through the Nano then through the NRF
53
transmitter. The data is received by the receiver at the ground station. The location of the
D7 << CE (NRF)
TX and RX Protocols between NRF Transmitter and Receiver in the ground station.
TXD and RXD Protocols between GPS module and Arduino Nano.
54
Figure 4.12 shows the schematic diagram of the GPS tracking system whilst Figure 4.13
shows pictorial diagram of the GPS tracking system wired onboard the quadcopter.
Figure 4.13 Pictorial diagram of the GPS tracking system wired onboard the quadcopter
55
GROUND STATION
D7 << CE (NRF)
GPS APPLICATION
The GPS application is an intergral part of the project. It is an application that will show
important parameters about our quadcopter. The GPS application indicates the following
parameters, longitude, latitude, altitude, HDOP, VDOP, status and more. These parameters
show the location of our quadcopter and the status of the quadcopter and the GPS application
itself. The pictures below indicates the User Interface of the GPS application. Figure 4.15
56
shows images of the GPS application interface indicating our location. Figure 4.16 shows an
Figure 4.15 Images of the GPS application interface indicating our location.
57
Figure 4.16 An image of the GPS System
58
Figure 4.17 An image of sensor orientation test.
59
Figure 4.19 An image of components assembling and setup.
60
Figure 4.21 Images of developed quadcopter
61
Figure 4.23 Images of flight tests.
62
CHAPTER FIVE
CONCLUSION
This project represents a successful endeavor in achieving the aims set forth at
its inception. Our primary objectives were to improve upon the flight control
quadcopter now exhibits stable flight, overcoming previous challenges, and the
integrated GPS tracking system provides real-time location monitoring during its
operations.
63
REFERENCES
Amar, P.F. (2016) "Building A Hands Free Quadcopter," Project Report, Degree On
Camacho, E., Robaina,M., Tasca, A., Cuberos, P., Tansel, I. & Tosunoglu, S. (2015)
Emmanuel, A.A., Pranavan, M., Vickram, V. & Girirajkumar, S.M. (2017) "Fertilizer
Spraying Quadcopter using Arduino U.N.O.," International Journal of Science Technology &
Engineering, Volume 3.
Gaur, V., Mishra, A., Aquil, M., Thapa, H., & Verma, R.K. (2015) "Gesture Controlled
Ghosh, A., Mitra, R., Mohalanobish, S., De, S., Bhattacharjee, S. & Bardhan, S. (2018)
"Wireless Irrigation System", Proc. 2018 IEEE International Conference on Recent Innovation
Hanafi, D., Qetkeaw, M., Ghazali, R., Than, M.N.M., Utomo,W.M. & Omar, R. (2013)
DOI:10.4236/ijcns.2013.61006.
Ipate, G., Voicu, G. & Dinu,I. (2015) "Research On The Use Of Drones In Precision
Agriculture," U.P.B. Sci. Bull., Series D, Vol. 77, Iss. 4, ISSN 1454-2358.
64
Jiinec,T. (2011) "Stabilization and control of unmanned quadcopter," Master's Thesis, Dept. of
Leong, B.T.M., Low, S.M. & Po-L. Ooi, M. (2012) "Low-Cost Microcontroller-based Hover
Sensors.
Mahen, M.A., Naik, A.S., Chethana, H.D. & Shashank, A.C. (2014) "Design And
Mane, S.R., Andhare, P.S. & Gaikwad, S.B. (2017) "Design And Implementation Of
Mustaffa, A.H.B.M. (2012) "Stability Control For Quadcopter With An Autonomous Flight
2023].
Ononiwu, G., Okoye, A., Onojo, J. & Onuekwusi, N. (2016) "Design And Implementation Of
A Real Time Wireless Quadcopter For Rescue Operations," American Journal of Engineering
Ortiz-Rivera, E.I., Estela, A., Romero, C. & Valentin, J.A. (2012) "The use of UAVS in
Patel, P.N., Patel, M.A., Faldu, R.M. & Dave, Y.R. (2013) "Quad Copter For Using
65
Picas, C.C. (2014) "An Android-Based Arduino-Governed Unmanned Quadcopter Platform,"
Qetkeaw, M. & Vechian, A.L. (2012) "Wireless Control Quadcopter With Stereo Camera,"
M.E. Thesis, Faculty of Electrical and Electronics Engineering, University Tun Hussein Onn
Malaysia.
Salaskar, P., Paranjpe, S., Reddy, J. & Shah, A. "QuadcopterObstacle detection & Collision
17 Number 2.
66
APPENDIX A (FLIGHT CONTROLLER CODES)
///////////////////////////////////////////////////////////////////////////////////////
//Safety note
///////////////////////////////////////////////////////////////////////////////////////
//Always remove the propellers and stay away from the motors unless you
//are 100% certain of what you are doing.
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//PID gain and limit settings
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
float pid_p_gain_roll = 1.3; //Gain setting for the roll P-controller
float pid_i_gain_roll = 0.04; //Gain setting for the roll I-controller
float pid_d_gain_roll = 18.0; //Gain setting for the roll D-controller
int pid_max_roll = 400; //Maximum output of the PID-controller (+/-)
float pid_p_gain_yaw = 4.0; //Gain setting for the pitch P-controller. //4.0
float pid_i_gain_yaw = 0.02; //Gain setting for the pitch I-controller. //0.02
float pid_d_gain_yaw = 0.0; //Gain setting for the pitch D-controller.
int pid_max_yaw = 400; //Maximum output of the PID-controller (+/-)
float maxInput=10;
float minInput=-10;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Declaring global variables
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
byte last_channel_1, last_channel_2, last_channel_3, last_channel_4;
byte eeprom_data[36];
byte highByte, lowByte;
volatile int receiver_input_channel_1, receiver_input_channel_2, receiver_input_channel_3,
receiver_input_channel_4;
67
int counter_channel_1, counter_channel_2, counter_channel_3, counter_channel_4,
loop_counter;
int esc_1, esc_2, esc_3, esc_4;
int throttle, battery_voltage;
int cal_int, start, gyro_address;
int receiver_input[5];
int temperature;
int acc_axis[4], gyro_axis[4];
float roll_level_adjust, pitch_level_adjust;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Setup routine
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup(){
Serial.begin(57600);
//Copy the EEPROM data for fast access data.
for(start = 0; start <= 35; start++)eeprom_data[start] = EEPROM.read(start);
start = 0; //Set start back to zero.
gyro_address = eeprom_data[32]; //Store the gyro address in the
variable.
//Arduino (Atmega) pins default to inputs, so they don't need to be explicitly declared as
inputs.
DDRD |= B11110000; //Configure digital poort 4, 5, 6 and
7 as output.
DDRB |= B00110000; //Configure digital poort 12 and 13
as output.
68
//Use the led on the Arduino for startup indication.
digitalWrite(12,HIGH); //Turn on the warning led.
//Check the EEPROM signature to make sure that the setup program is executed.
while(eeprom_data[33] != 'J' || eeprom_data[34] != 'M' || eeprom_data[35] != 'B')delay(10);
//The flight controller needs the MPU-6050 with gyro and accelerometer
//If setup is completed without MPU-6050 stop the flight controller program
if(eeprom_data[31] == 2 || eeprom_data[31] == 3)delay(10);
for (cal_int = 0; cal_int < 1250 ; cal_int ++){ //Wait 5 seconds before
continuing.
PORTD |= B11110000; //Set digital poort 4, 5, 6 and 7
high.
delayMicroseconds(1000); //Wait 1000us.
PORTD &= B00001111; //Set digital poort 4, 5, 6 and 7
low.
delayMicroseconds(3000); //Wait 3000us.
}
//Let's take multiple gyro data samples so we can determine the average gyro offset
(calibration).
for (cal_int = 0; cal_int < 2000 ; cal_int ++){ //Take 2000 readings for
calibration.
if(cal_int % 15 == 0)digitalWrite(12, !digitalRead(12)); //Change the led status to
indicate calibration.
gyro_signalen(); //Read the gyro output.
gyro_axis_cal[1] += gyro_axis[1]; //Ad roll value to gyro_roll_cal.
gyro_axis_cal[2] += gyro_axis[2]; //Ad pitch value to
gyro_pitch_cal.
gyro_axis_cal[3] += gyro_axis[3]; //Ad yaw value to gyro_yaw_cal.
//We don't want the esc's to be beeping annoyingly. So let's give them a 1000us puls while
calibrating the gyro.
PORTD |= B11110000; //Set digital poort 4, 5, 6 and 7
high.
delayMicroseconds(1000); //Wait 1000us.
PORTD &= B00001111; //Set digital poort 4, 5, 6 and 7
low.
delay(3); //Wait 3 milliseconds before the next loop.
}
//Now that we have 2000 measures, we need to divide by 2000 to get the average gyro offset.
gyro_axis_cal[1] /= 2000; //Divide the roll total by 2000.
gyro_axis_cal[2] /= 2000; //Divide the pitch total by 2000.
gyro_axis_cal[3] /= 2000; //Divide the yaw total by 2000.
69
PCMSK0 |= (1 << PCINT0); //Set PCINT0 (digital input 8) to
trigger an interrupt on state change.
PCMSK0 |= (1 << PCINT1); //Set PCINT1 (digital input 9)to
trigger an interrupt on state change.
PCMSK0 |= (1 << PCINT2); //Set PCINT2 (digital input 10)to
trigger an interrupt on state change.
PCMSK0 |= (1 << PCINT3); //Set PCINT3 (digital input 11)to
trigger an interrupt on state change.
//Wait until the receiver is active and the throtle is set to the lower position.
while(receiver_input_channel_3 < 990 || receiver_input_channel_3 > 1020 ||
receiver_input_channel_4 < 1400){
receiver_input_channel_3 = convert_receiver_channel(3); //Convert the actual
receiver signals for throttle to the standard 1000 - 2000us
receiver_input_channel_4 = convert_receiver_channel(4); //Convert the actual
receiver signals for yaw to the standard 1000 - 2000us
start ++; //While waiting increment start whith every
loop.
//We don't want the esc's to be beeping annoyingly. So let's give them a 1000us puls while
waiting for the receiver inputs.
PORTD |= B11110000; //Set digital poort 4, 5, 6 and 7
high.
delayMicroseconds(1000); //Wait 1000us.
PORTD &= B00001111; //Set digital poort 4, 5, 6 and 7
low.
delay(3); //Wait 3 milliseconds before the next loop.
if(start == 125){ //Every 125 loops (500ms).
digitalWrite(12, !digitalRead(12)); //Change the led status.
start = 0; //Start again at 0.
}
}
start = 0; //Set start back to 0.
70
void loop(){
//65.5 = 1 deg/sec (check the datasheet of the MPU-6050 for more information).
gyro_roll_input = (gyro_roll_input * 0.7) + ((gyro_roll / 65.5) * 0.3); //Gyro pid input is
deg/sec.
gyro_pitch_input = (gyro_pitch_input * 0.7) + ((gyro_pitch / 65.5) * 0.3);//Gyro pid input is
deg/sec.
gyro_yaw_input = (gyro_yaw_input * 0.7) + ((gyro_yaw / 65.5) * 0.3); //Gyro pid input is
deg/sec.
////////////////////////////////////////////////////////////////////////////////////////////////////
//This is the added IMU code from the videos:
//https://youtu.be/4BoIE8YQwM8
//https://youtu.be/j-kE0AMEWy4
////////////////////////////////////////////////////////////////////////////////////////////////////
//Place the MPU-6050 spirit level and note the values in the following two lines for
calibration.
angle_pitch_acc -= 0.0; //Accelerometer calibration value for
pitch.
71
angle_roll_acc -= 0.0; //Accelerometer calibration value for
roll.
//For starting the motors: throttle low and yaw left (step 1).
if(receiver_input_channel_3 < 1050 && receiver_input_channel_4 < 1050)start = 1;
//When yaw stick is back in the center position start the motors (step 2).
if(start == 1 && receiver_input_channel_3 < 1050 && receiver_input_channel_4 > 1450){
start = 2;
//The PID set point in degrees per second is determined by the roll receiver input.
//In the case of deviding by 3 the max roll rate is aprox 164 degrees per second ( (500-8)/3 =
164d/s ).
pid_roll_setpoint = 0;
//We need a little dead band of 16us for better results.
72
if(receiver_input_channel_1 > 1508)pid_roll_setpoint = receiver_input_channel_1 - 1508;
else if(receiver_input_channel_1 < 1492)pid_roll_setpoint = receiver_input_channel_1 -
1492;
//The PID set point in degrees per second is determined by the pitch receiver input.
//In the case of deviding by 3 the max pitch rate is aprox 164 degrees per second ( (500-8)/3
= 164d/s ).
pid_pitch_setpoint = 0;
//We need a little dead band of 16us for better results.
if(receiver_input_channel_2 > 1508)pid_pitch_setpoint = receiver_input_channel_2 - 1508;
else if(receiver_input_channel_2 < 1492)pid_pitch_setpoint = receiver_input_channel_2 -
1492;
//The PID set point in degrees per second is determined by the yaw receiver input.
//In the case of deviding by 3 the max yaw rate is aprox 164 degrees per second ( (500-8)/3 =
164d/s ).
pid_yaw_setpoint = 0;
//We need a little dead band of 16us for better results.
if(receiver_input_channel_3 > 1050){ //Do not yaw when turning off the motors.
if(receiver_input_channel_4 > 1508)pid_yaw_setpoint = (receiver_input_channel_4 -
1508)/3.0;
else if(receiver_input_channel_4 < 1492)pid_yaw_setpoint = (receiver_input_channel_4 -
1492)/3.0;
73
//0.09853 = 0.08 * 1.2317.
battery_voltage = battery_voltage * 0.92 + (analogRead(0) + 65) * 0.09853;
if (battery_voltage < 1240 && battery_voltage > 800){ //Is the battery
connected?
esc_1 += esc_1 * ((1240 - battery_voltage)/(float)3500); //Compensate the esc-1
pulse for voltage drop.
esc_2 += esc_2 * ((1240 - battery_voltage)/(float)3500); //Compensate the esc-2
pulse for voltage drop.
esc_3 += esc_3 * ((1240 - battery_voltage)/(float)3500); //Compensate the esc-3
pulse for voltage drop.
esc_4 += esc_4 * ((1240 - battery_voltage)/(float)3500); //Compensate the esc-4
pulse for voltage drop.
}
else{
esc_1 = 1000; //If start is not 2 keep a 1000us pulse for
ess-1.
74
esc_2 = 1000; //If start is not 2 keep a 1000us pulse for
ess-2.
esc_3 = 1000; //If start is not 2 keep a 1000us pulse for
ess-3.
esc_4 = 1000; //If start is not 2 keep a 1000us pulse for
ess-4.
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//Creating the pulses for the ESC's is explained in this video:
//https://youtu.be/fqEkVcqxtU8
////////////////////////////////////////////////////////////////////////////////////////////////////
//! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
//Because of the angle calculation the loop time is getting very important. If the loop time is
//longer or shorter than 4000us the angle calculation is off. If you modify the code make sure
//that the loop time is still 4000us and no longer! More information can be found on
//the Q&A page:
//! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
//There is always 1000us of spare time. So let's do something usefull that is very time
consuming.
//Get the current gyro and receiver data and scale it to degrees per second for the pid
calculations.
gyro_signalen();
75
if(timer_channel_1 <= esc_loop_timer)PORTD &= B11101111; //Set digital
output 4 to low if the time is expired.
if(timer_channel_2 <= esc_loop_timer)PORTD &= B11011111; //Set digital
output 5 to low if the time is expired.
if(timer_channel_3 <= esc_loop_timer)PORTD &= B10111111; //Set digital
output 6 to low if the time is expired.
if(timer_channel_4 <= esc_loop_timer)PORTD &= B01111111; //Set digital
output 7 to low if the time is expired.
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This routine is called every time input 8, 9, 10 or 11 changed state. This is used to read the
receiver signals.
//More information about this subroutine can be found in this video:
//https://youtu.be/bENjl1KQbvo
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ISR(PCINT0_vect){
current_time = micros();
//Channel 1=========================================
if(PINB & B00000001){ //Is input 8 high?
if(last_channel_1 == 0){ //Input 8 changed from 0 to 1.
last_channel_1 = 1; //Remember current input state.
timer_1 = current_time; //Set timer_1 to current_time.
}
}
else if(last_channel_1 == 1){ //Input 8 is not high and changed
from 1 to 0.
last_channel_1 = 0; //Remember current input state.
receiver_input[1] = current_time - timer_1; //Channel 1 is current_time -
timer_1.
}
//Channel 2=========================================
if(PINB & B00000010 ){ //Is input 9 high?
if(last_channel_2 == 0){ //Input 9 changed from 0 to 1.
last_channel_2 = 1; //Remember current input state.
timer_2 = current_time; //Set timer_2 to current_time.
}
}
else if(last_channel_2 == 1){ //Input 9 is not high and changed
from 1 to 0.
last_channel_2 = 0; //Remember current input state.
receiver_input[2] = current_time - timer_2; //Channel 2 is current_time -
timer_2.
}
//Channel 3=========================================
if(PINB & B00000100 ){ //Is input 10 high?
if(last_channel_3 == 0){ //Input 10 changed from 0 to 1.
last_channel_3 = 1; //Remember current input state.
76
timer_3 = current_time; //Set timer_3 to current_time.
}
}
else if(last_channel_3 == 1){ //Input 10 is not high and changed
from 1 to 0.
last_channel_3 = 0; //Remember current input state.
receiver_input[3] = current_time - timer_3; //Channel 3 is current_time -
timer_3.
}
//Channel 4=========================================
if(PINB & B00001000 ){ //Is input 11 high?
if(last_channel_4 == 0){ //Input 11 changed from 0 to 1.
last_channel_4 = 1; //Remember current input state.
timer_4 = current_time; //Set timer_4 to current_time.
}
}
else if(last_channel_4 == 1){ //Input 11 is not high and changed
from 1 to 0.
last_channel_4 = 0; //Remember current input state.
receiver_input[4] = current_time - timer_4; //Channel 4 is current_time -
timer_4.
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Subroutine for reading the gyro
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void gyro_signalen(){
//Read the MPU-6050
if(eeprom_data[31] == 1){
Wire.beginTransmission(gyro_address); //Start communication with
the gyro.
Wire.write(0x3B); //Start reading @ register 43h and auto
increment with every read.
Wire.endTransmission(); //End the transmission.
Wire.requestFrom(gyro_address,14); //Request 14 bytes from the
gyro.
77
while(Wire.available() < 14); //Wait until the 14 bytes are
received.
acc_axis[1] = Wire.read()<<8|Wire.read(); //Add the low and high byte
to the acc_x variable.
acc_axis[2] = Wire.read()<<8|Wire.read(); //Add the low and high byte
to the acc_y variable.
acc_axis[3] = Wire.read()<<8|Wire.read(); //Add the low and high byte
to the acc_z variable.
temperature = Wire.read()<<8|Wire.read(); //Add the low and high byte
to the temperature variable.
gyro_axis[1] = Wire.read()<<8|Wire.read(); //Read high and low part of
the angular data.
gyro_axis[2] = Wire.read()<<8|Wire.read(); //Read high and low part of
the angular data.
gyro_axis[3] = Wire.read()<<8|Wire.read(); //Read high and low part of
the angular data.
}
if(cal_int == 2000){
gyro_axis[1] -= gyro_axis_cal[1]; //Only compensate after the
calibration.
gyro_axis[2] -= gyro_axis_cal[2]; //Only compensate after the
calibration.
gyro_axis[3] -= gyro_axis_cal[3]; //Only compensate after the
calibration.
}
gyro_roll = gyro_axis[eeprom_data[28] & 0b00000011]; //Set gyro_roll to the
correct axis that was stored in the EEPROM.
if(eeprom_data[28] & 0b10000000)gyro_roll *= -1; //Invert gyro_roll if the
MSB of EEPROM bit 28 is set.
gyro_pitch = gyro_axis[eeprom_data[29] & 0b00000011]; //Set gyro_pitch to
the correct axis that was stored in the EEPROM.
if(eeprom_data[29] & 0b10000000)gyro_pitch *= -1; //Invert gyro_pitch if the
MSB of EEPROM bit 29 is set.
gyro_yaw = gyro_axis[eeprom_data[30] & 0b00000011]; //Set gyro_yaw to the
correct axis that was stored in the EEPROM.
if(eeprom_data[30] & 0b10000000)gyro_yaw *= -1; //Invert gyro_yaw if the
MSB of EEPROM bit 30 is set.
78
if(eeprom_data[30] & 0b10000000)acc_z *= -1; //Invert acc_z if the MSB
of EEPROM bit 30 is set.
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Subroutine for calculating pid outputs
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//The PID controllers are explained in part 5 of the YMFC-3D video session:
//https://youtu.be/JBvnB0279-Q
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void calculate_pid(){
//Roll calculations
pid_error_temp = gyro_roll_input - pid_roll_setpoint;
pid_i_mem_roll += pid_i_gain_roll * pid_error_temp;
if(pid_i_mem_roll > pid_max_roll)pid_i_mem_roll = pid_max_roll;
else if(pid_i_mem_roll < pid_max_roll * -1)pid_i_mem_roll = pid_max_roll * -1;
pid_last_roll_d_error = pid_error_temp;
//Pitch calculations
pid_error_temp = gyro_pitch_input - pid_pitch_setpoint;
pid_i_mem_pitch += pid_i_gain_pitch * pid_error_temp;
if(pid_i_mem_pitch > pid_max_pitch)pid_i_mem_pitch = pid_max_pitch;
else if(pid_i_mem_pitch < pid_max_pitch * -1)pid_i_mem_pitch = pid_max_pitch * -1;
pid_last_pitch_d_error = pid_error_temp;
//Yaw calculations
pid_error_temp = gyro_yaw_input - pid_yaw_setpoint;
pid_i_mem_yaw += pid_i_gain_yaw * pid_error_temp;
if(pid_i_mem_yaw > pid_max_yaw)pid_i_mem_yaw = pid_max_yaw;
else if(pid_i_mem_yaw < pid_max_yaw * -1)pid_i_mem_yaw = pid_max_yaw * -1;
pid_last_yaw_d_error = pid_error_temp;
79
}
//This part converts the actual receiver signals to a standardized 1000 – 1500 – 2000
microsecond value.
//The stored data in the EEPROM is used.
int convert_receiver_channel(byte function){
byte channel, reverse; //First we declare some local
variables
int low, center, high, actual;
int difference;
void set_gyro_registers(){
80
//Setup the MPU-6050
if(eeprom_data[31] == 1){
Wire.beginTransmission(gyro_address); //Start communication with
the address found during search.
Wire.write(0x6B); //We want to write to the
PWR_MGMT_1 register (6B hex)
Wire.write(0x00); //Set the register bits as 00000000 to
activate the gyro
Wire.endTransmission(); //End the transmission with the
gyro.
//Let's perform a random register check to see if the values are written correct
Wire.beginTransmission(gyro_address); //Start communication with
the address found during search
Wire.write(0x1B); //Start reading @ register 0x1B
Wire.endTransmission(); //End the transmission
Wire.requestFrom(gyro_address, 1); //Request 1 bytes from the
gyro
while(Wire.available() < 1); //Wait until the 6 bytes are
received
if(Wire.read() != 0x08){ //Check if the value is 0x08
digitalWrite(12,HIGH); //Turn on the warning led
while(1)delay(10); //Stay in this loop for ever
}
81
Wire.endTransmission(); //End the transmission with the
gyro
}
}
float rangeControl(float input){
float output=map(input,-164,164,-30,30);
if(input>(float)maxInput){
output=(float)maxInput;
}else if (output<(float)minInput){
output=(float)minInput;
}
return output;
}
82
APPENDIX B (GPS CODES)
TRANSMITTER
/*
* Rui Santos
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <SoftwareSerial.h>
int i = 0;
void splitmsg(const char *msg, const int arraySize, const int len){
Serial.println(arraySize);
byte P_iterator = 0;
83
if (arraySize % len > 0)
numPackets++;
Serial.print("num_Packets: ");
Serial.println(numPackets);
char t[len+1];
t[len] = '\0';
Serial.println(t);
radio.write(&t, sizeof(t));
P_iterator++;
void setup(){
pinMode(10, OUTPUT);
Serial.begin(115200);
ss.begin(9600);
Serial.flush();
Serial.print("Starting up\n");
radio.begin();
84
radio.openWritingPipe(address);
// radio.setChannel(0x76);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
radio.stopListening();
// radio.enableDynamicPayloads();
// radio.powerUp();
Serial.println("Starting to send");
void loop(){
// Serial.println(ss.available());
// radio.write(&text, sizeof(text)) ;
// Serial.println("Sending");
byte gpsd[sizebuf];
// // char gpsData;
in_loop = true;
gpsd[i] = gpsData;
85
i += 1;
// if (i < (sizebuf)){
// i += 1;
// }else{
// // Serial.print();
// Serial.print(gpsd[j]);
// }
// Serial.println(i);
// i = 0;
if (i != 0){
// Serial.print();
Serial.print((char)gpsd[j]);
86
Serial.println(i);
radio.write(&gpsd, i);
// delay(100);
i = 0;
//
// Serial.println(" here");
// Serial.println();
// radio.write((String)gpsd, sizeof(gpsd));
// }
RECEIVER
87
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//struct dataStruct{
// double latitude;
// double longitude;
//}gpsData;
void setup() {
pinMode(10, OUTPUT);
Serial.begin(115200);
radio.begin();
radio.openReadingPipe(1, address);
// radio.setChannel(0x76);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
radio.startListening();
// radio.enableDynamicPayloads();
88
// radio.powerUp();
Serial.println("Starting..");
Serial.println("Starting..dc");
void loop() {
// Serial.println(radio.available());
if (radio.available())
byte buf[32];
radio.read(&buf, sizeof(buf));
Serial.write(buf, 32);
// delay(100);
// el{
// Serial.println("No radio") ;
// }
89
APPENDIX C (LIST OF ITEMS ORDERED)
90