Sunteți pe pagina 1din 102

LOW COST FRAMEWORK FOR PARAMETER

IDENTIFICATION OF UNMANNED AERIAL


VEHICLES
By
Ahmad Adel Ahmad Metwalli Khattab
A Thesis Submitted to the
Faculty of Engineeringat Cairo University
in Partial Fulfillment of the
Requirements for the Degree of
MASTER OF SCIENCE
in
Aerospace Engineering

FACULTY OF ENGINEERING, CAIRO UNIVERSITY


GIZA, EGYPT
2015

LOW COST FRAMEWORK FOR PARAMETER


IDENTIFICATION OF UNMANNED AERIAL
VEHICLES
By
Ahmad Adel Ahmad Metwalli Khattab
A Thesis Submitted to the
Faculty of Engineeringat Cairo University
in Partial Fulfillment of the
Requirements for the Degree of
MASTER OF SCIENCE
in
Aerospace Engineering
Under the Supervision of
Prof.Dr. Ayman Hamdy Kassem Prof.Dr. Gamal Mahmoud Sayed Elbayoumi
Professor of flight dynamics and control

Professor of flight dynamics and control

Aerospace Engineering Department

Aerospace Engineering Department

Faculty of Engineering, Cairo University

Faculty of Engineering,Cairo university

FACULTY OF ENGINEERING, CAIRO UNIVERSITY


GIZA, EGYPT
2015

LOW COST FRAMEWORK FOR PARAMETER


IDENTIFICATION OF UNMANNED AERIAL
VEHICLES
By
Ahmad Adel Ahmad Metwalli Khattab
A Thesis Submitted to the
Faculty of Engineeringat Cairo University
in Partial Fulfillment of the
Requirements for the Degree of
MASTER OF SCIENCE
in
Aerospace Engineering
Approved by the Examining Committee:

Prof.Dr. Ayman Hamdy Kassem, Thesis Main Advisor

Prof.Dr. Gamal Mahmoud Sayed Elbayoumi, Thesis Co Advisor

Prof.Dr. Mohamed Nader Mohamed Abuelfoutouh, Internal Examiner

Prof.Dr.Omar Al-Farouk Abd El-hameid , External Examiner


Military Technical College
FACULTY OF ENGINEERING, CAIRO UNIVERSITY
GIZA, EGYPT
2015

Engineers Name:
Date of Birth:
Nationality:
E-mail:
Phone:
Address:
Registration Date:
Awarding Date:
Degree:
Department:

Ahmad Adel Ahmad Metwalli Khattab


1/10/1989
Egyptian
a.khattab73@yahoo.com
00201020549948
239L Hadaek Alahram
1/10/2011
/ /2015
Master of Science
Aerospace Engineering

Supervisors:
Prof.Dr. Ayman Hamdy Kassem
Prof.Dr. Gamal Mahmoud Sayed Elbayoumi
Examiners:
Prof.Dr. Ayman Hamdy Kassem
(Thesis main advisor)
Prof.Dr. Gamal Mahmoud Sayed Elbayoumi
(Thesis Co Advisor)
Prof.Dr. Mohamed Nader Mohamed Abuelfoutouh (Internal examiner)
Prof.Dr.Omar Al-Farouk Abd El-hameid
(External examiner)
Military Technical College
Title of Thesis:
LOW COST FRAMEWORK FOR PARAMETER IDENTIFICATION OF
UNMANNED AERIAL VEHICLES
Key Words:
Unmanned Aerial Vehicles;Parameter identification; Autopilot; Hopfield;
Recuurent neural network
Summary:
In this thesis a framework was designed and tested to identify the parameters
of a unmanned aerial vehicles.The framework was designed to be low in cost
and to be accessible to be modified and customized. Tests were done on two
small remotely piloted RC models. Offline Parameter identification was done
using Hopfield neural network.

Acknowledgements
Thanks to Allah for all his gifts to me.I want to thank my supervisors for guiding me
through the work. I would like to say thank you to my parents for their support to me
through all my life.I would like to thank my wife for her support to me. I would like to
thank all ASTL people for their help to me through my thesis work especially: Eng.Osama
Saied, Eng.Mohaned Draz , Eng.Mustafa Moharm .Thanks to all students I worked with
through their graduation projects for their accumulated work that increased the knowledge
and transfered it through years. I also would like to thank all my undergraduate professors
in Aerospace Engineering Department, Cairo University.

Dedication
To My family .... To My grand father Haj. Ahmad Khattab

ii

Contents
Acknowledgements

Dedication

ii

List of Figures

List of Tables

vii

List of Symbols and Abbreviations

viii

Abstract

1 Introduction

2 Literature Review
2.1 Parameter Identification Techniques . . . . . . . . . . . . . . . . . . . .
2.2 Work achieved in Aerospace department . . . . . . . . . . . . . . . . . .

5
5
8

3 Parameter Identification
3.1 Introduction . . . . . . . . . . . . . . . . . . .
3.2 Artificial neural network . . . . . . . . . . . .
3.2.1 Introduction . . . . . . . . . . . . . . .
3.2.2 Hopfield neural network . . . . . . . .
3.2.2.1 Introduction . . . . . . . . .
3.2.2.2 Parameter Estimation Problem
3.2.3 Results . . . . . . . . . . . . . . . . .
4 Data Gathering Module
4.1 Introduction . . . . . . . . . . . . . .
4.2 Hardware . . . . . . . . . . . . . . .
4.2.1 Microcontroller . . . . . . . .
4.2.2 Microcontroller shield . . . .
4.2.3 Servo Motors . . . . . . . . .
4.2.4 Servos and potentiometer Sets
4.2.5 Potentiometers . . . . . . . .
4.2.6 IMU . . . . . . . . . . . . . .
4.2.7 Pressure Sensor . . . . . . . .
4.2.8 Velocity sensor . . . . . . . .
4.2.9 Wireless module . . . . . . .
iii

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
. .

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

11
11
11
11
12
12
14
16

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

22
22
22
24
24
25
26
26
26
27
27
27

.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

27
28
31
31
31
31
32
33

5 Test flights and Results


5.1 KADET LT-40 RC model Test Flight . . . . .
5.1.1 Introduction . . . . . . . . . . . . .
5.1.2 PI of Longitudinal Dynamics . . . . .
5.1.3 PI of Lateral Dynamics . . . . . . . .
5.1.4 Test Summary and recommendation .
5.2 Low Super Trainer RC model . . . . . . . . .
5.2.1 Modifications for Test 2 . . . . . . . .
5.2.2 Flight test . . . . . . . . . . . . . . .
5.2.3 Longitudinal Dynamics Identification
5.2.4 Lateral Dynamics Identification . . .

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

35
35
35
36
40
42
43
43
48
48
50

.
.
.
.
.

53
53
53
53
53
53

4.3

4.2.10 GPS module . . . . . . . . . . . .


4.2.11 Alpha-Beta sensor . . . . . . . .
4.2.12 Batteries . . . . . . . . . . . . . .
4.2.13 RC Transmitter and receiver . . .
Software . . . . . . . . . . . . . . . . .
4.3.1 Arduino Mega Software . . . . .
4.3.2 Monitoring Software . . . . . . .
4.3.3 Parameter Identification Software

6 Conclusion and Future Work


6.1 The Future suggested work . . .
6.1.1 Parameter Identification .
6.1.1.1 Hardware . . .
6.1.1.2 Software . . .
6.1.2 Autopilot . . . . . . . .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

References

55

Appendix A Hopfield neural network matlab code

56

Appendix B ArduImu V3 Codes

66

Appendix C Arduino Mega code

69

Appendix D Simulink GCS

80

iv

List of Figures
1.1

Autopilot Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.1
2.2

Simplified block diagram of the estimation procedure[6] . . . . . . . . . 5


A sample of the used method for PI . . . . . . . . . . . . . . . . . . . . . 10

3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8

An artificial neuron as used in a Hopfield network . . . . . . . . . . . .


An artificial neuron as used in a Hopfield network with added sigmoid
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Example for Discrete image recognition using Hopfield Neural Network
Flow chart for Hopfield Neural Network PI . . . . . . . . . . . . . . .
Real,measured and Predicted data for states and states rate . . . . . . .
Real,measured and Predicted data for a sample state . . . . . . . . . . .
True and estimated parameters . . . . . . . . . . . . . . . . . . . . . .
Error in parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.

13
14
16
18
19
20
21

4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
4.10
4.11
4.12
4.13
4.14
4.15
4.16
4.17
4.18
4.19
4.20
4.21
4.22
4.23

Block Diagram for the whole system processes . . . . . . . . . . .


Data gathering Module Hardware . . . . . . . . . . . . . . . . . . .
Arduino mega 2650 microcontroller . . . . . . . . . . . . . . . . .
Arduino Customized shield . . . . . . . . . . . . . . . . . . . . . .
Servo Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Servos Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Potentiometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Arduimu V3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BMP085 Module GY-65 Pressure Sensor . . . . . . . . . . . . . . .
Velocity Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Xbee pro 52B wireless module . . . . . . . . . . . . . . . . . . . .
GPS Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
First Design (Not used because of middle flow from motor propeller)
Air data fin drown by Solid Works . . . . . . . . . . . . . . . . . .
CNC manufacturing of Air data fin . . . . . . . . . . . . . . . . . .
Air data fin for Side Slip angle . . . . . . . . . . . . . . . . . . . .
Air data fin for angle of attack . . . . . . . . . . . . . . . . . . . .
The total AOA and Side slip sensors attached to the wing tip . . . .
Flow Chart of Arduino Software . . . . . . . . . . . . . . . . . . .
Monitoring Software . . . . . . . . . . . . . . . . . . . . . . . . .
Simulink GCS . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Flow Chart of Simulink GCS . . . . . . . . . . . . . . . . . . . . .
Flow chart for Hopfield Neural Network PI . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

23
24
24
25
25
26
26
26
27
27
27
28
28
29
29
30
30
31
32
32
33
33
34

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

. 13

5.1
5.2
5.3
5.4

5.6
5.7
5.8
5.9
5.10
5.11
5.12
5.13
5.14
5.15
5.16
5.17
5.18
5.19
5.20
5.21
5.22
5.23

The Flight Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Ready to Fly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Captured photo from the flight test . . . . . . . . . . . . . . . . . . . . .
Longitudinal States (Measured and estimated).The yellow line is the elevator signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Longitudinal States (Measured and estimated) when using elevator and
change in elevator as inputs.The yellow line is the elevator signal . . . . .
Estimated Pole map of the Longitudinal dynamics . . . . . . . . . . . .
Lateral States (Measured and estimated).The last line is the aileron signal
Estimated Pole Map of the Lateral dynamics . . . . . . . . . . . . . . .
Low Super Trainer RC model . . . . . . . . . . . . . . . . . . . . . . .
Replacing the engine with an electric motor . . . . . . . . . . . . . . . .
The fin of the old sensor and the smaller one of the new sensor . . . . . .
The black potentiometer and the golden Encoder . . . . . . . . . . . . .
The modified Air data system . . . . . . . . . . . . . . . . . . . . . . . .
The Air data systems setup for both aircrfats . . . . . . . . . . . . . . .
The Air data systems of both two aircrfats . . . . . . . . . . . . . . . . .
The two sets of the new Air data system . . . . . . . . . . . . . . . . . .
The two velocity sensors data during the flight . . . . . . . . . . . . . .
The two beta sensors data during the flight . . . . . . . . . . . . . . . . .
Doublet elevator input . . . . . . . . . . . . . . . . . . . . . . . . . . .
Measured and Estimated Longitudinal States . . . . . . . . . . . . . . .
Longitudinal Pole Map . . . . . . . . . . . . . . . . . . . . . . . . . . .
Lateral States , Last line for Aileron . . . . . . . . . . . . . . . . . . . .
Lateral Pole Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6.1

Suggested Work

5.5

35
36
36
38
39
40
41
42
43
44
45
45
46
46
47
47
48
48
49
50
50
51
52

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

vi

List of Tables
3.1
3.2

Estimated elements of A and B matrices . . . . . . . . . . . . . . . . . . 17


Results of different combinations of data Sampling frequency and the type
of the input signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

5.1
5.2

KADET LT-40 RC model Specifications . . . . . . . . . . . . . . . . . . 35


Low Super trainer RC model Specifications . . . . . . . . . . . . . . . . 44

vii

List of Symbols and Abbreviations


A

Dynamics Matrix in State space model

Control Matrix in State space model

input vector for the state space model

States of the dynamical system

Aircraft angular velocity, z body axis (yaw rate), deg/sec

Time, sec

Velocity along body fixed x-axis, m/sec

Velocity along body fixed y-axis, m/sec

Velocity along body fixed z-axis, m/sec

Bias Vector

Weighting matrix

Error

Angle of attack, deg

Angle of sideslip, deg

Control surface deflection, deg

Roll Euler angle, deg

Pitch Euler angle, deg

Yaw Euler angle, deg

sigmoid function

ax

Acceleration in x-direction, m/sec2

az

Acceleration in z-direction, m/sec2

Acceleration due to gravity, m/sec2

Discrete time index

Aircraft mass,kg

Aircraft angular velocity, x body axis (roll rate), deg/sec

Aircraft angular velocity, y body axis (pitch rate), deg/sec


viii

ANN

Artificial Neural Network

AOA

Angle of attack

AS CD

Aerodynamic stability and control derivatives

AS T L

Aeronatical and Space technology laboratory, Cairo University

DGM

Data gathering Module

GCS

Ground control station

HNN

Hopfield Neural Network

I MU

Inertial measurment unit

NN

Neural Network

PCB

Printed circuit board

PI

Parameter Identification

RNN

Recurrent Neural Network

S NR

Signal to noise ratio

ix

Abstract
The rst step in the autopilot design phase is the estimation of the aerodynamic stability
and control derivatives. Parameter identication (PI) from ight data is one of the main and
accurate methods for nding aerodynamic stability and control derivatives especially for
small and unconventional aircrafts.
In this work, we are going to introduce an off-line PI system (software and hardware)
using a per-collected data from a remotely piloted RC model. The thesis is divided into
two main parts: 1) Flight segment: including data collection sensors and telemetry. 2)
Ground segment: including telemetry and parameters identication software.
KADET LT-40 RC model aircraft was rst used as a test case and the aerodynamic stability
and control derivatives estimated by our proposed system led to an estimated response
which was in a good match with the measured one with an error about 7%. Again using
another RC model Low Super Trainer RC model and after some modications to the data
Gathering system and sensors a better results was obtained the error was less than 1.5%
for longitudinal dynamics and 4% for lateral dynamics.

Chapter 1: Introduction
In conventional autopilot Design, Parameter identification (PI) is a very essential phase in
aircraft mathematical modeling. By means of real flight tests, Data of input and output
signals of the aircraft could be collected for a post processing task to identify the aerodynamic stability and control derivatives of the aircraft.
The Linear state space model of the aircraft consists of two matrices, The dynamics
and control matrices. By identifying these two matrices, it is possible to build a linear
mathematical model of the aircraft. Data are collected using a customized data gathering
module designed for this purpose.The module consists of calibrated sensors and a microcontroller to collect and send data to the ground control station to be saved for the sake
of PI in the post processing phase. The PI is done using Hopfield neural network HNN
with 24 neurons for longitudinal dynamics and another 24 neurons for the lateral dynamics.
In the following section main autopilot steps will be introduced to find where the thesis
work locate in the overall autopilot design steps. Starting from lower part in figure 1.1 it is
possible to find the main steps of autopilot design.

Figure 1.1: Autopilot Sequences


Starting from uncalibrated sensors and by adding a data acquisition tool for filtration
and calibration we have now a sensor module. Connecting between the sensor module and
a microcontroller and saving the data for post processing is the DGM. Using the readings
the next step is to use it for parameter identification.
By PI it is possible to build the appropriate mathematical model of the system. By
2

adding the control algorithm such as altitude hold and heading autopilot it is possible to
convert unstable aircraft into a stable one by control or to make a stable aircraft more
stable in the stability control phase.
In stability control phase it is possible to say that all required change in aircraft states is
equal zero i.e. you need to hold altitude at certain value or speed at constant cruise speed
or Euler angles to be all zero or little changes to maintain altitude and heading. Now we
can call that aircraft can draw a point i.e it will not fall, it will not stall and it will sustain
in the sky and avoid any disturbances like a standing baby who cannot till now move.
Now we convert to the phase of guidance to move the baby where the aircraft is required to move from one point to another from certain longitude and latitude value to
another one.By adding a mission requirements to the stability control we reach the final
point in autopilot design.Ground control station GCS is modified and become more complicated from a step to another.
In the thesis work, we will reach only the step of PI - the offline PI phase. The
work required to build a data gathering module DGM . DGM contains calibrated sensors
connected with a microcontroller to sense and save all aircraft data during flight i.e. input
and output signals for example elevator signal and pitch angle.
This data could be used for various applications. One may use them for PI another
one could use them for an autopilot circuit. In the present work test flights were made on a
remotely piloted RC models and a good flight sample was chosen to be used in the PI phase.
The tests were done for two RC models:KADET LT-40 and Low super trainer. The
KADET had the first tests and some modifications on the whole system was suggested
and taken into consideration in the Low super trainer test flights. Results showed that the
approach was successful with a very appealing results and open the way for future work in
on line parameter identification and the stability control autopilot design based on offline
parameter identification results.
In chapter 3, the Hopfield neural network for PI is introduced describing the problem of
PI then the branch in neural network where Hopfield is located then how to use HNN in
PI. The main proof of the method was introduced in Raol and others see [6] but for a two
states system with 2x2 A matrix and 2x1 B matrix. A general code for any nxn A and
nxm B matrices will be introduced where n for states and m for inputs of the system. A
general flow chart for the method will be introduced. To validate the method, a system
with a know state space model will be used. Input signal will applied to the system to
get its states responses. A noise signals will be applied to the states and input signals.
The noisy signals will be taken as input to the HNN code to get the original A,B matrices
of the system. A comparison with the original and estimated systems will be introduced
which will show an appealing results to be used further with the real flight data.
In Chapter 4, The data gathering module(DGM) will be introduced. The various components of the system will be shown and describing specifications and limitation of each

sensor.Then A full flow chart of the system will be introduced showing onboard compoments and ground control station(GCS) components. The varoius software used will be
introduced including the onboard software and GCS software and the PI software. The
full detailed software codes are introduced in the appendices.
In chapter 5, The flight tests will be introduced showing the specifications of each aircraft
used in flight then the flight data and cautions. The results of the first flight was introduced
and discussed to show the recommendation and cautions to be taken into concentration in
the second test flight. The recommended modification will be done and introduced in this
chapter. The second test flight will show a better performance and results.
In chapter 6, Conclusions and recommendation for future work will be introduced and
discussed.

Chapter 2: Literature Review


2.1

Parameter Identification Techniques

Parameter Identification is a wide research subject and when relating to aircraft systems, it
allows us to obtain a mathematical model of an aircraft from real flight data. These data
could get us the aerodynamic properties of an aircraft even this aircraft is in the designed
flight condition or not, even the flight was a stable flight or unstable and even the geometry
of the aircraft was changed through a crash or added external payloads or weights. Wind
tunnel experiments can be validated through real flight data and the real flights are more
reliable and accurate than the restricted wind tunnels. Flight simulation for pilot training
could be enhanced when the simulation is close to the real flight actions and this could be
grantee with the results of parameter identification techniques.
The problem of parameter estimation is based on minimization of some criterion (of
estimation error) and this criterion itself can serve as one of the means to establish the
adequacy of the identified model. Figure 2.1shows the simple approach to parameter

Figure 2.1: Simplified block diagram of the estimation procedure[6]


identification. Given the z measurements of a system which is the real state response to an
input but with added noise.Input signal is applied to the aircraft and the states are then
measured taking into consideration that the measured states responses may have an added
noise. On the other hand, an initial model of the system is assumed and the input signal is
applied to it to get the model response which will not be equal the measured one. So the
optimization criteria is introduced and iteration occurred till reaching an accepted output
error. The optimization criteria is the main difference between the various PI methods. We
have to take into consideration that the least output error is not the sufficient condition for
achieving good estimate so expanded versions are introduced to get the sufficient criteria.

Lots of methods were used for the problem of PI. One of them is The maximum likelihoodoutput error method. This method has a batch iterative procedure.This mean that in one
shot all the measurements are used and parameter corrections are obtained. Hence a new
parameters are calculated and iteration occurred and so on .
The output error method has two limitations:
i) it can handle only measurement noise not the process noise.
ii) Divergence may occur for unstable systems
Using Kalam Filter could help in solving the process noise. This leads to a new method
called the filter error method.In this method, the output states are filtered before applying
the cost function. This makes the method more complex and computationally intensive.
The filter error method can compete with the extended Kalman filter, which can handle
process as well as measurement noises and also estimate parameters as additional states.
One major advantage of Kalman filter/extended Kalman filter is that it is a recursive
technique and very suitable for on-line real-time applications. For the latter application, a
factorization filter might be very promising. One major drawback of Kalman filter is the
filter tuning, for which the adaptive approaches need to be used.
The second limitation of the output error method for unstable systems can be overcome by
using the so-called stabilized output error methods, which use measured states.
This stabilizes the estimation process.Alternatively, the extended Kalman filter or the
extended factorization filter can be used, since it has some implicit stability property in the
filtering equation. The filter error method can be efficiently used for unstable/augmented
systems.
Since the output error method is an iterative process, all the predicted measurements
are available and the measurement covariance matrix R can be computed in each iteration.
The extended Kalman filter for parameter estimation could pose some problems since
the covariance matrix part for the states and the parameters would be of quite different
magnitudes. Another major limitation of the Kalman filter type approach is that it cannot
determine the model error, although it can get good state estimates. The latter part is
achieved by process noise tuning. This limitation can be overcome by using the model
error estimation method.
The approach provides estimation of the model error, i.e., model discrepancy with respect
to time. However, it cannot handle process noise. In this sense, the model error estimation
can compete with the output error method, and additionally, it can be a recursive method.
However, it requires tuning like the Kalman filter. The model discrepancy needs to be
fitted with another model, the parameters of which can be estimated using recursive least
squares method.
Another approach, which parallels the model error estimation, is the estimation before
modeling approach. This approach has two steps:
i) the extended Kalman filter to estimate states (and scale factors and bias related parameters);
ii) a regression method to estimate the parameters of the state model or related model.

The modelerror estimation also has two steps:


i) state estimation and discrepancy estimation using the invariant embedding method.
ii) a regression method to estimate the parameters from the discrepancy time-history.
Both the estimation before modelling and the model error estimation can be used for
parameter estimation of a nonlinear system. The output error method and the filter error
method can be used for nonlinear problems.
The feed forward neural network based approach somewhat parallels the two-step methodologies, but it is quite distinct from these: it first predicts the measurements and then
the trained network is used repeatedly to obtain differential states/measurements. The
parameters are determined by Delta method and averaging.
The recurrent neural network based approach looks quite distinct from many approaches,
but a closer look reveals that the equation error method and the output error method based
formulations can be solved using the recurrent neural network based structures. In fact,
the equation error method and the output error method can be so formulated without
invoking recurrent neural network theory and still will look as if they are based on certain
variants of the recurrent neural networks. This revealing observation is important from
practical application of the recurrent neural networks for parameter estimation, especially
for on-line/real-time implementation using adaptive circuits/VLSI, etc. Of course, one
needs to address the problem of convergence of the recurrent neural network solutions to
true parameters. Interestingly, the parameter estimation procedure using recurrent neural
network differs from that based on the feed forward neural network. In the recurrent
neural network, the so-called weights (weighting matrix W) are pre-computed using the
correlation like expressions between x, x, u, etc. The integration of a certain expression,
which depends on the sigmoid nonlinearity, weight matrix and bias vector and some
initial guesstimate of the states of the recurrent neural network, results into the new states
of the network. These states are the estimated parameters (of the intended state-space
model). This quite contrasts with the procedure of estimation using the feed forward
neural network. In feed forward neural networks, the weights of the network are not the
parameters of direct interest. In recurrent neural network also, the weights are not of
direct interest, although they are precomputed and not updated as in feed forward neural
networks. In both the methods, we do not get to know more about the statistical properties
of the estimates and their errors. Further theoretical work needs to be done in this direction.
The genetic algorithms provide yet another alternative method that is based on direct
cost function minimization and not on the gradient of the cost function. This is very
useful for types of problems where the gradient could be ill-defined. However, the genetic algorithms need several iterations for convergence and stopping rules are needed.
One limitation is that we cannot get parameter uncertainties, since they are related to
second order gradients. In that case, some mixed approach can be used, i.e., after the
convergence, the second order gradients can be evaluated. Parameter estimation work
using the artificial neural networks and the genetic algorithms is in an evolving state. New
results on convergence, uniqueness, robustness and parameter error-covariance need to be
explored. Perhaps, such results could be obtained by using the existing analytical results
of estimation and statistical theories. Theoretical limit theorems are needed to obtain more

confidence in these approaches. The parameter estimation for inherently unstable/augmented system can be handled with several methods but certain precautions are needed.
The existing methods need certain modifications or extensions, the ramifications of which
are straightforward to appreciate. On-line/real-time approaches are interesting extensions
of some of the off-line methods. Useful approaches are:
i) factorisation-Kalman filtering algorithm.
ii) recurrent neural network.
iii) frequency domain methods.

2.2

Work achieved in Aerospace department

Through the last four years, various approaches to the autopilot design were made. In
2011, work started to get uncalibrated sensors and after then be filtered and calibrated.
The sensors varied from a very cheap one with low accuracy to the very expensive one.The
two approaches where canceled, the expensive one for budget and the lower one for low
accuracy.Then in the same year another approach was chosen to use a full autopilot and
upload a customized control gains for a flying wing UAV previously calculated. Micropilot
autopilot was chosen for the task, the autopilot wasnt easy to deal with like other open
source autopilots like ArduPilot. The autopilot had a problem in wireless module and
the warranty period was finished before the start of the project. The autopilot stopped
working after a while and the customer services told us that we have to send it to them
to be fixed and return back all on our charge.In 2012 atrial to use ArduPilot shows that
ArduPilot is easier and extremely cheaper than MicroPilot with appealing results for
student projects.ArduPilot board like Micropilot board wasnt easy to replace a fault part
or to add a custom sensors. In 2013 we began to purchase the ArduPilot inner components
separately i.e microcontroller and sensors.Work started to build our own autopilot circuit
based on Arduino mega microcontroller and Arduimu sensor. In 2014, a first DGM was
built to be used for PI.In the same year a stability control autopilot was built based on this
DGM and displacement autopilot was successfully done.In 2015 we did the offline PI for
both longitudinal and lateral aircraft dynamics using the customized DGM with a GCS
based on Simulink.
For the Control Algorithms, In 2011 we built a Linear and nonlinear simulation of
the aircraft using Matlab and Simulink, then Designing a Linear PID control for the
altitude hold autopilot.Verification of the gains on the nonlinear simulation was done and
iterated till getting a better nonlinear response of the altitude hold autopilot. The parameter
identification was done based on Roskam aerodynamic stability and control derivatives
book using a Matlab code. In 2013,another project modified the code to be generally used
for any dimensions of a conventional aircraft. The code was used to design PID controller
for altitude hold of Bixler RC model. The gains were very near to the documented gains
of Bixler used in ArduPilot autopilot but not so good in the lateral gains.Now Roskam
calculated parameters was successful for longitudinal dynamics but not sure for the lateral
ones. Aircraft aerodynamic stability and control derivatives ASCD change from a flight
condition to another.ASCD changes if a destruction or a modification occurred to any
part of the aircraft.New aircrafts need to define its ASCD using real experiments. Using
equation of motion to find the dynamics equations of an aircraft may be a difficult work
and also need to be verified. All these difficulties are solved using real flight tests designed
8

to do PI for aircrafts. A lot of work was done for PI based on real flights either using
offline PI or online PI. Doning a survey on offline PI, It was found that output error method
was the most famous used method.Studies shows that using NN for off-line PI is more
accurate than the output error method which is the most used technique for offline PI(see
(J.R. Raol, G. Girija and J. Singh, 2004)) [6]. In online PI Neural network is a very famous
technique.So a better track for a long term PI work is to use Neural network for offline
and then do modifications to neural network to be used for online. So in this study we are
mainly interested in studying the offline PI using NN.

Figure 2.2: A sample of the used method for PI

10

Chapter 3: Parameter Identification


3.1

Introduction

For our major of study, parameter identification techniques are used to estimate aerodynamic and stability derivatives of the aircraft. Given these derivatives we could build a
model that describes the dynamics of the aircraft. A lot of methods were generated to do
this job. Roskam built a good method to obtain parameters via experimental tests. Even
this method is more accepted for large aircrafts and depends on the calculated geometry
and properties of the aircraft. Parameter identification PI using real flight data is the most
reliable technique to measure the aircraft parameters where mathematical model of the
aircraft is not needed as you treat with the real body.Also changing in aircraft geometry
or flight condition through flight is not a problem where you could deal with the real
body problem specially for on-line PI. There are two techniques of PI using real flight
data: on-line and off-line . On-line estimation algorithms estimate the parameters of a
model when new data is available during the operation of the model. In contrast, if you
first collect all the input/output data and then estimate the model parameters, you perform
off-line estimation. Parameter values estimated using on-line estimation can vary with
time, but parameters estimated using off-line estimation do not.In this way, off-line training
is not restricted by the on-board computers computation power and the approximation can
be highly accurate.Traditional methods include recursive least-squares and the Kalman
filter for parameter estimation (Ljung, 1999). Newer alternative methods include Hopfield
Neural Networks (HNNs) for parameter estimation (see, for example, (Atencia, Joya, &
Sandoval, 2004; Hu & Balakrishnan, 2005)). Neural networks are used mainly for on-line
PI.The off-line learning cannot take the advantage of a neural networks learning ability to
adapt to the changing aircraft dynamics during the flight. The on-line learning method
uses the real-time flight data obtained for training and has much higher requirements for
on-board hardware and software implementation. However, this method has the ability to
learn the changing aircraft dynamics and give the controller some level of intelligence.
The on-line NNs learning speed and accuracy is limited by the natural frequency of the
system, the on-board computation power and available resources. This study benefits is
to learn NN for off-line PI so it may be easy using it when trying the on-line parameter
estimation. Also the onborad computer is restricted to be the lowest cost.Studies shows
that using NN for off-line PI is more accurate than the output error method which is the
most used technique for offline PI(see (J.R. Raol, G. Girija and J. Singh, 2004))[6].So in
this study we are mainly interested in studying the offline PI using NN.

3.2
3.2.1

Artificial neural network


Introduction

Artificial neural network ANN is a try to get a mathematical model for the human brain.
The human brain is consisting of a very large number of neurons. The artificial neuron
receives one or more inputs (representing the one or more dendrites) and sums them to
produce an output (representing a biological neurons axon). Usually the sums of each
11

node are weighted, and the sum is passed through a non-linear function known as an
activation function. The activation functions usually have a sigmoid shape. Modeling of
a system using artificial neural networks has recently become popular with application
to signal processing, pattern recognition, system identification and control. Estimation
of parameters using empirical data plays a crucial role in modeling and identification of
dynamic systems. Often equation error and output error methods are used for parameter
estimation of dynamic systems. These are generally batch iterative procedures where a set
of data is processed to compute the gradient of a cost function and estimation error. The
estimation of parameters is then refined using an iterative procedure based on the improved
estimates of error and its gradients. Such methods can be termed as batch iterative. The
artificial neural networks provide new/alternative paradigms to handle the problem of
parameter estimation with potential application to on-line estimation. Especially recurrent
neural networks are easily amenable to such possibilities due to their special structure-feed
forward neural networks with feedback feature. In order to obtain fast solutions, a system
of parallel computers can be used. This will require the parallelization of the conventional
parameter estimation algorithms. Since artificial neural networks have massively parallel
processing capacity, they can be adapted to parameter estimation problems for on-line
applications. In particular, the recurrent neural networks can be considered as more
suitable for the problem of parameter estimation of linear dynamical systems, as compared
with perhaps feed forward neural networks. The recurrent neural networks are dynamic
neural networks, and hence amenable to explicit parameter estimation in state-space
models. One of the architectures of RNN is the Hopfield neural network HNN. In the
following section HNN will be introduced to be used for PI.

3.2.2

Hopfield neural network

3.2.2.1

Introduction

One of the milestones for the current renaissance in the field of neural networks was the
associative model proposed by Hopfield at the beginning of the 1980s. Hopfields approach
illustrates the way theoretical physicists like to think about ensembles of computing units.
No synchronization is required, each unit behaving as a kind of elementary system in
complex interaction with the rest of the ensemble. Hopfield neural network HNN could
be successively used for the problem of PI. First we have to introduce HNN as a general
neural network. For Human neural network,lets have an example.a man recognizes photos
by both eyes. For a sick eye, the brain tries to depend on the better eye more than the other
one hence sends more blood to the better one.And perceptrons between eyes and the brain
become weaker in the sick one. It looks like brain take more weighting to the healthy eye
and less weighting to the sick one. Doctors advice to treat the sick eye because it now is
going to become weaker and weaker because the brain tries to neglect it time by time.This
weightings is what we try to do when trying to descibe what happens mathematically.
A simple way to show that as in figure 3.1. So to get the right output, it is a must first
to know the right values of weights and this is called learning. Then After getting the
appropriate weights and applying the input signals you could get the output and this is
called validation. Assume a discrete problem where it is required to recognize the C
character when writing it in a 4*3 pixels as shown in figure 3.3a. When writing the C
character as in figure 3.3b, The solid pixels are represented as 1 and the unsolid as -1 as in
12

Figure 3.1: An artificial neuron as used in a Hopfield network


figure 3.3c.From Hopfield Neural Network the weights are obtined between each pixel
and the other pixels as shown a sample of the weights in figure 3.3d and by the language
of neural network pixels are now neurons where:
wi j = xi x j

(3.1)

where i and j are the neuron index and x is the value of the neuron 1 or -1 . By obtaining
these weights, learning step has now ended. Now the validation where the pixels are let for
some one to write the C character on them as seen in figure 3.3e. What has been written
is transfeered into 1 and -1 as in figure 3.3f. The neural network now try to change the
pixels 1 and -1 values till reach a learned character which here is only the C character. To
update a neuron value hopfiled uses the following rule:
n
X
xi = sign( i j x j )

(3.2)

j=1

This equation is proofed that it will never diverge [6]. The values of the neurons will move
towards the nearest shape to the C character. So it may reach the C character or it will
not go worse. So the sign apperaed in equation 3.2 shows an added block to HNN shown
in figure 3.1 which is added after the summation rectangualr block which in general for
continuous system will not be a sign but generally will be a sigmoid function where the
sign is a special case in it as shown in figure 3.2.

Figure 3.2: An artificial neuron as used in a Hopfield network with added sigmoid function
13

This was a roughly description to what happen in Hopfiled neural network.

(a) 4*3 Pixels

(b) C character

(c) A subfigure

(e) A subfigure

(d) Sample of the weights

(f) A subfigure

Figure 3.3: Example for Discrete image recognition using Hopfield Neural Network
3.2.2.2

Parameter Estimation Problem

The Proof was given in Raol and others[6] and the main theory was revised from its main
paper[7] . Consider the state space representation of a dynamical system
x = Ax + Bu

(3.3)

The aim is to solve for A, B the system parameter matrices knowing x, x and u. Here
x is (n 1) state vector, u = u(t) is the control input (scalar), A = [ai j ] is n n matrix and
B = [bi ] is n 1 vector. The parameters ai j (elements of A) and bi (elements of B) to be
estimated are denoted by np 1 vector where:
= [a11 , a12 ....aln , a21 , a22 ...a2n ..an1 , an2 ...ann , b1 , b2 ...bn ]

(3.4)

where np is the number of parameters to be estimated i.e. (n2 + n). Next we describe
the dynamics of HNN as
n
X
=
i j i + bi
(3.5)
j=1

Our problem is to define the Weighting matrix W, the bias vector b, choose the sigmoid
function f and its coefficients then use these information to get the change in the parameters
.
i.e. then get the new parameter values as new = old + t
Given e(k) as the equation error where e = x Ax Bu we can define the cost function
as:
n
n
1X T
1X
E() =
e (k)e(k) =
( x Ax Bu)T ( x Ax Bu)
(3.6)
2 k=1
2 k=1
14

Also we have
E=

X
1 XX
i j i j
bi i
2 i j
i

(3.7)

as the energy landscape of the recurrent neural network.Now from optimization theory by
differentiating the cost function w.r.t we have
Pn
E
1 ( k=1 eT (k)e(k))

=
=
(3.8)
t

Since as a parameter vector contains the elements of A and B, we can obtain expressions
E/A and E/B for A and B vectors.
n

X
X
X
E X
=
( x Ax Bu)(x)T = A
xxT + B
uxT
x xT
A k=1

(3.9a)

X
X
X
E X
( x Ax Bu)(u) = A
xu + B
u2
xu
=
B k=1

(3.9b)

By expanding the elements of the above matrices we could get E/ai j and E/bi j . For
example
X
X
X
X
E
= a11
x12 + a12
x1 x2 ......... + b1
x1 u......
x1 x1
a11

(3.10)

Again by differentiating the energy equation w.r.t we have


n
X
E
i j i bi
=
i
j=1

(3.11)

By comparing equations 3.10 and 3.11 we could find the elements of both the weighting
matrix W and the bias vector b. Now Since i = f () then = f 1 (i ) then
i =

( f 1 (i ))
i

(3.12)

So we could define the change in parameters as


i =

1
( f 1 (i ))

i =

n
X

( f 1 (i ))
j=1

i j i + bi

(3.13)

Assuming
And by choosing a suitable sigmoid function we could get .
f (i ) = (
then
i =

1 ei
)
1 + ei

n
(2 2i ) X
i j i + bi
2
j=1

15

(3.14)

(3.15)

Finally to get the new parameters vector we have

i (k + 1) = i (k) + t
i (k + 1) = i (k) + t

n
(2 2i ) X
i j i + bi
2
j=1

(3.16)
(3.17)

Figure 3.4: Flow chart for Hopfield Neural Network PI

3.2.3

Results

A Matlab code was built depending on the previous illustrations. A set of data was
generated from a given linear state space model.The model has four states and one input
signal with 20 parameters. The estimation was carried out using noise free data and again
with additive noise(SNR=10). The tuning parameters and were kept at 0.001 and 200
respectively.Sampling time was set at .00025 sec. It was noted that RNN took around
200,000 iterations before the convergence of estimated parameters to true values for the
free noise signal and about 900,000 iterations for the noisy signal. Table 3.1 shows the
estimated parameters for the two data sets.Error was shown as only the difference between
the real and estimated value.

16

Table 3.1: Estimated elements of A and B matrices


True Values
iter
SNR
-0.045
-0.036
0
-30
-0.369
-2.02
1
0
0.0019
-0.0396
-20.948
0
0
0
1
0
0.56
-0.8
-0.5
-0.7
Error

Estimated
Error
200000
SNR=inf
-0.045003671 3.6707E-06
-0.036021552 2.15516E-05
0.00038355
-0.00038355
-30.00003794 3.79433E-05
-0.369084965 8.49649E-05
-2.020498759 0.000498759
1.008898544 -0.008898544
-0.000878168 0.000878168
0.000911806 0.000988194
-0.045400063 0.005800063
-20.84433291 -0.103667093
-0.010214947 0.010214947
0.000588044 -0.000588044
0.003451917 -0.003451917
0.938412706 0.061587294
0.006077832 -0.006077832
0.560001413 -1.41341E-06
-0.79996698 -3.30197E-05
-0.499613434 -0.000386566
-0.700228534 0.000228534
-0.04314389

Estimated
Error
900000
SNR=10
-0.027277008 -0.017722992
0.173624619 -0.209624619
-12.22945959 12.22945959
-26.46613445 -3.533865551
-0.075466871 -0.293533129
-0.184922364 -1.835077636
0.567241605 0.432758395
2.034148622 -2.034148622
-0.010721288 0.012621288
0.010295163 -0.049895163
-16.91628511 -4.031714892
0.375789166 -0.375789166
0.002145217 -0.002145217
0.018468908 -0.018468908
0.963367259 0.036632741
0.040599949 -0.040599949
-0.969877568 1.529877568
-0.536048355 -0.263951645
-0.478945969 -0.021054031
-0.653822901 -0.046177099
1.467580966

Estimated data for both data cases are shown in figures 3.6, 3.7 and 3.8 . Figure 3.6
shows the real and estimated states and change in states. Figure 3.7 shows the true A and B
matrices elements and the estimated parameters. Figure 3.8 shows the error in parameters
with iterations.
A study [6] was shown that using an input with 3211 signal will excite the long and
short period in the aircarft. Also using a sampling frequency when collecting data 0.01
Hz will be better in PI problem [10]. In the following table four situations will be studied
showing the impact of sampling frequency and the type of signal on HNN PI problem.
Table 3.2: Results of different combinations of data Sampling frequency and the type of
the input signal

3211 input
Pulse input
for 2 sec.
Doublet Input
0.5 Hz

100 HZ
Error= 0.0359 %
Time = 63.485 sec
Error= 0.0199 %
Time = 64.94 sec
Error= 0.0362 %
Time = 66.538 sec

20 HZ
Error= 0.2744 %
Time = 64.72 sec
Error= 0.1912 %
Time = 65.214 sec
Error= 0.3053 %
Time = 68.0966 sec

17

Comment
Long period Obtianed
Short Period Obtained
Long Period (Not Obtained)
Short Period Obtained
Long Period (Not Obtained)
Short Period Obtained

(a) S NR =

(b) S NR = 10

Figure 3.5: Real,measured and Predicted data for states and states rate

18

(a) S NR =

(b) S NR = 10

Figure 3.6: Real,measured and Predicted data for a sample state

19

(a) S NR =

(b) S NR = 10

Figure 3.7: True and estimated parameters

20

(a) S NR =

(b) S NR = 10

Figure 3.8: Error in parameters

21

Chapter 4: Data Gathering Module


4.1

Introduction

Autopilot is the brain of an aircraft. It is responsible of all orders given to the aircraft.It
collects data, processes it and finally makes the decision. The whole autopilot system
contains from its hardware elements ,the software saved on it and the ground control
station GCS. Autopilot hardware circuit contain all the elements required to make the
proper sensing to the aircraft and its situation like altitude, attitude,velocity, surrounding
atmosphere and so on and so far. Autopilot software transfer all the sensors data to the
autopilot processor.Autopilot software analyses the data in the processor unit then make
the decision and send it to the aircraft actuators.For now we are just using the autopilot as a
data gathering module.So data is just collected and stored with no resulting control action.
In the following sections a brief description will be presented about the hardware circuit
components, specifications and limits then a description to the data gathering module
software and GCS software .

4.2

Hardware

The DGM designed and tested in ASTL was of total weight about 250 gm and external
dimensions about 9x3x5 cm.The parts chosing crietrai was to get the best parts in the
local market.Most of parts were getting from Ram and future electronics, see[2],[3] . It is
consisting of 3 PCBs the first main one contains the microcontroller and the sensors and
the second one is a servo set PCB to connect between servos and the main PCB.The last
one conects between analog inputs (potentiometers and velocity sensors) and the main
board. The work done at west Virginia university was very helpful during the choosing and
testing of sensors.Dr Brad seanor did his PhD at 2002[10] and then he was of supervisors
of Dr YuGu during Dr Yu Gu PhD in 2004[5] and Eng. Amanda K. McGrail during her
Msc. in 2012 [8].

22

Figure 4.1: Block Diagram for the whole system processes

23

Figure 4.2: Data gathering Module Hardware

4.2.1

Microcontroller

As shown in figure, the used microcontroller was Arduino Mega 2560 16 MHz, 256
KB RAM. It collects data from various sensors and sends it to the computer via serial
communication or through wireless via wireless module. It is responsible on control
commands. The board also connects between the remote controller and the servos for the
purpose of manual flights. Its limitations come from the low processor and the low RAM
capacity.

Figure 4.3: Arduino mega 2650 microcontroller

4.2.2

Microcontroller shield

The Arduino shield is a two layer PCB. This customized shield was used to connect the
microcontroller with the various sensors.

24

(b) Back Layer

(a) Front Layer

(d) Implementation - Fixed with Arduino


(c) Implementation - Lower Layer

Figure 4.4: Arduino Customized shield

4.2.3

Servo Motors

The used servo motor was the Standard High-Torque BB Servo Futaba S3010. Its speed is
0.20 sec/60 @ 4.8V

Figure 4.5: Servo Motor

25

4.2.4

Servos and potentiometer Sets

This is a customized PCB to connect the servos to the main Arduino shield. This board is
good for longer servos distributions and to simplify the main Arduino shield. There are
two boards of this kind one for servos and the other one for potentiometers

(b) PCB Layout

(a) Implementation

Figure 4.6: Servos Set

4.2.5

Potentiometers

Potentiometers are used to measure the control surfaces deflections. The output is used to
be stored as the input signals. Input signals are used for parameter identification purposes
as will be shown later.

Figure 4.7: Potentiometer

4.2.6

IMU

As shown in figure, the used IMU was Arduimu V3. It is responsible for measuring the
Euler angles , and , the Euler angles rates p, q and r and the accelerations ax, ay and
az. Specifications of this Arduimu comes from the motion processing unit used inside
it which is MPU-6000. MPU-6000 comes integrated with a 3-axis MEMS gyroscope, a
3-axis MEMS accelerometer and a 3-axis magnetometer. The used ranges are 500 /sec for
gyroscope and 4g for the accelerometer, see [12].

Figure 4.8: Arduimu V3

26

4.2.7

Pressure Sensor

The used atmospheric pressure sensor was BMP085 Module GY-65.The sensor has a
range of 30:110KPa ( altitude 9000:-500m) with a resolution ratio of 6 Pa (0.5 meter) in
low power mode and 3 Pa (0.25 meter) in high linear mode. The response time equals 7.5
ms, see [11].

Figure 4.9: BMP085 Module GY-65 Pressure Sensor

4.2.8

Velocity sensor

The MPXV7002DP series piezoresistive transducer is a monolithic silicon pressure sensor


with a pressure range of 2 kPa and 2.5 % typical error and 6.25% maximum error over
+10C to +60C.

Figure 4.10: Velocity Sensor

4.2.9

Wireless module

The uses wireless module was Xbee PRO 52B.It is responsible for data transmission
between autopilot and the ground station. It has an outdoor line-of-sight at about 1500m.

Figure 4.11: Xbee pro 52B wireless module

4.2.10

GPS module

CJMCU-108-H is a UBLOX GPS with 5 Hz update rate and -148 dBm acquisition
sensitivity (cold start), -162 dBm tracking sensitivity. The error in location is about 1.5 m.

27

Figure 4.12: GPS Module

4.2.11

Alpha-Beta sensor

Air-data sensor is an alpha beta probe used for measuring the angle of attack and side slip
angle.The sensor was difficult to be obtained from the market for small aircrafts and the
available one was very expensive. So the sensor had to be built.The design of the fens was
taken from the Open Air Data Computer project through the web site[4]. The obtained
fens was capable of measuring the AOA when the velocity reaches about 14 m/sec. and
the alpha and beta fens were collected in one set. So a modification on the design were
done.First a 1.8 scaled fens was built to get readings at a velocity about 7 m/sec.Second
the fens were separated one at the right wing tip and the other one at the left wing tip.This
allow a better weight distribution and to be away from the propeller flow at the middle of
the aircraft. A 3D model for the whole sensor was built then manufactured in the ASTL.
After the first test flight the system was modified as shown in the flight test chapter later.

Figure 4.13: First Design (Not used because of middle flow from motor propeller)

28

Figure 4.14: Air data fin drown by Solid Works

Figure 4.15: CNC manufacturing of Air data fin

29

Figure 4.16: Air data fin for Side Slip angle

Figure 4.17: Air data fin for angle of attack


30

Figure 4.18: The total AOA and Side slip sensors attached to the wing tip

4.2.12

Batteries

The Power source of the Arduino mega and the servos was separated then collected at
only one ground. The Arduino used a battery of 7.4 volts with 2500 mhA which has a
very good capacity that could sustain for a very good time without needing recharging.
The servos are using the standard Ni-Cd 4.8 volt batteries.

4.2.13

RC Transmitter and receiver

A Futaba RC Remote was used for manual control of the servos. It sends signals to the
receiver. The receiver is connected to Arduino. Finally Arduino sends signals to servos.

4.3

Software

4.3.1

Arduino Mega Software

Sensors Signals to Microcontroller Software is used to transfer data from sensors to


the Arduino microcontroller. The software is based on Arduino programming program.
The software collects about 27 readings from various sensors. The data gained could
be used for parameter identification and for control purposes The output data are in
ASCII format. Through signal monitor data could be seen sending row by row. Each

31

row contains all the sensors readings as follow: RLL:0.07,PCH:0.08,YAW:0.33,altitude:0.50,velocity:0.00,elev:-683,ail:-713,rdr:-713,alpha:-737,beta:-690,AN0:0.13,AN1:-0.62,


AN2:0.22,AN3:17.78, AN4:-0.08,AN5:8190.33,lat:0.00,lon:0.00,gpsalt:17.00 , gpsgc0.00,
gpsgs0.00, fix:0,numsat:0,elevs:0,ails:0, ruds:0,throts:0. RC receiver is connected to Arduino mega through its digital ports. So Arduino could collect the RC remote signal to
store it then sends it to the servos through the PWM ports.The main code for Arduimu was
given from its website [12] and then modifications was done on the code as in Appendix
C to get the right angles and some website were very helpful in that, see[1].

Figure 4.19: Flow Chart of Arduino Software

4.3.2

Monitoring Software

Monitoring software is used to plot the various received data from the autopilot in real
time. This software could also save the data for after-processing. Saved data could be
used for analyzing the recorded flight and for off line parameter estimation purposes. The
software was built in Simulink environment. The autopilot sends data in ASCII format
then the monitoring software convert it to decimal. The software is connected to Google
earth program. Google earth receives the GPS data from the Simulink program to plot the
aircraft location using longitude and latitude readings , see Appendix D.

(a) the whole program

Figure 4.20: Monitoring Software

32

(b) ASCII to decimal Block

Figure 4.21: Simulink GCS

Figure 4.22: Flow Chart of Simulink GCS

4.3.3

Parameter Identification Software

Parameter identification software is a generated Matlab code. The inputs to the code are
the measured data received from the autopilot for the sensors signals and control surfaces
deflections signals. The code is based on Hopfield neural network as will be discussed
later. The outputs from the code are the A, B matrices of the linear state space model for
longitudinal and lateral aircraft dynamics. The whole software is shown in Appendix A.

33

Figure 4.23: Flow chart for Hopfield Neural Network PI

34

Chapter 5: Test flights and Results


5.1
5.1.1

KADET LT-40 RC model Test Flight


Introduction

The used aircraft specifications are shown in table 5.1. The test flight was performed at
9:00 am and the Airflow was quiet and suitable for the test. The test flight was performed
for about 5 min. as shown in the map in the red path.Through the flight the data were
collected and stored into the GCS.Post processing was performed

Figure 5.1: The Flight Path


Table 5.1: KADET LT-40 RC model Specifications
Wing Span
Wing Area
Length
Flying Weight
Wing Loading
Engine

1778 mm
58.1 dm
1447 mm
2490 - 2720g
43 - 47 g/m
2-Stroke .46 cu. in. (7.5 cc)

35

Figure 5.2: Ready to Fly

Figure 5.3: Captured photo from the flight test

5.1.2

PI of Longitudinal Dynamics

For the linearized longitudinal equation of motion we have




u
u


= A + Bu
q
q

(5.1)

Our aim now is to do the following:


1- Collect all the available data from the state space vector, its derivative and the input
u, , q, , u).
vector i.e (u, ,
q,
,
2- Estimate the data that was not capable to be measured.
3- Identify the A and B matrices.
36

The unavailable data that cannot be measured were the angular acceleration term q and
the angle of attack rate (AOA) .For

q the angular rate q was differentiated to get q and


this required a high sampling frequency to get accurate estimation usually 100 Hz is used
but in this test 10 Hz only was used and this was modified in the other test flight for Low
Super trainer RC model.Also u was replaced with the linear acceleration in x direction a x
and was replaced with the linear acceleration in z direction az .So finally the state space
model becomes


a x
u
a

h
i
z = A + B elev
(5.2)
q
q

In the flight the throttle was set constant and then the throttle was neglected.The data
were added to the Hopfield Neural Network code and using a good sample from the test
with smooth outputs and inputs for about 4 seconds. The code was designed to iterate
and get estimated A,B matrices. These A,B matrices are now the estimated linear state
space model to the aircraft.input data collected from the test are applied to this model and
compare its states response to the measured states.Error calculated was about 7.5 % where
P s Pn
|ei |
E= 1 1
(5.3)
n
where s is the number of states and n is the number of samples for each state.The
measured and estimated states are shown in figure 5.5 .

37

Figure 5.4: Longitudinal States (Measured and estimated).The yellow line is the elevator
signal
A remark was shown from this test is that the pitch angle (the 4th figure)indicates that
we have two peaks one at the 0.5 sec and the other one at about 2.3 sec and the difference
between the measured and estimated at 2.3 is higher than the one at 0.5.We can remark
that also the rate of change of the elevator signal is higher at 2.3 more that its at 0.5. This
indicates that the aircraft response is changing not only with the elevator signal but also
with the rate of change in elevator signal. So another model was suggested to consider
that we have not one input signal but two input signals the elevator signal and the change
. Now the state space model become as follow
in elevator signal (elev, elev)


a x
u
"
#
a

z = A + B elev
(5.4)
q
q

elev

By using the new state space model the error was reduced from 7.5 % to 6.3% and the
results are shown in figure 5.5. Another remark was shown now that the alpha signal has
the maximum error with 59.37 % of the total error.The error in other 3 states is equal only
2.56%.By this remark it was suggested to use another AOA and side slip sensor.

38

Figure 5.5: Longitudinal States (Measured and estimated) when using elevator and change
in elevator as inputs.The yellow line is the elevator signal
The estimated state space has the following form


a x 0.0858 0.2892 0.0004 9.7233 u 15.6149
a 0.1890 4.8213 21.2426 0.0004 0.0070

z =
q 0.0335 0.1529 4.6181 0.0201 q + 6.5863

0.0091 0.0076 0.9953 0.0074


1.3036

1.2472 "
#
0.0070 elev

0.8107 elev

0.4347
(5.5)
The A matrix shows a good match in the parameters order of magnitude with the linear
state space model derived in Nelson Flight Stability and Automatic Control book[9] as in
equation 5.6.


Xu
Xw
0
g u
u
w
Zu
Zw
uo
0 w
=
(5.6)
q Mu + Mw Zu Mw + Mw Zw Mq + Mw uo 0 q

0
0
1
0
The root locus of the longitudinal dynamics is shown in figure 5.6.It is shown that
the long period poles are lying on the real axes and it has two options. The first one is
that this is our situation and this is our aircraft dynamics.The second option is that we
didnt get the aircraft the sufficient elevator signal to force the aircraft to bring out all its
39

dynamics.So it is suggested in the coming test to use a doublet elevator input which is
very good in doing the job.

Figure 5.6: Estimated Pole map of the Longitudinal dynamics

5.1.3

PI of Lateral Dynamics

For the linearized lateral equation of motion we have






p

h i
= A p + B r
r
r

(5.7)

In this test we will differentiate all the four states to get their derivatives as it is not
available to measure them directly.This is also a recall to use higher sampling frequency
in the coming tests to get a good differentiation to the states. After setting the HNN code
with the lateral data and iterate, the state space model was reached as shown in equation
5.8.The order of magnitude of the parameters is reasonable with the general lateral state
space model derived in Nelson[9] as shown in equation 5.9

10.4457 0.0015 3.8845 0.5912 8.2618


i
p 9.4239 6.3545 9.6868 0.1196 p 45.1595 h
=
+
rdr
r 18.6195 0.3073 2.4556 0.6212 r 15.6159

0.0517 1.6458 0.6615 0.0308


2.4332

Y Y p
o
uo uo (1 uYor ) gcos

u
o
p

Lr
0 p
= L L p

r N N
Nr
0 r
p

0 1
0
0
40

(5.8)

(5.9)

The estimated lateral dynamic system is fed with the measured aileron data to get the
estimated states. Estimated and measured states are shown in figure 5.7.

Figure 5.7: Lateral States (Measured and estimated).The last line is the aileron signal
Again a recall that the AOA and side slip sensor must be changed. The Total error
between measured and estimated states calculated by equation 5.3 was equal 4.7% and the
error in side slip angle has alone a 42.13% from the total error where error in other three
states is only equal 2.72 %.
The root locus of the lateral dynamics is shown in figure 5.8. The roots of the
conventional aircraft are delivered : the spiral role root, the two imaginary poles of the
dutch roll mode and the role pole.

41

Figure 5.8: Estimated Pole Map of the Lateral dynamics

5.1.4

Test Summary and recommendation

Overall the results were appealing with total error equal 6.3% and 4.7% for longitudinal
and lateral dynamics perspectively. The total system was successful to estimate the linear
dynamics of the aircraft. In each stage suggestions were appearing with the results. Here
is a summary of this cautions to be taken under consideration in the next flight.
1. A better A/C is recommended because the used one was very old and has difficulties while flying which prevent from apply a full doublet signals to the aircraft as it tends
to diverge and moving unstable.
2. Electric Motor is recommended for constant thrust and also more clean.But for this
magnetic field must be taking under consideration
3.A Better Design of AOA and Beta sensors is very recommended because the highest value of error was coming from them.
4. Central Position for AOA and Beta sensors must be studied because when the fins are
in the tip, they are affected with the rolling motion.
5.It was noticed that the servos have some jumpy signals when no orders are send to
them. This happen around one time each 10 seconds.
6.A Better GCS Software is recommended for better inspection of the test while it is
performed to be able to assure the test was done in the right way. For example The servos
signals should be shown to assure that the doublet input is done. The AOA and side slip
sensors data should be shown to assure that they are normal with no ups and downs.
7. For servo to work: The transmitter sends data to receiver, then from receiver to

42

Arduino then Arduino saves data and also sends it to the servo. In this circuit if a problem
occurred to the Arduino board, The signal will not be able to transfer from transmitter to
the servos and the aircraft then is out of control. So a relay must be added to be able to
switch the signal directly from receiver to the servos if Arduino suddenly stopped working.
8.For the collected data to be saved the Arduino sends them by wireless Xbee module to the GCS and they make a restriction on the sampling frequency and if the Xbee
stopped working the data will not be able to be sent to the GCS So a data logging SD-Card
is recommended.
9.A newer PCB will be a newer edition to the data gathering system and it will be
better for a better sensors arrangement and to be able to put the system in a closed box
with better wires arrangement and to ensure more safety for the circuit.
10. For the new aircraft the aerodynamic stability and control derivatives could be
calculated with Datcom and compared with the Neural network results.

5.2

Low Super Trainer RC model

Figure 5.9: Low Super Trainer RC model

5.2.1

Modifications for Test 2

From Test 1 some suggestions were given to et better results for test 2. The modifications
were done as follow:
1- A new RC model aircraft was used for this test called Low super trainer.Specifications
of the aircraft are shown in table 5.2. It has a takeoff weight for about 3.5 kg. In this new
model we could guarantee that the Y plane is the a symmetric plane so a pure longitudinal
43

Table 5.2: Low Super trainer RC model Specifications


Wing Span
Wing Area
Length
Flying Weight
Engine required
Engine used

1650mm
45sq.dm
1250mm
3450g
2c 0.40 - 0.46 cu in
Brushless motor 46

motion could be achieved. Also the engine was replaced with an electric motor for constant
and a cleaner source of thrust as shown in figure 5.10.

Figure 5.10: Replacing the engine with an electric motor


2- The sampling frequency of collecting the data was doubled from 10 Hz to 20 Hz .
This increase assure a better smooth data and also better values when differentiating the
states.
3- The problem of alpha beta sensors was extremely solved here by the following modifications:
a- The fin was replaced with a similar fin but scaled by 0.7 . The new small fin could
guarantee a lower fin inertia and mass which could help in increasing the fin response to
the change in the flow direction. When the fin becomes low in its mass, it becomes more
easy to rotate it with a low speed flow.
b- Not only decreasing the mass will help, but also it is a must to decrease the potentiometer friction through using a very low friction encoder.
c- A central positioning for the air prob could help to get the right air data but because the
aircraft has a pusher motor fixed in the center, the air data sensors were fixed again at the
tip of the wing. But to guarantee good results, two sets of air data sensors were fixed one
at the right wing tip and another at the left wing tip. Before the flight it was found that one
of the angle of attack sensors was stopped working so one AOA sensors was only used to
44

measure the angle of attack.


d- limiters were added to the fins to make sure that fins will not rotate above 90 degree
and settle at the opposite direction. At last before the test flight, All sensors and control
surfaces deflections were calibrated and tested before the test flight.

Figure 5.11: The fin of the old sensor and the smaller one of the new sensor

Figure 5.12: The black potentiometer and the golden Encoder

45

Figure 5.13: The modified Air data system

Figure 5.14: The Air data systems setup for both aircrfats

46

Figure 5.15: The Air data systems of both two aircrfats

Figure 5.16: The two sets of the new Air data system
The results of the sensors were very appealing and each pair has a very close results.

47

Figure 5.17: The two velocity sensors data during the flight

Figure 5.18: The two beta sensors data during the flight

5.2.2

Flight test

The flight was done at about 3:00 pm in Sheikh Zayed flight area zone.The airflow was
quiet and suitable for the test. A failure was occurred in the electric motor and it suddenly
stopped working during the flight. The plane was fall down and the engine mount was
broken and one of air data sets was taken away from its place.But a flight for about 30
seconds was successfully recorded, a doublet input for the elevator was achieved and
a roughly pure longitudinal motion was done. In the coming sections longitudinal and
lateral dynamics will be discussed.

5.2.3

Longitudinal Dynamics Identification

To activate both the short and long period dynamics it is recommended to use 3211
input,see [6]. In this test a doublet input was applied with various frequencies and it was
48

helping in activating the dynamics even it is recommended to enhance it in the coming


flights. In the input vector the throttle was added even it doesnt changed and this ehnaced

Figure 5.19: Doublet elevator input


the results.It may be as a result of the initial value the throttle helps the states to start with
and maintain at a certain value till changing with elevator or other states. The results shows
that the error was about 1.47% and the results of the alpha sensor was accepted not like
the results of test 1. Using a sampling frequency of 20 Hz helped also in differentiating the
states. Through the test, It was accepted to use u not using a x . Also using not using az .


u
u
"
#


= A + B elev
(5.10)

q
q
elev

49

Figure 5.20: Measured and Estimated Longitudinal States


For the poles, The results showed both the imaginary short and long period poles.The
order of magnitude of A matrix was in good match with Nelson [9].

u 1.0422 76.9002 0.1338 9.7870 u 47.8624 0.2262 "


#
0.1386 15.8909
1
0.0106 2.3533 0.0215 elev
=
q 4.1345 216.1426 21.4856 0.0027 q + 240.0769 1.0633 throtle

0.0077 0.0102
1.1431 0.0126
0.0446 0.0034
(5.11)

Figure 5.21: Longitudinal Pole Map

5.2.4

Lateral Dynamics Identification

It was not able to get a pure lateral and directional motion from the flight with doublet
aileron or rudder as the engine was cutoff before the test and the only achievable control
50

surface deflection was the elevator. So we cannot make a final desision about the lateral
identification.However by testing the data it get some accepted results but the error cannot
be a rule here even it is lower than the first test(Error=4% and for test one it was 4.7% ) as
when the yaw angle increase than 180 degree, the data has a fault jump from 180 to -180
and this increases the error.The data measured and estimated and root locus results are
given below.The order of dynamic matrix A is very close to that is given in Nelson [9].

Figure 5.22: Lateral States , Last line for Aileron



2.0447
3.5779 0.0130
44.7421 2.4141
p 633.3455 88.9262 94.5293 0.0327 p 410.8903 h
i


=
r 440.4360 6.4201 24.9187 0.1893 r + 310.0469 ail



5.8755

0.0200
0.8450
0.2985 0.0426

51

(5.12)

Figure 5.23: Lateral Pole Map

52

Chapter 6: Conclusion and Future


Work
Hopfield neural network combined with the designed framework delivered an appalling
results in the problem of offline PI. With the low Arduino mega processing power and
RAM compared with other used microcontroller for PI purposes, It had an accepted
performance and durability in the project. The purpose of the was to use low cost for
decreasing the funds but for a first trial of PI and to make just a proof of concept. Higher
Microcontroller is planned to be used for the second iteration.The need for real flight
to know the dynamics of an aircraft seems to be a mandatory object in autopilot design
and we cannot fully depend on Datcom or Roskam to get the dynamics of a small UAV.
No remarkable work can be done by only one person, Team work and accumulation of
Knowledge is the way for successful and beneficial work.

6.1
6.1.1

The Future suggested work


Parameter Identification

PI work may be a second iteration on Offline PI or Online parameter identification and


here are suggested disciplines
6.1.1.1

Hardware

1- Using Arduino 2- Using MyRio(Labview) 3- Build an IMU


6.1.1.2

Software

A- Monitoring Software Try to increase its speed. You may use Visual Basic,Lab view or
Simulink. B- PI software You may iterate again for Neural network or try to use another
method may genetic alogrithm or frequency response techniques.You may use a new
method for Offline or using NN for online.

6.1.2

Autopilot

Using the calculated state space models, you may now transfer to the new stage of
Autopilot: Stability control. Stability control was introduced in the introduction chapter
before. You may try to work for Altitude hold then towards the heading autopilot and
finish your work by a horizontal loop mission.

53

Figure 6.1: Suggested Work

54

References
[1] DiyDrones. Diydrnes,http://diydrones.com/.
[2] electronics, R. Ram,http://ram-e-shop.com/oscmax/catalog/.
[3] futureelectronics egypt. futureelectronics egypt,http://www.fut-electronics.com/.
[4] George Zogopoulos Papaliakos, Graziano Capelli, J. L. J. Basic air data website,http://www.basicairdata.eu/.
[5] Gu, Y. Design and flight testing actuator failure accommodation controllers on WVU
YF-22 research UAVs. PhD thesis, College of Engineering and Mineral Resources at
West Virginia University, Morgantown, West Virginia, 2004.
[6] J.R. Raol, G. G., and Singh, J. Modelling and Parameter Estimation of Dynamic
Systems, 1st ed. The Institution of Engineering and Technology, 2004.
[7] J.R. Raol, H. Neural network architectures for parameter estimation of dynamical
systems. IEE Proceedings 143, 19960338 (July 1996), 386394.
[8] McGrail, A. K. Onboard parameter identification for a small uav. Msc. thesis,
College of Engineering and Mineral Resources at West Virginia University, 2012.
[9] Nelson, R. C. Flight Stability and Automatic Control, 1st ed. McGraw-Hil Book
Company, 1989.
[10] Seanor, B. A. Flight Testing of a Remotely Piloted Vehicle for Aircraft Parameter
Estimation Purposes. PhD thesis, College of Engineering and Mineral Resources at
West Virginia University, Morgantown, West Virginia, 2002.
[11] Sparkfun. Sparkfunwebsite, https://www.sparkfun.com/.
[12] Team, A. O. http://https://code.google.com/p/ardu-imu/wiki/introductionpage.

55

Appendix A: Hopfield neural network


matlab code
In t h i s code :
1 c h o o s e t h e d a t a f i l e t o u s e
2 i n i t i a t e w i t h a A, B i n i t i a l
3 c h o o s e r o t o v a r y f o r s i g m o i d f n
4 i n t r d o u c e t h e d a t a and s t a t e s
6 c h o o s e lamda f o r s i g m o i d f n
7 Get t h e w e i g h t i n g m a t r i x and t h e b i a s v e c t o r
8 i t e r a t e t o g e t new A, B m a t r i x f o r e a c h r o
9 g e t t h e r e s p o n s e f o r e a c h r o
10 c h o o s e t h e l o w e s t e r r o r r o
11 a g a i n g e t i t s A, B
12 i t e r a t e w i t h t h e new A, B
H i n t you may s t o p t h e p r o g r a m s e v e r a l t i m e s and f o r t h a t
r e p l a e t h e l a s t g i v e n A, B == AA, BB w i t h A, B i n i t a l
Here i s t h e f u l l c o d e :
close all ;
clear all ; clc ;
l o a d t e s t 2 v b 2 . mat
%% T E s t Regime
s t a r t =671+3.720+2.520;%805
s t o p =671+200; %906
%% d t and t i m e
d t =q . t i m e ( s t a r t +1)q . t i m e ( s t a r t ) ;
s a m p l e s = s t o p s t a r t +1;
t =q . t i m e ( s t a r t : s t o p ) ;
i t e r =1;
s t e p p =1;
d t t =1
;
%% N e u r a l n e t w o r k P a r a m e t e r s
r 1 =[ 200:50.1:200];
r 2 =[
.1:
.0313:.1];
r 3 =[ 4: 1 . 4 0 1 2 3 : 4 ] ;
r 4 =[ 400000: 1 0 0 0 0 . 2 1 : 4 0 0 0 0 0 ] ;
r 5 =[
.01: . 0 0 3 1 3 : . 0 1 ] ;
];
k a t =[
r 1 ,r 2 ,r 3
%% C o n t r o l S u r f a c e s
elevs=elevservo . data pi /180;
a i l s =ailservo . data pi /180;
t h r o t l e s = t h r o t l e s e r v o . d a t a +10 ;
rdrs=rdrservo . data pi /180;
56

[ elev , a i l , t h r o t l e , r dr ] =
cont surfaces ( elevs , ails

, throtles

, rdrs

e l e v = e l e v ( s t a r t : s t o p )+1 p i / 1 8 0 ;
a i l=a i l ( s t a r t : stop ) ;
t h r o t l e=t h r o t l e ( s t a r t : stop ) ;
rdr=rdr ( s t a r t : stop ) ;
%% I n i t i a l c o n d i t i o n s
AA=[

0
0.1353
1.7769
9.8
0
9.8555
1.2098
0.0254
0 184.2615
9.7172
0.1785
0
0.0133
1.1742
0.0613];
BB=[
10.8370
1.7455
166.1125
0.0192
];
% AA=[ 0 . 0 8 5 8 0 . 2 8 9 2 0.0004 9.7233
%
0.1890 4.8213 2 1 . 2 4 2 6 0.0004
%
0.0335 0.1529 4.6181 0 . 0 2 0 1
%
0.0091 0.0076 0 . 9 9 5 3 0.0074 ] ;
% BB=[ 1 5 . 6 1 4 9
%
0.0070
%
6.5863
%
1.3036 ] ;
AA= [
0.1603
4.7492
0.1893
9.1854
0.0236 11.4540
1.6679
0.0170
0.3632 51.8025 12.2717
1.0140
0.0073
0.0221
1.0347
0.0267

];
BB= [
4.0488 0
3.6889 0
110.0381 0
0.0087 0
];
AA=[
1.0422 76.9002

0.1338

9.7870

57

);

0.1386 15.8909
4 . 1 3 4 5 216.1426
0.0077
0.0102

1
0.0106
21.4856
0.0027
1.1431
0.0126

];
BB=[
47.8624
2.3533
240.0769
0.0446

0.2262
0.0215
1.0633
0.0034

];
%% s i z e s & i n i t i a l c o n d i t i o n s
[ ma , na ]= s i z e (AA ) ;
[ mb , nb ]= s i z e (BB ) ;

%% STATES
data (: ,1)= veldot . data ( s t a r t : stop ) ;
% d a t a ( : , 1 ) = axk . d a t a ( s t a r t : s t o p ) ;
data (: ,2)= alphadot . data ( s t a r t : stop ) ;
data (: ,3)= qdot . data ( s t a r t : stop ) ;
data (: ,4)= pchdot . data ( s t a r t : stop ) ;
%
d a t a ( : , 4 ) = qq . c o s ( R o l l . d a t a ( s t a r t : s t o p ) p i / 1 8 0 )
%
d a t a ( : , 4 ) = qk . d a t a ( s t a r t : s t o p )
d a t a ( : , 5 ) = vk . d a t a ( s t a r t : s t o p ) + . 5 ;
data (: ,6)= alphak . data ( s t a r t : stop ) ;

d a t a ( : , 7 ) = qk . d a t a ( s t a r t : s t o p ) ;
d a t a ( : , 8 ) = pchk . d a t a ( s t a r t : s t o p ) ;
data (: ,9)= elev ;
data (: ,10)= t h r o t l e ;
%
data (: ,11)= ailservo . data ( s t a r t : stop ) ;
n o s =4; % No Of S t a t e s
u =[ e l e v t h r o t l e ] ;
% u= [ e l e v
];
n =2; % no o f i n p u t s
n o i =2;% no o f i n p u t s
E l a s t =10100;
x i n t =[ d a t a ( 1 , 5 ) ; d a t a ( 1 , 6 ) ; d a t a ( 1 , 7 ) ; d a t a ( 1 , 8 ) ] ;

%% The NEURAL NETWORK method HOPFIELD

58

G e t t i n g W, b

f o r i =1: n o s
f o r j =1: n o s
a l p h a w ( i , j )= sum ( d a t a ( : , n o s+ i ) . d a t a ( : , n o s+ j ) ) ;
end
end
f o r i =1: n o s
f o r j =1: n o i
b e t a w ( i , j )= sum ( d a t a ( : , n o s+ i ) . d a t a ( : , 2 n o s+ j ) ) ;
end
end
f o r i =1: n o i
f o r j =1: n o i
t h e t a w ( i , j )= sum ( d a t a ( : , 2 n o s+ i ) . d a t a ( : , 2 n o s+ j ) ) ;
end
end
W1= z e r o s ( n o s nos , n o s n o s ) ;
W2= z e r o s ( n o s nos , n o i n o s ) ;
W4= z e r o s ( n o s n o i , n o s n o i ) ;
f o r i =1: n o s
W1( ( i 1) n o s +1: i nos , ( i 1) n o s +1: i n o s )= a l p h a w ;
end
f o r i =1: n o s
W4( ( i 1) n o i +1: i n o i , ( i 1) n o i +1: i n o i )= t h e t a w ;
end
f o r i =1: n o s
W2( ( i 1) n o s +1: i nos , ( i 1) n o i +1: i n o i )= b e t a w ;
end
W=[W1 W2
W2 W4 ] ;

% Weighting Matrix

f o r j =1: n o s
f o r i =1: n o s
b1 ( i , j )= sum ( d a t a ( : , j ) . d a t a ( : , n o s+ i ) ) ;
end
end
f o r j =1: n o s
f o r i =1: n o i
b2 ( i , j )= sum ( d a t a ( : , j ) . d a t a ( : , 2 n o s+ i ) ) ;
end
end
[ mb1 , nb1 ]= s i z e ( b1 ) ;
[ mb2 , nb2 ]= s i z e ( b2 ) ;
b= [ r e s h a p e ( b1 , mb1 nb1 , 1 ) ; r e s h a p e ( b2 , mb2 nb2 , 1 ) ] ;
% THE BIAS MATRIX %%%%%

59

%%

BETA=[ r e s h a p e (AA , ma na , 1 ) ; r e s h a p e (BB , mb nb , 1 ) ] ;


B e t a r i g h t =[ r e s h a p e (AA , ma na , 1 ) ; r e s h a p e (BB , mb nb , 1 ) ] ;
B e t a n e w= B e t a r i g h t ;
beta dot=zeros (1 ,24);
Q= z e r o s ( 1 , 2 4 ) ;
U= z e r o s ( 1 , 2 4 ) ;

lmda ( 1 : 2 4 ) = 1 0 5 ;
%
lmda ( 1 : 1 6 ) = 1 0 6 ;
lmda ( 1 3 : 1 6 ) = 1 0 8 ;
lmda ( 3 ) = 1 0 6 ;
lmda ( 4 ) = 1 0 9 ;
lmda ( 8 ) = 1 0 8 ;
lmda ( 1 2 ) = 1 0 8 ;
lmda ( 7 ) = 1 0 8 6 ;
% lmda ( 9 ) = 1 0 6 ;
% lmda ( 1 1 ) = 1 0 6 ;
% lmda ( 1 8 ) = 1 0 6 ;
% lmda ( 2 2 ) = 1 0 6 ;
% lmda ( 2 1 ) = 1 0 6 ;
% lmda ( 5 ) = 1 0 6 ;
% lmda ( 1 0 ) = 1 0 6 ;
% lmda ( 2 0 ) = 1 0 6 ;
% lmda ( 2 4 ) = 1 0 6 ;
%
lmda ( 1 0 ) = 1 0 4 ;
f o r LoL =1:520000000
%
f o r wew = [ 1 , 2 , 5 , 6 , 7 , 9 , 1 0 , 1 1
%
f o r wew=[1 : 1 6 , 1 7 , 1 9 , 2 1 , 2 3 ]
f o r wew = [ 1 : 2 4 ]
f o r k i t =1: l e n g t h ( k a t )
ro= k a t ( k i t ) ;

,17 ,18 ,19]

B e t a r i g h t =[ r e s h a p e (AA , ma na , 1 ) ; r e s h a p e (BB , mb nb , 1 ) ] ;
Beta old=Betaright ;
BBU= B e t a r i g h t ;

60

BBYT=0 B e t a r i g h t ;
% Betaright (2 ,3)=1;
f i g u r e (9090)
f o r i =1: i t e r
f o r s h o f =wew
r o o= r o ;
U( s h o f )=W( s h o f , : ) B e t a o l d +b ( s h o f ) ;
Q( s h o f )= ( lmda ( s h o f ) ( r o o 2
Beta old ( shof ) 2 ) ) / ( 2 roo
) ; % d e r i v a t i v e de l a s i g m o i d
%

Q=( lmda . ( r o 2 o n e s ( n o s n o s+ n o i nos , 1 ) B e t a o l d . 2 ) ) / ( 2 r o ) ;

b e t a d o t ( s h o f )=U( s h o f ) Q( s h o f ) ;
B e t a n e w ( s h o f )= B e t a o l d ( s h o f ) + ( b e t a d o t ( s h o f ) d t t ) ;
B e t a o l d ( s h o f )= B e t a n e w ( s h o f ) ;
end

B e t a=B e t a n e w ;
A= r e s h a p e ( B e t a ( 1 : n o s n o s ) , nos , n o s ) ;
B= r e s h a p e ( B e t a ( n o s n o s +1: l e n g t h ( B e t a ) ) , n o i , n o s ) ;
Remm = rem ( i , s t e p p ) ;
i f Remm==0
BBU=[BBU, r e s h a p e ( B e t a , n o s n o s+ n o i n o s , 1 ) ] ;
BBYT=[BBYT , r e s h a p e ( b e t a d o t , n o s n o s+ n o i n o s
C=[1 0 0 0 ; 0 1 0 0 ; 0 0 1 0 ; 0 0 0 1 ] ;
D=[0 0
;0 0 ; 0 0 ;0
0];

,1)];

t=e l e v s e r v o . time ( s t a r t : stop ) e l e v s e r v o . time ( s t a r t ) ;


x0 = x i n t ; % i n i t i a l c o n d i t i o n o f s y s t e m s t a t e s
[ y ] = l s i m (A, B , C , D, u , t , x0 ) ; %do t h e s i m u l a t i o n
f o r kuy =1:4
u i =a b s ( d a t a ( : , kuy+n o s ) y ( : , kuy ) ) ;
y t t =sum ( u i ) ;
e r r o r ( kuy )= ( ( y t t / sum ( a b s ( d a t a ( : , kuy+n o s ) ) ) ) 1 0 0 ) / s a m p l e s ;
end
E=sum ( e r r o r ) ;
% e r r o r (5)=E ;
p l o t ( i , E)

61

h o l d on

end
end
E r r o r ( k i t )=E ;

end
%%%%%%%%%%%%%%%%%%%]
%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
%

wew
if

E l a s t > min ( E r r o r )
E l a s t =min ( E r r o r ) ;
t o k t o k = f i n d ( E r r o r ==min ( E r r o r ) ) ;
ro=k a t ( t o k t o k ( 1 ) )
[ min ( E r r o r ) wew ]

B e t a r i g h t =[ r e s h a p e (AA , ma na , 1 ) ; r e s h a p e (BB , mb nb , 1 ) ] ;
Beta old=Betaright ;
BBU= B e t a r i g h t ;
BBYT=0 B e t a r i g h t ;
% Betaright (2 ,3)=1;
f i g u r e (9090)
s e t ( gcf , u n i t s , normalized , o u t e r p o s i t i o n , [ . 4 . 4 . 4 . 6 ] )
f o r i =1: i t e r
f o r s h o f =wew
r o o= r o ;
U( s h o f )=W( s h o f , : ) B e t a o l d +b ( s h o f ) ;
Q( s h o f )= ( lmda ( s h o f ) ( r o o 2
Beta old ( shof ) 2 ) ) / ( 2 roo
) ; % d e r i v a t i v e de l a s i g m o i d
%
Q=( lmda . ( r o 2 a b s ( B e t a r i g h t . 2 )
Beta old . 2 ) ) / ( 2 ro ) ;
%
Q=( lmda . ( r o 2 o n e s ( n o s n o s+ n o i nos , 1 ) B e t a o l d . 2 ) ) / ( 2 r o ) ;
b e t a d o t ( s h o f )=U( s h o f ) Q( s h o f ) ;
B e t a n e w ( s h o f )= B e t a o l d ( s h o f ) + ( b e t a d o t ( s h o f ) d t t ) ;
B e t a o l d ( s h o f )= B e t a n e w ( s h o f ) ;

62

end

B e t a=B e t a n e w ;
A= r e s h a p e ( B e t a ( 1 : n o s n o s ) , nos , n o s ) ;
B= r e s h a p e ( B e t a ( n o s n o s +1: l e n g t h ( B e t a ) ) , n o i , n o s ) ;
Remm = rem ( i , s t e p p ) ;
i f Remm==0
BBU=[BBU, r e s h a p e ( B e t a , n o s n o s+ n o i n o s , 1 ) ] ;
BBYT=[BBYT , r e s h a p e ( b e t a d o t , n o s n o s+ n o i n o s
C=[1 0 0 0 ; 0 1 0 0 ; 0 0 1 0 ; 0 0 0 1 ] ;
D=[0 0 ; 0 0 ; 0 0 ; 0 0 ] ;

,1)];

t=e l e v s e r v o . time ( s t a r t : stop ) e l e v s e r v o . time ( s t a r t ) ;


x0 = x i n t ; % i n i t i a l c o n d i t i o n o f s y s t e m s t a t e s
[ y ] = l s i m (A, B , C , D, u , t , x0 ) ; %do t h e s i m u l a t i o n
f o r kuy =1:4
u i =a b s ( d a t a ( : , kuy +4) y ( : , kuy ) ) ;
y t t =sum ( u i ) ;
e r r o r ( kuy )= ( ( y t t / sum ( a b s ( d a t a ( : , kuy+n o s ) ) ) ) 1 0 0 ) / s a m p l e s ;
end
E=sum ( e r r o r ) ;
% e r r o r (5)=E ;
p l o t ( i , E)
h o l d on

end
end

%%
figure (99)
s e t ( gcf , u n i t s , normalized , o u t e r p o s i t i o n , [ 0 . 2 . 4 . 8 ] )
subplot (5 ,1 ,1)

63

p l o t ( t , y ( : , 1 ) , m , l i n e w i d t h , 3 )
h o l d on
plot ( t , data (: ,5) , r , linewidth ,3)
hold off
t i t l e ( LONG. S t a t e s u \ a l p h a q \ t h e t a
l e g e n d ( e s t i m a t e d , measured )
legend ( boxoff )

subplot (5 ,1 ,2)
p l o t ( t , y ( : , 2 ) 1 8 0 / p i , m , l i n e w i d t h , 3 )
h o l d on
p l o t ( t , d a t a ( : , 2 + 4 ) 1 8 0 / pi , r , l i n e w i d t h , 3 )
hold off
subplot (5 ,1 ,3)
p l o t ( t , y ( : , 3 ) 1 8 0 / p i , m , l i n e w i d t h , 3 )
h o l d on
p l o t ( t , d a t a ( : , 3 + 4 ) 1 8 0 / pi , r , l i n e w i d t h , 3 )
hold off
subplot (5 ,1 ,4)
p l o t ( t , y ( : , 4 ) 1 8 0 / p i , m , l i n e w i d t h , 3 )
h o l d on
p l o t ( t , d a t a ( : , 4 + 4 ) 1 8 0 / pi , r , l i n e w i d t h , 3 )
hold off

subplot (5 ,1 ,5)
plot ( t , elev (180/ pi ) , linewidth ,3 )
h o l d on
plot ( t , t h r o t l e , r , linewidth ,3)
legend ( elev , t h r o t l e )
legend ( boxoff )
hold off
% p r i n t ( example , dpng , r1000 ) ;
%<Save a s PNG w i t h 1000 DPI
%%
BBB=B ( : , 1 ) ;
C=[0 0 0 1 ] ;
D= 0 ;
figure (3)
s e t ( gcf , u n i t s , normalized , o u t e r p o s i t i o n , [ . 8 . 4 . 2 . 5 ] )

64

AAA=A;
Ucons= d a t a ( 1 , 5 ) ;
AAA( 2 , 1 ) =A( 2 , 1 ) Ucons ;
AAA( 2 , 3 ) =A( 2 , 3 ) Ucons ;
AAA( 2 , 4 ) =A( 2 , 4 ) Ucons ;
AAA( 1 , 2 ) =A ( 1 , 2 ) / Ucons ;
AAA( 3 , 2 ) =A ( 3 , 2 ) / Ucons ;
AAA( 4 , 2 ) =A ( 4 , 2 ) / Ucons ;
BBB( 2 ) =BBB ( 2 ) Ucons ;
[ bb , a a ] = s s 2 t f (AAA ,BBB, C , D ) ;
h = t f ( 1 , aa ) ;
r l o c u s ( h , 0)
AA=A;
BB=B ;
figure (61)
p l o t ( LoL , E , )
h o l d on
s e t ( gcf , u n i t s , normalized , o u t e r p o s i t i o n , [ . 4 . 1 0 . 6 . 3 ] )
end
end
end

65

Appendix B: ArduImu V3 Codes


T h i s i s n o t a l l t h e c o d e t h i s i s a s a m p l e from i t where you c o u l d
f i n d t h e c h a n g e s i n t h i s c o d e from t h e w e b s i t e c o d e .
T h e s e c h a n g e s where made t o g e t t h e r i g h t a n g l e s .
H i n t when u p l a o d i n g a c o d e f o r Arduimu u s e t h e f o c a
and c o n n e c t w i t h i t s s e r i a l p o r t s and when u p l a o d i n g
t h e c o d e p r e s s on t h e r e s e t p u t t o n i n a r d u i m u and s t i l l p r e s s i n g
t i l l the upload f i n i s h
Here i s t h e l i n e s t h a t n e e d t o be c h a n g e d :
/ / I u s e t h i s web : h t t p : / / www. m a g n e t i c d e c l i n a t i o n . com /
# d e f i n e MAGNETIC DECLINATION 4 . 1 3 3 3 3
/ / c o r r e c t s magnetic bearing to t r u e north

/ / LPR530 & LY530 S e n s i t i v i t y ( from d a t a s h e e t )


/ / => 3 . 3 3mV/
/ s , 3 . 2 2mV/ADC s t e p => 1 . 0 3
/ / Tested values : 0.96 ,0.96 ,0.94
# d e f i n e Gyro Gain X 0 . 9 2 / / X a x i s Gyro g a i n
# d e f i n e Gyro Gain Y 0 . 9 2 / / Y a x i s Gyro g a i n
# d e f i n e G y r o G a i n Z 0 . 9 4 / / Z a x i s Gyro g a i n
# d e f i n e G y r o S c a l e d X ( x ) x ToRad ( Gyro Gain X )
/ / Return the scaled
/ / ADC raw d a t a o f t h e g y r o i n r a d i a n s f o r s e c o n d
# d e f i n e G y r o S c a l e d Y ( x ) x ToRad ( Gyro Gain Y )
/ / R e t u r n t h e s c a l e d ADC
/ / raw d a t a o f t h e g y r o i n r a d i a n s f o r s e c o n d
# d e f i n e G y r o S c a l e d Z ( x ) x ToRad ( G y r o G a i n Z )
/ / R e t u r n t h e s c a l e d ADC raw d a t a
/ / of the gyro in r a d i a n s f o r second
# endif
# i f BOARD VERSION == 3
# d e f i n e SERIAL MUX PIN 7
# d e f i n e RED LED PIN 5
# d e f i n e BLUE LED PIN 6
# d e f i n e YELLOW LED PIN 5
/ / Yellow l e d i s n o t u s e d on ArduIMU v3
/ / MPU6000 4g r a n g e => g = 8192
# d e f i n e GRAVITY 8192
/ / T h i s e q u i v a l e n t t o 1G i n t h e
/ / raw d a t a coming from t h e a c c e l e r o m e t e r
66

# d e f i n e A c c e l S c a l e ( x ) x (GRAVITY / 9 . 8 1 )
/ / S c a l i n g t h e raw d a t a o f t h e a c c e l
/ / to a c t u a l a c c e l e r a t i o n in meters for seconds square
/ / MPU6000 s e n s i b i l i t y
( t h e o r i c a l 0.0152
//= > 1 / 6 5 . 6 LSB / deg / s a t 500 deg / s ) ( t h e o r i c a l 0 . 0 3 0 5
/ / => 1 / 3 2 . 8 LSB / deg / s a t 1000 deg / s )
/ / ( 0 . 0 6 0 9 => 1 / 1 6 . 4 LSB / deg / s a t 2000 deg / s )
# d e f i n e Gyro Gain X 0 . 0 6 0 9
# d e f i n e Gyro Gain Y 0 . 0 6 0 9
# d e f i n e Gyro Gain Z 0.0609

Add t h e s e l i n e s t o t r a n s f e r d a t a b e t w e e n Arduimu and A r d u i n o


/ / Wire . b e g i n T r a n s m i s s i o n ( SLAVE ADDRESS&SLAVE ADDRESS2 ) ;
Wire . b e g i n T r a n s m i s s i o n ( SLAVE ADDRESS ) ;
I 2 C w r i t e A n y t h i n g (X ) ;
I 2 C w r i t e A n y t h i n g (Y ) ;
I2C writeAnything (Z ) ;
I2C writeAnything ( xgyro ) ;
I2C writeAnything ( ygyro ) ;
I2C writeAnything ( zgyro ) ;
I2C writeAnything ( xaccel ) ;
I2C writeAnything ( yaccel ) ;
Wire . e n d T r a n s m i s s i o n ( ) ;
/ / delay (2000);
Wire . b e g i n T r a n s m i s s i o n ( SLAVE ADDRESS2 ) ;
I2C writeAnything ( zaccel ) ;
I2C writeAnything ( l a t ) ;
I2C writeAnything ( lon ) ;
I2C writeAnything ( gpsalt ) ;
I2C writeAnything ( gpsgc ) ;
I2C writeAnything ( gpsgs ) ;
I2C writeAnything ( fix ) ;
I 2 C w r i t e A n y t h i n g ( numsat ) ;
Wire . e n d T r a n s m i s s i o n ( ) ;
delay (15);
}

67

IN DCM u s e t h e s e l i n e s

void E u l e r a n g l e s ( void )
{
# i f (OUTPUTMODE==2)
/ / Only a c c e l e r o m e t e r i n f o
/ / ( debugging purposes )
r o l l = (1 atan2 ( Accel Vector [ 1 ] , Accel Vector [ 2 ] ) ) ;
//57.2957795131;
/ / atan2 ( acc y , acc z )
/ / r o l l = ( 0.274( r o l l 2))+(6.6239 r o l l )+0.2537;
p i t c h = ( 1 a s i n ( ( A c c e l V e c t o r [ 0 ] ) / ( d o u b l e )GRAVITY ) ) ;
//57.2957795131; / / asin ( acc x )
/ / pitch = (0.0004( pitch 2))+(0.2564 pitch )+0.1953;
yaw = 0 ;
#else
p i t c h = 1 a s i n ( DCM Matrix [ 2 ] [ 0 ] ) ;
r o l l = 1 a t a n 2 ( DCM Matrix [ 2 ] [ 1 ] , DCM Matrix [ 2 ] [ 2 ] ) ;
yaw = a t a n 2 ( DCM Matrix [ 1 ] [ 0 ] , DCM Matrix [ 0 ] [ 0 ] ) ;
# endif
}

68

Appendix C: Arduino Mega code


T h i s c o d e i s u p l o a d e d i n t t h e a r d u i n o mega
m i c r o c o n t r o l l e r c hi p so as t o c o l l e c t a l l t h e s e n s o r s
d a t a and s a v e them .
# i n c l u d e < F a s t S e r i a l . h>
FastSerialPort0 ( Serial );
# i n c l u d e <Wire . h>
# i n c l u d e <PID v1 . h>
# i n c l u d e < I 2 C A n y t h i n g . h>
# i n c l u d e <BMP085 . h>
/ / a l t i t u d e sensor
c o n s t f l o a t AIRSPEED CH = 3 ;
/ / for airspeed sensor
# i n c l u d e <S e r v o . h>
# i n c l u d e Arduino . h
# include Receiver . h
# include Receiver Main . h
Servo e l e v s e r v o ;
/ / create servo object to control a servo
Servo a i l s e r v o ;
Servo r u ds er vo ;
Servo t h r o t t l e ;
float elevs ;
float elevss ;
/ / variable to store the servo position
float ails ;
float ailss ;
f l o a t ruds ;
f l o a t rudss ;
f l o a t t h r o t s = 0;
f l o a t alpha =0;// these for potentiometers
f l o a t b e t a =0;
i n t a i l e r o n =0;
i n t r u d d e r =0;
int f , alt , alt 2 ,H R;
float alpha st ;
float beta st ;

c o n s t b y t e MY ADDRESS = 4 2 ;
c o n s t b y t e MY ADDRESS2= 2 7 ;

69

f l o a t V, a i r s p e e d , r e f p r e s s u r e , a i r p r e s s u r e , p r e s s u r e d i f f ;
f l o a t a i r s p e e d r a t i o =1.633;
int i ;
f l o a t t i m e =0;
f l o a t X;
f l o a t Y;
float Z;
f l o a t xgyro ;
f l o a t ygyro ;
f l o a t zgyro ;
f l o a t xaccel ;
f l o a t yaccel ;
float zaccel ;
float lat ;
f l o a t lon ;
float gpsalt ;
f l o a t gpsgc ;
v o l a t i l e f l o a t gpsgs ;
v o l a t i l e double f i x ;
v o l a t i l e double numsat ;
i n t ADD;
f l o a t v = 0;
f l o a t x = 0;
f l o a t y = 0;
f l o a t z = 0;
f l o a t Vfss =3.5;
f l o a t Vs = 5 . 0 ;
unsigned
unsigned
unsigned
unsigned
unsigned

long
long
long
long
long

Ms
Ms
Ms
Ms
Ms

switch ;
Elevator ;
Aileron ;
Rudder ;
Throttle ;

/ / i n t S w i t c h p i n =10;
/ / i n t E l e v a t o r p i n =2;
/ i n t A i l e r o n p i n =6;
i n t R u d d e r p i n =4;
i n t Throttle pin =2;/

BMP085 bmp ;
void setup ( )
{
S e r i a l . begin (111111 , 128 , 1 6 ) ;
a l p h a s t = analogRead ( 1 ) 9 0 / 2 7 ;

70

beta st

= analogRead ( 2 ) 9 0 / 2 7 ;

initialize receiver ();


bmp . b e g i n ( ) ;
H R =bmp . r e a d A l t i t u d e ( 1 0 1 3 2 5 ) ;
//
/ / SETTING REFERANCE VALUES FOR PRESSURE / /
r e f p r e s s u r e = ( ( ( ( a n a l o g R e a d ( AIRSPEED CH )
5.0/1024.0) .06254.00)/5.0) .5)/.2;
f o r ( i =1; i <=200; i ++)
{
r e f p r e s s u r e = ( ( ( ( a n a l o g R e a d ( AIRSPEED CH ) 5 . 0 / 1 0 2 4 . 0 )
.06254.00)/5.0) .5)/.20.25 + ref pressure 0.75;
delay (20);
}
/ / SERVOS PINS / /
ailservo . attach (2);
elevservo . attach (3);
/ / create servo object to control a servo
rudservo . attach ( 4 ) ;
throttle . attach (5);
//
/
T h e t a = Y;
T h e t a R =0;
C o n t o u t p u t =90;
/ / EleVservo . w r i t e ( 9 0 ) ;
/ / n e u t r a l p o s i t i o n of the servo
P i t c h P I D . SetMode (AUTOMATIC ) ; / / t u r n t h e PID on
Pitch PID . SetOutputLimits (0 ,180);
/
}
/ / end o f s e t u p

void loop ( )
{
//
/ / STICK TO AUTOPILOT SWITCH / /
/ / Wire . e n d T r a n s m i s s i o n ( ) ;

71

/ / bmp . b e g i n ( ) ;
a l t = bmp . r e a d A l t i t u d e ( 1 0 1 3 2 5 ) ;
i f ( a b s ( a l t a l t 2 ) > 1 0 0 | | a b s ( a l t a l t 2 ) <2)
{
alt=alt 2 ;
}

read receiver ();


Ms Aileron=receiver command [ 0 ] ;
Ms Elevator=receiver command [ 1 ] ;
Ms Rudder= r e c e i v e r c o m m a n d [ 2 ] ;
M s T h r o t t l e=receiver command [ 3 ] ;
M s s w i t c h= r e c e i v e r c o m m a n d [ 4 ] ;
a i l s =Ms Aileron ;
e l e v s=Ms Elevator ;
r u d s =Ms Rudder ;
t h r o t s =Ms Throttle ;
elevservo . write ( elevs );
ailservo . write ( ails );
rudservo . write ( ruds ) ;
t h r o t t l e . write ( throts );
i f ( ruds < 1348)
{
r u d s s =.0555 ruds 73.335;
}
e l s e i f ( r u d s >= 1 3 4 8 )
{
r u d s s =.0333 ruds 45.434;
}

e l e v s s =.0756 elevs 108.72;


/ / e l e v s s =.0748 elevs 108.6;
a i l s s =.0738 a i l s 112.29;
/ / AIRSPEED SENSOR CALIBRATION
i f ( ( m i l l i s ( ) t i m e ) >= 2 0 )
{
time = m i l l i s ( ) ;
a i r p r e s s u r e = ( ( ( ( a n a l o g R e a d ( AIRSPEED CH ) 5 . 0 / 1 0 2 4 . 0 )

72

.06254.00)/5.0) .5)/.20.25 + air pressure 0.75;


i f ( a i r p r e s s u r e >= r e f p r e s s u r e )
{
pressure diff = air pressure ref pressure ;
}
else
{
pressure diff = 0.0;
}
a i r s p e e d = s q r t ( p r e s s u r e d i f f 1000 a i r s p e e d r a t i o ) ;
V= a i r s p e e d 1 8 / 5 ;
}
/ / f o r ( i =1; i <=300; i ++)
// {
/ / alpha =alpha+ analogRead (1)90/27 a l p h a s t ;
/ / beta = beta+ analogRead (2)90/27 b e t a s t ;
/ / delay ( 1 ) ;
//}
/ / a l p h a =( a l p h a ) / 3 0 0 ;
/ / b e t a =( b e t a ) / 3 0 0 ;
alpha = analogRead (1)90/27 a l p h a s t ;
beta = analogRead (2)90/27 b e t a s t ;
/ / delay (10);
//
/ / I2C t o r e a d more t h a n 8 v a r i a b l e s / /
i f (ADD == 1 )
{
Wire . b e g i n (MY ADDRESS ) ;
Wire . o n R e c e i v e ( r e c e i v e E v e n t ) ;
ADD=0;
}
e l s e i f (ADD == 0 )
{
Wire . b e g i n (MY ADDRESS2 ) ;
Wire . o n R e c e i v e ( r e c e i v e E v e n t 2 ) ;
ADD=1;

73

}
//
/ / SERIAL MONITORING / /

Serial .
Serial
Serial
Serial
Serial
Serial

print
. print
. print
. print
. print
. print

( RLL : ) ;
(X ) ;
( , PCH : ) ;
(Y ) ;
( ,YAW: ) ;
(Z ) ;

Serial . print ( , altitude : ) ;


S e r i a l . p r i n t ( a l t H R ) ;
Serial . print ( , velocity : ) ;
S e r i a l . p r i n t (V ) ;
S e r i a l . p r i n t ( , alpha : ) ;
S e r i a l . p r i n t ( alpha ) ;
Serial . print ( , beta : ) ;
Serial . print ( beta ) ;
S e r i a l . p r i n t ( , AN0 : ) ;
S e r i a l . p r i n t ( xgyro ) ;
S e r i a l . p r i n t ( , AN1 : ) ;
S e r i a l . p r i n t ( ygyro ) ;
S e r i a l . p r i n t ( , AN2 : ) ;
S e r i a l . p r i n t ( zgyro ) ;
S e r i a l . p r i n t ( , AN3 : ) ;
Serial . print ( xaccel ) ;
S e r i a l . p r i n t ( , AN4 : ) ;
Serial . print ( yaccel ) ;
S e r i a l . p r i n t ( , AN5 : ) ;
Serial . print ( zaccel );
Serial . print ( , lat : ) ;
Serial . print ( lat ,5);
S e r i a l . p r i n t ( , lon : ) ;
S e r i a l . p r i n t ( lon , 5 ) ;
delay (50);
/ / S e r i a l . p r i n t ( , GALT : ) ;
// Serial . print ( gpsalt );
S e r i a l . p r i n t ( , gpsgc : ) ;
S e r i a l . p r i n t ( gpsgc ) ;
S e r i a l . p r i n t ( , gpsgs : ) ;
S e r i a l . p r i n t ( gpsgs ) ;

74

Serial
Serial
Serial
Serial

.
.
.
.

print
print
print
print

( , fix : ) ;
( fix );
( , numsat : ) ;
( numsat ) ;

Serial . print ( , elevs : ) ;


Serial . print ( elevss );
Serial . print ( , a i l s : ) ;
Serial . print ( ailss );
Serial . print ( , rdrs : ) ;
/ / S e r i a l . p r i n t ( ruds ) ;
Serial . print ( rudss ) ;
Serial . print ( , throts : ) ;
S e r i a l . p r i n t ( t h r o t s 1009);
S e r i a l . p r i n t l n ( ,000000000000000);

alt 2=alt ;
//
delay ( 5 ) ;
/ / end o f l o o p

/ / c a l l e d by i n t e r r u p t s e r v i c e
/ / r o u t i n e when i n c o m i n g d a t a a r r i v e s
void receiveEvent ( i n t
{
I2C readAnything
I2C readAnything
I2C readAnything
I2C readAnything
I2C readAnything
I2C readAnything
I2C readAnything
I2C readAnything

howMany )
(X ) ;
(Y ) ;
(Z ) ;
( xgyro ) ;
( ygyro ) ;
( zgyro ) ;
( xaccel ) ;
( yaccel ) ;

75

v o i d r e c e i v e E v e n t 2 ( i n t howMany )
{
I2C readAnything ( zaccel ) ;
I2C readAnything ( l a t ) ;
I2C readAnything ( lon ) ;
I2C readAnything ( g p s a l t ) ;
I2C readAnything ( gpsgc ) ;
I2C readAnything ( gpsgs ) ;
I2C readAnything ( f i x ) ;
I 2 C r e ad A n y t hi n g ( numsat ) ;
}

RECEIVER . h CODE

# ifndef Receiver H
# define Receiver H
# d e f i n e N Channels 5
i n t receiver raw data ( byte channel ) ;
i n t receiver command [ N Channels ] = { 0 , 0 , 0 , 0 , 0 } ;
i n t MIN[ N C h a n n e l s ] = { 1 1 0 0 , 1 1 5 2 , 1 1 2 4 , 1 1 0 0 , 1 5 0 0 } ;
i n t MAX[ N C h a n n e l s ] = { 1 9 5 6 , 1 9 0 4 , 1 9 0 4 , 1 9 6 0 , 2 0 0 0 } ;
/ / i n t r e c e i v e r z e r o [ N Channels ]={1500 ,1000 ,1500 ,1500 ,1000 ,1000};
void r e a d r e c e i v e r ( ) {
f o r ( b y t e i =0; i < N C h a n n e l s ; i ++) {
r e c e i v e r c o m m a n d [ i ] = map ( r e c e i v e r r a w d a t a ( i ) ,
MIN[ i ] ,MAX[ i ] , 1 0 0 0 , 2 0 0 0 ) ;
}
}

# endif

Receiver main . h

#ifndef
# define

Receiver Main H
Receiver Main H

/ MIN ON = 1000

MAX OFF = 20000

76

MAX ON = 2000

Min OFF = 19000

# d e f i n e RISING 1
# d e f i n e FALLING 0
# d e f i n e MAX ON 2030
/ / Max on s t a t e o f
t h e p u l s e w i d t h due t o n o i s e
/ / Min on s t a t e o f t h e
# d e f i n e MIN ON 980
p u l s e w i d t h due t o n o i s e
/ / ( 2 0 1 0 0 0 ) + 4000
# d e f i n e MAX OFF 20050
/ / Max o f f s t a t e o f t h e p u l s e w i d t h due t o n o i s e
# d e f i n e MIN OFF 18000
/ / ( 1 9 1 0 0 0 ) 4000
/ / Min o f f s t a t e o f t h e p u l s e w i d t h due t o n o i s e

struct p {
b y t e edge ;
unsigned long r i s e t i m e ;
unsigned long f a l l t i m e ;
unsigned i n t width ;
};
volatile
volatile
/ / Array
of the
volatile

s t a t i c byte p o r t h i s t o r y ;
s t a t i c p p i n d a t a [ N Channels ] ;
o f s t r u c t s which w i l l g e t t h e d a t a
receiver pins
s t a t i c byte change ;

s t a t i c byte r e c e i v e r p i n [5] = {0 ,1 ,2 ,3 ,4};


/ Used f o r mapping b e t w e e n r e c i e v e r c o m m a n d
a r r a y & b i t p l a c e m e n t on PORTC r e g i s t e r i n s i d e
the i n t e r r u p t routine
/ / PORTB PCINT 0 : 4 / On a r d u i n o p i n f u n c t i o n 5352515010 /
> on a r d u i n o b o a r d /
SIGNAL ( PCINT0 vect ) { / / I n t e r r u p t R o u n t i n e
byte current ;
byte b i t ;
/ / byte change ;
/ / c a h n g e i s t h e PCINT p i n s t h a t ve c a h n g e d
byte pin ; / / pin i s t h e pin t h a t has changed

77

in the process
unsigned long c u r r e n t t i m e ;
unsigned long time ;
/ / t i m e i s t h e d u r a t i o n t h a t p u l s e w i d t h on s t a t u s
c u r r e n t = PINB ; / / p o r t I n p u t R e g i s t e r ( 2 ) ;
/ / which i s 11 t h p o r t i n ATMEGA 2560
/ / by a c c e s s i n g 11 t h e l e m e n t i n t h e a r r a y /
change = c u r r e n t p o r t h i s t o r y ;
/ / g e t change between l a s t i n t t e r u p t
/ / and t h e c u r r e n t PORT s t a t u s
port history = current ;
/ / s t o r e c u r r e n t PORT s t a t u s i n t o l a s t
/ / i n t t e r u p t for next operation
c u r r e n t t i m e = micros ( ) ;
f o r ( b y t e i =0; i <N C h a n n e l s ; i ++) {
/ / looping for every pin to get the
/ / pin t h a t has changed
b i t = 0 x01 << i ;
i f ( b i t & change ) {
/ / check whether t he c u r r e n t pin
/ / has changed or not
pin = i ;
if ( bit & port history ) {
time = c u r r e n t t i m e p i n d a t a [ pin ] . f a l l t i m e ;
/ / c h e c k i f i t s from LOW t o HIGH
pin data [ pin ] . r i s e t i m e = c u r r e n t t i m e ;
i f ( ( t i m e >= MIN OFF ) && ( t i m e <= MAX OFF ) )
p i n d a t a [ p i n ] . e d g e = RISING ;
else
p i n d a t a [ p i n ] . e d g e = FALLING ;
}
else {
/ / Check i f i t s from
/ / HIGH t o LOW
time = c u r r e n t t i m e p i n d a t a [ pin ] . r i s e t i m e ;
pin data [ pin ] . f a l l t i m e = c u r r e n t t i m e ;
i f ( ( t i m e >= MIN ON ) && ( t i m e <= MAX ON) &&
( p i n d a t a [ p i n ] . e d g e == RISING ) ) {
p i n d a t a [ pin ] . width = time ;

78

/ / Get t i m e o f ON p a r t o f t h e p u l s e w i d t h
p i n d a t a [ p i n ] . e d g e = FALLING ;
}
}
}
}
}

void i n i t i a l i z e r e c e i v e r ( ) {
DDRB=0;
PCICR = B00000001 ;
/ / E n a b l e i n t e r r u p t i n INT0
PCMSK0 = B00011111 ;
/ / E n a b l e i n t e r u p r t on p i n s 6 t o 9 (PWM) on PCINT2
sei ();
/ / Enable Global I n t e r r u p t
}
i n t receiver raw data ( byte channel ) {
byte pin = r e c e i v e r p i n [ channel ] ;
b y t e temp = SREG ;
/ / Save t h e s t a t u s r e g i s t e r b e f o r e
/ / a c c e s s i n g t h e s h a r e d v a r i a b l e s by t h e
// intterupts
cli ();
/ / Disable the Global i n t e r r u p t
unsigned i n t raw data = p i n d a t a [ pin ] . width ;
/ / Get p u l s e w i d t h o f c h a n n e l i a t t a c h e d t o
/ / pin using shared v a r i a b l e s
SREG = temp ;
/ / r e t u r n t h e s t a t u s r e g i s t e r and e n a b l i n g t h e
/ / global i n t e r r u p t again
return raw data ;
}
# endif

79

Appendix D: Simulink GCS


T h i s c o d e J u s t s e p a r a t e t h e d a t a t h a t was coming
a s one row i n t o v a r i a b l e s . Each v a r i a b l e c o n t a i n a
v e c t o r o f a one d a t a w i t h t i m e .

% f u n c t i o n [ r o l l , p i t c h , yaw , h e i g h t , v e l o c i t y , e l e v p o t ,
ail pot , rdr pot , alpha pot , beta pot , p , q , r ,
ax , ay , az , l a t , l o n , gpsgc , g p s g s , f i x , numsat ,
elevservo , ailservo , rdrservo , throtservo , stop ] = fcn ( u )
f u n c t i o n [ r o l l , p i t c h , yaw , h e i g h t , v e l o c i t y a ,
v e l o c i t y b , alphaa , alphab , betaa ,
b e t a b , p , q , r , ax , ay , az , l a t , l o n , gpsgc ,
g p s g s , f i x , numsat , e l e v s e r v o , a i l s e r v o ,
rdrservo , throtservo , stop ] = fcn ( u )
%% i n i t i a l i z e
u= d o u b l e ( u ) ;
roll=
double ([0 0 0 0 0 0 0 ] ) ;
pitch=
double ([0 0 0 0 0 0 0 ] ) ;
yaw=
double ([0 0 0 0 0 0 0 ] ) ;
height=
double ([0 0 0 0 0 0 0 ] ) ;
v e l o c i t y a= double ([0 0 0 0 0 0 0 ] ) ;
v e l o c i t y b= double ([0 0 0 0 0 0 0 ] ) ;
a l p h a a=double ( [ 0 0 0 0 0 0 0 ] ) ;
alphab=double ( [ 0 0 0 0 0 0 0 ] ) ;
betaa= double ([0 0 0 0 0 0 0 ] ) ;
betab= double ( [ 0 0 0 0 0 0 0 ] ) ;
p=
double ([0 0 0 0 0 0 0 ] ) ;
q=
double ([0 0 0 0 0 0 0 ] ) ;
r=
double ([0 0 0 0 0 0 0 ] ) ;
ax=
double ([0 0 0 0 0 0 0 ] ) ;
ay=
double ([0 0 0 0 0 0 0 ] ) ;
a z=
double ([0 0 0 0 0 0 0 ] ) ;
lat=
double ([0 0 0 0 0 0 0 ] ) ;
lon=
double ([0 0 0 0 0 0 0 ] ) ;
g p s g c=
double ([0 0 0 0 0 0 0 ] ) ;
gpsgs=
double ([0 0 0 0 0 0 0 ] ) ;
fix=
double ([0 0 0 0 0 0 0 ] ) ;
n u m s a t=
double ([0 0 0 0 0 0 0 ] ) ;
e l e v s e r v o=double ( [ 0 0 0 0 0 0 0 ] ) ;
a i l s e r v o = double ([0 0 0 0 0 0 0 ] ) ;
r d r s e r v o= double ([0 0 0 0 0 0 0 ] ) ;
80

t h r o t s e r v o =double ( [ 0 0 0 0 0 0 0 ] ) ;
s t o p=double ( 0 ) ;
% % g1 =0; g2 =0; g3 =0; g4 =0; g5 =0; g6 =0; g7 =0; g8 =0; g9 =0;
% % g10 =0; g11 =0; g12 =0; g13 =0; g14 =0; g15 =0; g16 =0; g17 =0; g18 =0;
% % g19 =0; g20 =0; g21 =0; g22 =0; g23 =0; g24 =0; g25 =0;
%% D i v i d i n g t h e o u t p u t s
f o r n t =1: l e n g t h ( u ) %1
i f ( u ( n t )==13)
stop=nt ;
break ;
%
g1=n t 1;
end
end
f o r n s =1: l e n g t h ( u)14%2
i f ( ns < n t&&u ( n s )==44&&u ( n s +1)==116&&u ( n s +2)==104
&&u ( n s +3)==114&&u ( n s +4)==111&&u ( n s +5)==116&&u
( n s +6)==115&&u ( n s +7)==58)
t h r o t s e r v o =u ( n s +8: n s + 1 4 ) ;
%
g2=ns 1;
break
end
end
f o r n r =1: l e n g t h ( u)12%3
i f ( nr < n t&&u ( n r )==44&&u ( n r +1)==114&&u ( n r +2)==
100&&u ( n r +3)==114&&u ( n r +4)==115&&u ( n r +5)==58)
r d r s e r v o =u ( n r +6: n r + 1 2 ) ;
break
%
g3=nr 1;
end
end
f o r nq =1: l e n g t h ( u)12%4
i f ( nq< n t&&u ( nq)==44&&u ( nq+1)==97&&u ( nq +2)==
105&&u ( nq+3)==108&&u ( nq+4)==115&&u ( nq +5)==58)
a i l s e r v o =u ( nq +6: nq + 1 2 ) ;
break
%
g4=nq 1;
end
end
f o r np =1: l e n g t h ( u)13%5
i f ( np< n t&&u ( np)==44&&u ( np+1)==101&&u ( np +2)==10
8&&u ( np+3)==101&&u ( np+4)==118&&u ( np+5)==115&&u ( np +6)==58)
e l e v s e r v o =u ( np +7: np + 1 3 ) ;
break
%
g5=np 1;

81

end
end
f o r no =1: l e n g t h ( u)14%6
i f ( no< n t&&u ( no)==44&&u ( no+1)==110&&u ( no +2)==11
7&&u ( no+3)==109&&u ( no+4)==115&&u ( no+5)==97&&
u ( no+6)==116&&u ( no +7)==58)
n u m s a t=u ( no +8: no + 1 4 ) ;
break
%
g6=no 1;
end
end
f o r nn =1: l e n g t h ( u)11%7
i f ( nn< n t&&u ( nn)==44&&u ( nn+1)==102&&u ( nn +2)==10
5&&u ( nn+3)==120&&u ( nn +4)==58)
f i x =u ( nn +5: nn + 1 1 ) ;
break
%
g7=nn 1;
end
end
f o r nm=1: l e n g t h ( u)13%8
i f ( nm< n t&&u ( nm)==44&&u ( nm+1)==103&&u ( nm+2)==1
12&&u ( nm+3)==115&&u ( nm+4)==103&&u ( nm+5)==115&&u ( nm+6)==58)
g p s g s =u ( nm+7:nm+ 1 3 ) ;
break
%
g8=nm1;
end
end
f o r n l =1: l e n g t h ( u)13%9
i f ( n l < n t&&u ( n l )==44&&u ( n l +1)==103&&u ( n l +2)==11
2&&u ( n l +3)==115&&u ( n l +4)==103&&u ( n l +5)==99&&u ( n l +6)==58)
g p s g c=u ( n l +7: n l + 1 3 ) ;
break
%
g9=n l 1;
end
end
f o r nk =1: l e n g t h ( u)11%10
i f ( nk< n t&&u ( nk)==44&&u ( nk+1)==108&&u ( nk +2)==1
11&&u ( nk+3)==110&&u ( nk +4)==58)
l o n =u ( nk +5: nk + 1 1 ) ;
break
%
g10=nk 1;
end

82

end
f o r n j =1: l e n g t h ( u)11%11
i f ( n j < n t&&u ( n j )==44&&u ( n j +1)==108&&u ( n j +2)==97&
&u ( n j +3)==116&&u ( n j +4)==58)
l a t =u ( n j +5: n j + 1 1 ) ;
break
%
g11=n j 1;
end
end
f o r n i =1: l e n g t h ( u)11%12
i f ( n i < n t&&u ( n i )==44&&u ( n i +1)==65&&u ( n i +2)==78&
&u ( n i +3)==53&&u ( n i +4)==58)
a z=u ( n i +5: n i + 1 1 ) ;
break
%
g12=n i 1;
end
end
f o r nh =1: l e n g t h ( u)11%13
i f ( nh< n t&&u ( nh)==44&&u ( nh+1)==65&&u ( nh+2)==78&
&u ( nh+3)==52&&u ( nh +4)==58)
ay=u ( nh +5: nh + 1 1 ) ;
break
%
g13=nh 1;
end
end
f o r ng =1: l e n g t h ( u)11%14
i f ( ng< n t&&u ( ng)==44&&u ( ng+1)==65&&u ( ng +2)==78
&&u ( ng+3)==51&&u ( ng +4)==58)
ax=u ( ng +5: ng + 1 1 ) ;
break
%
g14=ng 1;
end
end
f o r n f =1: l e n g t h ( u)11%15
i f ( nf < n t&&u ( n f )==44&&u ( n f +1)==65&&u ( n f +2)==78
&&u ( n f +3)==50&&u ( n f +4)==58)
r =u ( n f +5: n f + 1 1 ) ;
break
%
g15=nf 1;
end
end
f o r ne =1: l e n g t h ( u)11%16
i f ( ne < n t&&u ( ne)==44&&u ( ne+1)==65&&u ( ne +2)==7

83

8&&u ( ne+3)==49&&u ( ne +4)==58)


q=u ( ne +5: ne + 1 1 ) ;
break
%
g16=ne 1;
end
end
f o r nd =1: l e n g t h ( u)12%17
i f ( nd< n t&&u ( nd)==44&&u ( nd+1)==65&&u ( nd +2)==7
8&&u ( nd+3)==48&&u ( nd +4)==58)
p=u ( nd +5: nd + 1 1 ) ;
break
%
g17=nd 1;
end
end
f o r nc =1: l e n g t h ( u)12%18
i f ( nc < n t&&u ( nc)==44&&u ( nc+1)==98&&u ( nc +2)==10
1&&u ( nc +3)==116&&u ( nc+4)==97&&u ( nc+5)==97&&u ( nc +6)==58)
b e t a a =u ( nc +7: nc + 1 3 ) ;
break
%
g18=nc 1;
end
end
f o r nc =1: l e n g t h ( u)12%18
i f ( nc < n t&&u ( nc)==44&&u ( nc+1)==98&&u ( nc +2)==10
1&&u ( nc +3)==116&&u ( nc+4)==97&&u ( nc+5)==98&&u ( nc +6)==58)
b e t a b =u ( nc +7: nc + 1 3 ) ;
break
%
g18=nc 1;
end
end
f o r nb =1: l e n g t h ( u)13%19
i f ( nb< n t&&u ( nb)==44&&u ( nb+1)==97&&u ( nb +2)==10
8&&u ( nb+3)==112&&u ( nb+4)==104&&u ( nb+5)==97&&
u ( nb+6)==97&&u ( nb +7)==58)
a l p h a a =u ( nb +8: nb + 1 4 ) ;
break
%
g19=nb 1;
end
end
f o r nb =1: l e n g t h ( u)13%19
i f ( nb< n t&&u ( nb)==44&&u ( nb+1)==97&&u ( nb +2)==108
&&u ( nb+3)==112&&u ( nb+4)==104&&u ( nb+5)==97&&
u ( nb+6)==98&&u ( nb +7)==58)
a l p h a b =u ( nb +8: nb + 1 4 ) ;
break
%
g19=nb 1;

84

end
end
% f o r na =1: l e n g t h ( u)11%20
%
i f ( na < n t&&u ( na)==44&&u ( na +1)==114&&u ( na +2)==100&&u
( na +3)==114&&u ( na +4)==58)
%
r d r p o t =u ( na +5: na + 1 1 ) ;
%
break
%%
g20=na 1;
%
end
% end
% f o r o i =1: l e n g t h ( u ) 11 %21
%
i f ( o i < n t&&u ( o i )==44&&u ( o i +1)==97&&u ( o i +2)
==105&&u (
o i +3)==108&&u ( o i +4)==58)
%
%
a i l p o t =u ( o i +5: o i + 1 1 ) ;
%
break
%%
g21=o i 1;
%
end
% end
% f o r nnu =1: l e n g t h ( u)12%22
%
i f ( nnu < n t&&u ( nnu)==44&&u ( nnu+1)==101&&u ( nn
u +2)==10
8&&u ( nnu+3)==101&&u ( nnu+4)==118&&u ( nnu +5)==58)
%
%
e l e v p o t =u ( nnu +6: nnu + 1 2 ) ;
%
break
%%
g22=nnu 1;
%
end
% end
f o r G=1: l e n g t h ( u)16%23
i f (G< n t&&u (G)==44 && u (G+1)==118 && u (G+2)=
=101 && u (G+3)==108 && u (G+4)==111 && u (G+5)=
=99 && u (G+6)==105 && u (G+7)==116 && u (G+8)==
121 && u (G+9)==97&& u (G+10)==58)
v e l o c i t y a =u (G+11:G+ 1 7 ) ;
break
%
g23=G1;
end
end
f o r GF=1: l e n g t h ( u)16%23
i f ( GF< n t&&u ( GF)==44 && u ( GF+1)==118 && u ( GF+2
)==101 && u ( GF+3)==108 && u ( GF+4)==111 && u (G
F+5)==99 && u ( GF+6)==105 && u ( GF+7)==116 && u
( GF+8)==121 && u ( GF+9)==98&& u ( GF+10)==58)
v e l o c i t y b =u ( GF+11:GF+ 1 7 ) ;

85

break
%

g23=G1;

end
end
f o r K=1: l e n g t h ( u ) 16 %24
i f (K< n t&&u (K)==44 && u (K+1)==97 && u (K+2)==108 &&
u (K+3)==116 && u (K+4)==105 && u (K+5)==116 &&
u (K+6)==117 && u (K+7)==100 && u (K+8)==101
&& u (K+9)==58) %% a l t i t u d e
h e i g h t =u (K+10:K+ 1 6 ) ;
break
%
g24=K1;
break
end
end
f o r J =1: l e n g t h ( u ) 16 %25
i f ( J < n t&&u ( J )==44 && u ( J +1)==89 && u ( J +2)==65
&& u ( J +3)==87 && u ( J +4)==58)
yaw=u ( J +5: J + 1 1 ) ;
break
%
g25=J 1;
end
end
f o r l =1: l e n g t h ( u ) 16 %26
i f ( l < n t&&u ( l )==44 && u ( l +1)==80 && u ( l +2)==67 &&
u ( l +3)==72 && u ( l +4)==58) %pch :
p i t c h =u ( l +5: l + 1 1 ) ;
break
end
end
r o l l =u ( 1 : 7 ) ;

86

The coming c o d e i s t o t r a n s f e r e a c h v a r i a b e l from a s c i i i n t o


Decimal
f u n c t i o n SIGNAL = f c n ( u )
SIGNAL= d o u b l e ( 5 0 0 ) ;
t=length ( u ( 1 , 1 , : ) ) ;
l e f t =double ( 0 ) ;
x =[0];
%% Remove a l l d a t a a f t e r 4 4 .
N=u ;
f o r i =1: l e n g t h ( u )
i f u ( i )==44
N=u ( 1 : i 1 ) ;
break
end
end
u=N ;
%% Case I ve w i t h s i g n
i f u ( 1 , 1 , t )==45
% i f ve
f o r i =1: l e n g t h ( u )
i f u ( i )==46
x (1)= i ;
break
end
end
i f x (1)= 0
%
i f l e n g t h ( u ( 1 , : , t )) > x ( 1 ) + 3
%
f o r j =x ( 1 ) + 1 : 1 : x ( 1 ) + 3
%
n=1+n ;
%
r = r +( u ( 1 , j , t ) 48) ( 0 . 1 ) n ;
%
end
%
else
n =0;
r=double ( 0 ) ;
f o r j =x ( 1 ) + 1 : 1 : l e n g t h ( u ( 1 , : , t ) )
n=1+n ;
r = d o u b l e ( r +( u ( 1 , j , t ) 48) ( ( 0 . 1 ) n ) ) ;

87

end
n =0;
f o r j =2: x ( 1 ) 1 ;
l e f t = d o u b l e ( l e f t + ( u ( 1 , j , t ) 4 8 ) ( 1 0 ) ( x (1) 3 n ) ) ;
n=n +1;
end
SIGNAL= 1( r + l e f t ) ;
SIGNAL= d o u b l e ( SIGNAL ) ;
end
%% Case I I ve and no d e c i m a l
i f x (1)==0 % no d e c i m a l b u t s t i l l
n =0;

negative

SIGNAL= d o u b l e ( 0 ) ;
for j=length ( u (1 ,: , t )): 1:2
SIGNAL= d o u b l e ( SIGNAL+ ( u ( 1 , j , t ) 4 8 ) ( 1 0 ) n ) ;
n=n +1;
end
SIGNAL= d o u b l e ( SIGNAL ) ;
end
%% c a s e I I I p o s i t i v e w i t h d e c i m a l
e l s e i f u ( 1 , 1 , t ) > 45 %% i f was +ve
%%
f o r i =1: l e n g t h ( u )
i f u ( i )==46
x (1)= i ;
break ;
else
x (1)=0;
end
end
i f x (1)=0
n =0;
r=double ( 0 ) ;
f o r j =x ( 1 ) + 1 : l e n g t h ( u ( 1 , : , t ) )
n=1+n ;
r = d o u b l e ( r +( u ( 1 , j , t ) 48) ( . 1 ) n ) ;
end
n =0;
l e f t =double ( 0 ) ;
f o r j =1: x ( 1 ) 1 ;
l e f t = d o u b l e ( l e f t + ( u ( 1 , j , t ) 4 8 ) ( 1 0 ) ( x (1) 2 n ) ) ;
n=n +1;

88

end
SIGNAL=( r + l e f t ) ;
SIGNAL= d o u b l e ( SIGNAL ) ;
%% Case IV P o s i t i v e w i t h no d e c i m a l
e l s e % no d e c i m a l b u t s t i l l p o s i t i v e
n =0;
SIGNAL= d o u b l e ( 0 ) ;
for j=length ( u (1 ,: , t )): 1:1
SIGNAL= d o u b l e ( SIGNAL+ ( u ( 1 , j , t ) 4 8 ) ( 1 0 ) n ) ;
n=n +1;
end
end
else
SIGNAL= d o u b l e ( 5 0 0 ) ;
end
end

89

S-ar putea să vă placă și