SlideShare a Scribd company logo
1 of 174
Download to read offline
Unmanned Aerial Vehicle




Arab Academy for Science and Technology and
           Maritime Transport

                  College of Engineering and Technology
                   Department of Computer Engineering




        UNMANNED AERIAL VEHICLE
                (UAV)

 Presented by:
            Alexander Mohamed Osman
            Riyad Ahmed El-laithy
            Ruyyan Ahmed El-laithy
            Peter Raouf Zaky


 Supervised by:
            Dr. Ibrahim Imam

                               ((July 2007))
                                                          Page 1
Unmanned Aerial Vehicle



                     ACKNOWLEDGEMENTS

          After thanking God the Merciful we would like to send our thanks to the following
people:


          Firstly we would like to thank Dr. Ibrahim Imam for proposing the idea of an
Unmanned Aerial Vehicle and for accepting us to carry on that project.


          Secondly we would like to thank Dr. Atallah Hashad for giving us a helping hand
whenever we needed one and for providing us with solutions for all the challenges we
faced.


          We would like to thank Dr. Hassan Ibrahim for providing us with help with the
electrical problems we faced in our circuits.


          We would also like to thank Dr. Gamal Selim for his encouragement, assistance and
understanding.


          We would like to thank Dr. Yasser Galal for answering some questions we had
about DC motors.


          We would also like to thank Eng. Ahmed Akl, Eng. Renad Kamal, Muhab Bahgat,
Ruyhan El-Laithy, Fady Mounier, Beshoy Helmy, Todd Elliot, and Sparkfun Electronics
for supporting us and/or making this possible.


          Last but not least we would like to thank our parents & families for their love,
support, and understanding.




                                                                                     Page 2
Unmanned Aerial Vehicle



                                  ABSTRACT

       Gathering information from locations which are inhabitable, hostile, or difficult to
reach is a crucial aspect for learning new information about unmarked territories and
activities and aids in human technological advancement. This project is concerned with
developing an agent for gathering visual information by holding a stationary position or
pursuing a dynamic target. The agent is a quadrotor VTOL (Vertical Take Off and
Landing) aircraft. This agent should have the capability to hover, fly and follow targets. It
should receive and transmit data wirelessly into a base station. It should move through a
predefined plan using a GPS receiver. It should also balance itself in the air through a
gyrometer and an accelerometer. In addition it would utilize four ultrasonic sensors for
obstacle avoidance and an extra one for landing assistance. The agent would also utilize a
wireless camera to transmit a bird s eye view to the base station.




                                                                                           Page 3
Unmanned Aerial Vehicle

                 TABLE OF CONTENTS

1. INTRODUCTION                                                             .......................7


2. CONCEPTUAL DESIGN & PHYSICAL ASSEMBLY                                      ..                 12


3. ANALYSIS, COMPONENT-LEVEL DESIGN & SELECTION                                                 .18
     3.1 Major Components                                                                      ..18
     3.2 PCB Design ..                                                                    .......25
            3.2.1 Interface Boards                                                            ...27
                     3.2.1.1    GPS interface board                                            .27
                     3.2.1.2    Accelerometer / Gyrometer interface board         ................28
                     3.2.1.3    RF Interface boards 24-G                     ..      ............28
            3.2.2 Motor Driver                                                                  29
            3.2.3 The Brain..                                                                ...31


4. CONTROL                                                                                       33
     4.1 Introduction                                                                   .........33
     4.2 SPI communication                                                                      .35
     4.3   Main PIC Implementation                                                ................38
            4.3.1 Pulse Width Modulation (Motors)                                             ...38
            4.3.2 ADC Operation                                                      ............43
                     4.3.2.1 Ultrasonic Sensors                                                 50
                     4.3.2.2 Gyrometer              ..                                       ...52
                     4.3.2.3 Accelerometer      .                                              ..52
     4.4   Secondary PIC Implementation                                                    ......55
            4.4.1 GPS System                                                                   .55
            4.4.2 RF Transceiver                                                                .66
     4.5   RC Unit                                                                         ......75




                                                                                            Page 4
Unmanned Aerial Vehicle
5. TESTING TROUBLESHOOTING AND REDESIGN                                                78
     5.1 Testing                                                                     ..78
                    5.1.1 LED Testing                                                ..78
                    5.1.1.1 Accelerometer Testing                                    ..78
                    5.1.1.2 Gyrometer Testing                                          78
                    5.1.1.3 SPI Testing                                                79
                    5.1.1.4 RC unit testing                          ..................79
           5.1.2    LCD Testing                                                      ..80
                    5.1.2.1 Ultrasonic testing       .                               ..81
                    5.1.2.2 Accelerometer Testing    .                               ..81
                    5.1.2.3 RC unit Testing              .               ................82
                    5.1.2.4 GPS Testing                      .                        .83
           5.1.3 RF Testing                      .           .                       .83
                    5.1.3.1 Ultrasonic Testing               .                        83
                    5.1.3.2 Gyro Testing                     .                        83
                    5.1.3.3 RC Unit                          .                        85
     5.2 Previous Chassis designs                                .                  ...88
     5.3 RF Drivers                                                  .            .....90
           5.3.1 Laipac RF TX/RX                                                   ...90
     5.4 Configuration 1                                                        ......92
     5.5 Configuration 2                                                            ..96
     5.6 Brain #3                                                                .....99
     5.7 Correcting Gyro Output                                                      100


6. FUTURE IMPLEMENTATIONS                                                          ..102


7. CONCLUSION                                                                  .......103




                                                                                  Page 5
Unmanned Aerial Vehicle
APPENDIX A : COMPONENT DATABASE AND CHARACTERISTICS   .    .104


APPENDIX B : CONTROL CODE                       .          106


APPENDIX C : WEIGHT & THRUST CHARTS   ..    .               165


APPENDIX D : LITHIUM POLYMER BATTERY CARE                  .167


APPENDIX E : ICSP PROGRAMMING                              .169


APPENDIX F : REFERENCES                                    .170


APPENDIX G : BIBLIOGRAPHY                                 ..173




                                                          Page 6
Unmanned Aerial Vehicle

                           INTRODUCTION

       The rapid development of micro-processor technology and the continuous growth of
integration density of electronical and mechatronical components yields a significant cost
reduction of high tech products. Driven by this development it becomes feasible to embed
information processing and communicating devices in all sorts of appliances, toys,
production facilities, communication systems, traffic and transport systems etc.


       With this integration and the aid of global positioning systems, there has been a
surge of development in Unmanned Vehicles (UV). The main benefits of UV s are that
they do not require human control and thus can be reduced in size and cost. They also limit
human error in several aspects, and reduce if not eliminate human endangerment.
Unmanned vehicles are developed for use in air, over land and under water by both private
and government agencies. Several unmanned systems exist such as Autonomous
Underwater Vehicles (AUV), Unmanned Ground Vehicle (UGV), and Unmanned Combat
Vehicles (UCV). NASA deploys USVs (Unmanned Space Vehicles) on rock gathering
missions from the Moon and Mars. The military advanced UAVs and renamed them to
UAVS (Unmanned Aerial Vehicle Systems) and are used in flight combat.


       Government search and rescue departments find the UAVs helpful in inhabitable or
hazardous terrain such as earthquakes, floods or volcanoes, where no human lives have to
be risked. Institutions which have onsite geologists use UAVs for uncovering terrain and
rock identification, without having to deploy a whole crew working outside. Departments
of transportation can use this device to cover footage of inaccessible situations such as
dead-lock traffic jams or multiple car-crashes. Government law enforcement and
intelligence agencies can specifically find this device useful for reconnaissance and target
pursuance, where the UAV provides the advantages of cheap costs, stealth and a
diminished human risk factor.


       The Unmanned Aerial Vehicle project has been an ongoing attempt to produce a
reliable autonomous hovering or flying vehicle. The project designed and implemented a
four-rotor hovering aerial vehicle. The advantages of a hovering vehicle over a fixed-wing
                                                                                     Page 7
Unmanned Aerial Vehicle
flying vehicle include less complexity in design, minimal space for take-off and landing
(vertical take-off and landing (VTOL)), indoor flight, maneuverability in obstacle heavy
environments and of course the eye-catching ability of being able to maintain a static
position in mid-air.


       The advantage of quadrotors over helicopters is that they do not require mechanical
linkages to vary rotor angle of attack as they spin, this simplifies design and control. The
use of four rotors allows each individual rotor to have a smaller diameter than the
equivalent helicopter rotor, for a given vehicle size, allowing them to store less kinetic
energy during flight. These smaller propellers reduce the damage caused should the rotors
hit any objects, this also makes the vehicles safer to interact with in close proximity.


       The first RC application of a 4-rotor vehicle was the Roswell Flyer made by Area51
technologies. Now there are several commercially available quadrotor aerial vehicles, to list
a few, Atair aerospace quadcopter , Hammacher Schlemmer four rotor UFO , Keyence
Engager and gyrosaucer and the DraganFlyer V Ti . The team s design was inspired by
the DraganFlyer V, made by Draganfly Innovations Inc. where the four motors and props
are laid at the ends of an X Chassis, and in the center lay the majority of the circuit boards
and microprocessor dubbed by DraganFlyer Inc. as The Brain . (See figure below)




                                                                                           Page 8
Unmanned Aerial Vehicle
System Block Diagram




        A general control scheme can be seen in the diagram above. The controller block is
composed of two communicating MCU s (MicroController Units). The main MCU does
most of the calculations and decision making. The main MCU also receives inputs from the
proximity sensors and stability sensors, while the secondary MCU is responsible for
communicating with a GPS receiver for positioning and an RF module for wireless
communication. Both MCU s then drive the outputs for the four motors together.


        The stability sensors block consists of a 3-axis Gyrometer for angular velocity
measurement and a 3-axis accelerometer for measuring acceleration. The proximity sensors
block consists of 5 ultrasonic sensors placed around the vehicle and under it, for obstacle
avoidance and assisted landing.


        The GPS receiver block consists of a GPS module that provides position, velocity,
heading and altitude readings. The RF transceiver block consists of a 2.4GHz RF Module
that communicates bi-directionally with a remote control unit for sending and receiving
data.




                                                                                    Page 9
Unmanned Aerial Vehicle
        The Motor block consists of 4 high powered brushed motors with a gear ratio of
5.33:1 and 10x4.5 propellers. Both of these features provide a high thrust vehicle (As
opposed to high speed). These motors are controlled through switching transistor circuits
using PWM (Pulse Width Modulation).


        The UAV works in three different modes, in the simplest mode a land based PC
sends out signals through an RF transceiver in order to steer the UAV in different
directions. In the second mode a land based PC receives images from an onboard camera,
then a pattern recognition system identifies a target object and sends signals to the UAV
through the RF transceiver to steer it toward the desired object. If the object is not found the
UAV rises in altitude quickly in order to find the object and re-track it. The third mode uses
an onboard GPS that gives the current position of the UAV and it compares that to its target
destination, and steers to its target destination then comes back to its initial point. In all
modes an accelerometer and gyrometer are used to provide stability, and ultrasonic sensors
are used to measure height and avoid obstacles and in turn to steer the UAV away from
them.


        Because of the ambitious nature of the project, the team decided to build the UAV
from ground up. Development of our 4-rotor vehicle can be divided into four major
branches.


1. Conceptual Design and Physical Assembly.
2. Analysis, component-level design & selection.
3. Control.
4. Testing, Troubleshooting & Redesign.


        Although these four stages overlapped and interfered with one another they can be
discussed independently, without much referencing to other sections.




                                                                                        Page 10
Unmanned Aerial Vehicle

     CONCEPTUAL DESIGN & PHYSICAL
                                  ASSEMBLY

       The conceptual design as stated previously was inspired by the DraganFlyer, and
the team s first step was to identify the design goals. These were the fundamental
requirements the team decided upon:


       1. Ability to hover, in the sense of generating enough thrust and have enough
           control in order to maintain a mid-air static position.
       2. Maneuverability in all directions of a three-dimensional plane.
       3. Sufficient endurance of no less than 10-15 minutes.
       4. A very light-weight body, including a battery with the highest power to weight
           ratio we could find since the battery is the heaviest single component of the
           vehicle.
       5. High residual thrust to hover thrust ratio, an acrobatic vehicle was desirable for
           ability to demonstrate controllability and to perform difficult flight maneuvers.
       6. Minimal size & complexity.


       The team decided to stick very close to traditional designs of 4-rotor vehicles, where
four electric motors are placed on the corners of a rectangle, and drive four counter-rotating
propellers. These propellers would produce sufficient thrust for take-off, and according to
their different allocated power distributed on the four motors would provide
maneuverability. Any propeller spinning produces a torque on the body it is attached to. For
stability in flight the total resulting differential torque on the body should be zero. This is
demonstrated very clearly in helicopters. The main rotor on the roof of the helicopter
produces a large yaw torque on the body which is countered by the tail rotor on the rear of
the plane. Assuming the main rotor is on a constant rpm, the difference in power to the rear
propeller moves the helicopter around the z-axis.




                                                                                       Page 11
Unmanned Aerial Vehicle




       The proper rotation of the propellers, goes such as any two adjacent propellers
rotate in opposite directions, and any two diagonal propellers rotate in the same direction.
The sum of rotations of any two diagonal propellers should equal the sum of the remaining
two diagonal propellers. This makes the total differential torque on the body about the z-
axis zero. The figure below demonstrates the prop rotation direction.




       At hover mode, all four propellers would be producing the same amount of torque
resulting in zero-net force on the vehicle about any-axis once gravity is taken into account.
To make the vehicle increase or decrease in altitude, the speed on all four propellers are
increased or decreased respectively. In order to move the vehicle in any direction of the x
or y axis, two propellers adjacent propellers are increased in thrust, this causes the vehicle
to pitch or roll in the desired direction, since the sum of the any two diagonal rotors is still
the same as their other diagonal pair, this prevents the vehicle from yawing in any direction
other than the desired course. Assuming the vehicle is in hover mode the following table
yields a summary of the vehicle control scheme. Use the previous figure for propeller
reference.

                                                                                        Page 12
Unmanned Aerial Vehicle


                         Propeller 1       Propeller 2       Propeller 3        Propeller 4
  Z+ (Up)            +                 +                 +                  +
  Z- (Down)          -                 -                 -                  -
  X+ (Left)          +                 0                 0                  +
  X- (Right)         0                 +                 +                  0
  Y+ (Forward)       +                 +                 0                  0
  Y- (Backward)      0                 0                 +                  +


       As stated earlier, a lightweight body was a must in order to achieve maximum thrust
for ease of flight and acrobatic maneuvers. For the chassis of the plane carbon-fiber was
used, a very stiff and lightweight material, with a variety of practical uses commonly used
in racecars and RC planes for their unique characteristics. To save even more weight we
used the X-chassis design, where four motors would be placed on every end of the X-
chassis. This would also give a better chance for the high pressure to accumulate and
increase under the blade of the propellers to give higher lift than in a rectangular design. It
would also reduce the overall air resistance. The arms of the X-chassis were made from
hollow carbon-fiber tubes, and at the end of the tubes the motor mounts were placed. They
were welded together using a common adhesive known to the RC world as Epoxy .


       On the bottom of the X-chassis the battery was mounted, keeping the battery on a
lower point would lower the center of gravity of the vehicle giving the vehicle smoother
pitching and rolling. On the four battery sides four ultrasonic sensors would be placed for
obstacle avoidance. On the bottom of the battery the fifth ultrasonic sensor was placed to
determine height, along with the wireless camera placed for surveillance purposes, video or
image capturing.


       On the top of the X-chassis the UAV brain board was placed. It carries the
accelerometer, gyrometer, RF Transceiver, GPS, motor controllers, ultrasonic sensors
connections, and of course the Microcontrollers. The following figure below displays the
chassis.



                                                                                        Page 13
Unmanned Aerial Vehicle
       After going through the design and experimentation of three different prototypes
(found in 5.2 Previous Chassis designs). One of the most difficult tasks for us, that
absorbed most of our time was coming up with the chassis that can have completely
reduced air resistance, maximized technical output power when compared to theoretical
power of the DC Brushed Motors involved, uniform density, and as extremely lightweight
as possible with all the components that we have had to add on the UAV. The net weight on
the UAV including all added components added up 990g when measured on the scale,
which is almost 1 Kg. The theoretical output power given to us by the DC Brushed Motors
added to up to a maximum thrust of 390 grams per motor. (See APPENDIX C) Since we
have 4 motors on the UAV, the complete output power given by those motors is 1560
grams (1.56Kg). Technically, the team managed to output only around 350 grams per
motor, adding up to 1400 grams (1.40Kg) of thrust. The efficiency of our design brought us
89.74% of that power. The loss in power comes up to 10.26% due to friction forces, and
minimized air resistance.
       It is made mostly out of lightweight Carbon Fiber and Balsa Wood for the base of
the electrical circuit. The total weight of the chassis without all the components comes to 43
grams. A CAD model was designed, shown in the following figures. An isometric view is
shown below, and the dimensions of the chassis design are shown in the next few pages.




                                                                                      Page 14
Unmanned Aerial Vehicle
Top View:




Front View:




Right Side View:




                                             Page 15
Unmanned Aerial Vehicle

Calculations:

Motor Force:


         Max OutputTheoretical/Ideal           = 390 grams/Motor
         Max OutputTechnical                   = 350 grams/Motor


Therefore, the Total Motor Output of 4 Motors at Full Power:
         Max Output4Motors                     = 1400 grams/4 Motors
         Maximum Payload                       = 1400     990 = 410 grams


Hence,
         Max Output in Newtons = 1400 x 9.807 = 13.730 Newtons
         Max Output per Motor = 13.730/4 = 3.432 Newtons


Net Force:


Therefore, Lift of Chassis at Full Power and when Differential Torque = 0.
         Chassis mass = 990 grams = 0.99 Kg
         Chassis weight = 0.99 Kg x 9.807 m/s2 = 9.709N
         Lift = 13.730     9.709 = 4.021 Newtons


Acceleration:


Net Force        =        Lift - Gravity
                 =        ma mg
4.021            =        13.730       9.709
0.99a =          1.4(9.807) 0.99(9.807)
a                = (0.41(9.807)) / 0.99
acceleration     = 4.061m/s2
Therefore, the Power to Weight Ratio:                   1.5 : 1
Therefore, Lateral Thrust beyond Hover thrust = (4.061m/s2) / (9.807m/s2) = 0.4141g

                                                                                  Page 16
Unmanned Aerial Vehicle




Torque:




   = Acceleration / Distance to Center

   = 4.061 m/s2 / 0.14m = 29.007 rad/sec2

  = mass * radius2 * (angular velocity) = (0.495) x (0.14) 2 (29.007)
; where (0.99/2 Motors = 0.495 grams, since it takes 2 motors for the UAV to move front, back, left or right).

  = 0.2814 Newtons

 MAX =     4.061 x 0.14 = 0.56854 Newtons
           A picture of the UAV with complete physical assembly can be seen below in the
following figure.




                                                                                                                 Page 17
Unmanned Aerial Vehicle

ANALYSIS, COMPONENT-LEVEL DESIGN
                              & SELECTION

3.1 Major Components :


       The selection of the motors were brushed motors the GWS EPS-350C with a
gearing ratio of 5.33:1, which peak out at 8.0V and 8.0A, each of these weigh 63g and are
projected to deliver 15.37oz (435.73g) of thrust at peak power. Four of these motors are
used, with one on each end of the X -chassis. A figure is placed below.




       Counter-rotating propellers were selected as our default propellers, which are a must
in any quadrotor plane, because motors do not turn in the same direction. We selected
10*4.5 propellers which are large considered for our motor. Larger propellers are more
suitable for high thrust application, and smaller rotors are more suitable for high velocity
and aerodynamic capabilities. Our choice was the EPP1045 propeller. A figure of the
propeller is placed below.




                                                                                    Page 18
Unmanned Aerial Vehicle
       Heat syncs were also used to cool down the motors to increase durability and
efficiency as well as to dissipate the heat created by the motors for a longer, more durable
life. The team selected EHS300 an aluminum, multi-fin heat sync for good heat dissipation
and proper venting respectively. The heat sync has two large fins and 24 smaller fins. A
figure of the heat sync is placed below.




       We needed a battery source that can provide more than 32A continuously,
considering each motor can consume 8A, the battery of choice was a Lithium-polymer
Thunder Power TP8000-2S4P two-cell 7.4V, 8AH battery. It can work continuously at 12C
(96A), and can burst at 18C (144A) which is more than sufficient to have all motors
working at full thrust. With a weight of 320 grams and dimensions of 128*50*29mm it had
a high power to weight ratio and size relative to its competitors. It would also give us about
a good 15 minutes of airtime if the UAV is flying at full power. A figure of the battery is
placed below.




                                                                                      Page 19
Unmanned Aerial Vehicle
       A compatible charger the Astro-flight 109D was selected. Charging rates from
50mA - 8A. Lithium polymer batteries can charge at a maximum of 1C of their rating, so
this charger can charge the battery in the fastest possible time which is 1 hour, for quick
practical testing. The battery is two cells, any battery with more than one cell requires a
balancer, so a blinky battery balancer was used which balances the cells before, after and
during recharge. A wattmeter was also required to measure the voltage and current of the
battery before and after recharge. A powerful and bulky power supply is required to
continuously deliver such current to the charger. The astro-flight power supply was used,
with an input of 110V/220V and an output of 13.5V, it delivers 12.5A. Figures of the
charger (top left), blinky battery balancer (top right), wattmeter (bottom left), and power
supply (bottom right) are placed below.




                                                                                        Page 20
Unmanned Aerial Vehicle
       The accelerometer used was the triple-axis ADXL-330. Works at 3.3V logic, and
consumes 0.32mA, it has three outputs for x, y and z axes. Minimum full scale range is
±3g, and a sensitivity of 300mV/g. The gyrometer used is the IDG-300 which also works at
3.0V logic and has a full scale range of 500°/sec, and consumes 9.5mA, but has only two
outputs, x and y. Because of this the team had to place two of these IC s onboard, to get
angular velocity about all three axes. Pictures of the accelerometer and gyrometer are
displayed below from left to right.




       The IMU five degrees of freedom is an IMU (Inertia Measurement Unit) that
combines the IDG300 gyrometer and an ADXL330 accelerometer. This unit measures x
and y angular velocity and x, y, z accelerometer outputs, hence the name 5 degrees of
freedom . Its advantages over two separate units are firstly that the x and y outputs of both
have identical headings, and you only have one VCC and one GND connection.
Disadvantages are if this IC for any reason becomes defective you lose two IC s. A figure
of this IC is displayed below.




                                                                                     Page 21
Unmanned Aerial Vehicle
        Ultrasonic sensors used were the Max sonar LV-EZ1 which work at 5.0V logic and
have a maximum range of 255in (6.45m), which measures in increments of an inch, they
have analog, digital and pulse width modulated outputs. It consumes 2mA. Five of these are
placed onboard, four facing x and y axes, in order to detect obstacles around the vehicle,
and one on the bottom of the battery facing downwards to detect height and aid in landing.
We could not rely on the altitude reading of the GPS system for height because there is an
error tolerance of ±5m, this could result in hazardous landings. The extra ultrasonic sensor
on the bottom would virtually eliminate that error because its resolution is relatively quite
high.




        For communication with ground, radio frequency IC s are used. The Laipac
TRF2.4-G transceiver was used. It operates at a high frequency, 2.4GHz. Data rate
transmission can work at either 250kbps or 1Mbps. It works at 3.0V logic consumes
10.5mA in TX mode and 18.5mA in RX mode. Maximum range is 280m. Each unit can
send and receive data interchangeably. One of the transceivers is placed onboard, and the
other is connected to a land-based PC, they send and receive data to and from each other.




                                                                                     Page 22
Unmanned Aerial Vehicle
         For unmanned guidance to different destinations a GPS system, the EM-406 was
used. Readings of latitude, longitude and altitude obtained serially are used to triangulate
the position of the IC. Power input is rated between 4.5V-6.5V and power consumption is
70mA, operating frequency is at 1.58GHz. A figure of the GPS is placed below.




jhnjh




         For the surveillance system the WS-309AS system was used, the package comes
with 1.2GHz camera with a resolution of 628*582 and a horizontal definition of 380 lines.
The camera works at 9.0V, and consumes 85mA. A simple 9V battery operates the camera.
The package also comes with a receiver with audio out and video out. Linear transmission
distance ranges from 50m-100m. A picture of the camera and components are placed
below.




                                                                                    Page 23
Unmanned Aerial Vehicle
      The selected PIC programmer was the Olimex PIC-MCP-USB programmer. It is a
low cost PICSTART alternative, is MPLAB compatible and thus does not require a RS232
port. In addition it has an ICSP (In Circuit Serial Programming) connector (ICSP
programming explained in APPENDIX E). A figure of the programmer is displayed below.




                                                                              Page 24
Unmanned Aerial Vehicle

3.2      PCB Design

       Required components for designing and etching a PCB are acetone, a laser printer,
glossy paper, a clothing iron, acid and a steel sponge. Firstly the surface of the brass board
is scrubbed with a steel sponge to remove any impurities and any oxidized brass. It is then
cleaned thoroughly with cotton drained in acetone. The team used the circuit designing
program called EAGLE 4.16r1 . Any circuit is printed on glossy paper, the printed glossy
paper is then well folded around the board to prevent any slip during ironing, then ironed
on the brass board. Ironing continues until the circuit becomes visible from the other side of
the printed glossy paper, or preferably when the white paper takes a yellowish/brownish
color indicating a slight burn. (Caution should be taken during ironing, if the brass board
becomes too hot, the brass actually deforms). After ironing, the paper should be removed
leaving the toner ink on the brass board. The brass board is then placed in the acid and left
until all brass surrounding the printed circuit is dissolved. After removing from acid and
rinsing in water, a steel sponge is gently scrubbed on the toner ink to leave the brass trace
under the toner ink while removing the ink. Holes are drilled into the circuit board in the
appropriate places where components are to be placed. After drilling is complete,
components are welded onto the board using solder and a soldering iron. All circuits used
for this project were designed in this manner. Pictures below (left to right) display this
procedure.
       Before these boards were actually designed they were tested on bread boards first in
order to assure everything is working in order, because making an incorrect PCB means
much wasted time and raw materials. More of this can be referenced in Section 7, Testing
troubleshooting and redesign.




                                                                                      Page 25
Unmanned Aerial Vehicle




                          Page 26
Unmanned Aerial Vehicle


3.2.1 Interface Boards


        Learning from previous errors we found it would be more convenient to create
interface boards for individual IC s rather than integrate them into one large circuit. (Much
the way a desktop motherboard uses PCI cards instead of making one large board.) This is
because if any errors occur in the design, or redesigning is desired, the individual IC s
wouldn t need to be removed. Frequently exposing IC s to strong heat when welding can
damage these components.


3.2.1.1 GPS Interface Board




        In his board the GPS cable is welded onto the left row of pins. The descending order
of these pins is; not used, GND, TX, RX, VIN, & GND, again. The first pin is ignored. The
second and last pins (both GND) connect to the right side second pin. The third pin TX
connects to the fourth pin on the right. The 4th pin on the left is RX that connects to the
third pin on the right.




                                                                                     Page 27
Unmanned Aerial Vehicle
3.2.1.2 Accelerometer / Gyrometer Interface Board




This follows the same method as the GPS interface board. The E$1 row is the yaw gyro,
E$2 row is the roll/pitch gyro. E$3 row is the three axis accelerometer. E$4 row is the pin
headers that connect onto the main board.



3.2.1.3        RF boards




The TRW-24G is a very sensitive component therefore we designed this interface board
with a TRW-24G socket for plug and play action onto the board.




                                                                                   Page 28
Unmanned Aerial Vehicle

3.2.2 Motor Drivers :

    Designing a suitable motor controller circuit was a challenging task, especially due to
the lack of components here in Egypt. The controlled motors could take up to 64 Ampere
bursts for a startup current and up to 8 Amperes as a continuous current. In order to achieve
maximum power we needed to cause a minimal voltage drop in our circuit. We came up
with the following design objectives:


- Switching speed of up to 2KHz (for PWM control)
- Minimum Vce drop possible for more powerful motors
- High current Ic
- Low current Ib


       Unfortunately the transistors fitting this description could not be found here in
Egypt, but we found a transistor 2SD1062. It is capable of running a current of up to 15A
and Vce of as low as 0.3V, but it needed a larger current for Ib than a PIC could provide,
therefore we added a TIP120 transistor as an interface between the PIC and the 2SD1062.
Since Vce of the 2SD1062 was a function of the Ic current we put 2 transistors in parallel to
drop the Vce as low as possible while at the same time assuring that it has enough capacity
to pass through the required current for the motor.


       A main feature of this circuit is the PC817 optocoupler, an IC that interfaces
between the PIC circuit and the motor circuit. Isolating these circuits was necessary
because combining high current components with low current ones can damage the low
current components. The optocoupler in the following diagram is labeled as 2. The left
side of the optocoupler is connected to the PIC circuit and the right side is connected to the
motor circuit. The first rows of pins in order are GND (PIC circuit), Vcc (PIC circuit), GND
(Motor circuit) and Vcc (Motor circuit). Vcc from PIC (PWM output) circuit goes through a
1.5K   resistor through optocouplers where the phototransistor is activated and returns to
the PIC ground. The signal in turn goes through the base of the TIP120 turning it on. The
emitter of the TIP120 connects to the base of the 2SD1062 transistors, whose collectors are



                                                                                      Page 29
Unmanned Aerial Vehicle
connected to the motor and the motor is connected to the Li-Poly battery. A circuit
schematic is shown below. Resistors were placed to produce desired voltage drops.




       In the final motor driver design, the optocoupler was removed from the motor driver
and put on the main brain. This was done in order to have smaller motor drivers, and to
have less connections between the main board and the motor driver. Also large motor
drivers facing upwards would make contact with revolving propellers, and if facing
downwards could cause noise with the ultrasonic sensors.




                                                                                     Page 30
Unmanned Aerial Vehicle

3.2.3         The Brain
        To avoid the mistakes that occurred in Configuration 2 mentioned in the Testing,
Troubleshooting & redesign section the team changed two things mainly. FirstlyTo avoid
the problem of circuit design or re-altering, it was decided that the IC s would be mounted
on separate boards that would mount on the main Brain board, much the way PCI slots
are mounted on a normal PC. In our previous design, should any circuit design errors occur,
a new board would have to be made, and all components would have to be welded off the
old board, and re-welded to the new brain. This takes a lot of time, and it is also potentially
damaging to the components to be frequently exposed to the welder. Secondly as for having
the problem of high power rated components alongside low power rated ones in one circuit,
optocouplers were used to interface between the Brain board and motor drivers, this is
more thoroughly explained in the previous section 4.6 Motor Drivers .




                                                                                       Page 31
Unmanned Aerial Vehicle




       This Main board was designed to accommodate two PIC16LF777s, 4 Motor
controller boards connected through 4 opto-couplers, a 3-axis accelerometer, 2 dual-axis
gyrometers, 5 ultrasonic sensors, a GPS receiver and a RF transceiver. To keep the circuit
as small as possible we used the internal 8MHz oscillators available in PIC16LF777 PICs
instead of adding more components to the circuit in the form of crystals and capacitors. The
circuit is powered by a 9V battery and has a 5V regulator as well as a 3V regulator for all
5V Logic components as well as the 3V Logic components to operate. We also added some
LEDs to simplify debugging. Later on we manually welded on some wires to two ICSP
connectors to program the two PICs without removing them from the circuit. (As seen in
the previous picture).



                                                                                      Page 32
Unmanned Aerial Vehicle

                                     CONTROL
4.1 Introduction

   The Main PIC is responsible for reading and calculating the orientation of the plane,
and accordingly take a decision. The Main PIC has only 3 PWM modules, therefore we use
an extra PWM from the Secondary PIC. The Main PIC sends commands to the Secondary
PIC to increase or decrease the power of one PWM output, it also sends the orientation data
to be sent through the RF to the base computer station. The Secondary PIC takes the GPS
messages and extracts the required values and sends them to the Main PIC, as well as
through the RF to the base station. Regarding the control scheme, there are four separate
operation modes:


1. Hover Mode
2. RC Mode
3. GPS Mode
4. Tracking Mode


In Hover Mode:
       Tries to keep the vehicle stable in position. The following pseudocode demonstrates
the operating algorithm.
Start up system
Read bias values from IMU sensors
Loop:
        Read sensors
        Calculate Angles & Height
        If(Height<Required Meters)
                   Increase PWM
        if(Height>Required Meters)
                   Decrease PWM
        if tilted left
                   Tilt right
        If tilted right
                   Tilt left
        If tilted forwards
                   Tilt backwards
        If tilted backwards
                   Tilt forwards
Repeat loop

                                                                                     Page 33
Unmanned Aerial Vehicle
In RC Mode:


       The Secondary PIC is the one that receives the RC commands through the RF, then
forwards them to the Main PIC to execute.


In GPS Mode:


       The Secondary PIC takes the GPS messages and extracts the required values and
sends it to the Main PIC, and it sends all other useful data through the RF to the base
station. The Main PIC takes decisions according to its coordinates achieved from the GPS
from the Secondary PIC.


In Tracking Mode:
       The base station receives the Video Feed from the Wireless Camera on board the
vehicle and searches for a blue target in view, if it is not found the vehicle will gain altitude
and search again. Once a target is found the plane will descend quickly and hover above the
target and keep following it. The Secondary PIC receives the commands from the base
station through RF and forwards the commands to the Main PIC which performs the
required actions.




                                                                                         Page 34
Unmanned Aerial Vehicle

4.2 SPI communication
       SPI communication enables quick communication between two PIC s. One is set as
a Master PIC and the other as a slave. Originally one PIC was intended to be used, but
failed. (refer to Testing, Troubleshooting & Design : Configuration 2). The connection is as
follows on the diagram below. The left block represents the Master PIC and the left block is
the slave. A bit is released from the Master SSPSR to SD0, and the slave PIC releases a bit
through it s SD0 also. The clocks SCK of both PICS are connected together. When a clock
pulse rises and falls from the master PIC a bit is transferred. Every consecutive clock
transfers a bit. Once the shift registers reach 8-bits (1 byte) the byte is transferred to the
serial input buffer and the shift register is ready to receive data again. Three connections are
required, CLK to CLK (C3-C3), Master data out to slave data in (C5        C4), and master data
in to slave data out (C4 C5).




       Two registers must be set in both PIC s in order to enable this mode; SSPSTAT and
SSPCON. (Actual settings for these registers can be found in APPENDIX B : CONTROL
CODE)




                                                                                        Page 35
Unmanned Aerial Vehicle
SSPSTAT (Status Register)




                                                      Page 36
Unmanned Aerial Vehicle
SSPSCON (MSSP Control Register)




       For desired interrupts bits 6 and 7 of INTCON (Global and peripheral interrupts)
should be set. Bit7 of PIE1(SSPIE) should be set. When interrupt occurs bit7 of
PIR1(SSPIR) is set. This occurs if either a byte is successfully transferred, also in case of
collision occurs or overflow occurs.




                                                                                     Page 37
Unmanned Aerial Vehicle

4.3       Main PIC Implementation

        Generally as aforementioned, this PIC uses PWM, SPI, and ADC, it decides the
orientation and heading of the plane. The following sections divide these tasks and explain
each of these elements independently.



4.3.1      Pulse Width Modulation
      After we have finally tested all our sensors, GPS device and RF devices for correct
processed data, we can now begin to implement the results as output on the propellers
through motor control. This is achieved by the use of PWM. In the PIC 16LF777, it has
three pins for PWM. The control registers used to enable PWM on this PIC are CCP1CON,
CCP2CON, CCP3CON, PR2 and most importantly T2CON, since PWM is controlled by
Timer 2 in the microcontroller. These three CCPXCON registers let us enable capture
modes, compare modes or PWM. Of course here, we will enable the PWM.




                                                                                   Page 38
Unmanned Aerial Vehicle




Bit 7: Unimplemented.
Bit 6: Unimplemented.
Bit 5: Should be set as 0. Second Least Significant bit in PWM mode. (10-bit Resolution).
Bit 4: Should be set as 0. First Least Significant bit in PWM mode. (10-bit Resolution).
Bit 3: Should be set as 1. (To enable PWM mode).
Bit 2: Should be set as 1. (To enable PWM mode).
Bit 1: Don t care in PWM. (To enable PWM mode).
Bit 0: Don t care in PWM. (To enable PWM mode).


The CCPXCON registers will be all set as following:
CCP1CON:      0x0F =         0b00001111;
CCP2CON:      0x0F =         0b00001111;
CCP3CON:      0x0F =         0b00001111;
                                                                                    Page 39
Unmanned Aerial Vehicle
     After setting the CCPXCON registers, we must now set the T2CON register where
most importantly we must enable TIMER2 of the microcontroller and then set the period
we need to control our DC Brushed Motors in an optimum way using the PR2 register and
setting it with a fixed value. By means of research and supervision, it was decided to
control our motors at a frequency of 750Hz (750 times per second).


For T2CON, we place the following settings:


     After setting the CCPXCON registers, we need to now set the T2CON register which
enables TIMER2 in the microcontroller that will then control over the frequency or period
we need on the Pulse Width Modulation. In order do this we must set the following bits as
follows.




Bit 7:        Unimplemented.
Bit 6:        Should be set as 0. (Postscaling will not be needed).
Bit 5:        Should be set as 0. (Postscaling will not be needed).
Bit 4:        Should be set as 0. (Postscaling will not be needed).
Bit 3:        Should be set as 0. (Postscaling will not be needed).
Bit 2:        Should be set as 1 in order to enable and turn on Timer 2.
Bit 1:        Should be set as 1. (Since prescale with a value of 16 is required).
Bit 0:        Should be set as 1. (Since prescale with a value of 16 is required).

                                                                                     Page 40
Unmanned Aerial Vehicle
     Our goal to control our motors at around 750Hz. Now since the microcontroller can
execute 2 million instructions per second (500 nanoseconds). Speed should be reduced by
prescaling. When you prescale your instructions per second over 16 which is our
maximum, then we have reduced the frequency to 125 KHz (125000Hz). This is where the
PR2 register comes in handy to further reduce frequency to 750Hz.


For PR2, we place the following settings:


     PR2 is an 8-bit register made available in order to control the frequency output
needed on the DC Brushed Motors. After using the T2CON register for prescaling to
reduce frequency to 125 KHz, PR2 register is used to enter a decimal value that will control
and limit our frequency to 750Hz. The value to be placed in the PR2 register is calculated
as follows. We divide the 125000 Hz obtained by 750Hz which is what is needed.
125000/750 = 166.666667. Since the value to be placed in the PR2 register should be an
integer value and is an 8-bit register and carries no space for a floating point number, 167
should be entered after subtracting 1 from it.
         Therefore,
PR2 = 166
The equation for PR2 is: round (Fosc / (4 x 16 x Period Required)) - 1
Hence,
                Fosc = 8 x 10^6
                PR2 = round(8 x10^6 / ( 4 x 16 x 750)) - 1
                PR2 = round(8 x 10^6/ (48000)) - 1
                PR2 = round(166.66666667)) - 1
                PR2 = 167 - 1
                PR2 = 166




                                                                                    Page 41
Unmanned Aerial Vehicle
Setting outputs on the Tri-State Buffers on all ports of the Microcontroller:


      Since the PWM pins are driving the motors they need to be se as output pins. This is
done by setting the registers TRISB and TRISC.


TRISC = 0x00 Hex      =      0b00000000.
TRISB = 0x00 Hex      =      0b00000000.


The diagram of the PIC 16LF777 can be used as a reference below for the output pins
CCP1 on Port C2, CCP2 on Port C1, and CCP3 on Port B5.




*NOTE: Please see APPENDIX B for the sample code of Pulse Width Modulation and how
to control it.




                                                                                  Page 42
Unmanned Aerial Vehicle

4.3.2           ADC Operation

      Here using the Analog - to - Digital converters is most crucial in order to automate
our Unmanned Aerial Vehicle (UAV). For the most part, most or all of our sensors,
ultrasonic, gyrometer and accelerometer give us feedback on our control system. The
Ultrasonic provides us with a way for collision detection and obstacle avoidance. The
accelerometer and gyrometer provide us with crucial data to help us stabilize our UAV in
mid-air and maintain a static hovering position. It can also help the UAV to auto-level after
traveling in a certain direction, like a co-pilot.


      The outputs of those sensors are analog voltages. The Analog - to - digital converter
here helps with converting those outputs into useful data ready to be used and processed by
the microcontroller. In this project we use the 16LF777 PIC by Microchip. It contains an
abundant 14 channel 10-bit ADC.


      We have 11 inputs from those sensors. Five alone for the ultrasonic sensors, placed on
the front, back, left, right, and bottom sides of our UAV for height accuracy. The
ultrasonic s range is far as 6.45m (254 inches) and as small as 15cm (6 inches) to aid the
UAV in landing due to its blind spot. Six channels are used for 2 Gyrometers and an
accelerometer. Each gyrometer outputs the rate of angular velocity in the X and Y planes,
so we need three channels since we have 2 gyrometers. One input/channel will be ignored
from the second gyrometer. The accelerometer needs 3 channels since it measures
acceleration in the X, Y, and Z directions. This makes a total of 11 channels. Therefore, 3
channels on our 16LF777 microcontroller will not be used out of the 14 channels.


      In order to set this up in our PIC we must enable certain bits in our control registers of
the 16LF777 microchip. These control registers are the ADCON0, ADCON1, ADCON2,
PIE1, and PIR1 and last but not least the INTCON register to enable our interrupts
especially when the ADIF (AD Interrupt Flag) is set after every conversion in the PIR
register.
      The result of the Analog-to-Digital Converter is placed in the ADRES (AD Result)
register. It consists of 2 8-bit registers, ADRESL (AD Result LOW) and ADRESH (AD
Result HIGH).
                                                                                        Page 43
Unmanned Aerial Vehicle




                          Page 44
Unmanned Aerial Vehicle




                          Page 45
Unmanned Aerial Vehicle




For ADCON0, we place the following settings:


Bit 7: <ADCS1>        Must be set as 1 since we are using the Internal Oscillator.
Bit 6: <ADCS1>        Must be set as 1 since we are using the Internal Oscillator.
Bit 5: <CHS2>         Analog Channel Select bit.
Bit 4: <CHS1>         Analog Channel Select bit.
Bit 3: <CHS0>         Analog Channel Select bit.
Bit 2: <GO/DONE> A bit that controls the start of conversion or end of conversion.
Bit 1: <CHS3>         Analog Channel Select bit.
Bit 0: <ADON>         Turns on the ADC module in the microcontroller.


Bits 5,4,3,1 are used to select the channels we need to take our inputs from. Therefore, you
need to toggle through them as we read our values over the output interval time. We start
out by reading through channel 0, then 1, then 2, until we reach channel 10 (11 Channels)
then go back to Channel 0 to take new readings to process for our new interval.


                                                                                     Page 46
Unmanned Aerial Vehicle
For ADCON1, we place the following settings:


Bit 7: <ADFM>         Must be set as 1 for Right Justification in the ADRES
                      register. In reading our result from the ADRES register,
                      we read all the 8 bits from ADRESL and the least significant bits
                      of ADRESH and multiply it by 256.


Bit 6: <ADCS2>        Must be set as 1 since we are using the Internal Oscillator.


Bit 5: <VCFG1>        Must be set as 0 since our Vref+ is normally the VDD of the PIC.
Bit 4: <VCFG0>        Must be set as 0 since our Vref- is normally the VDD of the PIC.


Bit 3: <PCFG3>        Must be set as 0 since we need to enable 11 Channels.
Bit 2: <PCFG2>        Must be set as 1 since we need to enable 11 Channels.
Bit 1: <PCFG1>        Must be set as 0 since we need to enable 11 Channels.
Bit 0: <PCFG0>        Must be set as 0 since we need to enable 11 Channels.


     The bits 3,2,1,0 of PCFG(X) remain fixed since we are enabling only 11 Channels for
the ADC to read from. The pins where pins AN11, AN12 and AN13 of the microcontroller
16LF777 remain digital I/O pins depending on the settings of the Tri-State Buffers for the
ports.


For ADCON2, we place the following settings:


Bit 7: Unimplemented.
Bit 6: Unimplemented.
Bit 5: Must be set as 1, since we wish the conversion to take 12TAD (24 sec).
Bit 4: Must be set as 0, since we wish the conversion to take 12TAD (24 sec).
Bit 3: Must be set as 1, since we wish the conversion to take 12TAD (24 sec).
Bit 2: Unimplemented.
Bit 1: Unimplemented.
Bit 0: Unimplemented.


                                                                                     Page 47
Unmanned Aerial Vehicle
     The reason why 12TAD is necessary here is simply because one TAD is equivalent to
2 sec. The acquisition time must not exceed the minimum of 19.72 s which is how long
the ADC before the ADC starts conversion automatically.


     Therefore, 2 s * 12 = 24 sec, which is how long the ADC needs to acquire our data
from one input channel.


     In order to keep the microcontroller working efficiently and processing data without
having it constantly polling and wasting processing power on all kinds of data coming in
through the Sensors, GPS device or RF transceivers, we use interrupts. Concerning our
sensors we set the PIE1 control register in our microcontroller. The Analog-to-Digital
Interrupt Enable (ADIE) is bit number 6. We set it to 1. Whenever the ADC finishes a
conversion, it will set the Analog-to-Digital Interrupt Flag in (ADIF) to 1 in register PIR1,
interrupting the PIC. After we take our reading for the ADC, we must clear the ADIF in the
PIR1 register in our software or else the PIC will keep itself running in a loop. Then we
must change our channel through the bits 5, 4, 3, and 1 in the ADCON0 register. When this
is done, we start a new conversion by the setting the bit number 2 (GO/DONE) as 1 in the
ADCON0 register until the end of conversion is complete and the ADIF is set again calling
the interrupt function in our microcontroller.


Setting our inputs on the Tri-State Buffers on all ports of the Microcontroller:


     Since we have already set our control registers of the ADC module most importantly,
we need to set the tri-state buffers on our ports in order to receive our inputs from the
sensors. This is done by setting the registers TRISA, TRISB, and TRISE.


TRISA = 0xFF Hex       =       0b11111111.
TRISB = 0x0E Hex       =       0b00001110.
TRISE = 0x07 Hex       =       0b00000111.




                                                                                        Page 48
Unmanned Aerial Vehicle




      In the summary of registers shown above, we must be very careful when setting the
TRISE register because only the three least significant bits here control the PORTE Data
Direction Bus, unlike TRISA where the complete register is used for only 6 pins. If we set
the TRISE = 0xFF, it will cause the PIC to set two interrupt flags IBF and OBF and
enable PSP Mode , which will cause PORTD to engage in parallel communication. This
will cause the PIC to enter in an infinite loop of interrupts and if the flags are not cleared in
the software. It almost causes the microcontroller to seem to Halt in a sense.




                                                                                          Page 49
Unmanned Aerial Vehicle
4.3.2.1    Ultrasonic Sensors
      The ultrasonic sensors used on the UAV can detect up to 254 inches 6.45 (meters) and
the minimum distance it can detect due to its blind spot is 6 inches (15 cm). The sensor
generates a new reading every 49 milliseconds. Since the microcontroller can take readings
much faster than the ultrasonic sensor s output, if we take the readings at that speed, it will
cause a lot of noise in our program for the UAV, so it is best we take our readings every
49 milliseconds to avoid the noise and make sure we have a new reading every time to be
put to good use.


      Every 0.01 Volts on our Ultrasonic sensor represents 1 inch of distance. Therefore, if
the voltage on the output pin of the ultrasonic sensor is 0.20 Volts, then the distance it reads
is 20 inches, therefore it is very simple to use.


      In order to calculate the distance we need in our PIC 16LF777 we use a very simple
equation which is:


Distance (in Hexadecimal) = (Vin/Vref) X (2N) ;
                where Vin       : is the Voltage input coming from the Ultrasonic Sensor.
                        Vref    : is the reference voltage from our circuit which is 3.30V
                        N       : is the number of bits of the ADC which is 10, therefore is
                                 1024
For example,
                If      Vin     =       0.50V (which is equivalent to 50 inches read).
                        Vref    =       3.30V


Then, 0.50/3.30 X 1024 = 155.1515 Hexadecimal


      In the ADC of the PIC 16LF777, the ADRES (AD Result) register will read 155 and
will truncate the 0.1515.


      If we take the reading 155 from the ADC and try to convert it back, it will be as
follows:

                                                                                         Page 50
Unmanned Aerial Vehicle
Vin = (Reading from ADRES Register in HEX / 2N) X Vref


     Vin = (155/1024) X 3.30V = 0.4995 Volts.


     Therefore the error is: (1    (0.4995/0.5)) X 100 = 0.1 %
     which is quite accurate.


*NOTE: Please see APPENDIX B for the sample code of the Ultrasonic Sensors.




                                                                              Page 51
Unmanned Aerial Vehicle


4.3.2.2    Gyrometer
The gyrometer used was the IDG300. This IC gives accurate readings of angular velocity.
All three angles were needed for control of the UAV, on the x, y and z axes; traditionally in
flight labeled as roll, pitch and yaw angles. Angular velocity is measured accurately with a
sensitivity of 2 mV/ º/s. So every degree of rotation would indicate 0.002V electronically.
The first thing to do was to interpret the signals into degrees, 0º - 360º.
        This IC operates so that if the IC is rotated suddenly then stopped, you would get a
change in reading only when the IC is moving, only when there is angular velocity. Thus an
adder function is needed to constantly integrate the tilt intervally through the selected
frequency, as general equation is as follows:

  SUM           SUM        new   t
Where     SUM   is initially set to 0.   new   is the latest reading from the gyro output and T is the
sampling period.
        After the electric signal would be received on the ADC ports of the PIC it would be
multiplied by the following equation to give degrees:

                                                        1024     t
AngleNew               AngleOld                Vin *         *
                                                         3.3   0.62
        Also any negative value for tilt had 360 added to it, since simple sin and cos
functions behave differently to negative values.


4.3.2.3    Accelerometer
        The accelerometer used was the ADXL330. This gives accurate measures of
acceleration about all three axes. Typical sensitivity of this IC is 300mV/g, so every 1m/s2
of acceleration would indicate 30.58mV electronically. Primarily this IC has two main
functions. The first is to indicate the initial angles of x and y in reference to the xy plane
perpendicular to the gravity vector, so that the UAV can take off from any angled surface,
if an accelerometer was not used, the system would always assume that the plane it was
taking off from was always perpendicular to the vector of gravity, causing flight to be
unstable. To use the accelerometer as an inclinometer, assuming X and Y are the
acceleration values obtained from the corresponding axes on the accelerometer then, simply
                                                                                              Page 52
Unmanned Aerial Vehicle

              X
         -1
 X=sin
              g
       Y
         -1
 Y=sin g


          The second use is to produce accurate estimations of acceleration, velocity and
position, for use in the simulation. A fixed reference point is taken, more accurately the
fixed axes at the point of takeoff. Acceleration and velocity in reference to that point are
calculated. Distance from that point is calculated, and distance traveled around that point is
also calculated. Considering the accelerometer uses the angles supplied from the gyrometer,
a traditional 3D rotational matrix is used to rotate the constantly generated acceleration
vectors around the reference axes, so that every value from the accelerometer has a X, Y
and Z component on the reference axes.


Rotation around the x-axis is defined as :

              1           0              0
RX( X) = 0          cos       X      sin     X    where       X   is the roll angle
              0     sin       X      cos     X




Rotation around the y-axis is defined as :

              cos   Y         0      sin     Y

RY( Y) =         0            1        0          where       Y   is the pitch angle
              sin Y           0      cos     Y




Rotation around the z-axis is defined as :

         cos        Z         sin    Z       0
RZ( Z) = sin          Z       cos    Z       0   where    Z   is the pitch angle
           0                     0           1


Multiplying all these matrices together would give the following matrix:

                                                                                       Page 53
Unmanned Aerial Vehicle

                   cos Y cos Z                                                      cos Y sin Z                                 sin Y
    1
A        sin Y sin X cos Z cos                         X   sin       Z    sin Y sin X sin Z cos               X   cos   Z   sin X cos       Y

         sin    Y   cos       X   cos   Z        sin   X   sin       Z    sin   Y   cos   X   sin   Z   sin   X   cos   Z   cos   X   cos   Y



if X,Y and Z are the acceleration values obtained from the corresponding axes on the
accelerometer then,
ReferenceX      =        Xcos Xcos           Y    +        Y(sin Ycos Xsin Z-sin Xcos Z)                 +
                         Z(sin Ycos Xcos Z+sin Xsin Z)


ReferenceY      =     Xsin Xcos             Y     +        Y(sin Ysin Xsin Z+cos Xcos Z)                 +
                         Z(sin Ysin Xcos Z-cos Xsin Z)


ReferenceZ      = - Xsin           Y    +       Ycos Ysin        Z       + Zcos Ycos      Z




         Integrating with respect to time once gives velocity, and integrating twice gives
position. Adder functions are used for velocity and position for each reference axes.
Another adder function is created taking the absolute value of every acceleration reading,
then multiplying them by time twice in order to calculate the distance traveled. All adder
functions for total rigid body acceleration, velocity, distance from origin and distance
traveled, this simple equation is used.
                2         2
V alue      X        Y            Z2




                                                                                                                        Page 54
Unmanned Aerial Vehicle

4.4           Secondary PIC Implementation

        Generally as aforementioned, this PIC uses PWM, SPI, USART, and communicates
with an RF module. It handles communication tasks for the Main PIC. It also acts as a
secondary PWM module. The following sections divide these tasks and explain each of
these elements independently.


4.4.1 GPS System

        GPS has become a widely used aid to navigation worldwide, and a useful tool for
map-making, land surveying, commerce, and scientific uses. GPS also provides a precise
time reference used in many applications including scientific study of earthquakes, and
synchronization of telecommunications networks. There is a constellation of 30 (earth
orbiting satellites as of April 2007) that transmit precise radio signals. Their orbits are set
up so that at any given point and time on the earth s surface there are at least six of these
satellites in reach. A figure below demonstrates the constellation of NAVSTAR GPS
satellites.




                                                                                       Page 55
Unmanned Aerial Vehicle
        A GPS receiver calculates its position by measuring the distance between itself and
three or more GPS satellites, using trilateration. Measuring the time delay between
transmission and reception of each GPS radio signal gives the distance to each satellite,
since the signal travels at a known speed. The signals also carry information about the
satellites' location. By determining the position of, and distance to, at least three satellites,
the receiver can compute its position using trilateration. Receivers typically do not have
perfectly accurate clocks and therefore track one or more additional satellites to correct the
receiver's clock error.


        The figures below briefly explain trilateration, where at the center of each sphere
there is a satellite. When two spheres intersect they create lines. When the third sphere
intersects it creates a point revealing the location of the receiver.




        The coordinates are calculated according to the World Geodetic System WGS84
coordinate system. Position is determined by latitude and longitude which are basically
angles, latitude ranges from 0-90 north and south, and longitude ranges from 0-180 west
and east. The figures below display latitude and longitude.




                                                                                         Page 56
Unmanned Aerial Vehicle




        To calculate its position, a receiver needs to know the precise time. The satellites
are equipped with extremely accurate atomic clocks, and the receiver uses an internal
crystal oscillator-based clock that is continually updated using the signals from the
satellites.


        GPS satellites continuously transmit almanac and ephemeris at 50bps. The almanac
consists of coarse time information and orbital data (speed and path). The ephemeris gives
the satellites precise orbit. The almanac assists in the acquisition of other satellites. A
complete almanac transmission is a 37,500 bit navigation message that takes 12.5 minutes
to download. This long delay occurs when a new receiver is first turned on. Each satellite
transmits its navigation message with at least two distinct spread spectrum codes: the
Coarse / Acquisition (C/A) code, which is freely available to the public, and the Precise (P)
code, which is usually encrypted and reserved for military applications. The C/A code is a
1,023 bit long pseudo-random code broadcast at 1.023 MHz, repeating every millisecond.
Each satellite sends a distinct C/A code, which allows it to be uniquely identified.
                                                                                       Page 57
Unmanned Aerial Vehicle
       The receiver identifies each satellite's signal by its distinct C/A code pattern, then
measures the time delay for each satellite. To do this, the receiver produces an identical
C/A sequence using the same seed number as the satellite (two or more systems using
matching seeds can generate matching sequences of non-repeating numbers which can be
used to synchronize remote systems). By lining up the two sequences, the receiver can
measure the delay and calculate the distance to the satellite, called the pseudorange. The
pseudoranges are then the time the signal has taken from there to the receiver, multiplied by
the speed of light. The orbital position data from the Navigation Message is then used to
calculate the satellite's precise position. Knowing the position and the distance of a satellite
indicates that the receiver is located somewhere on the surface of an imaginary sphere
centered on that satellite and whose radius is the distance to it. When four satellites are
measured simultaneously, the intersection of the four imaginary spheres reveals the location
of the receiver. The orbital position data from the Navigation Message is then used to
calculate the satellite's precise position. Knowing the position and the distance of a satellite
indicates that the receiver is located somewhere on the surface of an imaginary sphere
centered on that satellite and whose radius is the distance to it. When four satellites are
measured simultaneously, the intersections of all four imaginary spheres reveal the location
of the receiver.


       Often, these spheres will overlap slightly instead of meeting at one point. The
receiver then moves the overlapping pseudoranges with the same amount (regardless of
distance of receiver to satellite) till an intersection point is created this point is usually the
most probable position. This scenario is shown in the following figure.




                                                                                          Page 58
Unmanned Aerial Vehicle
       An overlapping pseudorange occurs here. Instead of having one intersection point, a
room is created by all three points of B . All distances are subtracted by the same amount,
in this case 0.5, in order to receive an intersection point at A . Point A is considered the
most probable point of the receiver.


       Regarding GPS time as opposed to the conventional second, minute and hour; you
only have seconds, more precisely seconds of the week. In a normal clock when the
seconds reach 60 it starts a new minute. In GPS time when the seconds reach 604,800 it
starts a new week, this is calculated by 7(days)*24(hours)*60(minutes)*60(seconds).


       As for GPS date as opposed to the year, month, and day format of the Julian
calendar, the GPS date is expressed as a week number and a day-of-week number. The
week number is transmitted as a ten-bit field, and so it becomes zero again every 1,024
weeks (19.6 years). GPS week zero started at (00:00:19 TAI) on January 6, 1980 and the
week number became zero again for the first time at on August 21, 1999. This event is
known as a rollover.


       After a GPS does a full almanac download, GPS systems boot in 3 different modes.
Those would be cold start, warm start and hot start. In cold start, time and position are
known within some limits, the almanac is known and the ephemeris is unknown. In warm
start, time and position are known within some limits, the almanac is known, and at least
three satellite ephemeris are known from the previous operation. In a hot start all ephemeris
for all satellites are known so a hot start occurs. The GPS receiver chooses how to start
based on the time between last turn off and current turn on. If this time was a few minutes
the GPS chooses hot start which takes 1 second, if it was a few hours the choice is warm
start which takes 38 seconds, anything longer than that produces a cold start which takes 42
seconds.


       Most GPS systems have two protocols SirF protocol and NMEA protocol. In our
case the NMEA protocol was used. NMEA protocol simply contains input messages and
output messages. (Refer to the NMEA reference manual)



                                                                                     Page 59
Unmanned Aerial Vehicle
Input messages selected to initialize the GPS are:
$PSRF100,1,4800,8,1,0*0Ern
$PSRF103,04,00,02,01*22rn
$PSRF105,0*3Frn
$PSRF is used for input messages. The star means the following two characters are
checksum, NMEA checksum operates by 16-bit XOR a checksum calculator code is shown
in the APPENDIX B : CONTROL CODE, and /r/n represent carriage return and line feed,
whose HEX code are 0D 0A. All other fields in between them are data fields for different
settings.
$PSRF100,1,4800,8,1,0*0Ern
This message was used for setting the serial port. 100 in the first field represents serial port
settings. 1 in the second field is for NMEA protocol, 4800 is for baud rate, 8 is for 8 data
bits, 1 is for 1 stop bit, and 0 is for no parity bit.
$PSRF103,04,00,02,01*22rn
This line is used for enabling and disabling output messages, 103 is used for query/control
mode. 04 is used for RMC mode, 02 is used for releasing the message at 2Hz, 01 is used for
enabling checksum.
$PSRF105,0*3Frn
105 is used for development data. The 0 represents debug off should any error occur, so
that our PIC does not receive any unnecessary input. When a GPS is turned off, it s last
settings before being switched off will be saved in it s battery powered RAM. When turned
on, these settings resume. These input messages were considered necessary in order to set
the serial port correctly for USART communication, RMC mode was chosen because this
one single message had all the necessary information required. The third message is for
turning off debug to avoid unnecessary input to the MCU.


        A 16-bit XOR CRC creator was necessary to give input messages. A JAVA code is
displayed in the APPENDIX B: CONTROL CODE.




                                                                                        Page 60
Unmanned Aerial Vehicle
       Later on a program called SiRF Demo PC GPS Utility v3.83 was found very helpful
for obtaining latitude and longitude coordinates for our tested range area. It can also be
used as an initialization alternative. To initialize your GPS time, you simply click setup
then click GPS Time      PC Time as shown in the figure below. Usually the demo starts
in SiRF protocol. To switch it to NMEA protocol you simply click action then Switch to
NMEA Protocol , to open NMEA Setup. In this window as shown in the figure below, you
can select each message and it s frequency per second. Highlighting checksum is preferred
for message validation. For NMEA, baud rate should be set at 4800bps. After powering off
the GPS receiver, GPS time, message type and frequency are saved.




                                                                                  Page 61
Unmanned Aerial Vehicle
       Output messages received from RMC mode (in order) are UTC time, data validity,
latitude, north/south indicator, longitude, west/east indicator, velocity over ground in knots,
heading measured clockwise from north in degrees, and date A sample output message is
shown below:
$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120507, ,*10
The first two letters following the $ represent the device in use. The GP stands for GPS.
There are other devices such as:
LC Loran-C
TR Transit SATNAV
AP Autopilot (magnetic)
HC Magnetic heading compass
RA Radar
SD Depth sounder
VW Mechanical speed log


       Latitude and longitude are displayed in degrees and minutes, At a latitude of 30° N
(Cairo, Egypt), the latitude minute = 1847.54m and longitude minute = 1608.1m (distances
change because the circumference of parallel of latitude changes, Earth is not a cylinder,
please refer to http://home.online.no/~sigurdhu/Grid_1deg.htm ), velocity is multiplied by
1.852 to change from knots to km/hr. Then course heading in degrees ranging from 0°-
360° moving clockwise from north. The final field before the checksum is date. The only
fields needed were data validity, latitude, longitude, velocity and heading. VTG mode was
desired to attain height, but during testing, height in MSL (Mean Sea Level) was quite
inaccurate. At a change of height of about 4 meters, the GPS detected a change of height of
10 meters which is an error of over 150%. Latitude, longitude velocity and heading are
transmitted via RF to the simulation.




                                                                                       Page 62
Unmanned Aerial Vehicle
       A destination in GPS mode is set by pre-inputting a target destination, in the PIC
program, in latitude and longitude. The following steps are taken:


1. Y = Target Latitude    Present Altitude
2. X = Target longitude Present Latitude

3. Distance =   X2 Y2

                                             1   Y
4. TempAngle is obtained by           tan
                                                 X
Desired course heading is obtained by the following scheme:
Y      X         Course
+      +         TempAngle + 0°
-      -         TempAngle + 180°
+      -         TempAngle + 360° (TempAngle is negative)
-      +         TempAngle + 180° (TempAngle is negative)


Resgister Settings


       Communication between the PIC and GPS system is acheived by the Universal
Synchronous Asynchronous Receiver Transmitter (USART). In this case Asynchronous
mode is used. (refer to the PIC 16F777 pdf file, section 11.0 for more detailed information)
To enable this serial mode three registers must be set; TXSTA, RCSTA and SPBRG.
TXSTA is set in the following manner:


Bit 7: 0 Don t care (for Asynchrous mdoe)
Bit 6: 0 for 8-bit transmission
Bit 5: 0 for transmission enabled
Bit 4: 0 for Asynchronous mode
Bit 3: 0 this bit is unimplemented
Bit 2: 0 for High speed
Bit 1: 1 for TSR empty (TRMT)
Bit 0: 0 not used in 8-bit transmission


                                                                                    Page 63
Unmanned Aerial Vehicle
       SPBRG is the simplest where only a value is entered into the register. Considering
asynchronous mode is used and the system is low speed, the following equation is used,
where X is the value entered in SPBRG:


            FOSC
X                    1
        64* BaudRate

       When a baud rate of 4800bps with a frequency of 8MHz is entered into the equation
the resulting X value is 25.04, so 25 is the value used in SPBRG.
The RCSTA register is set in the following manner:


Bit 7: 1 for Serial port enabled
Bit 6: 0 for Enables 8-bit reception
Bit 5: 0 Don t care for Asynchronous mode
Bit 4: 1 to Enable continuous receive (called CREN)
Bit 3: 0 Don t care for 8-bit mode
Bit 2: 0 for no Overrun error(OERR)
Bit 1: 0 for no Framing error(FERR)
Bit 0: 0 Don t care for 8-bit mode




       When transmitting input messages to the GPS system to initialize data, the data
message had to be inserted in the PIC s EEPROM via MPLAB before programming to PIC
(an .ECH file can be created with your EEPROM input by exporting a file (MPLAB), this
file is easier to load than re-inputting every time), because it consumed too much RAM.
Data is transmitted bit by bit via the TXREG register, the TSR register must be polled to
see whether the bit was sent out or not when TSR is empty only can u fill in the next bit.
Interrupts are undesired in this mode.




                                                                                  Page 64
Unmanned Aerial Vehicle
       For Universal Asynchronous reception, the 6th and 7th bit of the INTCON register
must be set, to enable interrupts, along with the 5th bit of register PIE1. An interrupt occurs
(bit5 of register PIR is set) under three cases, when a byte is received successfully, when an
OERR (Overrun error) or when a FERR (Framing error) occurs. If a FERR occurs the
message is discarded. The message is valid if; the message starts with a $ and ends with
0D 0A, the GPS sends an A in the 19th byte, no FERR error occurs, and the CRC check is
correct. If the message is valid, SPI communication transmits the latitude, longitude and
heading to the Main PIC, Also the RF transmits function is called to send this data (for use
in the simulator). This code in detail can be seen in APPENDIX B: CONTROL CODE.




                                                                                       Page 65
Unmanned Aerial Vehicle

4.4.2 Radio Transceiver


       This RF device is called a transceiver in the sense that the same unit can send and
receive, to and from another identical unit. Operating frequency is 2.4GHz, and data
transmission rate can be selected at either 250Kbps or 1Mbps. 250kbps works at a longer
range of 280m but after testing, range proved to be approximately 180m. Also 250kbps
improves receiver sensitivity. There are two modes direct mode and shock burst mode.
Shock burst works at a lower current and relaxed PIC operation. Low current consumption
occurs by using an onboard FIFO to transmit data at a low rate then transmit at a high rate.
PIC   resources   are   saved    by   having    an   onboard    CRC     creator/checker    for
transmitting/receiving respectively. Pre-amble, address, and CRC are stored on a buffer on
the RF then transmitted out, instead of letting the PIC do all this work. The transceiver can
receive simultaneously on two different channels. Only one channel was used in this
project.


Pins used


       Used pins were CE (Chip Enable), CS (Chip Select), CLK (Clock), DR1 (Data
Ready1), DATA1, Vcc, and GND (1 represents pins pertaining to Channel1). The
transceiver requires a configuration word of up to 15 bytes. This is done through three pins;
CS, CLK and DATA1. Generally CE is turned off, CS is turned on, a delay is done to allow
onboard processing, and then data is fed in bit by bit as the clock toggles. The Shock burst
configuration word is as follows:


Shock Burst configuration Word:


The section bit[119:16] contains the segments of the configuration register dedicated to
Shock Burst operational protocol. After VDD is turned on Shock Burst configuration is done
once and remains set whilst VDD is present. During operation only the first byte for
frequency channel and RX/TX switching need to be changed.




                                                                                       Page 66
Unmanned Aerial Vehicle
PLL_CTRL




Bit 121-120:


          Controls the setting of the PLL for test purposes. With closed PLL in TX no
deviation will be present. For normal operational mode these two bits must both be low.


DATAx_W




Bit 119     112:
          DATA2_W: Length of RF package payload section for receive-channel 2.
Bit 111     104:
          DATA1_W: Length of RF package payload section for receive-channel 1.
NOTE:
          The total number of bits in a Shock Burst RF package may not exceed 256!
Maximum length of payload section is hence given by:


                        DATAx_W(bits) = 256      (ADDR_W+ CRC)
ADDRx




Bit 103 64:
          ADDR2: Receiver address channel 2, up to 40 bit.
Bit 63     24: ADDR1
          ADDR1: Receiver address channel 1, up to 40 bit.
*NOTE:
          Bits in ADDRx exceeding the address width set in ADDR_W are redundant and can
be set to logic 0.
                                                                                        Page 67
Unmanned Aerial Vehicle
ADDR_W & CRC




Bit 103 64:
          ADDR2: Receiver address channel 2, up to 40 bit.
Bit 63     24: ADDR1
          ADDR1: Receiver address channel 1, up to 40 bit.


NOTE:
          Bits in ADDRx exceeding the address width set in ADDR_W are redundant and can
be set to logic 0.


ADDR_W & CRC




Bit 23     18:
          ADDR_W: Number of bits reserved for RX address in Shock Burst packages.
NOTE:
          Maximum number of address bits is 40 (5 bytes). Values over 40 in ADDR_W are
not valid.
Bit 17:
  CRC_L: CRC length to be calculated by nRF2401 in Shock Burst.
          Logic 0: 8 bit CRC
          Logic 1: 16 bit CRC
Bit: 16:
 CRC_EN: Enables on-chip CRC generation (TX) and verification (RX).
          Logic 0: On-chip CRC generation/checking disabled
          Logic 1: On-chip CRC generation/checking enabled



                                                                                 Page 68
Unmanned Aerial Vehicle
This section of the configuration word handles RF and device related parameters.


Modes:
General device configuration:




Bit 15:
 RX2_EN:
          Logic 0: One channel receive
          Logic 1: Two channels receive


NOTE:
             In two channel receive, the nRF2401 receives on two, separate frequency
channels simultaneously. The frequency of receive channel 1 is set in the configuration
word bit[7-1], receive channel 2 is always 8 channels (8 MHz) above receive channel 1.
Bit 14:


Communication Mode:
          Logic 0: nRF2401 operates in direct mode.
          Logic 1: nRF2401 operates in Shock Burst mode


Bit 13:
          RF Data Rate:
          Logic 0: 250 kbps
          Logic 1: 1 Mbps


*NOTE:
          Utilizing 250 kbps instead of 1Mbps will improve the receiver sensitivity by 10 dB.
1Mbps requires 16MHz crystal.




                                                                                       Page 69
Unmanned Aerial Vehicle




Bit 12-10:
        XO_F: Selects the nRF2401 crystal frequency to be used:




Bit 9-8:
        RF_PWR: Sets nRF2401 RF output power in transmit mode:


RF channel & direction


Bit 7   1:
        RF_CH#: Sets the frequency channel the nRF2401 operates on.
The channel frequency in transmit is given by:
               ChannelRF =2400MHz + RF_CH# * 1.0MHz
RF_CH #: between 2400MHz and 2527MHz may be set. The channel frequency in data
channel 1 is given by:
               ChannelRF =2400MHz + RF_CH# * 1.0MHz
(Receive at PIN#8)
RF_CH #: between 2400MHz and 2524MHz may be set.


The channel frequency in data channel 2 is given by:
               ChannelRF =2400MHz + RF_CH# * 1.0MHz + 8MHz
(Receive at PIN#4)
RF_CH #: between 2408MHz and 2524MHz may be set.




                                                                          Page 70
Unmanned Aerial Vehicle
Bit 0:
          Set active mode:
          Logic 0: transmit mode
          Logic 1: receive mode


For more intricate details about the configuration word refer to the nRF2401 datasheet page
19.


Within Shockburst mode there are four different modes. They are displayed in the
following table.




ACTIVE MODE
There are two different options in Active mode, Transmit and Receive.


Transmit
1. When the application MCU has data to send, set CE high. This activates nRF2401
  onboard data processing.
2. The address of the receiving node (RX address) and payload data is clocked into the
      nRF2401. The application protocol or MCU sets the speed <1Mbps (ex: 10kbps).
3. MCU sets the CE to low, this activates a nRF2401 Shock Burst transmission.
4. nRF2401 Shock Burst:
      RF front end is powered up
      RF package is completed (preamble added, CRC calculated
      Data is transmitted at high speed (250 kbps or 1 Mbps configured by user).
      nRF2401 return to stand-by when finished


                                                                                     Page 71
Unmanned Aerial Vehicle
Receive
1. Correct address and size of payload of incoming RF packages are set when nRF2401 is
   configured to Shock Burst RX.
2. To activate RX, set CE high.
3. After 200ms settling, nRF2401 is monitoring the air for incoming communication.
4. When a valid package has been received (correct address and CRC found), nRF2401
   removes the preamble, address and CRC bits.
5. nRF2401 then notifies (interrupts) the MCU by setting the DR1 pin high.
6. MCU may (or may not) set the CE low to disable the RF front end (low current mode).
7. The MCU will clock out just the payload data at a suitable rate (ex. 10kbps).
8. When all payload data is retrieved nRF2401 sets DR1 low again, and is ready for new
   incoming data package if CE is kept high during data download. If the CE was set
   low, a new start up sequence can begin.


The following flowchart displays the processes of receiving and transmitting.




                                                                                   Page 72
Unmanned Aerial Vehicle
CONFIGURATION MODE
Similar to active mode Configuration mode has two options, Configure Transmitter, and
Configure Receiver.


Configure Transmitter
1. In configure transmitter, CE is turned off, and CS is turned on.
2. DATA1 with CLK send the configuration word to the RF.
3. A delay of (1ms) is issued to allow ample time for onboard processing.
4. Both CE and CS are turned off.




Configure Receiver
1. In configure receiver, CE is turned off and CS is turned on.
2. A delay (1ms) is issued. The configuration is then sent through DATA1 from the PIC
  as the clock toggles.
3. CE and CS are then turned off and a delay (1ms) is used also for onboard processing.
4. CE is then left on as to enable receiving.




STAND-BY MODE
        Stand by mode is used to minimize average current consumption while maintaining
short start up times. In this mode, part of the crystal oscillator is active. Current
consumption is dependent on crystal frequency.


POWER DOWN MODE
        In power down the nRF2401 is disabled with minimal current consumption,
typically less than 1µA. Entering this mode when the device is not active minimizes
average current consumption, maximizing battery lifetime.




                                                                                        Page 73
Unmanned Aerial Vehicle
DATA PACKAGE DESCRIPTION




       Data packages contain four main sections, in MSB order Pre-amble, address,
payload and CRC. Pre-amble is either 4 or 8 bits and is added to the data packet. Address is
between 8 and 40 bits. Payload is the desired data being transmitted or received. CRC is
either 8 or 16 bits and used for validating message. More detail about the data package can
be seen in the table below.




       For information regarding delays, (please refer to the RF-24G datasheet page22).


Recommendations:
   1. Delays should be taken very carefully, ample time is required for onboard
       processing.
   2. Sequence of turning on CE and CS should be very accurate, or the transceiver will
       not operate as desired.
   3. Configuration word should be set very carefully.
   4. Configuration word entry starts from the MSB to the LSB.
   5. This IC is unlike other ICs, it is very sensitive to physical shock and short circuits,
       three of these units were irreversibly damaged, which in our case cost much time.



                                                                                     Page 74
Unmanned Aerial Vehicle

4.5 RC UNIT

       The main purpose of this RC Unit besides enabling RC mode, is that the user can
interfere manually should any errors occur, such as vehicle misguidance. This can save the
vehicle from possible crashes.


1. KEYPAD TESTING


       Required components are the keypad encoder MM74C923, 0.1uF capacitor, 1uF
capacitor, and a 16 key keypad. The 1uF capacitor determines the debounce key mask. This
is done by creating a debounce period of 0.01s (delay) of on the encoder. The 0.1uF
determines the scanning frequency at 400Hz. The encoder has an output enable as which
should be set at active low.




       These CMOS key encoders provide all the necessary logic to fully encode an array
of SPST switches. The keyboard scan can be implemented by either an external clock or
external capacitor. These encoders also have on-chip pullup devices which permit switches
with up to 50 KHz on resistance to be used. No diodes in the switch array are needed to
eliminate ghost switches. The internal debounce circuit needs only a single external

                                                                                       Page 75
Unmanned Aerial Vehicle
capacitor and can be defeated by omitting the capacitor. A Data Available output goes to a
high level when a valid keyboard entry has been made. The Data Available output returns
to a low level when the entered key is released, even if another key is pressed. The Data
Available will return high to indicate acceptance of the new key after a normal debounce
period; this two-key rollover is provided between any two switches. An internal register
remembers the last key pressed even after the key is released. The TRI-STATEÉ outputs
provide for easy expansion and bus operation and are LPTTL compatible.




       Both the keyboard scan rate and the key debounce period by altering the oscillator
capacitor, COSE, and the key debounce mask capacitor, CMSK. Thus, the MM74C923's
performance can be optimized for many keyboards. The keyboard encoders connect to a
switch matrix that is 4 rows by 4 columns or 5 rows by 4 columns (MM74C923). When no
keys are pressed, the row inputs are pulled high by internal pull-ups and the column outputs
sequentially output a logic 0 . These outputs are open drain and are therefore low for 25%
of the time and otherwise off. The column scan rate is controlled by the oscillator input,
which consists of a Schmitt trigger oscillator, a 2-bit counter, and a 2±4-bit decoder. When
a key is pressed, key 0, for example, nothing will happen when the X1 input is off, since Y1
will remain high. When the X1 column is scanned, X1 goes low and Y1 will go low. This
disables the counter and keeps X1 low. Y1 going low also initiates the key debounce circuit
timing and locks out the other Y inputs. The key code to be output is a combination of the
frozen counter value and the decoded Y inputs. Once the key debounce circuit times out,
the data is latched, and the Data Available (DAV) output goes high. If, during the key
closure the switch debounces, Y1 input will go high again, restarting the scan and resetting
the key debounce circuitry. The key may debounce several times, but as soon as the switch
stays low for a debounce period, the closure is assumed valid and the data is latched. A key
                                                                                      Page 76
Unmanned Aerial Vehicle
may also debounce when it is released. To ensure that the encoder does not recognize this
debounce as another key closure, the debounce circuit must time out before another closure
is recognized. The two-key roll-over feature can be illustrated by assuming a key is pressed,
and then a second key is pressed. Since all scanning has stopped, and all other Y inputs are
disabled, the second key is not recognized until the first key is lifted and the key debounce
circuitry has reset. The output latches feed TRI-STATE, which is enabled when the Output
Enable (OE) input is taken low.




The following circuit schematic was
used to connect the keypad to the
encoder.




For testing refer to the section 5.1 Testing.




                                                                                       Page 77
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle
Unmanned Aerial Vehicle

More Related Content

What's hot

Design and Operation of UAV
Design and Operation of UAVDesign and Operation of UAV
Design and Operation of UAVSai Shubhankar
 
CAA Pakistan
CAA PakistanCAA Pakistan
CAA PakistanAli Raza
 
V.o.r ppt
V.o.r pptV.o.r ppt
V.o.r pptbtinus
 
AVORA I successful participation in SAUC-E'12
AVORA I successful participation in SAUC-E'12AVORA I successful participation in SAUC-E'12
AVORA I successful participation in SAUC-E'12avora_auv
 
Quadcopter final report anand
Quadcopter final report anandQuadcopter final report anand
Quadcopter final report anandAnand kumar
 
ERAP GSE 2015_e catalogue
ERAP GSE  2015_e catalogueERAP GSE  2015_e catalogue
ERAP GSE 2015_e catalogueSashi B
 
Nav Topic 4 hf communication system
Nav Topic 4 hf communication systemNav Topic 4 hf communication system
Nav Topic 4 hf communication systemIzah Asmadi
 
Iaetsd design of rf based voice-controlled multi-terrain robot to
Iaetsd design of rf based voice-controlled multi-terrain robot toIaetsd design of rf based voice-controlled multi-terrain robot to
Iaetsd design of rf based voice-controlled multi-terrain robot toIaetsd Iaetsd
 
Air craft surveillance & instrumental landing system
Air craft surveillance & instrumental landing systemAir craft surveillance & instrumental landing system
Air craft surveillance & instrumental landing systemBikas Sadashiv
 
Nav Topic 8 automatic direction finder
Nav Topic 8 automatic direction finderNav Topic 8 automatic direction finder
Nav Topic 8 automatic direction finderIzah Asmadi
 
ESA Qualified Polymer Capacitors
ESA Qualified Polymer CapacitorsESA Qualified Polymer Capacitors
ESA Qualified Polymer CapacitorsRandall Ghany
 
4 IGARSS2011kobayashiPi-SARearthquak20110724b.ppt
4 IGARSS2011kobayashiPi-SARearthquak20110724b.ppt4 IGARSS2011kobayashiPi-SARearthquak20110724b.ppt
4 IGARSS2011kobayashiPi-SARearthquak20110724b.pptgrssieee
 
Fundamentals of Air Traffic Control
Fundamentals of Air Traffic ControlFundamentals of Air Traffic Control
Fundamentals of Air Traffic Controlcrystalboy024
 

What's hot (20)

Caa khet
Caa khetCaa khet
Caa khet
 
Design and Operation of UAV
Design and Operation of UAVDesign and Operation of UAV
Design and Operation of UAV
 
CAA Pakistan
CAA PakistanCAA Pakistan
CAA Pakistan
 
Copy of syed muhammad zaidi caa
Copy of syed muhammad zaidi caaCopy of syed muhammad zaidi caa
Copy of syed muhammad zaidi caa
 
Open-Source Based Direct Georeferencing Thermal Camera System
Open-Source Based Direct Georeferencing Thermal Camera SystemOpen-Source Based Direct Georeferencing Thermal Camera System
Open-Source Based Direct Georeferencing Thermal Camera System
 
V.o.r ppt
V.o.r pptV.o.r ppt
V.o.r ppt
 
Hsb 2011 diffuse
Hsb 2011 diffuseHsb 2011 diffuse
Hsb 2011 diffuse
 
AVORA I successful participation in SAUC-E'12
AVORA I successful participation in SAUC-E'12AVORA I successful participation in SAUC-E'12
AVORA I successful participation in SAUC-E'12
 
AUV based on EL - Copy
AUV based on EL - CopyAUV based on EL - Copy
AUV based on EL - Copy
 
Quadcopter final report anand
Quadcopter final report anandQuadcopter final report anand
Quadcopter final report anand
 
Brown_ESTF2011
Brown_ESTF2011Brown_ESTF2011
Brown_ESTF2011
 
ERAP GSE 2015_e catalogue
ERAP GSE  2015_e catalogueERAP GSE  2015_e catalogue
ERAP GSE 2015_e catalogue
 
Nav Topic 4 hf communication system
Nav Topic 4 hf communication systemNav Topic 4 hf communication system
Nav Topic 4 hf communication system
 
Iaetsd design of rf based voice-controlled multi-terrain robot to
Iaetsd design of rf based voice-controlled multi-terrain robot toIaetsd design of rf based voice-controlled multi-terrain robot to
Iaetsd design of rf based voice-controlled multi-terrain robot to
 
Air craft surveillance & instrumental landing system
Air craft surveillance & instrumental landing systemAir craft surveillance & instrumental landing system
Air craft surveillance & instrumental landing system
 
Nav Topic 8 automatic direction finder
Nav Topic 8 automatic direction finderNav Topic 8 automatic direction finder
Nav Topic 8 automatic direction finder
 
ESA Qualified Polymer Capacitors
ESA Qualified Polymer CapacitorsESA Qualified Polymer Capacitors
ESA Qualified Polymer Capacitors
 
4 IGARSS2011kobayashiPi-SARearthquak20110724b.ppt
4 IGARSS2011kobayashiPi-SARearthquak20110724b.ppt4 IGARSS2011kobayashiPi-SARearthquak20110724b.ppt
4 IGARSS2011kobayashiPi-SARearthquak20110724b.ppt
 
Arpa
ArpaArpa
Arpa
 
Fundamentals of Air Traffic Control
Fundamentals of Air Traffic ControlFundamentals of Air Traffic Control
Fundamentals of Air Traffic Control
 

Similar to Unmanned Aerial Vehicle

TFG_Cristobal_Cuevas_Garcia_2018.pdf
TFG_Cristobal_Cuevas_Garcia_2018.pdfTFG_Cristobal_Cuevas_Garcia_2018.pdf
TFG_Cristobal_Cuevas_Garcia_2018.pdfGerard Labernia
 
Fibaro advanced users guide
Fibaro advanced users guideFibaro advanced users guide
Fibaro advanced users guideRomAudioVideo
 
Motorola solutions ap6522 access point installation guide wi ng 5.5 version...
Motorola solutions ap6522 access point installation guide   wi ng 5.5 version...Motorola solutions ap6522 access point installation guide   wi ng 5.5 version...
Motorola solutions ap6522 access point installation guide wi ng 5.5 version...Advantec Distribution
 
Real-time and high-speed vibrissae monitoring with dynamic vision sensors and...
Real-time and high-speed vibrissae monitoring with dynamic vision sensors and...Real-time and high-speed vibrissae monitoring with dynamic vision sensors and...
Real-time and high-speed vibrissae monitoring with dynamic vision sensors and...Aryan Esfandiari
 
Motorola ap 8222 access point installation guide mn000046 a01
Motorola ap 8222 access point installation guide mn000046 a01Motorola ap 8222 access point installation guide mn000046 a01
Motorola ap 8222 access point installation guide mn000046 a01Advantec Distribution
 
Motorola ap 8232 access point installation guide mn000032 a01
Motorola ap 8232 access point installation guide mn000032 a01Motorola ap 8232 access point installation guide mn000032 a01
Motorola ap 8232 access point installation guide mn000032 a01Advantec Distribution
 
Implementation of a Localization System for Sensor Networks-berkley
Implementation of a Localization System for Sensor Networks-berkleyImplementation of a Localization System for Sensor Networks-berkley
Implementation of a Localization System for Sensor Networks-berkleyFarhad Gholami
 
Accident reporting system using mems
Accident reporting system using memsAccident reporting system using mems
Accident reporting system using memsRohit Sinha
 
Badripatro dissertation 09307903
Badripatro dissertation 09307903Badripatro dissertation 09307903
Badripatro dissertation 09307903patrobadri
 
Final Report 9505482 5845742
Final Report 9505482 5845742Final Report 9505482 5845742
Final Report 9505482 5845742Bawantha Liyanage
 
Motorola solutions ap6522 m access point installation guide wing 5.5 versio...
Motorola solutions ap6522 m access point installation guide   wing 5.5 versio...Motorola solutions ap6522 m access point installation guide   wing 5.5 versio...
Motorola solutions ap6522 m access point installation guide wing 5.5 versio...Advantec Distribution
 
Shb900 rm001 -en-p
Shb900 rm001 -en-pShb900 rm001 -en-p
Shb900 rm001 -en-pVo Quoc Hieu
 
ACCELEROMETER BASED HAND GESTURE CONTROLLED ROBOT USING ARDUINO
ACCELEROMETER BASED HAND GESTURE CONTROLLED ROBOT USING ARDUINOACCELEROMETER BASED HAND GESTURE CONTROLLED ROBOT USING ARDUINO
ACCELEROMETER BASED HAND GESTURE CONTROLLED ROBOT USING ARDUINOSnehasis Mondal
 
Uni v e r si t ei t
Uni v e r si t ei tUni v e r si t ei t
Uni v e r si t ei tAnandhu Sp
 

Similar to Unmanned Aerial Vehicle (20)

TFG_Cristobal_Cuevas_Garcia_2018.pdf
TFG_Cristobal_Cuevas_Garcia_2018.pdfTFG_Cristobal_Cuevas_Garcia_2018.pdf
TFG_Cristobal_Cuevas_Garcia_2018.pdf
 
Fibaro advanced users guide
Fibaro advanced users guideFibaro advanced users guide
Fibaro advanced users guide
 
Motorola solutions ap6522 access point installation guide wi ng 5.5 version...
Motorola solutions ap6522 access point installation guide   wi ng 5.5 version...Motorola solutions ap6522 access point installation guide   wi ng 5.5 version...
Motorola solutions ap6522 access point installation guide wi ng 5.5 version...
 
Real-time and high-speed vibrissae monitoring with dynamic vision sensors and...
Real-time and high-speed vibrissae monitoring with dynamic vision sensors and...Real-time and high-speed vibrissae monitoring with dynamic vision sensors and...
Real-time and high-speed vibrissae monitoring with dynamic vision sensors and...
 
Motorola ap 8222 access point installation guide mn000046 a01
Motorola ap 8222 access point installation guide mn000046 a01Motorola ap 8222 access point installation guide mn000046 a01
Motorola ap 8222 access point installation guide mn000046 a01
 
Motorola ap 8232 access point installation guide mn000032 a01
Motorola ap 8232 access point installation guide mn000032 a01Motorola ap 8232 access point installation guide mn000032 a01
Motorola ap 8232 access point installation guide mn000032 a01
 
Thesis
ThesisThesis
Thesis
 
Implementation of a Localization System for Sensor Networks-berkley
Implementation of a Localization System for Sensor Networks-berkleyImplementation of a Localization System for Sensor Networks-berkley
Implementation of a Localization System for Sensor Networks-berkley
 
Accident reporting system using mems
Accident reporting system using memsAccident reporting system using mems
Accident reporting system using mems
 
Badripatro dissertation 09307903
Badripatro dissertation 09307903Badripatro dissertation 09307903
Badripatro dissertation 09307903
 
Final Report 9505482 5845742
Final Report 9505482 5845742Final Report 9505482 5845742
Final Report 9505482 5845742
 
wronski_ugthesis[1]
wronski_ugthesis[1]wronski_ugthesis[1]
wronski_ugthesis[1]
 
Motorola solutions ap6522 m access point installation guide wing 5.5 versio...
Motorola solutions ap6522 m access point installation guide   wing 5.5 versio...Motorola solutions ap6522 m access point installation guide   wing 5.5 versio...
Motorola solutions ap6522 m access point installation guide wing 5.5 versio...
 
Shb900 rm001 -en-p
Shb900 rm001 -en-pShb900 rm001 -en-p
Shb900 rm001 -en-p
 
RFID
RFIDRFID
RFID
 
ACCELEROMETER BASED HAND GESTURE CONTROLLED ROBOT USING ARDUINO
ACCELEROMETER BASED HAND GESTURE CONTROLLED ROBOT USING ARDUINOACCELEROMETER BASED HAND GESTURE CONTROLLED ROBOT USING ARDUINO
ACCELEROMETER BASED HAND GESTURE CONTROLLED ROBOT USING ARDUINO
 
report
reportreport
report
 
Uni v e r si t ei t
Uni v e r si t ei tUni v e r si t ei t
Uni v e r si t ei t
 
Okotech Catwww3
Okotech Catwww3Okotech Catwww3
Okotech Catwww3
 
Okotech Catwww3
Okotech Catwww3Okotech Catwww3
Okotech Catwww3
 

Unmanned Aerial Vehicle

  • 1. Unmanned Aerial Vehicle Arab Academy for Science and Technology and Maritime Transport College of Engineering and Technology Department of Computer Engineering UNMANNED AERIAL VEHICLE (UAV) Presented by: Alexander Mohamed Osman Riyad Ahmed El-laithy Ruyyan Ahmed El-laithy Peter Raouf Zaky Supervised by: Dr. Ibrahim Imam ((July 2007)) Page 1
  • 2. Unmanned Aerial Vehicle ACKNOWLEDGEMENTS After thanking God the Merciful we would like to send our thanks to the following people: Firstly we would like to thank Dr. Ibrahim Imam for proposing the idea of an Unmanned Aerial Vehicle and for accepting us to carry on that project. Secondly we would like to thank Dr. Atallah Hashad for giving us a helping hand whenever we needed one and for providing us with solutions for all the challenges we faced. We would like to thank Dr. Hassan Ibrahim for providing us with help with the electrical problems we faced in our circuits. We would also like to thank Dr. Gamal Selim for his encouragement, assistance and understanding. We would like to thank Dr. Yasser Galal for answering some questions we had about DC motors. We would also like to thank Eng. Ahmed Akl, Eng. Renad Kamal, Muhab Bahgat, Ruyhan El-Laithy, Fady Mounier, Beshoy Helmy, Todd Elliot, and Sparkfun Electronics for supporting us and/or making this possible. Last but not least we would like to thank our parents & families for their love, support, and understanding. Page 2
  • 3. Unmanned Aerial Vehicle ABSTRACT Gathering information from locations which are inhabitable, hostile, or difficult to reach is a crucial aspect for learning new information about unmarked territories and activities and aids in human technological advancement. This project is concerned with developing an agent for gathering visual information by holding a stationary position or pursuing a dynamic target. The agent is a quadrotor VTOL (Vertical Take Off and Landing) aircraft. This agent should have the capability to hover, fly and follow targets. It should receive and transmit data wirelessly into a base station. It should move through a predefined plan using a GPS receiver. It should also balance itself in the air through a gyrometer and an accelerometer. In addition it would utilize four ultrasonic sensors for obstacle avoidance and an extra one for landing assistance. The agent would also utilize a wireless camera to transmit a bird s eye view to the base station. Page 3
  • 4. Unmanned Aerial Vehicle TABLE OF CONTENTS 1. INTRODUCTION .......................7 2. CONCEPTUAL DESIGN & PHYSICAL ASSEMBLY .. 12 3. ANALYSIS, COMPONENT-LEVEL DESIGN & SELECTION .18 3.1 Major Components ..18 3.2 PCB Design .. .......25 3.2.1 Interface Boards ...27 3.2.1.1 GPS interface board .27 3.2.1.2 Accelerometer / Gyrometer interface board ................28 3.2.1.3 RF Interface boards 24-G .. ............28 3.2.2 Motor Driver 29 3.2.3 The Brain.. ...31 4. CONTROL 33 4.1 Introduction .........33 4.2 SPI communication .35 4.3 Main PIC Implementation ................38 4.3.1 Pulse Width Modulation (Motors) ...38 4.3.2 ADC Operation ............43 4.3.2.1 Ultrasonic Sensors 50 4.3.2.2 Gyrometer .. ...52 4.3.2.3 Accelerometer . ..52 4.4 Secondary PIC Implementation ......55 4.4.1 GPS System .55 4.4.2 RF Transceiver .66 4.5 RC Unit ......75 Page 4
  • 5. Unmanned Aerial Vehicle 5. TESTING TROUBLESHOOTING AND REDESIGN 78 5.1 Testing ..78 5.1.1 LED Testing ..78 5.1.1.1 Accelerometer Testing ..78 5.1.1.2 Gyrometer Testing 78 5.1.1.3 SPI Testing 79 5.1.1.4 RC unit testing ..................79 5.1.2 LCD Testing ..80 5.1.2.1 Ultrasonic testing . ..81 5.1.2.2 Accelerometer Testing . ..81 5.1.2.3 RC unit Testing . ................82 5.1.2.4 GPS Testing . .83 5.1.3 RF Testing . . .83 5.1.3.1 Ultrasonic Testing . 83 5.1.3.2 Gyro Testing . 83 5.1.3.3 RC Unit . 85 5.2 Previous Chassis designs . ...88 5.3 RF Drivers . .....90 5.3.1 Laipac RF TX/RX ...90 5.4 Configuration 1 ......92 5.5 Configuration 2 ..96 5.6 Brain #3 .....99 5.7 Correcting Gyro Output 100 6. FUTURE IMPLEMENTATIONS ..102 7. CONCLUSION .......103 Page 5
  • 6. Unmanned Aerial Vehicle APPENDIX A : COMPONENT DATABASE AND CHARACTERISTICS . .104 APPENDIX B : CONTROL CODE . 106 APPENDIX C : WEIGHT & THRUST CHARTS .. . 165 APPENDIX D : LITHIUM POLYMER BATTERY CARE .167 APPENDIX E : ICSP PROGRAMMING .169 APPENDIX F : REFERENCES .170 APPENDIX G : BIBLIOGRAPHY ..173 Page 6
  • 7. Unmanned Aerial Vehicle INTRODUCTION The rapid development of micro-processor technology and the continuous growth of integration density of electronical and mechatronical components yields a significant cost reduction of high tech products. Driven by this development it becomes feasible to embed information processing and communicating devices in all sorts of appliances, toys, production facilities, communication systems, traffic and transport systems etc. With this integration and the aid of global positioning systems, there has been a surge of development in Unmanned Vehicles (UV). The main benefits of UV s are that they do not require human control and thus can be reduced in size and cost. They also limit human error in several aspects, and reduce if not eliminate human endangerment. Unmanned vehicles are developed for use in air, over land and under water by both private and government agencies. Several unmanned systems exist such as Autonomous Underwater Vehicles (AUV), Unmanned Ground Vehicle (UGV), and Unmanned Combat Vehicles (UCV). NASA deploys USVs (Unmanned Space Vehicles) on rock gathering missions from the Moon and Mars. The military advanced UAVs and renamed them to UAVS (Unmanned Aerial Vehicle Systems) and are used in flight combat. Government search and rescue departments find the UAVs helpful in inhabitable or hazardous terrain such as earthquakes, floods or volcanoes, where no human lives have to be risked. Institutions which have onsite geologists use UAVs for uncovering terrain and rock identification, without having to deploy a whole crew working outside. Departments of transportation can use this device to cover footage of inaccessible situations such as dead-lock traffic jams or multiple car-crashes. Government law enforcement and intelligence agencies can specifically find this device useful for reconnaissance and target pursuance, where the UAV provides the advantages of cheap costs, stealth and a diminished human risk factor. The Unmanned Aerial Vehicle project has been an ongoing attempt to produce a reliable autonomous hovering or flying vehicle. The project designed and implemented a four-rotor hovering aerial vehicle. The advantages of a hovering vehicle over a fixed-wing Page 7
  • 8. Unmanned Aerial Vehicle flying vehicle include less complexity in design, minimal space for take-off and landing (vertical take-off and landing (VTOL)), indoor flight, maneuverability in obstacle heavy environments and of course the eye-catching ability of being able to maintain a static position in mid-air. The advantage of quadrotors over helicopters is that they do not require mechanical linkages to vary rotor angle of attack as they spin, this simplifies design and control. The use of four rotors allows each individual rotor to have a smaller diameter than the equivalent helicopter rotor, for a given vehicle size, allowing them to store less kinetic energy during flight. These smaller propellers reduce the damage caused should the rotors hit any objects, this also makes the vehicles safer to interact with in close proximity. The first RC application of a 4-rotor vehicle was the Roswell Flyer made by Area51 technologies. Now there are several commercially available quadrotor aerial vehicles, to list a few, Atair aerospace quadcopter , Hammacher Schlemmer four rotor UFO , Keyence Engager and gyrosaucer and the DraganFlyer V Ti . The team s design was inspired by the DraganFlyer V, made by Draganfly Innovations Inc. where the four motors and props are laid at the ends of an X Chassis, and in the center lay the majority of the circuit boards and microprocessor dubbed by DraganFlyer Inc. as The Brain . (See figure below) Page 8
  • 9. Unmanned Aerial Vehicle System Block Diagram A general control scheme can be seen in the diagram above. The controller block is composed of two communicating MCU s (MicroController Units). The main MCU does most of the calculations and decision making. The main MCU also receives inputs from the proximity sensors and stability sensors, while the secondary MCU is responsible for communicating with a GPS receiver for positioning and an RF module for wireless communication. Both MCU s then drive the outputs for the four motors together. The stability sensors block consists of a 3-axis Gyrometer for angular velocity measurement and a 3-axis accelerometer for measuring acceleration. The proximity sensors block consists of 5 ultrasonic sensors placed around the vehicle and under it, for obstacle avoidance and assisted landing. The GPS receiver block consists of a GPS module that provides position, velocity, heading and altitude readings. The RF transceiver block consists of a 2.4GHz RF Module that communicates bi-directionally with a remote control unit for sending and receiving data. Page 9
  • 10. Unmanned Aerial Vehicle The Motor block consists of 4 high powered brushed motors with a gear ratio of 5.33:1 and 10x4.5 propellers. Both of these features provide a high thrust vehicle (As opposed to high speed). These motors are controlled through switching transistor circuits using PWM (Pulse Width Modulation). The UAV works in three different modes, in the simplest mode a land based PC sends out signals through an RF transceiver in order to steer the UAV in different directions. In the second mode a land based PC receives images from an onboard camera, then a pattern recognition system identifies a target object and sends signals to the UAV through the RF transceiver to steer it toward the desired object. If the object is not found the UAV rises in altitude quickly in order to find the object and re-track it. The third mode uses an onboard GPS that gives the current position of the UAV and it compares that to its target destination, and steers to its target destination then comes back to its initial point. In all modes an accelerometer and gyrometer are used to provide stability, and ultrasonic sensors are used to measure height and avoid obstacles and in turn to steer the UAV away from them. Because of the ambitious nature of the project, the team decided to build the UAV from ground up. Development of our 4-rotor vehicle can be divided into four major branches. 1. Conceptual Design and Physical Assembly. 2. Analysis, component-level design & selection. 3. Control. 4. Testing, Troubleshooting & Redesign. Although these four stages overlapped and interfered with one another they can be discussed independently, without much referencing to other sections. Page 10
  • 11. Unmanned Aerial Vehicle CONCEPTUAL DESIGN & PHYSICAL ASSEMBLY The conceptual design as stated previously was inspired by the DraganFlyer, and the team s first step was to identify the design goals. These were the fundamental requirements the team decided upon: 1. Ability to hover, in the sense of generating enough thrust and have enough control in order to maintain a mid-air static position. 2. Maneuverability in all directions of a three-dimensional plane. 3. Sufficient endurance of no less than 10-15 minutes. 4. A very light-weight body, including a battery with the highest power to weight ratio we could find since the battery is the heaviest single component of the vehicle. 5. High residual thrust to hover thrust ratio, an acrobatic vehicle was desirable for ability to demonstrate controllability and to perform difficult flight maneuvers. 6. Minimal size & complexity. The team decided to stick very close to traditional designs of 4-rotor vehicles, where four electric motors are placed on the corners of a rectangle, and drive four counter-rotating propellers. These propellers would produce sufficient thrust for take-off, and according to their different allocated power distributed on the four motors would provide maneuverability. Any propeller spinning produces a torque on the body it is attached to. For stability in flight the total resulting differential torque on the body should be zero. This is demonstrated very clearly in helicopters. The main rotor on the roof of the helicopter produces a large yaw torque on the body which is countered by the tail rotor on the rear of the plane. Assuming the main rotor is on a constant rpm, the difference in power to the rear propeller moves the helicopter around the z-axis. Page 11
  • 12. Unmanned Aerial Vehicle The proper rotation of the propellers, goes such as any two adjacent propellers rotate in opposite directions, and any two diagonal propellers rotate in the same direction. The sum of rotations of any two diagonal propellers should equal the sum of the remaining two diagonal propellers. This makes the total differential torque on the body about the z- axis zero. The figure below demonstrates the prop rotation direction. At hover mode, all four propellers would be producing the same amount of torque resulting in zero-net force on the vehicle about any-axis once gravity is taken into account. To make the vehicle increase or decrease in altitude, the speed on all four propellers are increased or decreased respectively. In order to move the vehicle in any direction of the x or y axis, two propellers adjacent propellers are increased in thrust, this causes the vehicle to pitch or roll in the desired direction, since the sum of the any two diagonal rotors is still the same as their other diagonal pair, this prevents the vehicle from yawing in any direction other than the desired course. Assuming the vehicle is in hover mode the following table yields a summary of the vehicle control scheme. Use the previous figure for propeller reference. Page 12
  • 13. Unmanned Aerial Vehicle Propeller 1 Propeller 2 Propeller 3 Propeller 4 Z+ (Up) + + + + Z- (Down) - - - - X+ (Left) + 0 0 + X- (Right) 0 + + 0 Y+ (Forward) + + 0 0 Y- (Backward) 0 0 + + As stated earlier, a lightweight body was a must in order to achieve maximum thrust for ease of flight and acrobatic maneuvers. For the chassis of the plane carbon-fiber was used, a very stiff and lightweight material, with a variety of practical uses commonly used in racecars and RC planes for their unique characteristics. To save even more weight we used the X-chassis design, where four motors would be placed on every end of the X- chassis. This would also give a better chance for the high pressure to accumulate and increase under the blade of the propellers to give higher lift than in a rectangular design. It would also reduce the overall air resistance. The arms of the X-chassis were made from hollow carbon-fiber tubes, and at the end of the tubes the motor mounts were placed. They were welded together using a common adhesive known to the RC world as Epoxy . On the bottom of the X-chassis the battery was mounted, keeping the battery on a lower point would lower the center of gravity of the vehicle giving the vehicle smoother pitching and rolling. On the four battery sides four ultrasonic sensors would be placed for obstacle avoidance. On the bottom of the battery the fifth ultrasonic sensor was placed to determine height, along with the wireless camera placed for surveillance purposes, video or image capturing. On the top of the X-chassis the UAV brain board was placed. It carries the accelerometer, gyrometer, RF Transceiver, GPS, motor controllers, ultrasonic sensors connections, and of course the Microcontrollers. The following figure below displays the chassis. Page 13
  • 14. Unmanned Aerial Vehicle After going through the design and experimentation of three different prototypes (found in 5.2 Previous Chassis designs). One of the most difficult tasks for us, that absorbed most of our time was coming up with the chassis that can have completely reduced air resistance, maximized technical output power when compared to theoretical power of the DC Brushed Motors involved, uniform density, and as extremely lightweight as possible with all the components that we have had to add on the UAV. The net weight on the UAV including all added components added up 990g when measured on the scale, which is almost 1 Kg. The theoretical output power given to us by the DC Brushed Motors added to up to a maximum thrust of 390 grams per motor. (See APPENDIX C) Since we have 4 motors on the UAV, the complete output power given by those motors is 1560 grams (1.56Kg). Technically, the team managed to output only around 350 grams per motor, adding up to 1400 grams (1.40Kg) of thrust. The efficiency of our design brought us 89.74% of that power. The loss in power comes up to 10.26% due to friction forces, and minimized air resistance. It is made mostly out of lightweight Carbon Fiber and Balsa Wood for the base of the electrical circuit. The total weight of the chassis without all the components comes to 43 grams. A CAD model was designed, shown in the following figures. An isometric view is shown below, and the dimensions of the chassis design are shown in the next few pages. Page 14
  • 15. Unmanned Aerial Vehicle Top View: Front View: Right Side View: Page 15
  • 16. Unmanned Aerial Vehicle Calculations: Motor Force: Max OutputTheoretical/Ideal = 390 grams/Motor Max OutputTechnical = 350 grams/Motor Therefore, the Total Motor Output of 4 Motors at Full Power: Max Output4Motors = 1400 grams/4 Motors Maximum Payload = 1400 990 = 410 grams Hence, Max Output in Newtons = 1400 x 9.807 = 13.730 Newtons Max Output per Motor = 13.730/4 = 3.432 Newtons Net Force: Therefore, Lift of Chassis at Full Power and when Differential Torque = 0. Chassis mass = 990 grams = 0.99 Kg Chassis weight = 0.99 Kg x 9.807 m/s2 = 9.709N Lift = 13.730 9.709 = 4.021 Newtons Acceleration: Net Force = Lift - Gravity = ma mg 4.021 = 13.730 9.709 0.99a = 1.4(9.807) 0.99(9.807) a = (0.41(9.807)) / 0.99 acceleration = 4.061m/s2 Therefore, the Power to Weight Ratio: 1.5 : 1 Therefore, Lateral Thrust beyond Hover thrust = (4.061m/s2) / (9.807m/s2) = 0.4141g Page 16
  • 17. Unmanned Aerial Vehicle Torque: = Acceleration / Distance to Center = 4.061 m/s2 / 0.14m = 29.007 rad/sec2 = mass * radius2 * (angular velocity) = (0.495) x (0.14) 2 (29.007) ; where (0.99/2 Motors = 0.495 grams, since it takes 2 motors for the UAV to move front, back, left or right). = 0.2814 Newtons MAX = 4.061 x 0.14 = 0.56854 Newtons A picture of the UAV with complete physical assembly can be seen below in the following figure. Page 17
  • 18. Unmanned Aerial Vehicle ANALYSIS, COMPONENT-LEVEL DESIGN & SELECTION 3.1 Major Components : The selection of the motors were brushed motors the GWS EPS-350C with a gearing ratio of 5.33:1, which peak out at 8.0V and 8.0A, each of these weigh 63g and are projected to deliver 15.37oz (435.73g) of thrust at peak power. Four of these motors are used, with one on each end of the X -chassis. A figure is placed below. Counter-rotating propellers were selected as our default propellers, which are a must in any quadrotor plane, because motors do not turn in the same direction. We selected 10*4.5 propellers which are large considered for our motor. Larger propellers are more suitable for high thrust application, and smaller rotors are more suitable for high velocity and aerodynamic capabilities. Our choice was the EPP1045 propeller. A figure of the propeller is placed below. Page 18
  • 19. Unmanned Aerial Vehicle Heat syncs were also used to cool down the motors to increase durability and efficiency as well as to dissipate the heat created by the motors for a longer, more durable life. The team selected EHS300 an aluminum, multi-fin heat sync for good heat dissipation and proper venting respectively. The heat sync has two large fins and 24 smaller fins. A figure of the heat sync is placed below. We needed a battery source that can provide more than 32A continuously, considering each motor can consume 8A, the battery of choice was a Lithium-polymer Thunder Power TP8000-2S4P two-cell 7.4V, 8AH battery. It can work continuously at 12C (96A), and can burst at 18C (144A) which is more than sufficient to have all motors working at full thrust. With a weight of 320 grams and dimensions of 128*50*29mm it had a high power to weight ratio and size relative to its competitors. It would also give us about a good 15 minutes of airtime if the UAV is flying at full power. A figure of the battery is placed below. Page 19
  • 20. Unmanned Aerial Vehicle A compatible charger the Astro-flight 109D was selected. Charging rates from 50mA - 8A. Lithium polymer batteries can charge at a maximum of 1C of their rating, so this charger can charge the battery in the fastest possible time which is 1 hour, for quick practical testing. The battery is two cells, any battery with more than one cell requires a balancer, so a blinky battery balancer was used which balances the cells before, after and during recharge. A wattmeter was also required to measure the voltage and current of the battery before and after recharge. A powerful and bulky power supply is required to continuously deliver such current to the charger. The astro-flight power supply was used, with an input of 110V/220V and an output of 13.5V, it delivers 12.5A. Figures of the charger (top left), blinky battery balancer (top right), wattmeter (bottom left), and power supply (bottom right) are placed below. Page 20
  • 21. Unmanned Aerial Vehicle The accelerometer used was the triple-axis ADXL-330. Works at 3.3V logic, and consumes 0.32mA, it has three outputs for x, y and z axes. Minimum full scale range is ±3g, and a sensitivity of 300mV/g. The gyrometer used is the IDG-300 which also works at 3.0V logic and has a full scale range of 500°/sec, and consumes 9.5mA, but has only two outputs, x and y. Because of this the team had to place two of these IC s onboard, to get angular velocity about all three axes. Pictures of the accelerometer and gyrometer are displayed below from left to right. The IMU five degrees of freedom is an IMU (Inertia Measurement Unit) that combines the IDG300 gyrometer and an ADXL330 accelerometer. This unit measures x and y angular velocity and x, y, z accelerometer outputs, hence the name 5 degrees of freedom . Its advantages over two separate units are firstly that the x and y outputs of both have identical headings, and you only have one VCC and one GND connection. Disadvantages are if this IC for any reason becomes defective you lose two IC s. A figure of this IC is displayed below. Page 21
  • 22. Unmanned Aerial Vehicle Ultrasonic sensors used were the Max sonar LV-EZ1 which work at 5.0V logic and have a maximum range of 255in (6.45m), which measures in increments of an inch, they have analog, digital and pulse width modulated outputs. It consumes 2mA. Five of these are placed onboard, four facing x and y axes, in order to detect obstacles around the vehicle, and one on the bottom of the battery facing downwards to detect height and aid in landing. We could not rely on the altitude reading of the GPS system for height because there is an error tolerance of ±5m, this could result in hazardous landings. The extra ultrasonic sensor on the bottom would virtually eliminate that error because its resolution is relatively quite high. For communication with ground, radio frequency IC s are used. The Laipac TRF2.4-G transceiver was used. It operates at a high frequency, 2.4GHz. Data rate transmission can work at either 250kbps or 1Mbps. It works at 3.0V logic consumes 10.5mA in TX mode and 18.5mA in RX mode. Maximum range is 280m. Each unit can send and receive data interchangeably. One of the transceivers is placed onboard, and the other is connected to a land-based PC, they send and receive data to and from each other. Page 22
  • 23. Unmanned Aerial Vehicle For unmanned guidance to different destinations a GPS system, the EM-406 was used. Readings of latitude, longitude and altitude obtained serially are used to triangulate the position of the IC. Power input is rated between 4.5V-6.5V and power consumption is 70mA, operating frequency is at 1.58GHz. A figure of the GPS is placed below. jhnjh For the surveillance system the WS-309AS system was used, the package comes with 1.2GHz camera with a resolution of 628*582 and a horizontal definition of 380 lines. The camera works at 9.0V, and consumes 85mA. A simple 9V battery operates the camera. The package also comes with a receiver with audio out and video out. Linear transmission distance ranges from 50m-100m. A picture of the camera and components are placed below. Page 23
  • 24. Unmanned Aerial Vehicle The selected PIC programmer was the Olimex PIC-MCP-USB programmer. It is a low cost PICSTART alternative, is MPLAB compatible and thus does not require a RS232 port. In addition it has an ICSP (In Circuit Serial Programming) connector (ICSP programming explained in APPENDIX E). A figure of the programmer is displayed below. Page 24
  • 25. Unmanned Aerial Vehicle 3.2 PCB Design Required components for designing and etching a PCB are acetone, a laser printer, glossy paper, a clothing iron, acid and a steel sponge. Firstly the surface of the brass board is scrubbed with a steel sponge to remove any impurities and any oxidized brass. It is then cleaned thoroughly with cotton drained in acetone. The team used the circuit designing program called EAGLE 4.16r1 . Any circuit is printed on glossy paper, the printed glossy paper is then well folded around the board to prevent any slip during ironing, then ironed on the brass board. Ironing continues until the circuit becomes visible from the other side of the printed glossy paper, or preferably when the white paper takes a yellowish/brownish color indicating a slight burn. (Caution should be taken during ironing, if the brass board becomes too hot, the brass actually deforms). After ironing, the paper should be removed leaving the toner ink on the brass board. The brass board is then placed in the acid and left until all brass surrounding the printed circuit is dissolved. After removing from acid and rinsing in water, a steel sponge is gently scrubbed on the toner ink to leave the brass trace under the toner ink while removing the ink. Holes are drilled into the circuit board in the appropriate places where components are to be placed. After drilling is complete, components are welded onto the board using solder and a soldering iron. All circuits used for this project were designed in this manner. Pictures below (left to right) display this procedure. Before these boards were actually designed they were tested on bread boards first in order to assure everything is working in order, because making an incorrect PCB means much wasted time and raw materials. More of this can be referenced in Section 7, Testing troubleshooting and redesign. Page 25
  • 27. Unmanned Aerial Vehicle 3.2.1 Interface Boards Learning from previous errors we found it would be more convenient to create interface boards for individual IC s rather than integrate them into one large circuit. (Much the way a desktop motherboard uses PCI cards instead of making one large board.) This is because if any errors occur in the design, or redesigning is desired, the individual IC s wouldn t need to be removed. Frequently exposing IC s to strong heat when welding can damage these components. 3.2.1.1 GPS Interface Board In his board the GPS cable is welded onto the left row of pins. The descending order of these pins is; not used, GND, TX, RX, VIN, & GND, again. The first pin is ignored. The second and last pins (both GND) connect to the right side second pin. The third pin TX connects to the fourth pin on the right. The 4th pin on the left is RX that connects to the third pin on the right. Page 27
  • 28. Unmanned Aerial Vehicle 3.2.1.2 Accelerometer / Gyrometer Interface Board This follows the same method as the GPS interface board. The E$1 row is the yaw gyro, E$2 row is the roll/pitch gyro. E$3 row is the three axis accelerometer. E$4 row is the pin headers that connect onto the main board. 3.2.1.3 RF boards The TRW-24G is a very sensitive component therefore we designed this interface board with a TRW-24G socket for plug and play action onto the board. Page 28
  • 29. Unmanned Aerial Vehicle 3.2.2 Motor Drivers : Designing a suitable motor controller circuit was a challenging task, especially due to the lack of components here in Egypt. The controlled motors could take up to 64 Ampere bursts for a startup current and up to 8 Amperes as a continuous current. In order to achieve maximum power we needed to cause a minimal voltage drop in our circuit. We came up with the following design objectives: - Switching speed of up to 2KHz (for PWM control) - Minimum Vce drop possible for more powerful motors - High current Ic - Low current Ib Unfortunately the transistors fitting this description could not be found here in Egypt, but we found a transistor 2SD1062. It is capable of running a current of up to 15A and Vce of as low as 0.3V, but it needed a larger current for Ib than a PIC could provide, therefore we added a TIP120 transistor as an interface between the PIC and the 2SD1062. Since Vce of the 2SD1062 was a function of the Ic current we put 2 transistors in parallel to drop the Vce as low as possible while at the same time assuring that it has enough capacity to pass through the required current for the motor. A main feature of this circuit is the PC817 optocoupler, an IC that interfaces between the PIC circuit and the motor circuit. Isolating these circuits was necessary because combining high current components with low current ones can damage the low current components. The optocoupler in the following diagram is labeled as 2. The left side of the optocoupler is connected to the PIC circuit and the right side is connected to the motor circuit. The first rows of pins in order are GND (PIC circuit), Vcc (PIC circuit), GND (Motor circuit) and Vcc (Motor circuit). Vcc from PIC (PWM output) circuit goes through a 1.5K resistor through optocouplers where the phototransistor is activated and returns to the PIC ground. The signal in turn goes through the base of the TIP120 turning it on. The emitter of the TIP120 connects to the base of the 2SD1062 transistors, whose collectors are Page 29
  • 30. Unmanned Aerial Vehicle connected to the motor and the motor is connected to the Li-Poly battery. A circuit schematic is shown below. Resistors were placed to produce desired voltage drops. In the final motor driver design, the optocoupler was removed from the motor driver and put on the main brain. This was done in order to have smaller motor drivers, and to have less connections between the main board and the motor driver. Also large motor drivers facing upwards would make contact with revolving propellers, and if facing downwards could cause noise with the ultrasonic sensors. Page 30
  • 31. Unmanned Aerial Vehicle 3.2.3 The Brain To avoid the mistakes that occurred in Configuration 2 mentioned in the Testing, Troubleshooting & redesign section the team changed two things mainly. FirstlyTo avoid the problem of circuit design or re-altering, it was decided that the IC s would be mounted on separate boards that would mount on the main Brain board, much the way PCI slots are mounted on a normal PC. In our previous design, should any circuit design errors occur, a new board would have to be made, and all components would have to be welded off the old board, and re-welded to the new brain. This takes a lot of time, and it is also potentially damaging to the components to be frequently exposed to the welder. Secondly as for having the problem of high power rated components alongside low power rated ones in one circuit, optocouplers were used to interface between the Brain board and motor drivers, this is more thoroughly explained in the previous section 4.6 Motor Drivers . Page 31
  • 32. Unmanned Aerial Vehicle This Main board was designed to accommodate two PIC16LF777s, 4 Motor controller boards connected through 4 opto-couplers, a 3-axis accelerometer, 2 dual-axis gyrometers, 5 ultrasonic sensors, a GPS receiver and a RF transceiver. To keep the circuit as small as possible we used the internal 8MHz oscillators available in PIC16LF777 PICs instead of adding more components to the circuit in the form of crystals and capacitors. The circuit is powered by a 9V battery and has a 5V regulator as well as a 3V regulator for all 5V Logic components as well as the 3V Logic components to operate. We also added some LEDs to simplify debugging. Later on we manually welded on some wires to two ICSP connectors to program the two PICs without removing them from the circuit. (As seen in the previous picture). Page 32
  • 33. Unmanned Aerial Vehicle CONTROL 4.1 Introduction The Main PIC is responsible for reading and calculating the orientation of the plane, and accordingly take a decision. The Main PIC has only 3 PWM modules, therefore we use an extra PWM from the Secondary PIC. The Main PIC sends commands to the Secondary PIC to increase or decrease the power of one PWM output, it also sends the orientation data to be sent through the RF to the base computer station. The Secondary PIC takes the GPS messages and extracts the required values and sends them to the Main PIC, as well as through the RF to the base station. Regarding the control scheme, there are four separate operation modes: 1. Hover Mode 2. RC Mode 3. GPS Mode 4. Tracking Mode In Hover Mode: Tries to keep the vehicle stable in position. The following pseudocode demonstrates the operating algorithm. Start up system Read bias values from IMU sensors Loop: Read sensors Calculate Angles & Height If(Height<Required Meters) Increase PWM if(Height>Required Meters) Decrease PWM if tilted left Tilt right If tilted right Tilt left If tilted forwards Tilt backwards If tilted backwards Tilt forwards Repeat loop Page 33
  • 34. Unmanned Aerial Vehicle In RC Mode: The Secondary PIC is the one that receives the RC commands through the RF, then forwards them to the Main PIC to execute. In GPS Mode: The Secondary PIC takes the GPS messages and extracts the required values and sends it to the Main PIC, and it sends all other useful data through the RF to the base station. The Main PIC takes decisions according to its coordinates achieved from the GPS from the Secondary PIC. In Tracking Mode: The base station receives the Video Feed from the Wireless Camera on board the vehicle and searches for a blue target in view, if it is not found the vehicle will gain altitude and search again. Once a target is found the plane will descend quickly and hover above the target and keep following it. The Secondary PIC receives the commands from the base station through RF and forwards the commands to the Main PIC which performs the required actions. Page 34
  • 35. Unmanned Aerial Vehicle 4.2 SPI communication SPI communication enables quick communication between two PIC s. One is set as a Master PIC and the other as a slave. Originally one PIC was intended to be used, but failed. (refer to Testing, Troubleshooting & Design : Configuration 2). The connection is as follows on the diagram below. The left block represents the Master PIC and the left block is the slave. A bit is released from the Master SSPSR to SD0, and the slave PIC releases a bit through it s SD0 also. The clocks SCK of both PICS are connected together. When a clock pulse rises and falls from the master PIC a bit is transferred. Every consecutive clock transfers a bit. Once the shift registers reach 8-bits (1 byte) the byte is transferred to the serial input buffer and the shift register is ready to receive data again. Three connections are required, CLK to CLK (C3-C3), Master data out to slave data in (C5 C4), and master data in to slave data out (C4 C5). Two registers must be set in both PIC s in order to enable this mode; SSPSTAT and SSPCON. (Actual settings for these registers can be found in APPENDIX B : CONTROL CODE) Page 35
  • 36. Unmanned Aerial Vehicle SSPSTAT (Status Register) Page 36
  • 37. Unmanned Aerial Vehicle SSPSCON (MSSP Control Register) For desired interrupts bits 6 and 7 of INTCON (Global and peripheral interrupts) should be set. Bit7 of PIE1(SSPIE) should be set. When interrupt occurs bit7 of PIR1(SSPIR) is set. This occurs if either a byte is successfully transferred, also in case of collision occurs or overflow occurs. Page 37
  • 38. Unmanned Aerial Vehicle 4.3 Main PIC Implementation Generally as aforementioned, this PIC uses PWM, SPI, and ADC, it decides the orientation and heading of the plane. The following sections divide these tasks and explain each of these elements independently. 4.3.1 Pulse Width Modulation After we have finally tested all our sensors, GPS device and RF devices for correct processed data, we can now begin to implement the results as output on the propellers through motor control. This is achieved by the use of PWM. In the PIC 16LF777, it has three pins for PWM. The control registers used to enable PWM on this PIC are CCP1CON, CCP2CON, CCP3CON, PR2 and most importantly T2CON, since PWM is controlled by Timer 2 in the microcontroller. These three CCPXCON registers let us enable capture modes, compare modes or PWM. Of course here, we will enable the PWM. Page 38
  • 39. Unmanned Aerial Vehicle Bit 7: Unimplemented. Bit 6: Unimplemented. Bit 5: Should be set as 0. Second Least Significant bit in PWM mode. (10-bit Resolution). Bit 4: Should be set as 0. First Least Significant bit in PWM mode. (10-bit Resolution). Bit 3: Should be set as 1. (To enable PWM mode). Bit 2: Should be set as 1. (To enable PWM mode). Bit 1: Don t care in PWM. (To enable PWM mode). Bit 0: Don t care in PWM. (To enable PWM mode). The CCPXCON registers will be all set as following: CCP1CON: 0x0F = 0b00001111; CCP2CON: 0x0F = 0b00001111; CCP3CON: 0x0F = 0b00001111; Page 39
  • 40. Unmanned Aerial Vehicle After setting the CCPXCON registers, we must now set the T2CON register where most importantly we must enable TIMER2 of the microcontroller and then set the period we need to control our DC Brushed Motors in an optimum way using the PR2 register and setting it with a fixed value. By means of research and supervision, it was decided to control our motors at a frequency of 750Hz (750 times per second). For T2CON, we place the following settings: After setting the CCPXCON registers, we need to now set the T2CON register which enables TIMER2 in the microcontroller that will then control over the frequency or period we need on the Pulse Width Modulation. In order do this we must set the following bits as follows. Bit 7: Unimplemented. Bit 6: Should be set as 0. (Postscaling will not be needed). Bit 5: Should be set as 0. (Postscaling will not be needed). Bit 4: Should be set as 0. (Postscaling will not be needed). Bit 3: Should be set as 0. (Postscaling will not be needed). Bit 2: Should be set as 1 in order to enable and turn on Timer 2. Bit 1: Should be set as 1. (Since prescale with a value of 16 is required). Bit 0: Should be set as 1. (Since prescale with a value of 16 is required). Page 40
  • 41. Unmanned Aerial Vehicle Our goal to control our motors at around 750Hz. Now since the microcontroller can execute 2 million instructions per second (500 nanoseconds). Speed should be reduced by prescaling. When you prescale your instructions per second over 16 which is our maximum, then we have reduced the frequency to 125 KHz (125000Hz). This is where the PR2 register comes in handy to further reduce frequency to 750Hz. For PR2, we place the following settings: PR2 is an 8-bit register made available in order to control the frequency output needed on the DC Brushed Motors. After using the T2CON register for prescaling to reduce frequency to 125 KHz, PR2 register is used to enter a decimal value that will control and limit our frequency to 750Hz. The value to be placed in the PR2 register is calculated as follows. We divide the 125000 Hz obtained by 750Hz which is what is needed. 125000/750 = 166.666667. Since the value to be placed in the PR2 register should be an integer value and is an 8-bit register and carries no space for a floating point number, 167 should be entered after subtracting 1 from it. Therefore, PR2 = 166 The equation for PR2 is: round (Fosc / (4 x 16 x Period Required)) - 1 Hence, Fosc = 8 x 10^6 PR2 = round(8 x10^6 / ( 4 x 16 x 750)) - 1 PR2 = round(8 x 10^6/ (48000)) - 1 PR2 = round(166.66666667)) - 1 PR2 = 167 - 1 PR2 = 166 Page 41
  • 42. Unmanned Aerial Vehicle Setting outputs on the Tri-State Buffers on all ports of the Microcontroller: Since the PWM pins are driving the motors they need to be se as output pins. This is done by setting the registers TRISB and TRISC. TRISC = 0x00 Hex = 0b00000000. TRISB = 0x00 Hex = 0b00000000. The diagram of the PIC 16LF777 can be used as a reference below for the output pins CCP1 on Port C2, CCP2 on Port C1, and CCP3 on Port B5. *NOTE: Please see APPENDIX B for the sample code of Pulse Width Modulation and how to control it. Page 42
  • 43. Unmanned Aerial Vehicle 4.3.2 ADC Operation Here using the Analog - to - Digital converters is most crucial in order to automate our Unmanned Aerial Vehicle (UAV). For the most part, most or all of our sensors, ultrasonic, gyrometer and accelerometer give us feedback on our control system. The Ultrasonic provides us with a way for collision detection and obstacle avoidance. The accelerometer and gyrometer provide us with crucial data to help us stabilize our UAV in mid-air and maintain a static hovering position. It can also help the UAV to auto-level after traveling in a certain direction, like a co-pilot. The outputs of those sensors are analog voltages. The Analog - to - digital converter here helps with converting those outputs into useful data ready to be used and processed by the microcontroller. In this project we use the 16LF777 PIC by Microchip. It contains an abundant 14 channel 10-bit ADC. We have 11 inputs from those sensors. Five alone for the ultrasonic sensors, placed on the front, back, left, right, and bottom sides of our UAV for height accuracy. The ultrasonic s range is far as 6.45m (254 inches) and as small as 15cm (6 inches) to aid the UAV in landing due to its blind spot. Six channels are used for 2 Gyrometers and an accelerometer. Each gyrometer outputs the rate of angular velocity in the X and Y planes, so we need three channels since we have 2 gyrometers. One input/channel will be ignored from the second gyrometer. The accelerometer needs 3 channels since it measures acceleration in the X, Y, and Z directions. This makes a total of 11 channels. Therefore, 3 channels on our 16LF777 microcontroller will not be used out of the 14 channels. In order to set this up in our PIC we must enable certain bits in our control registers of the 16LF777 microchip. These control registers are the ADCON0, ADCON1, ADCON2, PIE1, and PIR1 and last but not least the INTCON register to enable our interrupts especially when the ADIF (AD Interrupt Flag) is set after every conversion in the PIR register. The result of the Analog-to-Digital Converter is placed in the ADRES (AD Result) register. It consists of 2 8-bit registers, ADRESL (AD Result LOW) and ADRESH (AD Result HIGH). Page 43
  • 46. Unmanned Aerial Vehicle For ADCON0, we place the following settings: Bit 7: <ADCS1> Must be set as 1 since we are using the Internal Oscillator. Bit 6: <ADCS1> Must be set as 1 since we are using the Internal Oscillator. Bit 5: <CHS2> Analog Channel Select bit. Bit 4: <CHS1> Analog Channel Select bit. Bit 3: <CHS0> Analog Channel Select bit. Bit 2: <GO/DONE> A bit that controls the start of conversion or end of conversion. Bit 1: <CHS3> Analog Channel Select bit. Bit 0: <ADON> Turns on the ADC module in the microcontroller. Bits 5,4,3,1 are used to select the channels we need to take our inputs from. Therefore, you need to toggle through them as we read our values over the output interval time. We start out by reading through channel 0, then 1, then 2, until we reach channel 10 (11 Channels) then go back to Channel 0 to take new readings to process for our new interval. Page 46
  • 47. Unmanned Aerial Vehicle For ADCON1, we place the following settings: Bit 7: <ADFM> Must be set as 1 for Right Justification in the ADRES register. In reading our result from the ADRES register, we read all the 8 bits from ADRESL and the least significant bits of ADRESH and multiply it by 256. Bit 6: <ADCS2> Must be set as 1 since we are using the Internal Oscillator. Bit 5: <VCFG1> Must be set as 0 since our Vref+ is normally the VDD of the PIC. Bit 4: <VCFG0> Must be set as 0 since our Vref- is normally the VDD of the PIC. Bit 3: <PCFG3> Must be set as 0 since we need to enable 11 Channels. Bit 2: <PCFG2> Must be set as 1 since we need to enable 11 Channels. Bit 1: <PCFG1> Must be set as 0 since we need to enable 11 Channels. Bit 0: <PCFG0> Must be set as 0 since we need to enable 11 Channels. The bits 3,2,1,0 of PCFG(X) remain fixed since we are enabling only 11 Channels for the ADC to read from. The pins where pins AN11, AN12 and AN13 of the microcontroller 16LF777 remain digital I/O pins depending on the settings of the Tri-State Buffers for the ports. For ADCON2, we place the following settings: Bit 7: Unimplemented. Bit 6: Unimplemented. Bit 5: Must be set as 1, since we wish the conversion to take 12TAD (24 sec). Bit 4: Must be set as 0, since we wish the conversion to take 12TAD (24 sec). Bit 3: Must be set as 1, since we wish the conversion to take 12TAD (24 sec). Bit 2: Unimplemented. Bit 1: Unimplemented. Bit 0: Unimplemented. Page 47
  • 48. Unmanned Aerial Vehicle The reason why 12TAD is necessary here is simply because one TAD is equivalent to 2 sec. The acquisition time must not exceed the minimum of 19.72 s which is how long the ADC before the ADC starts conversion automatically. Therefore, 2 s * 12 = 24 sec, which is how long the ADC needs to acquire our data from one input channel. In order to keep the microcontroller working efficiently and processing data without having it constantly polling and wasting processing power on all kinds of data coming in through the Sensors, GPS device or RF transceivers, we use interrupts. Concerning our sensors we set the PIE1 control register in our microcontroller. The Analog-to-Digital Interrupt Enable (ADIE) is bit number 6. We set it to 1. Whenever the ADC finishes a conversion, it will set the Analog-to-Digital Interrupt Flag in (ADIF) to 1 in register PIR1, interrupting the PIC. After we take our reading for the ADC, we must clear the ADIF in the PIR1 register in our software or else the PIC will keep itself running in a loop. Then we must change our channel through the bits 5, 4, 3, and 1 in the ADCON0 register. When this is done, we start a new conversion by the setting the bit number 2 (GO/DONE) as 1 in the ADCON0 register until the end of conversion is complete and the ADIF is set again calling the interrupt function in our microcontroller. Setting our inputs on the Tri-State Buffers on all ports of the Microcontroller: Since we have already set our control registers of the ADC module most importantly, we need to set the tri-state buffers on our ports in order to receive our inputs from the sensors. This is done by setting the registers TRISA, TRISB, and TRISE. TRISA = 0xFF Hex = 0b11111111. TRISB = 0x0E Hex = 0b00001110. TRISE = 0x07 Hex = 0b00000111. Page 48
  • 49. Unmanned Aerial Vehicle In the summary of registers shown above, we must be very careful when setting the TRISE register because only the three least significant bits here control the PORTE Data Direction Bus, unlike TRISA where the complete register is used for only 6 pins. If we set the TRISE = 0xFF, it will cause the PIC to set two interrupt flags IBF and OBF and enable PSP Mode , which will cause PORTD to engage in parallel communication. This will cause the PIC to enter in an infinite loop of interrupts and if the flags are not cleared in the software. It almost causes the microcontroller to seem to Halt in a sense. Page 49
  • 50. Unmanned Aerial Vehicle 4.3.2.1 Ultrasonic Sensors The ultrasonic sensors used on the UAV can detect up to 254 inches 6.45 (meters) and the minimum distance it can detect due to its blind spot is 6 inches (15 cm). The sensor generates a new reading every 49 milliseconds. Since the microcontroller can take readings much faster than the ultrasonic sensor s output, if we take the readings at that speed, it will cause a lot of noise in our program for the UAV, so it is best we take our readings every 49 milliseconds to avoid the noise and make sure we have a new reading every time to be put to good use. Every 0.01 Volts on our Ultrasonic sensor represents 1 inch of distance. Therefore, if the voltage on the output pin of the ultrasonic sensor is 0.20 Volts, then the distance it reads is 20 inches, therefore it is very simple to use. In order to calculate the distance we need in our PIC 16LF777 we use a very simple equation which is: Distance (in Hexadecimal) = (Vin/Vref) X (2N) ; where Vin : is the Voltage input coming from the Ultrasonic Sensor. Vref : is the reference voltage from our circuit which is 3.30V N : is the number of bits of the ADC which is 10, therefore is 1024 For example, If Vin = 0.50V (which is equivalent to 50 inches read). Vref = 3.30V Then, 0.50/3.30 X 1024 = 155.1515 Hexadecimal In the ADC of the PIC 16LF777, the ADRES (AD Result) register will read 155 and will truncate the 0.1515. If we take the reading 155 from the ADC and try to convert it back, it will be as follows: Page 50
  • 51. Unmanned Aerial Vehicle Vin = (Reading from ADRES Register in HEX / 2N) X Vref Vin = (155/1024) X 3.30V = 0.4995 Volts. Therefore the error is: (1 (0.4995/0.5)) X 100 = 0.1 % which is quite accurate. *NOTE: Please see APPENDIX B for the sample code of the Ultrasonic Sensors. Page 51
  • 52. Unmanned Aerial Vehicle 4.3.2.2 Gyrometer The gyrometer used was the IDG300. This IC gives accurate readings of angular velocity. All three angles were needed for control of the UAV, on the x, y and z axes; traditionally in flight labeled as roll, pitch and yaw angles. Angular velocity is measured accurately with a sensitivity of 2 mV/ º/s. So every degree of rotation would indicate 0.002V electronically. The first thing to do was to interpret the signals into degrees, 0º - 360º. This IC operates so that if the IC is rotated suddenly then stopped, you would get a change in reading only when the IC is moving, only when there is angular velocity. Thus an adder function is needed to constantly integrate the tilt intervally through the selected frequency, as general equation is as follows: SUM SUM new t Where SUM is initially set to 0. new is the latest reading from the gyro output and T is the sampling period. After the electric signal would be received on the ADC ports of the PIC it would be multiplied by the following equation to give degrees: 1024 t AngleNew AngleOld Vin * * 3.3 0.62 Also any negative value for tilt had 360 added to it, since simple sin and cos functions behave differently to negative values. 4.3.2.3 Accelerometer The accelerometer used was the ADXL330. This gives accurate measures of acceleration about all three axes. Typical sensitivity of this IC is 300mV/g, so every 1m/s2 of acceleration would indicate 30.58mV electronically. Primarily this IC has two main functions. The first is to indicate the initial angles of x and y in reference to the xy plane perpendicular to the gravity vector, so that the UAV can take off from any angled surface, if an accelerometer was not used, the system would always assume that the plane it was taking off from was always perpendicular to the vector of gravity, causing flight to be unstable. To use the accelerometer as an inclinometer, assuming X and Y are the acceleration values obtained from the corresponding axes on the accelerometer then, simply Page 52
  • 53. Unmanned Aerial Vehicle X -1 X=sin g Y -1 Y=sin g The second use is to produce accurate estimations of acceleration, velocity and position, for use in the simulation. A fixed reference point is taken, more accurately the fixed axes at the point of takeoff. Acceleration and velocity in reference to that point are calculated. Distance from that point is calculated, and distance traveled around that point is also calculated. Considering the accelerometer uses the angles supplied from the gyrometer, a traditional 3D rotational matrix is used to rotate the constantly generated acceleration vectors around the reference axes, so that every value from the accelerometer has a X, Y and Z component on the reference axes. Rotation around the x-axis is defined as : 1 0 0 RX( X) = 0 cos X sin X where X is the roll angle 0 sin X cos X Rotation around the y-axis is defined as : cos Y 0 sin Y RY( Y) = 0 1 0 where Y is the pitch angle sin Y 0 cos Y Rotation around the z-axis is defined as : cos Z sin Z 0 RZ( Z) = sin Z cos Z 0 where Z is the pitch angle 0 0 1 Multiplying all these matrices together would give the following matrix: Page 53
  • 54. Unmanned Aerial Vehicle cos Y cos Z cos Y sin Z sin Y 1 A sin Y sin X cos Z cos X sin Z sin Y sin X sin Z cos X cos Z sin X cos Y sin Y cos X cos Z sin X sin Z sin Y cos X sin Z sin X cos Z cos X cos Y if X,Y and Z are the acceleration values obtained from the corresponding axes on the accelerometer then, ReferenceX = Xcos Xcos Y + Y(sin Ycos Xsin Z-sin Xcos Z) + Z(sin Ycos Xcos Z+sin Xsin Z) ReferenceY = Xsin Xcos Y + Y(sin Ysin Xsin Z+cos Xcos Z) + Z(sin Ysin Xcos Z-cos Xsin Z) ReferenceZ = - Xsin Y + Ycos Ysin Z + Zcos Ycos Z Integrating with respect to time once gives velocity, and integrating twice gives position. Adder functions are used for velocity and position for each reference axes. Another adder function is created taking the absolute value of every acceleration reading, then multiplying them by time twice in order to calculate the distance traveled. All adder functions for total rigid body acceleration, velocity, distance from origin and distance traveled, this simple equation is used. 2 2 V alue X Y Z2 Page 54
  • 55. Unmanned Aerial Vehicle 4.4 Secondary PIC Implementation Generally as aforementioned, this PIC uses PWM, SPI, USART, and communicates with an RF module. It handles communication tasks for the Main PIC. It also acts as a secondary PWM module. The following sections divide these tasks and explain each of these elements independently. 4.4.1 GPS System GPS has become a widely used aid to navigation worldwide, and a useful tool for map-making, land surveying, commerce, and scientific uses. GPS also provides a precise time reference used in many applications including scientific study of earthquakes, and synchronization of telecommunications networks. There is a constellation of 30 (earth orbiting satellites as of April 2007) that transmit precise radio signals. Their orbits are set up so that at any given point and time on the earth s surface there are at least six of these satellites in reach. A figure below demonstrates the constellation of NAVSTAR GPS satellites. Page 55
  • 56. Unmanned Aerial Vehicle A GPS receiver calculates its position by measuring the distance between itself and three or more GPS satellites, using trilateration. Measuring the time delay between transmission and reception of each GPS radio signal gives the distance to each satellite, since the signal travels at a known speed. The signals also carry information about the satellites' location. By determining the position of, and distance to, at least three satellites, the receiver can compute its position using trilateration. Receivers typically do not have perfectly accurate clocks and therefore track one or more additional satellites to correct the receiver's clock error. The figures below briefly explain trilateration, where at the center of each sphere there is a satellite. When two spheres intersect they create lines. When the third sphere intersects it creates a point revealing the location of the receiver. The coordinates are calculated according to the World Geodetic System WGS84 coordinate system. Position is determined by latitude and longitude which are basically angles, latitude ranges from 0-90 north and south, and longitude ranges from 0-180 west and east. The figures below display latitude and longitude. Page 56
  • 57. Unmanned Aerial Vehicle To calculate its position, a receiver needs to know the precise time. The satellites are equipped with extremely accurate atomic clocks, and the receiver uses an internal crystal oscillator-based clock that is continually updated using the signals from the satellites. GPS satellites continuously transmit almanac and ephemeris at 50bps. The almanac consists of coarse time information and orbital data (speed and path). The ephemeris gives the satellites precise orbit. The almanac assists in the acquisition of other satellites. A complete almanac transmission is a 37,500 bit navigation message that takes 12.5 minutes to download. This long delay occurs when a new receiver is first turned on. Each satellite transmits its navigation message with at least two distinct spread spectrum codes: the Coarse / Acquisition (C/A) code, which is freely available to the public, and the Precise (P) code, which is usually encrypted and reserved for military applications. The C/A code is a 1,023 bit long pseudo-random code broadcast at 1.023 MHz, repeating every millisecond. Each satellite sends a distinct C/A code, which allows it to be uniquely identified. Page 57
  • 58. Unmanned Aerial Vehicle The receiver identifies each satellite's signal by its distinct C/A code pattern, then measures the time delay for each satellite. To do this, the receiver produces an identical C/A sequence using the same seed number as the satellite (two or more systems using matching seeds can generate matching sequences of non-repeating numbers which can be used to synchronize remote systems). By lining up the two sequences, the receiver can measure the delay and calculate the distance to the satellite, called the pseudorange. The pseudoranges are then the time the signal has taken from there to the receiver, multiplied by the speed of light. The orbital position data from the Navigation Message is then used to calculate the satellite's precise position. Knowing the position and the distance of a satellite indicates that the receiver is located somewhere on the surface of an imaginary sphere centered on that satellite and whose radius is the distance to it. When four satellites are measured simultaneously, the intersection of the four imaginary spheres reveals the location of the receiver. The orbital position data from the Navigation Message is then used to calculate the satellite's precise position. Knowing the position and the distance of a satellite indicates that the receiver is located somewhere on the surface of an imaginary sphere centered on that satellite and whose radius is the distance to it. When four satellites are measured simultaneously, the intersections of all four imaginary spheres reveal the location of the receiver. Often, these spheres will overlap slightly instead of meeting at one point. The receiver then moves the overlapping pseudoranges with the same amount (regardless of distance of receiver to satellite) till an intersection point is created this point is usually the most probable position. This scenario is shown in the following figure. Page 58
  • 59. Unmanned Aerial Vehicle An overlapping pseudorange occurs here. Instead of having one intersection point, a room is created by all three points of B . All distances are subtracted by the same amount, in this case 0.5, in order to receive an intersection point at A . Point A is considered the most probable point of the receiver. Regarding GPS time as opposed to the conventional second, minute and hour; you only have seconds, more precisely seconds of the week. In a normal clock when the seconds reach 60 it starts a new minute. In GPS time when the seconds reach 604,800 it starts a new week, this is calculated by 7(days)*24(hours)*60(minutes)*60(seconds). As for GPS date as opposed to the year, month, and day format of the Julian calendar, the GPS date is expressed as a week number and a day-of-week number. The week number is transmitted as a ten-bit field, and so it becomes zero again every 1,024 weeks (19.6 years). GPS week zero started at (00:00:19 TAI) on January 6, 1980 and the week number became zero again for the first time at on August 21, 1999. This event is known as a rollover. After a GPS does a full almanac download, GPS systems boot in 3 different modes. Those would be cold start, warm start and hot start. In cold start, time and position are known within some limits, the almanac is known and the ephemeris is unknown. In warm start, time and position are known within some limits, the almanac is known, and at least three satellite ephemeris are known from the previous operation. In a hot start all ephemeris for all satellites are known so a hot start occurs. The GPS receiver chooses how to start based on the time between last turn off and current turn on. If this time was a few minutes the GPS chooses hot start which takes 1 second, if it was a few hours the choice is warm start which takes 38 seconds, anything longer than that produces a cold start which takes 42 seconds. Most GPS systems have two protocols SirF protocol and NMEA protocol. In our case the NMEA protocol was used. NMEA protocol simply contains input messages and output messages. (Refer to the NMEA reference manual) Page 59
  • 60. Unmanned Aerial Vehicle Input messages selected to initialize the GPS are: $PSRF100,1,4800,8,1,0*0Ern $PSRF103,04,00,02,01*22rn $PSRF105,0*3Frn $PSRF is used for input messages. The star means the following two characters are checksum, NMEA checksum operates by 16-bit XOR a checksum calculator code is shown in the APPENDIX B : CONTROL CODE, and /r/n represent carriage return and line feed, whose HEX code are 0D 0A. All other fields in between them are data fields for different settings. $PSRF100,1,4800,8,1,0*0Ern This message was used for setting the serial port. 100 in the first field represents serial port settings. 1 in the second field is for NMEA protocol, 4800 is for baud rate, 8 is for 8 data bits, 1 is for 1 stop bit, and 0 is for no parity bit. $PSRF103,04,00,02,01*22rn This line is used for enabling and disabling output messages, 103 is used for query/control mode. 04 is used for RMC mode, 02 is used for releasing the message at 2Hz, 01 is used for enabling checksum. $PSRF105,0*3Frn 105 is used for development data. The 0 represents debug off should any error occur, so that our PIC does not receive any unnecessary input. When a GPS is turned off, it s last settings before being switched off will be saved in it s battery powered RAM. When turned on, these settings resume. These input messages were considered necessary in order to set the serial port correctly for USART communication, RMC mode was chosen because this one single message had all the necessary information required. The third message is for turning off debug to avoid unnecessary input to the MCU. A 16-bit XOR CRC creator was necessary to give input messages. A JAVA code is displayed in the APPENDIX B: CONTROL CODE. Page 60
  • 61. Unmanned Aerial Vehicle Later on a program called SiRF Demo PC GPS Utility v3.83 was found very helpful for obtaining latitude and longitude coordinates for our tested range area. It can also be used as an initialization alternative. To initialize your GPS time, you simply click setup then click GPS Time PC Time as shown in the figure below. Usually the demo starts in SiRF protocol. To switch it to NMEA protocol you simply click action then Switch to NMEA Protocol , to open NMEA Setup. In this window as shown in the figure below, you can select each message and it s frequency per second. Highlighting checksum is preferred for message validation. For NMEA, baud rate should be set at 4800bps. After powering off the GPS receiver, GPS time, message type and frequency are saved. Page 61
  • 62. Unmanned Aerial Vehicle Output messages received from RMC mode (in order) are UTC time, data validity, latitude, north/south indicator, longitude, west/east indicator, velocity over ground in knots, heading measured clockwise from north in degrees, and date A sample output message is shown below: $GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120507, ,*10 The first two letters following the $ represent the device in use. The GP stands for GPS. There are other devices such as: LC Loran-C TR Transit SATNAV AP Autopilot (magnetic) HC Magnetic heading compass RA Radar SD Depth sounder VW Mechanical speed log Latitude and longitude are displayed in degrees and minutes, At a latitude of 30° N (Cairo, Egypt), the latitude minute = 1847.54m and longitude minute = 1608.1m (distances change because the circumference of parallel of latitude changes, Earth is not a cylinder, please refer to http://home.online.no/~sigurdhu/Grid_1deg.htm ), velocity is multiplied by 1.852 to change from knots to km/hr. Then course heading in degrees ranging from 0°- 360° moving clockwise from north. The final field before the checksum is date. The only fields needed were data validity, latitude, longitude, velocity and heading. VTG mode was desired to attain height, but during testing, height in MSL (Mean Sea Level) was quite inaccurate. At a change of height of about 4 meters, the GPS detected a change of height of 10 meters which is an error of over 150%. Latitude, longitude velocity and heading are transmitted via RF to the simulation. Page 62
  • 63. Unmanned Aerial Vehicle A destination in GPS mode is set by pre-inputting a target destination, in the PIC program, in latitude and longitude. The following steps are taken: 1. Y = Target Latitude Present Altitude 2. X = Target longitude Present Latitude 3. Distance = X2 Y2 1 Y 4. TempAngle is obtained by tan X Desired course heading is obtained by the following scheme: Y X Course + + TempAngle + 0° - - TempAngle + 180° + - TempAngle + 360° (TempAngle is negative) - + TempAngle + 180° (TempAngle is negative) Resgister Settings Communication between the PIC and GPS system is acheived by the Universal Synchronous Asynchronous Receiver Transmitter (USART). In this case Asynchronous mode is used. (refer to the PIC 16F777 pdf file, section 11.0 for more detailed information) To enable this serial mode three registers must be set; TXSTA, RCSTA and SPBRG. TXSTA is set in the following manner: Bit 7: 0 Don t care (for Asynchrous mdoe) Bit 6: 0 for 8-bit transmission Bit 5: 0 for transmission enabled Bit 4: 0 for Asynchronous mode Bit 3: 0 this bit is unimplemented Bit 2: 0 for High speed Bit 1: 1 for TSR empty (TRMT) Bit 0: 0 not used in 8-bit transmission Page 63
  • 64. Unmanned Aerial Vehicle SPBRG is the simplest where only a value is entered into the register. Considering asynchronous mode is used and the system is low speed, the following equation is used, where X is the value entered in SPBRG: FOSC X 1 64* BaudRate When a baud rate of 4800bps with a frequency of 8MHz is entered into the equation the resulting X value is 25.04, so 25 is the value used in SPBRG. The RCSTA register is set in the following manner: Bit 7: 1 for Serial port enabled Bit 6: 0 for Enables 8-bit reception Bit 5: 0 Don t care for Asynchronous mode Bit 4: 1 to Enable continuous receive (called CREN) Bit 3: 0 Don t care for 8-bit mode Bit 2: 0 for no Overrun error(OERR) Bit 1: 0 for no Framing error(FERR) Bit 0: 0 Don t care for 8-bit mode When transmitting input messages to the GPS system to initialize data, the data message had to be inserted in the PIC s EEPROM via MPLAB before programming to PIC (an .ECH file can be created with your EEPROM input by exporting a file (MPLAB), this file is easier to load than re-inputting every time), because it consumed too much RAM. Data is transmitted bit by bit via the TXREG register, the TSR register must be polled to see whether the bit was sent out or not when TSR is empty only can u fill in the next bit. Interrupts are undesired in this mode. Page 64
  • 65. Unmanned Aerial Vehicle For Universal Asynchronous reception, the 6th and 7th bit of the INTCON register must be set, to enable interrupts, along with the 5th bit of register PIE1. An interrupt occurs (bit5 of register PIR is set) under three cases, when a byte is received successfully, when an OERR (Overrun error) or when a FERR (Framing error) occurs. If a FERR occurs the message is discarded. The message is valid if; the message starts with a $ and ends with 0D 0A, the GPS sends an A in the 19th byte, no FERR error occurs, and the CRC check is correct. If the message is valid, SPI communication transmits the latitude, longitude and heading to the Main PIC, Also the RF transmits function is called to send this data (for use in the simulator). This code in detail can be seen in APPENDIX B: CONTROL CODE. Page 65
  • 66. Unmanned Aerial Vehicle 4.4.2 Radio Transceiver This RF device is called a transceiver in the sense that the same unit can send and receive, to and from another identical unit. Operating frequency is 2.4GHz, and data transmission rate can be selected at either 250Kbps or 1Mbps. 250kbps works at a longer range of 280m but after testing, range proved to be approximately 180m. Also 250kbps improves receiver sensitivity. There are two modes direct mode and shock burst mode. Shock burst works at a lower current and relaxed PIC operation. Low current consumption occurs by using an onboard FIFO to transmit data at a low rate then transmit at a high rate. PIC resources are saved by having an onboard CRC creator/checker for transmitting/receiving respectively. Pre-amble, address, and CRC are stored on a buffer on the RF then transmitted out, instead of letting the PIC do all this work. The transceiver can receive simultaneously on two different channels. Only one channel was used in this project. Pins used Used pins were CE (Chip Enable), CS (Chip Select), CLK (Clock), DR1 (Data Ready1), DATA1, Vcc, and GND (1 represents pins pertaining to Channel1). The transceiver requires a configuration word of up to 15 bytes. This is done through three pins; CS, CLK and DATA1. Generally CE is turned off, CS is turned on, a delay is done to allow onboard processing, and then data is fed in bit by bit as the clock toggles. The Shock burst configuration word is as follows: Shock Burst configuration Word: The section bit[119:16] contains the segments of the configuration register dedicated to Shock Burst operational protocol. After VDD is turned on Shock Burst configuration is done once and remains set whilst VDD is present. During operation only the first byte for frequency channel and RX/TX switching need to be changed. Page 66
  • 67. Unmanned Aerial Vehicle PLL_CTRL Bit 121-120: Controls the setting of the PLL for test purposes. With closed PLL in TX no deviation will be present. For normal operational mode these two bits must both be low. DATAx_W Bit 119 112: DATA2_W: Length of RF package payload section for receive-channel 2. Bit 111 104: DATA1_W: Length of RF package payload section for receive-channel 1. NOTE: The total number of bits in a Shock Burst RF package may not exceed 256! Maximum length of payload section is hence given by: DATAx_W(bits) = 256 (ADDR_W+ CRC) ADDRx Bit 103 64: ADDR2: Receiver address channel 2, up to 40 bit. Bit 63 24: ADDR1 ADDR1: Receiver address channel 1, up to 40 bit. *NOTE: Bits in ADDRx exceeding the address width set in ADDR_W are redundant and can be set to logic 0. Page 67
  • 68. Unmanned Aerial Vehicle ADDR_W & CRC Bit 103 64: ADDR2: Receiver address channel 2, up to 40 bit. Bit 63 24: ADDR1 ADDR1: Receiver address channel 1, up to 40 bit. NOTE: Bits in ADDRx exceeding the address width set in ADDR_W are redundant and can be set to logic 0. ADDR_W & CRC Bit 23 18: ADDR_W: Number of bits reserved for RX address in Shock Burst packages. NOTE: Maximum number of address bits is 40 (5 bytes). Values over 40 in ADDR_W are not valid. Bit 17: CRC_L: CRC length to be calculated by nRF2401 in Shock Burst. Logic 0: 8 bit CRC Logic 1: 16 bit CRC Bit: 16: CRC_EN: Enables on-chip CRC generation (TX) and verification (RX). Logic 0: On-chip CRC generation/checking disabled Logic 1: On-chip CRC generation/checking enabled Page 68
  • 69. Unmanned Aerial Vehicle This section of the configuration word handles RF and device related parameters. Modes: General device configuration: Bit 15: RX2_EN: Logic 0: One channel receive Logic 1: Two channels receive NOTE: In two channel receive, the nRF2401 receives on two, separate frequency channels simultaneously. The frequency of receive channel 1 is set in the configuration word bit[7-1], receive channel 2 is always 8 channels (8 MHz) above receive channel 1. Bit 14: Communication Mode: Logic 0: nRF2401 operates in direct mode. Logic 1: nRF2401 operates in Shock Burst mode Bit 13: RF Data Rate: Logic 0: 250 kbps Logic 1: 1 Mbps *NOTE: Utilizing 250 kbps instead of 1Mbps will improve the receiver sensitivity by 10 dB. 1Mbps requires 16MHz crystal. Page 69
  • 70. Unmanned Aerial Vehicle Bit 12-10: XO_F: Selects the nRF2401 crystal frequency to be used: Bit 9-8: RF_PWR: Sets nRF2401 RF output power in transmit mode: RF channel & direction Bit 7 1: RF_CH#: Sets the frequency channel the nRF2401 operates on. The channel frequency in transmit is given by: ChannelRF =2400MHz + RF_CH# * 1.0MHz RF_CH #: between 2400MHz and 2527MHz may be set. The channel frequency in data channel 1 is given by: ChannelRF =2400MHz + RF_CH# * 1.0MHz (Receive at PIN#8) RF_CH #: between 2400MHz and 2524MHz may be set. The channel frequency in data channel 2 is given by: ChannelRF =2400MHz + RF_CH# * 1.0MHz + 8MHz (Receive at PIN#4) RF_CH #: between 2408MHz and 2524MHz may be set. Page 70
  • 71. Unmanned Aerial Vehicle Bit 0: Set active mode: Logic 0: transmit mode Logic 1: receive mode For more intricate details about the configuration word refer to the nRF2401 datasheet page 19. Within Shockburst mode there are four different modes. They are displayed in the following table. ACTIVE MODE There are two different options in Active mode, Transmit and Receive. Transmit 1. When the application MCU has data to send, set CE high. This activates nRF2401 onboard data processing. 2. The address of the receiving node (RX address) and payload data is clocked into the nRF2401. The application protocol or MCU sets the speed <1Mbps (ex: 10kbps). 3. MCU sets the CE to low, this activates a nRF2401 Shock Burst transmission. 4. nRF2401 Shock Burst: RF front end is powered up RF package is completed (preamble added, CRC calculated Data is transmitted at high speed (250 kbps or 1 Mbps configured by user). nRF2401 return to stand-by when finished Page 71
  • 72. Unmanned Aerial Vehicle Receive 1. Correct address and size of payload of incoming RF packages are set when nRF2401 is configured to Shock Burst RX. 2. To activate RX, set CE high. 3. After 200ms settling, nRF2401 is monitoring the air for incoming communication. 4. When a valid package has been received (correct address and CRC found), nRF2401 removes the preamble, address and CRC bits. 5. nRF2401 then notifies (interrupts) the MCU by setting the DR1 pin high. 6. MCU may (or may not) set the CE low to disable the RF front end (low current mode). 7. The MCU will clock out just the payload data at a suitable rate (ex. 10kbps). 8. When all payload data is retrieved nRF2401 sets DR1 low again, and is ready for new incoming data package if CE is kept high during data download. If the CE was set low, a new start up sequence can begin. The following flowchart displays the processes of receiving and transmitting. Page 72
  • 73. Unmanned Aerial Vehicle CONFIGURATION MODE Similar to active mode Configuration mode has two options, Configure Transmitter, and Configure Receiver. Configure Transmitter 1. In configure transmitter, CE is turned off, and CS is turned on. 2. DATA1 with CLK send the configuration word to the RF. 3. A delay of (1ms) is issued to allow ample time for onboard processing. 4. Both CE and CS are turned off. Configure Receiver 1. In configure receiver, CE is turned off and CS is turned on. 2. A delay (1ms) is issued. The configuration is then sent through DATA1 from the PIC as the clock toggles. 3. CE and CS are then turned off and a delay (1ms) is used also for onboard processing. 4. CE is then left on as to enable receiving. STAND-BY MODE Stand by mode is used to minimize average current consumption while maintaining short start up times. In this mode, part of the crystal oscillator is active. Current consumption is dependent on crystal frequency. POWER DOWN MODE In power down the nRF2401 is disabled with minimal current consumption, typically less than 1µA. Entering this mode when the device is not active minimizes average current consumption, maximizing battery lifetime. Page 73
  • 74. Unmanned Aerial Vehicle DATA PACKAGE DESCRIPTION Data packages contain four main sections, in MSB order Pre-amble, address, payload and CRC. Pre-amble is either 4 or 8 bits and is added to the data packet. Address is between 8 and 40 bits. Payload is the desired data being transmitted or received. CRC is either 8 or 16 bits and used for validating message. More detail about the data package can be seen in the table below. For information regarding delays, (please refer to the RF-24G datasheet page22). Recommendations: 1. Delays should be taken very carefully, ample time is required for onboard processing. 2. Sequence of turning on CE and CS should be very accurate, or the transceiver will not operate as desired. 3. Configuration word should be set very carefully. 4. Configuration word entry starts from the MSB to the LSB. 5. This IC is unlike other ICs, it is very sensitive to physical shock and short circuits, three of these units were irreversibly damaged, which in our case cost much time. Page 74
  • 75. Unmanned Aerial Vehicle 4.5 RC UNIT The main purpose of this RC Unit besides enabling RC mode, is that the user can interfere manually should any errors occur, such as vehicle misguidance. This can save the vehicle from possible crashes. 1. KEYPAD TESTING Required components are the keypad encoder MM74C923, 0.1uF capacitor, 1uF capacitor, and a 16 key keypad. The 1uF capacitor determines the debounce key mask. This is done by creating a debounce period of 0.01s (delay) of on the encoder. The 0.1uF determines the scanning frequency at 400Hz. The encoder has an output enable as which should be set at active low. These CMOS key encoders provide all the necessary logic to fully encode an array of SPST switches. The keyboard scan can be implemented by either an external clock or external capacitor. These encoders also have on-chip pullup devices which permit switches with up to 50 KHz on resistance to be used. No diodes in the switch array are needed to eliminate ghost switches. The internal debounce circuit needs only a single external Page 75
  • 76. Unmanned Aerial Vehicle capacitor and can be defeated by omitting the capacitor. A Data Available output goes to a high level when a valid keyboard entry has been made. The Data Available output returns to a low level when the entered key is released, even if another key is pressed. The Data Available will return high to indicate acceptance of the new key after a normal debounce period; this two-key rollover is provided between any two switches. An internal register remembers the last key pressed even after the key is released. The TRI-STATEÉ outputs provide for easy expansion and bus operation and are LPTTL compatible. Both the keyboard scan rate and the key debounce period by altering the oscillator capacitor, COSE, and the key debounce mask capacitor, CMSK. Thus, the MM74C923's performance can be optimized for many keyboards. The keyboard encoders connect to a switch matrix that is 4 rows by 4 columns or 5 rows by 4 columns (MM74C923). When no keys are pressed, the row inputs are pulled high by internal pull-ups and the column outputs sequentially output a logic 0 . These outputs are open drain and are therefore low for 25% of the time and otherwise off. The column scan rate is controlled by the oscillator input, which consists of a Schmitt trigger oscillator, a 2-bit counter, and a 2±4-bit decoder. When a key is pressed, key 0, for example, nothing will happen when the X1 input is off, since Y1 will remain high. When the X1 column is scanned, X1 goes low and Y1 will go low. This disables the counter and keeps X1 low. Y1 going low also initiates the key debounce circuit timing and locks out the other Y inputs. The key code to be output is a combination of the frozen counter value and the decoded Y inputs. Once the key debounce circuit times out, the data is latched, and the Data Available (DAV) output goes high. If, during the key closure the switch debounces, Y1 input will go high again, restarting the scan and resetting the key debounce circuitry. The key may debounce several times, but as soon as the switch stays low for a debounce period, the closure is assumed valid and the data is latched. A key Page 76
  • 77. Unmanned Aerial Vehicle may also debounce when it is released. To ensure that the encoder does not recognize this debounce as another key closure, the debounce circuit must time out before another closure is recognized. The two-key roll-over feature can be illustrated by assuming a key is pressed, and then a second key is pressed. Since all scanning has stopped, and all other Y inputs are disabled, the second key is not recognized until the first key is lifted and the key debounce circuitry has reset. The output latches feed TRI-STATE, which is enabled when the Output Enable (OE) input is taken low. The following circuit schematic was used to connect the keypad to the encoder. For testing refer to the section 5.1 Testing. Page 77