Documente Academic
Documente Profesional
Documente Cultură
Engineers Name:
Date of Birth:
Nationality:
E-mail:
Phone:
Address:
Registration Date:
Awarding Date:
Degree:
Department:
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
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
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
35
35
35
36
40
42
43
43
48
48
50
.
.
.
.
.
53
53
53
53
53
53
4.3
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
References
55
56
66
69
80
iv
List of Figures
1.1
Autopilot Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1
2.2
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
.
.
.
.
.
.
.
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
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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
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
5.1
5.2
vii
Time, sec
Bias Vector
Weighting matrix
Error
sigmoid function
ax
az
Aircraft mass,kg
ANN
AOA
Angle of attack
AS CD
AS T L
DGM
GCS
HNN
I MU
NN
Neural Network
PCB
PI
Parameter Identification
RNN
S NR
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.
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.
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
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.
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
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.
10
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 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
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
(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
(b) C character
(c) A subfigure
(e) A subfigure
(f) A subfigure
Figure 3.3: Example for Discrete image recognition using Hopfield Neural Network
3.2.2.2
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)
(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)
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)
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)
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
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
19
(a) S NR =
(b) S NR = 10
20
(a) S NR =
(b) S NR = 10
21
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
23
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.
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
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
25
4.2.4
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
(a) Implementation
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.
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].
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].
4.2.8
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.
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
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
29
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
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
31
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.
32
4.3.3
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
34
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
1778 mm
58.1 dm
1447 mm
2490 - 2720g
43 - 47 g/m
2-Stroke .46 cu. in. (7.5 cc)
35
5.1.2
PI of Longitudinal Dynamics
(5.1)
The unavailable data that cannot be measured were the angular acceleration term q and
the angle of attack rate (AOA) .For
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
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.
5.1.3
PI of Lateral Dynamics
(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
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
5.1.4
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
5.2.1
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
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.11: The fin of the old sensor and the smaller one of the new sensor
45
Figure 5.14: The Air data systems setup for both aircrfats
46
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
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
q
q
elev
49
0.0077 0.0102
1.1431 0.0126
0.0446 0.0034
(5.11)
5.2.4
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].
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)
52
6.1
6.1.1
Hardware
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
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
[ 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 ) ] ;
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
%%
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 ) ;
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
%
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)];
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)];
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
# 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
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
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 ;
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 ;
}
72
73
}
//
/ / SERIAL MONITORING / /
Serial .
Serial
Serial
Serial
Serial
Serial
print
. print
. print
. print
. print
. print
( RLL : ) ;
(X ) ;
( , PCH : ) ;
(Y ) ;
( ,YAW: ) ;
(Z ) ;
74
Serial
Serial
Serial
Serial
.
.
.
.
print
print
print
print
( , fix : ) ;
( fix );
( , numsat : ) ;
( numsat ) ;
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
76
MAX ON = 2000
# 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 ;
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
% 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
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
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