You are on page 1of 105

1

On-line PID Controller


Tuning using Genetic
Algorithms



Student: Ian Griffin
ID: 98072358
Date: 22/08/03


M.Eng. in Electronic Systems

Supervisor: Ms Jennifer Bruton

2
1.0 Abstract
The aim of this project is to create a PID controller for the ball and hoop system
that is tuned online using genetic algorithms The ball and hoop system is notoriously
difficult to control optimally using a PID controller because the system parameters are
constantly changing. It is for this reason that an online tuning strategy was applied.
Genetic Algorithms are effective at finding high performance areas in large domains
and are the ideal choice to tune the online PID controller.
Genetic Algorithms were examined in detail, it was decided to create an objective
function that evaluated the optimum PID gains based on the controlled systems
overall error. GAs outperformed standard tuning practices, e.g. Ziegler Nichols, at
designing PID controllers, in the tests carried out. It was experimentally determined
that the Mean Square Error (MSE) performance criterion produces the most effective
PID controllers when compared with other performance criterion.
The ball and hoop apparatus was experimented with to attain its transfer function.
A Recursive Least Squares estimator was then created to estimate the system online
and provide the most accurate estimation of the system for the genetic algorithm to
design a PID controller. It was discovered that the RLS estimator failed to work
accurately when used in conjunction with the real system and only worked in
simulation. As a result of this, it was infeasible to perform online tuning on the actual
ball and hoop rig and the rest of the project focuses on achieving this in simulation.
An online genetic algorithm was created. It was discovered that the GA would
sometimes create a controller that would make the overall system unstable. Despite
rigorous testing, the cause of this could not be established. To prevent any unstable
controllers being implemented by the genetic algorithm additional functionality was
added so that the last stable controller created by the genetic algorithm would be
implemented if the current controller were unstable.
The online genetic algorithm proved difficult to test in simulation due to the fact
that Simulink simulations dont run in real time.
The online genetic algorithm was tested as thoroughly as possible and was
established as an effective controller for the Ball and Hoop system.



3
Table of Contents
1.0 ABSTRACT................................................................................................................................ 2
2.0 INTRODUCTION...................................................................................................................... 5
3.0 PID CONTROL............................................................................................................................ 6
3.1 Proportional Control ........................................................................................................... 6
3.2 Integral Control................................................................................................................... 6
3.3 Derivative Control............................................................................................................... 6
3.4 Continuous PID Controller.................................................................................................. 6
3.5 Discrete PID Controller ...................................................................................................... 7
4.0 BALL AND HOOP SYSTEM...................................................................................................... 8
5.0 GENETIC ALGORITHMS......................................................................................................... 11
5.1 Reproduction..................................................................................................................... 11
5.2 Crossover.......................................................................................................................... 12
5.3 Mutation............................................................................................................................ 14
5.4 Genetic Algorithm Process ................................................................................................ 15
5.5 Elitism............................................................................................................................... 16
5.6 Genetic Algorithms versus Traditional Methods ................................................................. 16
5.7 Initialising the Population of the Genetic Algorithm........................................................... 17
5.8 Initialising the Genetic Algorithm...................................................................................... 18
5.9 Performing the Genetic Algorithm..................................................................................... 20
5.10 Writing the Objective Function for a Genetic Algorithm................................................... 21
6.0 DEVELOPMENT OF GENETIC ALGORITHM FOR PID TUNING.................................. 24
6.1 Ziegler-Nichols Designed PID Controller .......................................................................... 24
6.2 Performance Indices.......................................................................................................... 25
6.3 Evaluation of Performance Criterion................................................................................. 27
7.0 IDENTIFYING THE BALL AND HOOP SYSTEM................................................................... 29
7.1 Operating Conditions ........................................................................................................ 29
7.2 Identifying the Hoop.......................................................................................................... 29
7.3 Calculating Steady State Gain............................................................................................ 30
7.4 Calculating the Time Constant ........................................................................................... 30
7.5 Calculating Hoop Gain...................................................................................................... 31
7.6 Evaluation of and
n
.................................................................................................... 34
6.7 Calculating of Coefficient of Rolling Friction..................................................................... 36
7.8 Ziegler-Nichols PID Controller for the Ball and Hoop System. ........................................... 37
8.0 SYSTEM ESTIMATOR............................................................................................................. 39
8.1 Least Squares Estimation................................................................................................... 39
8.2 Recursive Least Squares .................................................................................................... 40
8.4 RLS Algorithm: Matrix Inversion Lemma RLS.................................................................... 41
8.5 Initialisation of the Parameter Vector ) 0 ( ...................................................................... 41
8.6 Initialisation of the Covariance Matrix............................................................................... 42
8.7 RLS Input Signal................................................................................................................ 42
8.8 Zero-Order Hold ............................................................................................................... 44
8.9 Forgetting Factor.............................................................................................................. 44
8.10 S-Functions ..................................................................................................................... 46
8.11 Initialising the RLS Algorithm.......................................................................................... 49
8.12 Analysing the Effect of the Initial Parameter Estimate...................................................... 53
8.13 Testing the RLS estimator on the Ball and Hoop Apparatus .............................................. 55
9.0 ONLINE GENETIC ALGORITHM............................................................................................ 58
9.1 Choosing the Discrete Transfer Function........................................................................... 58
4
9.2 Creating a Discrete Genetic Algorithm.............................................................................. 59
9.3 Evaluating the Optimum PID Controller Gains.................................................................. 59
9.4 Online Genetic Algorithm.................................................................................................. 61
9.5 Genetic Algorithm Coding for Online Tuner....................................................................... 63
9.6 Testing the Genetic Algorithm used for Online Tuning........................................................ 64
10.0 CONCLUSIONS..................................................................................................................... 69
11.0 REFERENCES....................................................................................................................... 71
APPENDIX A.1 INITIAL_PID_GA.M............................................................................................. 73
APPENDIX A.2 PID_OBJFUN_ITAE.M......................................................................................... 74
APPENDIX A.3 PID_OBJFUN_IAE.M........................................................................................... 75
APPENDIX A.4 PID_OBJFUN_ISE.M............................................................................................ 76
APPENDIX A.5 PID_OBJFUN_MSE.M.......................................................................................... 77
APPENDIX A.6 M_PRBS.M........................................................................................................... 78
APPENDIX A.7 RLS.M................................................................................................................... 78
APPENDIX A.8 MODEL_SAMPLE_TIME.M................................................................................ 80
APPENDIX A.9 ULTIMATE_PID_GA.M....................................................................................... 81
APPENDIX A.10 ULTIMATE_PID_OBJFUN_MSE.M................................................................... 83
APPENDIX A.11 SELFTUNING_RLS_GA.M................................................................................ 85
APPENDIX A.12 SELFTUNING_RLS_GA_OBJFUN.M................................................................ 89
APPENDIX B.1 DERIVATION OF RECURSIVE LEAST SQUARES............................................ 92
APPENDIX C.1 FIRST TEN GA RESULTS.................................................................................... 95
APPENDIX C.2 POPULATION PRODUCING STABLE CONTROLLERS DURING THE FOURTH
ITERATION OF THE GENETIC ALGORITHM............................................................................. 98














5
2.0 Introduction
The ball and hoop apparatus consists of a steel ball that is free to roll on the
inside of a rotating circular hoop. This system illustrates the complex dynamics of
liquid slosh i.e. the way liquid behaves in a moving container. The ball and hoop
apparatus is difficult to control optimally using a PID controller because the system
parameters are constantly changing. In order to retune the controller of the system it is
necessary to take the system offline.
It is proposed that an online PID controller would result in the best overall
performance of the system. The online controller will be tuned using Genetic
Algorithms. The application of genetic algorithms to PID optimisation has been
largely overlooked, particularly as a tuning technique for processes that are difficult to
tune [1].
Genetic Algorithms (GAs) are a stochastic global search method that mimics
the process of natural evolution. Genetic Algorithms have been shown to be capable
of locating high performance areas in complex domains without experiencing the
difficulties associated with high dimensionality or false optima as may occur with
gradient decent techniques [2]. Using genetic algorithms to perform the online tuning
of the controller will result in the optimum controller being evaluated for the system
every time.
To estimate the ever-changing parameters of the Ball and Hoop system, a
Recursive Least Squares (RLS) estimator will be implemented. This will provide an
up-to-date estimate of the system for the Genetic algorithm to evaluate the optimum
PID controller.
The online tuned PID controller will initially be tested in a simulation
environment and the results will then be compared to the online tuning of the ball and
hoop rig.
Matlab and the Real-Time Control box in Simulink will be utilized to provide
the online controller tuning of the PID values both in simulation and in conjunction
with the physical rig.




6
3.0 PID Control
PID control consists of three types of control, Proportional, Integral and
Derivative control.

Figure 3.1 Schematic of PID Controller

3.1 Proportional Control
The proportional controller output uses a proportion of the system error to
control the system. However, this introduces an offset error into the system.
Error K P
p term

3.2 Integral Control
The integral controller output is proportional to the amount of time there is an
error present in the system. The integral action removes the offset introduced by the
proportional control but introduces a phase lag into the system.

Errordt K I
I tetm

3.3 Derivative Control
The derivative controller output is proportional to the rate of change of the
error. Derivative control is used to reduce/eliminate overshoot and introduces a phase
lead action that removes the phase lag introduced by the integral action.
dt
Error d
K D
D term
) (

3.4 Continuous PID Controller
The three types of control are combined together to form a PID controller with
the transfer function:
s
K s K s K
s C
I P D
PID
+ +

2
) ( (3.1)
7
3.5 Discrete PID Controller
This project proposes to use a PID controller that is tuned online. To facilitate
the real time aspect of this, a discrete PID controller must be used. The PID controller
will be discretised using the Trapezoidal Difference method.

3.5.1 Trapezoidal Difference Method
The trapezoidal difference method is the most popular method for discretizing
a PID controller [3]. The trapezoidal difference method maps a stable continuous
controller to a stable discrete controller. The substitution
1
1 2
+

z
z
T
s is used to
produce a mapping as shown in Figure 3.2.
Figure 3.2 Illustration of Mapping using Trapezoidal Difference Method [3]

The trapezoidal method is implemented in Matlab using the tustin operator
in conjunction with the C2D (Continuous to Discrete) command:
Discrete_PID = c2d (Continuous_PID, 0.01,'tustin');










8
4.0 Ball and Hoop System
The Ball and Hoop System [3] illustrates the dynamics of a steel ball that is
free to roll on the inside of a rotating circular hoop. There is a groove on the inside
edge of the hoop so that a steel ball can roll freely inside the hoop. This introduces the
complexity of the rolling radius of the ball being different to the actual radius of the
ball as illustrated in Figure 4.1

Figure 4.1 Illustration of the Ball Rolling in its Groove

The overall system is shown in Figure 4.2 where the ball position is based on
the assumption that the hoop is rotating anti-clockwise. The hoop is mounted
vertically on the shaft of an electric motor so that it can be rotated about its axis.
When the hoop is rotated, the ball will tend to move in the direction of hoop rotation.
At some point, gravity will overcome the frictional forces and the ball will fall back.
This process will repeat, causing the ball to have oscillatory motion. The motor drives
the hoop so that its angular position can be placed under control. In Figure 4.2 the
angle, , is the hoop angular position. The position of the ball is given by:
1. Y, the position of the ball on the hoop periphery with respect to a
datum point.
2. , the slosh angle which measures the deviation of the ball from its
rest position.
Figure 4.3 shows how the ball and hoop system is used to illustrate the
complex dynamics of the oscillations of a liquid in a container when the container is
moving and undergoing changes in velocity and direction.
Oscillation in liquids is called slosh or slop and is important because the
movement of large quantities of liquid can strongly influence the movement of the
container itself this is usually undesirable and often dangerous.
9

Figure 4.2 The Ball and Hoop System [3]


Figure 4.3 Illustration of Liquid Analogy [3]

Practical examples where slosh effects are important:
1. The movement of the liquid cargo in an oil tanker as it changes direction can
alter the handling and stability of a truck.
2. The slosh of aviation fuel in an aircraft as it turns may effect its overall
stability
3. The liquid load in a railway wagon tanker can rock from side to side on an
uneven railway track, causing undue wear to the wagon suspension and
railway track.
4. The liquid cargo of a ship may slosh when the ship is in heavy seas, which
may subsequently reduce the stability of the ship.
5. The movement of the fuel load in a Formula 1 car as it corners will affect its
handling and overall lap performance.
6. Stabilising a missile containing liquid fuel.

10
Any action involving the rapid movement of large quantities of fluid can exhibit
the characteristic oscillations of liquid slop. Traditionally, for a system like the ball
and hoop system, a PID controller would be evaluated using standard tuning
techniques like Ziegler-Nichols and then implemented. The PID controller would
remain in place until the system had changed so much that the controller was no
longer effective. The system would be taken offline and a new PID controller would
be evaluated and implemented. This process is very laborious, time consuming and
difficult to apply because it is not always possible to take a system off-line. It is for
these reasons that online control is a better option for a system, like the ball and hoop,
which is constantly changing.
This project will look at how effective a PID controller, tuned on line using
genetic algorithms, is at reducing the impact of liquid slosh.






















11
5.0 Genetic Algorithms
Genetic Algorithms (GAs) are a stochastic global search method that mimics
the process of natural evolution. The genetic algorithm starts with no knowledge of
the correct solution and depends entirely on responses from its environment and
evolution operators (i.e. reproduction, crossover and mutation) to arrive at the best
solution. By starting at several independent points and searching in parallel, the
algorithm avoids local minima and converging to sub optimal solutions.
In this way, GAs have been shown to be capable of locating high performance areas
in complex domains without experiencing the difficulties associated with high
dimensionality, as may occur with gradient decent techniques or methods that rely on
derivative information [1].
A genetic algorithm is typically initialised with a random population
consisting of between 20-100 individuals. This population (mating pool) is usually
represented by a real-valued number or a binary string called a chromosome. For
illustrative purposes, the rest of this section represents each chromosome as a binary
string. How well an individual performs a task is measured is assessed by the
objective function. The objective function assigns each individual a corresponding
number called its fitness. The fitness of each chromosome is assessed and a survival
of the fittest strategy is applied. In this project, the magnitude of the error will be used
to assess the fitness of each chromosome.
There are three main stages of a genetic algorithm, these are known as
reproduction, crossover and mutation.

5.1 Reproduction
During the reproduction phase the fitness value of each chromosome is
assessed. This value is used in the selection process to provide bias towards fitter
individuals. Just like in natural evolution, a fit chromosome has a higher probability
of being selected for reproduction.
An example of a common selection technique is the Roulette Wheel selection
method, Figure 5.1. Each individual in the population is allocated a section of a
roulette wheel; the size of the section is proportional to the fitness of the individual. A
pointer is spun and the individual to whom it points is selected. This continues until
the selection criterion has been met. The probability of an individual being selected is
12
thus related to its fitness, ensuring that fitter individuals are more likely to leave
offspring.
Multiple copies of the same string may be selected for reproduction and the
fitter strings should begin to dominate. However, for the situation illustrated in Figure
5.1, it is not implausible for the weakest string (01001) to dominate the selection
process.
Figure 5.1 Depiction of roulette wheel selection

There are a number of other selection methods available and it is up to the user
to select the appropriate one for each process. All selection methods are based on the
same principal i.e. giving fitter chromosomes a larger probability of selection.
Four common methods for selection are:
1. Roulette Wheel selection
2. Stochastic Universal sampling
3. Normalised geometric selection
4. Tournament selection

5.2 Crossover
Once the selection process is complete, the crossover algorithm is initiated. The
crossover operations swaps certain parts of the two selected strings in a bid to capture
the good parts of old chromosomes and create better new ones. Genetic operators
manipulate the characters of a chromosome directly, using the assumption that certain
individuals gene codes, on average, produce fitter individuals. The crossover
probability indicates how often crossover is performed. A probability of 0% means
that the offspring will be exact replicas of their parents and a probability of 100%
means that each generation will be composed of entirely new offspring. The simplest
crossover technique is the Single Point Crossover. There are two stages involved in
single point crossover:
13
1. Members of the newly reproduced strings in the mating pool are mated
(paired) at random.
2. Each pair of strings undergoes a crossover as follows: An integer k is
randomly selected between one and the length of the string less one, [1,L-1].
Swapping all the characters between positions k+1 and L inclusively creates
two new strings.
Example: If the strings 10000 and 01110 are selected for crossover and the value of k
is randomly set to 3 then the newly created strings will be 10010 and 01100 as shown
in Figure 5.2.
Figure 5.2 Illustration of a Single Point Crossover

More complex crossover techniques exist in the form of Multi-point and Uniform
Crossover Algorithms. Multi-point crossover is an extension of the single point
crossover algorithm and operates on the principle that the parts of a chromosome that
contribute most to its fitness might not be adjacent. There are three main stages
involved in a Multi-point crossover.
1. Members of the newly reproduced strings in the mating pool are mated
(paired) at random.
2. Multiple positions are selected randomly with no duplicates and sorted into
ascending order.
3. The bits between successive crossover points are exchanged to produce new
offspring.
Example: If the string 11111 and 00000 were selected for crossover and the
multipoint crossover positions were selected to be 2 and 4 then the newly created
strings will be 11001 and 00110 as shown in Figure 5.3.

Figure 5.3 Illustration of a Multi-Point Crossover

In uniform crossover, a random mask of ones and zeros of the same length as the
parent strings is used in a procedure as follows.
14
1. Members of the newly reproduced strings in the mating pool are mated
(paired) at random.
2. A mask is placed over each string. If the mask bit is a one, the underlying bit
is kept. If the mask bit is a zero then the corresponding bit from the other
string is placed in this position.
Example: If the string 10101 and 01010 were selected for crossover with the mask
10101 then newly created strings would be 11111 and 00000 as shown in Fig. 5.4.


Figure 5.4 Illustration of a Uniform Crossover

Uniform crossover is the most disruptive of the crossover algorithms [4] and
has the capability to completely dismantle a fit string, rendering it useless in the next
generation. Because of this Uniform Crossover will not be used in this project.

5.3 Mutation
Using selection and crossover on their own will generate a large amount of
different strings. However there are two main problems with this:
1. Depending on the initial population chosen, there may not be enough
diversity in the initial strings to ensure the GA searches the entire problem
space.
2. The GA may converge on sub-optimum strings due to a bad choice of initial
population.
These problems may be overcome by the introduction of a mutation operator into
the GA. Mutation is the occasional random alteration of a value of a string position. It
is considered a background operator in the genetic algorithm
The probability of mutation is normally low because a high mutation rate would
destroy fit strings and degenerate the genetic algorithm into a random search.
Mutation probability values of around 0.1% or 0.01% are common, these values
represent the probability that a certain string will be selected for mutation i.e. for a
probability of 0.1%; one string in one thousand will be selected for mutation.
Once a string is selected for mutation, a randomly chosen element of the string
is changed or mutated. For example, if the GA chooses bit position 4 for mutation in
15
the binary string 10000, the resulting string is 10010 as the fourth bit in the string is
flipped as shown in Figure 5.5.
Figure 5.5 Illustration of Mutation Operation

5.4 Genetic Algorithm Process

Figure 5.6 Graphical Illustration the Genetic Algorithm Outline

The steps involved in creating and implementing a genetic algorithm are as
follows:
1. Generate an initial, random population of individuals for a fixed size.
2. Evaluate their fitness.
3. Select the fittest members of the population.
4. Reproduce using a probabilistic method (e.g., roulette wheel).
5. Implement crossover operation on the reproduced chromosomes
(choosing probabilistically both the crossover site and the mates).
6. Execute mutation operation with low probability.
7. Repeat step 2 until a predefined convergence criterion is met.
16
The convergence criterion of a genetic algorithm is a user-specified condition e.g.
the maximum number of generations or when the string fitness value exceeds a
certain threshold.

5.5 Elitism
With crossover and mutation taking place, there is a high risk that the
optimum solution could be lost as there is no guarantee that these operators will
preserve the fittest string. To counteract this, elitist models are often used. In an elitist
model, the best individual from a population is saved before any of these operations
take place. After the new population is formed and evaluated, it is examined to see if
this best structure has been preserved. If not, the saved copy is reinserted back into the
population. The GA then continues on as normal [5]

5.6 Genetic Algorithms versus Traditional Methods
Genetic algorithms are substantially different to the more traditional search and
optimisation techniques. The five main differences are:
1. Genetic algorithms search a population of points in parallel, not from a single
point.
2. Genetic algorithms do not require derivative information or other auxiliary
knowledge; only the objective function and corresponding fitness levels
influence the direction of the search.
3. Genetic algorithms use probabilistic transition rules, not deterministic rules.
4. Genetic algorithms work on an encoding of a parameter set not the parameter
set itself (except where real-valued individuals are used).
5. Genetic algorithms may provide a number of potential solutions to a given
problem and the choice of the final is left up to the user.







17
5.7 Initialising the Population of the Genetic Algorithm
The following code is based on the Genetic Algorithm Optimisation Toolbox
(GAOT) [6].


Figure 5.7 Code Initialising the Population of a Genetic Algorithm

PopulationSize - The first stage of writing a Genetic Algorithm is to create a
population. This command defines the population size.
VariableBounds - Since this project is using genetic algorithms to optimise the
gains of a PID controller there are going to be three strings assigned to each
member of the population, these members will be comprised of a P, I and a D
string that will be evaluated throughout the course of the GA. The three terms
are entered into the genetic algorithm via the declaration of a three-row
variablebounds matrix. The number of rows in the variablebounds matrix
represents the number of terms in each member of the population. Figure 5.7
illustrates a population of eighty members being initialised with values
randomly selected between -100 and 100.
EvalFN - The evaluation function is the declaration of the file name containing
the objective function.
Options - Although the previous examples in this section were all binary
encoded, this was just for illustrative purposes. Binary strings have two main
drawbacks:
1. They take longer to evaluate due to the fact they have to be converted
to/from binary.
2. Binary strings lose precision during conversion.
As a result of this and the fact that they use less memory, real (floating point)
numbers will be used to encode the population. This is signified in the options
command in Figure 5.7, where the 1e-6 term is the floating point precision
18
and the 1 term indicates that real numbers are being used (0 indicates binary
encoding is being used).
Initialisega - This command combines all the previously described terms and
creates an initial population of 80 real valued members between 100 and 100
with 6 decimal place precision.

5.8 Initialising the Genetic Algorithm
A genetic algorithm is initialised as shown in Figure 5.8.

Figure 5.8 Initialising the Genetic Algorithm

Bounds - The bounds for the genetic algorithm to search within are set using
this command. These bounds may be different from the ones used to initialise
the population and they define the entire search space for the genetic
algorithm.
startPop - The starting population of the GA, startPop, is defined as the
population described in the previous section, i.e. initPop, see Figure 5.7.
opts - The options for the Genetic Algorithm consist of the precision of the
string values i.e. 1e-6, the declaration of real coded values, 1, and a request for
the progress of the GA to be displayed, 1, or suppressed, 0.
TermFN - This is the declaration of the termination function for the genetic
algorithm. This is used to terminate the genetic algorithm once certain
criterion has been met. In this project, every GA will be terminated when it
reaches a certain number of generations using the maxGenTerm function.
This termination method allows for more control over the compile time (i.e.
the amount of time it takes for the genetic algorithm to reach its termination
19
criterion) of the genetic algorithm when compared with other termination
criteria e.g. convergence termination criterion.
TermOps - This command defines the options, if any, for the termination
function. In this example the termination options are set to 100, which means
that the GA will reproduce one hundred generations before terminating. This
number may be altered to best suit the convergence criteria of the genetic
algorithm i.e. if the GA converges quickly then the termination options should
be reduced.
SelectFN - Normalised geometric selection (normGeomSelect) is the primary
selection process to be used in this project. The GAOT toolbox provides two
other selection functions, Tournament selection and Roulette wheel selection.
Tournament selection has a longer compilation time than the rest and as the
overall run time of the genetic algorithm is an issue, tournament selection will
not be used. The roulette wheel option is inappropriate due to the reasons
mentioned in section 5.1.
SelectOps - When using the normGeomSelect option, the only parameter that
has to be declared is the probability of selecting the fittest chromosome of
each generation, in this example this probability is set to 0.08.
XOverFN - Arithmetic crossover was chosen as the crossover procedure.
Single point crossover is too simplistic to work effectively on a chromosome
with three alleles, a more uniform crossover procedure throughout the
chromosome is required. Heuristic crossover was discarded because it
performs the crossover procedure a number of times and then picks the best
one. This increases the compilation time of the program and is undesirable.
The Arithmetic crossover procedure is specifically used for floating point
numbers and is the ideal crossover option for use in this project.
XOverOptions -This is where the number of crossover points is specified. In
the example shown in Figure 5.8, the number of crossovers points is set to
four.
mutFNs - The multiNonUnifMutation, or multi non-uniformly distributed
mutation operator, was chosen as the mutation operator as it is considered to
function well with multiple variables.
20
MutOps - The mutation operator takes in three options when using the
multiNonUnifMutation function. The first is the total number of mutations,
normally set with a probability of around 0.1%. The second parameter is the
maximum number of generations and the third parameter is the shape of the
distribution. This last parameter is set to a value of two, three or four where
the number reflects the variance of the distribution.

5.9 Performing the Genetic Algorithm
The genetic algorithm is compiled using the command shown in Figure 5.9.
Once this command is entered, the genetic algorithm will iterate until it fulfils the
criteria described by its termination function.

Figure 5.9 Command to Compile the Genetic Algorithm

Once the genetic algorithm is complete, it returns four variables:
x = The best population found during the GA.
endPop = The GAs final population.
bestPop = The GAs best solution tracked over generations.
trace = The best value and average value for each generation.

The best population may be plotted to give an insight into how the genetic
algorithm converged to its final values as illustrated in Figure 5.10
21

Figure 5.10 Illustration of the Genetic Algorithm Converging through Generations



5.10 Writing the Objective Function for a Genetic Algorithm
Writing an objective function is the most difficult part of creating a genetic
algorithm. In this project, the objective function is required to evaluate the best PID
controller for the Ball and Hoop system. An objective function could be created to
find a PID controller that gives the smallest overshoot, fastest rise time or quickest
settling time but in order to combine all of these objectives it was decided to design an
objective function that will minimise the error of the controlled system.
Each chromosome in the population is passed into the objective function one
at a time. The chromosome is then evaluated and assigned a number to represent its
fitness, the bigger its number the better its fitness. The genetic algorithm uses the
chromosomes fitness value to create a new population consisting of the fittest
members.
22

Figure 5.11 Creating PID Controller in Objective Function

Each chromosome consists of three separate strings constituting a P, I and D
term, as defined by the 3-row bounds declaration when creating the population.
When the chromosome enters the evaluation function, it is split up into its three terms,
as shown in Figure 5.11, and the P, I and D gains are used to create a PID controller
according to Equation (5.1).

s
K s K s K
C
I P D
PID
+ +

2
(5.1)
The newly formed PID controller is placed in a unity feedback loop with the
Ball and Hoop transfer function. In order to reduce the compile time of the program
the Ball and Hoop transfer function is defined in another file and imported as a global
variable. The controlled system is given a step input and the error is assessed using an
appropriate error performance criterion i.e. ITAE, ISE, IAE or MSE. The
chromosome is assigned an overall fitness value according to the magnitude of the
error, the smaller the error the larger the fitness value.

Figure 5.12 Calculating the Error of the Controlled System

Additional code was added to ensure that the genetic algorithm converges to a
controller that produces a stable system. The code, shown in Figure 5.12, assesses the
poles of the controlled system and if they are found to be unstable i.e. on the right half
of the s-plane, the error is assigned an extremely large value to make sure that the
chromosome is not reselected.
23

Figure 5.12 Checking the Stability of the Controlled System

In order to evaluate an optimum genetic algorithm for use in this project, several GAs
were created and analysed as shown in the next section.






















24
6.0 Development of Genetic Algorithm for PID Tuning
To aid with the development of this project a system was chosen at random
and a PID controller was designed for it using conventional methods. A genetic
algorithm was then created to evaluate the PID coefficients of the same system and
the results of the two techniques were compared. A fourth order system was selected
as the Ball and Hoop system is of order four.
The system chosen was:
G(s) =
s s s s 6 11 6
1
2 3 4
+ + +
(6.1)

6.1 Ziegler-Nichols Designed PID Controller
The Ziegler-Nichols tuning method using root-locus was the conventional
method used to evaluate the PID gains for the system. Using the rlocfind command
in Matlab, the crossover point and gain of the system were found to be j1 and 10
respectively, as shown in Figure 6.1.
Figure 6.1 Plot of root locus for G(s)

With a frequency (
c
) of 1rad/s, the period
c
T is calculated as:
sec 28 . 6
2

c
c
T



25
Placing the values of
c
K and
c
T into Table 6.1
Controller
p
K
I
T
D
T
PID
C
K 6 . 0 2 /
C
T 8 /
C
T
Table 6.1 Ziegler-Nichols PID tuning parameters
Gives
Controller
p
K
I
T
D
T
PID 6 3.14 0.79
Table 6.2 Ziegler-Nichols PID Tuning Values
Using the relationship
I
P
I
T
K
K and
D P D
T K K , the PID gains can be evaluated.
Controller
p
K
I
K
D
K
PID 6 1.91 4.74
Table 6.3 Ziegler-Nichols PID Gain values

Table 6.3 shows the PID gain values for the system G(s). A genetic algorithm,
Initial_PID_GA.m, (Appendix A.1) was created to evaluate the optimum PID gain
values for the system G(s). A number of objective functions were created in order to
evaluate the PID values chosen by the Genetic Algorithm.

6.2 Performance Indices
Various objective functions were written based on error performance criterion.
Each objective function is fundamentally the same except for the section of code that
defines the specific error performance criterion being implemented.
To optimise the performance of a PID controlled system, the PID gains of the
system are adjusted to maximise or minimise a certain performance index. The
performance index is calculated over a time interval; T , normally in the region of
s
t T 0 where
s
t is the settling time of the system. The performance indices used
were:

6.2.1 Integral of Time multiplied by Absolute Error (ITAE)

T
ITAE
dt t e t I
0
) ( (6.2)
26
The ITAE weights the error with time and hence emphasises the error values later on
in the response rather than the initial large errors.

Figure 6.2 ITAE Objective Function

6.2.2 Integral of Absolute Magnitude of the Error (IAE)
dt t e I
T
IAE

0
) ( (6.3)
IAE gets the absolute value of the error to remove negative error components.
IAE is good for simulation studies.

Figure 6.3 IAE Objective Function


6.2.3 Integral of the Square of the Error (ISE)

T
ISE
dt t e I
0
2
) ( (6.3)
The ISE squares the error to remove negative error components. ISE
discriminates between over-damped and under damped systems, i.e. a compromise
minimises the ISE.

Figure 6.4 ISE Objective Function

27
6.2.4 Mean of the Square of the Error (MSE)

n
i
MSE
t e
n
I
1
2
)) ( (
1
(6.4)

MSE reflects all variation and deviation from the target value.

Figure 6.5 MSE Objective Function

6.3 Evaluation of Performance Criterion
An experiment was undertaken to evaluate which of the four performance
criterion produce the best results when used in conjunction with a genetic algorithm.
An objective function was created for each individual performance criterion as
depicted in: PID_objfun_ITAE.m, PID_objfun_IAE.m, PID_objfun_ISE.m and
PID_obfun_MSE.m (Appendix A.2, A.3, A.4 and A.5 respectively).
The same Genetic Algorithm, Initial_PID_GA.m, was used for each objective
function. The genetic algorithm was initialised with a population of twenty and was
iterated for 100 generations. The total number of mutations was set to three and each
of the bounds was set to 50 t . To ensure that all of the genetic algorithms had the
exact same initial conditions the matlab command was used.
This command guarantees that each population is initialised to the same set of values.
Figure 6.6 distinguishes the step response of the root locus designed PID
controller versus a Genetic Algorithm tuned PID controller using each of the objective
functions. Table 6.4 describes the steady state characteristics of each of the controlled
systems.
Table 6.4 Comparisons of Steady State Responses
Title Root Locus ITAE IAE ISE MSE
Rise Time 2.1000 1.3000 1.2000 1.2000 1.2000
% Overshoot 58.1561 57.1908 44.9741 28.8045 28.5908
Settling Time 14.8000 8.2000 9.3000 20.4000 20.4000
28

Figure 6.6 Graph of Ziegler-Nichols designed PID controller (red) Vs GA designed
PID Controller (green) using (a) ITAE, (b) IAE, (c) ISE and (d) MSE as performance
criterion.

Under the conditions of this experiment, it can be seen that the ISE and MSE
objective functions perform almost identically, having a smaller rise time, smaller
overshoot and bigger settling time than the other controllers. Each of the genetic
algorithm-tuned PID controllers outperforms the Ziegler-Nichols tuned controller in
terms of rise time and overshoot but only the ITAE and IAE objective functions
outperform it in terms of settling time. The MSE objective function was chosen as the
primary performance criterion for the remainder of this project due to its smaller rise
time and smaller overshoot than any other method in conjunction with a slightly faster
compile time due to there being just one multiplication to be carried after the error has
been calculated. This is coupled with the fact that MSE has been a proven measure
of control and quality for many years [7] makes it the ideal performance criterion for
this project.




29
7.0 Identifying the Ball and Hoop System
7.1 Operating Conditions
The hoop in the Ball and Hoop system is driven by a motor, this introduces
two common operational characteristics associated with motors i.e. saturation and
dead band. The saturation effect is caused because the magnitude of the current that
the amplifier is capable of creating is lower than may be required in certain situations.
Dead band in a system is a region where for a given input there is no output. The dead
band in this system is caused mainly due to the static friction of the motor and the
load.

Figure 7.1 Illustration of Dead Band and Saturation Regions

The dead band level of the system was found by increasing the input voltage
by .01V until the hoop began to move. Using this procedure the dead band level was
found to be 0.7V. The operating conditions in the manual of the Ball and Hoop
system stipulate that the maximum input into the ball and hoop system should not
exceed 10V. Due to this requirement, the ball and hoop system should never reach its
saturation level. Consequently, the input voltage level to the Ball and Hoop system
must remain in the linear region of the graph between 0.7V -10V.

7.2 Identifying the Hoop
The hoop is driven by a motor, as a result, it displays the same characteristics
as a motor, i.e. it has a gain and a time delay. The general transfer function for a hoop
is illustrated in Figure 7.2.
30

Figure 7.2 Transfer Function Relating Input Voltage and Hoop Position

7.3 Calculating Steady State Gain
The steady state gain, G, can be measured by plotting the steady state hoop
speed for a range of constant drive amplifier input voltages, to obtain a curve of
the form shown in Figure 7.1. The slope of the ramp part of this curve may be
calculated. This slope is equal to the linear region gain, g.
Alternatively, the change in steady state speed is given by,
i
v g . (6.1)

Figure 7.3 Change of Motor Speed in Time [3]
Where,
V V V 21 . 2 34 . 2 55 . 4 (As read from voltmeter)
V 2 V
i

2
21 . 2
G
105 . 1 G

7.4 Calculating the Time Constant
The time constant of the system is found by operating the system in its linear
region and applying a small step increase
i
V in the drive voltage
i
V . The drive
voltage was chosen to be 4V, as this will give an output of around 3000RPM. The
31
step increase was added in the form of a V 1 t square-wave with a frequency of
0.05Hz as can be seen in Figure 7.4.
In a first-order system such as the motor, there is no overshoot. Due to this, the
rise time of the system is calculated as the time at which the system reaches 63.2% of
its final value. The time taken for the speed to change by 632 . 0 is equal to the time
constant of the system, .
Figure 7.4 Motor Speed Response to Square Wave Input

The time constant was evaluated using Matlab and was found to have a value
of .66 seconds.
sec 66 . 0

7.5 Calculating Hoop Gain
H is a steady state gain of the hoop and is calculated by plotting the
tachometer output voltage versus the product of the frequency times the amplitude.

Tachometer
Output (V)
Frequency
(Hz)
Period
(Seconds)
Amplitude
(V)
Frequency X
Amplitude
1 5 0.2 13.5 67.5
2 10 0.01 13.5 135
3 15 0.065 13.5 202.5
4 20 0.05 13.5 270
Table 7.1 Data Used to Calculate H
32

Figure 7.5 Plot of Data in Table 7.1

Calculating the slope of the line in Figure 7.5 and hence the value of H gives;
5 . 67
2
135
H
Now that the coefficients for G, H and are known the transfer function for
the hoop is as depicted in Figure 7.6


Figure 7.6 Hoop Transfer function

The derived transfer function for the hoop was compared against the actual
hoop for a step input of 4V, using the hoop speed, , as the output. Simulink scales
down the voltage by a factor of ten, hence the amplitude shown in the graphs is ten
times smaller than the actual voltage. For a step input of 4V there was a large
discrepancy in the outputs of the actual hoop and the mathematical model of the hoop
as shown in Figure 7.7.
The difference in outputs is a gain of just under two. In order to remedy this
error the gain value of the derived transfer function of the hoop, i.e. G, was adjusted
manually until the error between the predicted output and the actual output for a step
input of 4V was minimal as shown in Figure 7.9.

33
Figure 7.7 Graph of the Real Vs Simulated Output of the Hoop

The newly found gain has a value of 1.75 and the overall transfer function for
the hoop is now as depicted in Figure 7.8

Figure 7.8 Illustration of New Hoop Transfer Function

The new transfer function for the hoop only represents the hoop for an input of
4V. For any other input an error occurs. If the model for the ball and hoop project is
based around an input of 4V then this transfer function is an accurate representation of
the hoop.
Figure 7.9 New Hoop Transfer Function Vs Physical Hoop

34
7.6 Evaluation of and
n

The ball was placed in the hoop between the blades of the Slop Angle
transducer arms. It was deflected by hand to an angle of
o
40 and then released. The
oscillatory response of the ball was recorded using Matlab. Utilizing the oscillatory
response, the values of and
d
may be determined by comparing the ball response to
the standard response characteristic of a second order system.

Figure 7.10 Illustration of Expected Oscillations [3]

Fractional Overshoot (FO) is defined as:

1
1
]
1

2
1
exp

FO (7.2)
Figure 7.11 Illustration of Actual Oscillations

35
The fractional overshoot of the system was measured at 0.825 using Matlab.
Rearranging Equation (7.2) and solving for yields a value of 0.066 for the damping
factor.
066 . 0
Time to the first peak overshoot (
p
t ) is defined as:
d
p
t

(7.3)
A time to first peak value of
p
t = 0.32 was evaluated in Matlab. Rearranging the
Equation (7.3) yields a damped frequency value of:
d
= 9.82 rad/sec
The undamped natural frequency,
n
, is obtained by substituting
d
and into:
2
1

d
n
(7.4)
The Ball and Hoop system has an undamped frequency of:
n
=9.841rad/sec.
The transfer function relating the hoop angle, ) (s , to the slop angle, ) (s , is
detailed in Equation (7.5)

,
_

+ +
,
_

,
_

+
,
_

R
g
s
mr
b
s
r
r
mr
b
s
r
r
s
s
s
b b
b b
2
2
2
2
2
5
2
5
2
) (
) (

(7.5)

Where:
b
r = Radius of the Ball (= 9.53mm)
r = Rolling Radius of the Ball (= 9.3mm)
g = Gravity (= 9.81m/s)
m = Mass of the Ball (= 0.0282kg)
R = Radius of the Hoop (= 87.5mm)
b
b = Coefficient of Rolling Friction

36
All of these coefficients for the ball and hoop system are known except one. The next
step is to calculate the coefficient of rolling friction.

6.7 Calculating of Coefficient of Rolling Friction
The characteristic equation of Equation (7.5) is:
0 1
5
2
2
2
2
+ +

,
_

+
1
]
1

R
g
s
mr
b
s
r
r
b b
(7.6)

0
1
5
2
1
5
2
2 2
2
2

,
_

+
1
]
1

,
_

+
1
]
1

+
r
r
R
g
s
r
r
mr
b
s
b b
b


Using the standard characteristic equation for a second order system:
0 2
2 2
+ +
n n
s s
And equating the coefficients of the s terms to solve for
b
b :

,
_

+
1
]
1

1
5
2
2
2
2
r
r
mr
b
b
b
n

Rearranging,

,
_

+
1
]
1

1
5
2
2
2
2
r
r
mr b
b
n b
(7.7)
Where:
0.066

n
9.987 rad/sec.
m = 28.2g
b
r = 9.53mm
r = 9.3mm
Substituting these values into Equation (7.7) gives:

,
_

+
1
]
1

1
3 . 9
53 . 9
5
2
) 0093 )(. 0282 )(. 987 . 9 )( 066 . 0 ( 2
2
2
b
b
6
10 57 . 4


b
b
37

Now that the coefficient of rolling friction is known, the transfer function shown in
Equation (7.5) can be evaluated as:
11 . 112 873 . 1 42 . 1
873 . 1 42 . 0
) (
) (
2
2
+ +
+

s s
s s
s
s


The experimentally derived Ball and Hoop transfer function is shown in Figure 7.12

Figure 7.12 Transfer Function of the Ball and Hoop System

This can be condensed down to:

Figure 7.13 Overall Transfer Function of the Ball and Hoop System

7.8 Ziegler-Nichols PID Controller for the Ball and Hoop System.
The Ziegler-Nichols tuning technique was again used to design a PID controller for
evaluation purposes. Using the same method as described in Section 6.1, the
crossover point and gain of the system were found to be j12.6233 and 1.5813
respectively, as illustrated in Figure 7.14.

Figure 7.14 Root locus for Ball and Hoop System
38
With a frequency (
c
) of 1 rad/s, the period
c
T is calculated as
c

2
= 0.5 sec.
Placing the values of
c
K and
c
T into Table 6.1 gives:
Controller
p
K
I
T
D
T
PID .9478 0.25 .0625
Table 7.2 Ziegler-Nichols PID Tuning Values
Using the relationship
I
P
I
T
K
K and
D P D
T K K the PID gains can be evaluated.
Controller
p
K
I
K
D
K
PID .9478 3.7912 .06
Table 7.3 Ziegler-Nichols PID Gain values

Analysing the transfer function in Figure 7.13 shows that the ball and hoop system is
stable as it has three poles located on the left hand side of the s-plane at -0.6595 +
8.8609i, -0.6595 - 8.8609i and -1.5152 and one critically stable pole located at the
origin. The presence of a critically stable pole will result in a more oscillatory open
loop response. From the transfer function, it is clear that there will be an open-loop
steady state gain of 84 . 1
1 . 112
1 . 206
. This gain is shown in Figure 7.15 when the open
loop response of the system is plotted against a PID controlled system using the
previously derived Ziegler-Nichols controller.

Figure 7.15 Open Loop Vs PID Controlled Response of Ball and Hoop System
39
8.0 System Estimator
The ball and hoop system parameters are constantly changing. Because of this,
a mechanism is need by which the system parameters can be obtained. It is proposed
that a Recursive Least Squares estimator, implemented in the form of an
s-function will perform this task.

8.1 Least Squares Estimation
Least Squares Estimation is the parameter estimation technique that RLS is
derived from. The basic model of an unknown system may be written in the form:
A.y(t) = B.u(t - 1) + C.e(t) + D (8.1)
Where a, b, c and d are the parameters of the system to be estimated. When
estimating the unknown parameters of a system the data is grouped into the form:
) ( . ) ( t e x t y
T
+ (8.2)
Where is a group of unknown vectors defined by:
] ,..., , , ,..., , ,..., , ,..., [
1 0 1 0 1
d c b a
n c n n
T
d d d c c b b a a
And the regression vector, x(t), is a matrix of input and output variables in the form:
] ,..., , 1 ), ( ),..., 1 ( ), 1 ( ),..., 1 ( ), ( ),..., 1 ( [ ) (
d
n
c b a
T
t t n t e t e n t u t u n t y t y t x
) (t e represents the error of the estimates at time t. The aim of least squares is to select
a value for so that the overall error is minimised. To be able to estimate parameters
effectively the number of equations must not be less than the number of unknown
parameters in the vector .
Rearranging the Equation (8.2) in terms of the error gives:

X y e (8.3)
Where,
1
1
1
1
1
]
1

) (
:
) 2 (
) 1 (
N x
x
x
X
T
T
T

To find

, minimise the Error Performance Index, J, where J is the sum of the squares
of the error.


N
t
T
e e t e J
1
2
) ( (8.4)

40
To find the least squares estimate, insert Equation (8.3) into Equation (8.4).
)

( )

( X y X y J
T



X X X y y X y y J
T T T T T
+
Taking the derivative of J with respect to

and setting it equal to zero:


0

2 2

X X y X
J
T T

Taking the transpose:

y X y X
T T

Rearranging produces the least squares estimate for the parameter vector:
] [ ] [

1
y X X X
T T
(8.5)
8.2 Recursive Least Squares
It is advantageous if the parameter estimator in a self-tuning controller is
iterative. This allows the system to be estimated at each sample time, thus providing
the most accurate estimate of the system. If the system should change between sample
times, the estimated parameters will reflect this. RLS introduces computational
savings into the estimation of parameters when compared with least squares by not
requiring a matrix inversion. In addition, using the least squares approach to
parameter estimation requires storing all previous data whereas with RLS it is only
necessary to store the old estimates calculated at time t, denoted by ) (

t , and to
obtain the new estimates ) 1 ( + t by updating using new observations only.

Figure 8.1 Illustration of the RLS Algorithm

Figure 8.1 graphically illustrates the RLS technique. At each sample time the
input and output data of the system becomes available. The estimated system ) 1 (

t ,
41
predicts an output and compares it to the system output. The error of the two outputs
is then used to update the parameter estimates.
The RLS derivation is detailed in Appendix B. The procedure for updating
) (

t using Recursive Least Squares is detailed in the following summary.



8.4 RLS Algorithm: Matrix Inversion Lemma RLS
Where x(t) = Data Vector at time t,
P(t) = Covariance Matrix at time t,
(t) = Parameter Estimate at time t,
(t) = Error at time t.

At time step 1 + t :
(i) Form ) 1 ( + t x using the new data.
(ii) Form ) 1 ( + t
using

(iii) Form ) 1 ( + t P using
1
]
1

+ + +
+ +
+
) 1 ( ) ( ) 1 ( 1
) ( ) 1 ( ) 1 (
) ( ) 1 (
t x t P t x
t P t x t x
I t P t P
T
T
m
(8.6)

(iv) Update ) (

t
) 1 ( ) 1 ( ) 1 ( ) (

) 1 (

+ + + + + t t x t P t t
(v) Repeat from step (i) during next time step.



8.5 Initialisation of the Parameter Vector ) 0 (
Recursive Least Square requires an initial estimate, ) 0 ( , of the parameter
vector as a starting point for the algorithm. If no prior knowledge of the coefficients to
be estimated exists, then ) 0 ( may be set to zero for the initial estimate. Alternatively,
it may be assumed that the system is a single integrator with a unit gain.

) (

) 1 ( ) 1 ( ) 1 ( t t x t y t
T
+ + +
42
Laplace Transform
G(s)
z-transform
G(z)
s
1

1 z
s


Table 8.1 Single Integrator with Unit Gain

Given that the Ball and Hoop system has already been identified, ) 0 ( will be
initialised to the experimentally derived coefficients of the system. (See Equation
(8.11) for derivation)
1
1
1
1
1
1
1
1
]
1

002382 . 0
0001215 . 0
002477 . 0
9721 . 0
936 . 2
964 . 2
) 0 (

8.6 Initialisation of the Covariance Matrix
The covariance matrix represents the level of confidence in the initial values
of the parameter vector. If no prior knowledge of the system or its parameters is
available then the covariance matrix should be initialised to large initial values
between 100 and 1000. However, if the system has been identified and the initial
parameter estimation ) 0 ( is known to be accurate then a small covariance matrix
should be chosen with values from 1-10.

8.7 RLS Input Signal
Since the Ball and Hoop system that is to be estimated is part of a control loop
an additional problem is introduced. The feedback signal may cause an ambiguity in
the relationship between the input and the output signal causing the RLS estimator to
malfunction. The most effective way around this problem is to add an independent
signal into the loop, Figure 8.2. This extra dither signal should satisfy the requirement
for persistent excitation and should not have large amplitude components that could
drive the system into non-linear operation [8].
43

Figure 8.2 Dither Signal System

There are four main choices for the proposed dither signal.
1. Gaussian Distributed Noise
2. Uniformly Distributed Noise
3. Square Wave
4. Pseudo Random Binary Signal (PRBS)

8.7.1 Gaussian Distributed Noise
Gaussian distributed noise is to be avoided in general because it contains high
amplitude outliers that can excite the nonlinear modes of a system. In addition, the
concentration of signal energy at low amplitudes will cause nonlinear distortion due to
the dead zones present in the Ball and Hoop system.

8.7.2 Uniformly Distributed Noise
The amplitude range of this signal is also uniformly distributed and the
presence of low amplitudes will cause nonlinear distortion due to the dead zone
nonlinearity in the Ball and Hoop system.

8.7.3 Square Wave
Square waves are a good choice of input signal for a system to be estimated.
They are easy to implement and the amplitude can be limited so that the system stays
in the linear region.

8.7.4 Pseudo Random Binary Signal (PRBS)
PRBS share the advantage of square waves in that they only have two
amplitude levels that may be selected so that the amplitude does not exceed the bands
44
of linearity of the system. The main advantage of PRBS is that it has a rich spectrum
and is an ideal input for a system to be estimated. (See Appendix A.6 for code)

8.8 Zero-Order Hold
The Ball and Hoop System is a continuous system but the RLS estimator
requires that the input/output data remains constant between sampling intervals. To
support this requirement, a zero-order hold block is placed before the system to
ensure that the input/output data is constant between sampling intervals.

Figure 8.3 Diagram of Zero-Order Hold in Operation

8.9 Forgetting Factor
Given that the input of the system provides sufficient excitation, the RLS
algorithm ensures that the elements of the covariance matrix, P(t), decrease in size as
the algorithm progresses. A small covariance matrix indicates that the estimates are
accurate and only a small adjustment is necessary. In a constantly changing system a
small covariance matrix may be a disadvantage. If the system being estimated
changes considerably then the RLS estimator will take a long time to reconverge. The
manipulation of the size of the covariance matrix is the principal method for
controlling the adaptive capabilities of the estimator. In order to aid the RLS estimator
in parameter tracking a forgetting factor is introduced into the covariance matrix
calculation.
The forgetting factor, , is a value between 0 and 1 and is used to provide bias
toward more recent data thus placing less emphasis on older data and helping the
estimator react more quickly to parameter changes in the system.
The idea of the forgetting factor can be understood by considering the
following example of the way information is weighted in the least squares cost
function [8].
45
The least squares approach, Equation (8.5), to minimising the cost function at
each time t implies that all the values of ) ( i e from 1 i to t i carry an equal
weighting.

t
i
t
i e J
1
) ( (8.7)
The forgetting factor approach applies a differential weighting to the data by
use of a modified cost function (1.2).

t
i
i t
t
i e J
1
2
) ( (8.8)
The discounting effect of on past errors can be seen by writing (8.8) in the
form:
) (
2
1
t e J J
t t
+

(8.9)
The forgetting mechanism uses the influence of lambda to progressively reduce
the importance given to old data.

Figure 8.4 Variations of Data Weighting with Constant Forgetting Factor [8]

It is clear from Figure 8.4, that the optimal value for a forgetting factor is
between 0.95 and 1. By reducing the value of it increases the sensitivity of the
system to change but this also increases the variability of the estimates so a
compromise must be reached. It is proposed that a value of 0.975 is used for the
forgetting factor in this project.
With the inclusion of a forgetting factor the equation for updating the
covariance matrix, Equation (8.6), becomes:
46
1
]
1

+ + +
+ +
+
) 1 ( ) ( ) 1 (
) ( ) 1 ( ) 1 ( ) (
) (
1
) 1 (
t x t P t x
t P t x t x t P
t P t P
T
T

(8.10)
8.10 S-Functions
To incorporate an RLS estimator into the control scheme for the Ball and
Hoop system requires that the RLS algorithm is able to fully interact with the Real-
Time toolbox in Simulink. To this end, the RLS estimator must be written as an S-
Function in Simulink.
An S-function is a computer language description of a Simulink block that
may be written in MATLAB, C, C++, Ada, or Fortran. S-functions allow the user to
create their own blocks in Simulink. They use a special calling syntax that enables
direct interaction with Simulink equation solvers. This interaction is similar to the
interaction that takes place between the solvers and built-in Simulink blocks. The
form of an S-function is general and can accommodate continuous, discrete, and
hybrid systems. S-functions are fully compatible with the Real-Time toolbox. [9]

8.10.1 How S-functions work [9]
Each Simulink block consists of a set of inputs, u, a set of states, x, and a set of
outputs, y, where the outputs are a function of the sample time, the inputs, and the
block's states.

Figure 8.5 Illustration of a Simulink Block

Execution of a Simulink model proceeds in stages. The first stage is the
initialisation phase. In this phase, Simulink incorporates library blocks into the model,
propagates widths, data types, and sample times, evaluates block parameters,
determines block execution order, and allocates memory. Simulink then enters a
simulation loop, where each pass through the loop is referred to as a simulation step.
During each simulation step, Simulink executes each of the model's blocks in the
order determined during initialisation. For each block, Simulink invokes functions
that compute the block's states, derivatives, and outputs for the current sample time.
This continues until the simulation is complete.
47
Each S-function utilises a set of callback methods that perform tasks required at
each stage. Simulink calls the appropriate methods for each S-Function block in the
model at the relevant stage during simulation. Tasks performed by S-function
methods include

Initialisation Initialisation of the S-function. During this stage, Simulink
1. Initialises the SimStruct, a simulation structure that contains
information about the S-function
2. Sets the number and dimensions of input and output ports
3. Sets the block sample times
4. Allocates storage areas and the sizes array

Calculation of next sample hit Used for variable sample time systems only,
calculates the time of the next sample hit; i.e. calculates the next step size.
Calculation of outputs in the major time step Validates all output ports for
the current time step.
Updates discrete states in the major time step All blocks perform once-per-
time-step activities e.g. updating discrete states for next simulation loop.
Integration -- This applies to models with continuous states and/or nonsampled
zero crossings. If your S-function has continuous states, Simulink calls the
output and derivative portions of your S-function at minor time steps. This is
so Simulink can compute the states for your S-function.
48

Figure 8.6 Tasks Performed by S-function [9]

An S-function written in an m-file consists of a MATLAB function of the
following form:
[sys,x0,str,ts]=fun(t,x,u,flag,p1,...)
Outputs: Inputs:
sys Returns system sizes fun - S-function's name
x0 Returns initial states x - State vector
str Returns state ordering strings u - Block's inputs
ts Returns sample times flag - indicates a task to be performed

t - Current time
Table 8.2 S-Function Inputs and Outputs

8.10.3 Flags in Simulink
Simulink uses a flag system to indicate which task is to be performed at each
instant. The flag constantly changes its value and in this way, an S-function can
cycle through its various tasks.
49

Simulation Stage

S-Function Routine

Flag

Initialisation

mdlInitializeSizes

flag = 0

Calculation of next sample hit (variable sample time only)

mdlTimeOfNextVarHit

flag = 4

Calculation of outputs

mdlOutputs

flag = 3

Update of discrete states

mdlUpdate

flag = 2

Calculation of derivatives

mdlDerivatives

flag = 1

End of simulation tasks

mdlTerminate

flag = 9

Table 8.3 Table of Flag Values and their Functions [9]

8.11 Initialising the RLS Algorithm
The RLS algorithm requires that the input/output data is constant between
sampling intervals. This involves discretizing the Ball and Hoop system using Zero-
Order Hold.

8.11.1 System Sample Time
According to Shannons theorem, the sample time of the Ball and Hoop
system should be at least two times larger than the highest frequency component of
the system. It was decided to use the bandwidth of the system to calculate the sample
time. Using the file Model_Sample_Time.m (Appendix A.8), the sample time was
calculated to be 0.2635 seconds. This sample time was found to be inadequate as
indicated in Figure 8.8, this is probably due to the motor driving the hoop because
motors generally require a faster sample time. The sample time found using the
bandwidth is only an indicative value and may be changed as long as it obeys
Shannons theorem. The sample time of the system was chosen to be 0.01seconds as
this produces an accurate representation of the system response to a step input as
illustrated in Figure 8.8.



50

Figure 8.7 Graph of Bode Plot of System

Figure 8.8 Step Response of Discrete System using Different Sample Times

51
Continuous Ball and Hoop Transfer Function:
s s s s
s s
s U
s Y
1 . 112 87 . 75 656 . 2 9372 . 0
1 . 206 21 . 46
) (
) (
2 3 4
2
+ + +
+

Discrete Ball and Hoop Transfer Function (Using ZOH):
9721 . 0 936 . 2 964 . 2
002382 . 0 0001215 . 0 002477 . 0
) (
) (
2 3
2
+
+

z z z
z z
z U
z Y

Converting to the form of
1
z :
3 2 1
3 2 1
1
1
9721 . 0 936 . 2 964 . 2 1
002382 . 0 0001215 . 0 002477 . 0
) (
) (

+
+

z z
z z z
z U
z Y

y(k) - 2.964y(k-1) + 2.936y(k-2) 0.9721y(k- 3) = 0.002477u(k-1) + 0.0001215u(k-2) 0.02382u(k-3)

y(k) = 2.964y(k-1) - 2.936y(k-2) + 0.9721y(k - 3) + 0.002477u(k-1) + 0.0001215u(k-2) 0.02382u(k-3)

) ( ) ( k X k y
T


[ ]
1
1
1
1
1
1
1
]
1


002382 . 0
0001215 . 0
002477 . 0
9721 . 0
936 . 2
964 . 2
) 3 ( ) 2 ( ) 1 ( ) 3 ( ) 2 ( ) 1 ( ) ( k u k u k u k y k y k y k y (8.11)
The regression vector,
T
X , is an input into the RLS estimator. U and Y are the
inputs and outputs of the system, respectively. The (k-1) etc. terms represent the
various time slots e.g. y(k-2) is the output two sample times ago. In order to achieve
the appropriate delays in Simulink a unit delay block will be inserted as required. The
RLS Simulink file should take the form of the diagram illustrated in Figure 8.9.
The RLS estimator requires a minimum of three inputs. The first input is the
number of parameters to be identified, the second is the forgetting factor and the final
input is the sample time of the system.
52

Figure 8.9 Simulink Illustration of RLS Set-up

In this project, the quick convergence of the RLS algorithm to the system
parameters is essential. To assist this, two additional inputs were added to the RLS S-
function. The two extra inputs are the initial covariance matrix P(0) and the initial
parameter estimate ) 0 ( . The initial parameter estimate will be the same as was
derived in (8.12) and because ) 0 ( can be presumed accurate the covariance matrix
will be initialised small.
1
1
1
1
1
1
1
1
]
1

002382 . 0
0001215 . 0
002477 . 0
9721 . 0
936 . 2
964 . 2
) 0 (
1
1
1
1
1
1
1
1
]
1

10 0 0 0 0 0
0 10 0 0 0 0
0 0 10 0 0 0
0 0 0 10 0 0
0 0 0 0 10 0
0 0 0 0 0 10
) 0 ( P
Equation 8.12 Initial Parameter and Covariance matrix
When writing an S-Function a mandatory four inputs are required. These are:
T - The Current Time
X - The Current State Vector
U- The Input Vector
Flag - The current value of the FLAG
53
These four inputs are taken care of internally by Simulink and require no user
interaction. Any additional inputs must be coded and specified by the user.
When using the RLS.m S-Function (Appendix A1.7), five inputs are requested from
the user:
n - number of parameters,
theta_init - initial parameter estimates,
P_init - initial covariance matrix,
lambda - forgetting factor,
samp_t - sampling interval.

These additional inputs must be specified in the s-function dialogue box as
illustrated in Figure 8.10.
The initialisation of the S-Function RLS.m is as depicted in Figure 8.10
Figure 8.10 Initialisation of the S-Function RLS.m

8.12 Analysing the Effect of the Initial Parameter Estimate
If the RLS estimator were designed without the inclusion of the initial
parameter estimate option, the estimator would still work as shown in Figure 8.11.
However, the preliminary values of the RLS estimates are largely inaccurate and if
54
these estimates were requested by the genetic algorithm at an early stage, the
estimated system would turn out to be largely inaccurate and result in an inadequate
controller being designed by the GA.
Because of the large error, it is vital that the parameter estimates are initialised
to the values derived in Equation (8.11). Figure 8.11 shows the RLS estimator
response when the initial parameter estimates have been set to these values. At first
glance, there seems to be a lot of agitation before the estimates converge to their final
values but when the amplitude of the estimations is observed it can be seen that the
estimates are only varying minutely. If these estimates were requested at an early
stage of the RLS algorithm, the estimated system would be highly accurate and the
controller designed by the genetic algorithm would perform adequately.

Figure 8.11 RLS Estimates with ) 0 (

Initialised to Zero

55

Figure 8.12 RLS Estimates with ) 0 (

Initialised to their Derived Values



8.13 Testing the RLS estimator on the Ball and Hoop Apparatus
The RLS estimator s-function, rls.m, was tested on the ball and hoop rig to establish if
it would function correctly. The file used is described in Figure 8.13.

56
Figure 8.13 RLS Estimator Simulink file for Ball and Hoop Rig

The RLS estimator was initialised as described in Figure 8.10. The resulting output
was as shown in Figure 8.14. It is obvious that the RLS estimator did not perform as
desired as it converged to the wrong parameter estimates. The RLS estimator was
tested again with different sized covariance matrices but the system never converged
to the correct values.
All of the estimates in Figure 8.14 show noise like qualities when they reach a steady
state value. This is most likely caused be the chipped paint on the ball and hoop rig
making the ball to vibrate as the hoop rotates. When trying to estimate coefficients
that have values to six decimal places, this noise could have a substantial effect on the
overall accuracy. Analysing the denominator coefficients, which are of magnitude 1-
3, the estimates are still incorrect and indicate that the RLS estimator doesnt function
correctly in conjunction with the physical ball and hoop rig.
As a result of this, it is infeasible to perform the online tuning on the ball and hoop rig
and the remainder of this project shall be carried out in simulation only.

57
Figure 8.14 RLS estimator working on the Ball and Hoop system




.














58
9.0 Online Genetic Algorithm
9.1 Choosing the Discrete Transfer Function
The RLS estimator estimates the coefficients of the discrete transfer function
of the ball and hoop system. Initially, it was decided to take the discrete estimated
system, perform a discrete to continuous transformation and then execute a genetic
algorithm similar to the one described in Initial_PID_GA.m to find the ideal PID
values of the system.
However, there was one major problem encountered with this approach; when
performing the discrete to continuous transformation, the resulting continuous
system was discovered to be different than the derived continuous ball and hoop
system.

Figure 9.1 Illustration of C2D and D2C Irregularity using Zero-Order Hold

After experimentation, it was found that if a continuous system is transformed
into the discrete domain using zero-order hold in matlab and then immediately
transformed back into the continuous domain using zero-order hold, the two
continuous systems are not the same. It was later established that this irregularity
occurs due to the partial fraction expansion that takes place when transforming a
continuous system into its discrete equivalent using zero-order hold. This partial
fraction expansion doesnt have a unique solution, so when the discrete system is
transformed into the continuous domain, certain assumptions are made by Matlab that
are not the same as the assumptions it made during the continuous to discrete
transformation. Because of this, errors in the coefficients of the continuous transfer
function of the ball and hoop system will occur. These errors make it unfeasible to
proceed using this method and it was decided to create a genetic algorithm that will
evaluate a PID controller for the discrete version of the system.



59
9.2 Creating a Discrete Genetic Algorithm
Creating a genetic algorithm that evaluates the discrete gains of a PID
controller for the discrete ball and hoop transfer function was achieved by extending
the functionality of previous algorithms. The main change introduced was in the
objective function. Now, the continuous PID gains are passed into the objective
function from the genetic algorithm just like before but when the continuous PID
controller transfer function is evaluated, it is converted into its discrete form using the
trapezoidal difference method. This controller is then evaluated using the Mean
Square Error of the step response of the controlled system. This genetic algorithm,
described in Ultimate_GA.m, will return the continuous gains of a PID controller
whose discrete equivalent was used for evaluation, these gains are converted into their
discrete form, again using the trapezoidal difference method to give the optimum
discrete controller evaluated by the genetic algorithm.

9.3 Evaluating the Optimum PID Controller Gains
The genetic algorithm to evaluate the discrete coefficients of a PID controller
will now be used to evaluate the optimum PID gain values for the ball and hoop
system. The genetic algorithms bounds, population and number of generations are set
to large values so that the GA will converge to a set of coefficients that will be the
optimum PID gain values for the ball and hoop system.
The population of the genetic algorithm was set to a value of 3000 with the
variable bounds of each of the three gains of the controller set to 10000 and +10000.
The termination options for the genetic algorithm was set with a maximum generation
termination value of 300 and the number of mutations to take place throughout the
course of the GA was set to 500.
After some considerable time the genetic algorithm, Ultimate_PID_GA.m
(Appendix A.9) and Ultimate_PID_objfun_mse.m (Appendix A.10), evaluated the
continuous PID gain values of:
2.7407
P
K
145.0226
I
K
0208 . 2
D
K
60
Performing a continuous to discrete transformation on a PID controller with
these gain values using the trapezoidal difference method yields the discrete
controller:
1 z
402.1 z 806.9 - z 407.6
) (
2
2

+
z C
PID
(9.1)
The controller in Equation (9.1) produces an output as described in Figure 9.2
when used to control the discrete ball and hoop system for a step input of 0.4.
Figure 9.2 Step Response using the Ultimate PID Controller

From Figure 9.2, it is apparent that this is a well-controlled system, there is a visibly
small over shoot with very well damped oscillations. The steady state characteristics
of the system are:
Rise time = 0.01
Overshoot of = 1.36%
Settling Time = 0.11
From the plot of the convergence of the genetic algorithm to its final values, Figure
9.3, it can be seen that the GA searched a large range of possible combinations for the
P,I and D gains between the bounds of 10000 and 10000.
61
Figure 9.3 Convergence of the Genetic Algorithm to its Final Values

Now that the optimum PID controller values are known, the bounds of the
online genetic algorithm can be reduced to a smaller range of numbers. This will
ensure quick convergence and a reduction in the number of generations necessary for
the algorithm to converge to optimum PID gain values, which in turn will reduce the
overall runtime of the online genetic algorithm.

9.4 Online Genetic Algorithm
It is at this stage in the project that the online genetic algorithm may be
implemented in a simulation environment. A simulink file used to simulate the online
algorithm is depicted in Figure 9.4.
62
Figure 9.4 Simulink file used for On-line Simulations

The majority of the blocks in Figure 9.4 are used as part of the RLS estimation of the
ball and hoop system. The main point to note is that the PID controller is not hard
coded but takes the shape of a variable transfer function i.e. both the numerator,
Discrete_PID_num, and the denominator, Discrete_PID_den, are variables that are
defined by the Genetic Algorithm. This allows the genetic algorithm to update the
gain values of the PID controller instantaneously by just assigning a new value to the
Discrete_PID_num variable.
The main problem with the genetic algorithm, used to tune the controller
online, is its compilation time. The compile time of the algorithm is highly dependent
on the speed of the hardware being used. Considering this, it was decided not to create
a GA that updated the PID controller values every time period (where a time
period is the time it takes for the genetic algorithm to compile). This would cause
incompatibility between different hardware and may cause difficulties when using the
same hardware but the CPU usage varies, as both would cause the compile time of the
GA to vary. If the compile time of the GA exceeded the allotted time-period, then the
controller would not be updated until the next time-period.
63
In order to avoid this problem, the online genetic algorithm is designed to run
in an infinite while loop, this allow the genetic algorithm to constantly reiterate. Once
the genetic algorithm has calculated the optimum PID gain values for the system it
immediately updates the online controller, then gets the most recent estimation of the
plant from the RLS estimator and then performs a the genetic algorithm on the new
plant
Figure 9.5 Overview of On-line Control

9.5 Genetic Algorithm Coding for Online Tuner
This section of the report details the code used in the online genetic algorithm,
Selftuning_RLS_GA.m (Appendix A.11) and its objective function
Selftuning_RLS_GA_OBJFUN.m (Appendix A.12)

9.5.1 Estimating the Plant
The first stage of the online GA is to estimate the plant. This is achieved using the
RLS estimator but this introduces a problem; the RLS estimates arent instantaneous
and wont be available at the start of the program. This problem may be solved in two
ways:
1. Allow a period of time before the main system input is applied. During this
time the only input into the system is the PRBS signal, this will allow the RLS
estimator to estimate the plant and then the GA can proceed on from here.
2. Initiate the PID gain values to the ones derived using the Ziegler-Nichols
tuning method and start the simulation immediately. Add in a delay before the
RLS estimates are read to allow convergence.
64
The RLS estimates are entered into the GA using the To Workspace function in
Simulink. This block saves the RLS output in a matrix format. Getting the most recent
entry into the matrix attains the most recent estimate. Example: The latest entry for
the B0 coefficient into the matrix is acquired by the command:
B0=b0 (max (size (b0)));
In order to avoid the matrices containing the RLS estimates becoming
excessively large and crashing the computer the sample time of the To Workspace
function is enlarged to a value of around 2 seconds.
Once the RLS estimates have been updated and the discrete ball and hoop
transfer function formed, the genetic algorithm is carried out as normal.

9.6 Testing the Genetic Algorithm used for Online Tuning
The testing of the genetic algorithm proved to be very difficult. The GA,
Selftuning_RLS_GA.m, automatically simulates the simulink file described in Figure
9.4. This simulink file has a user-defined runtime, for example 200secs, defined in its
parameter box. The genetic algorithm takes in the parameter estimates and then
performs the genetic algorithm taking a total time of around 15 seconds. During this
15 seconds the simulink file has already completed its simulation due to the fact that
simulink simulations dont run in real time. The genetic algorithm then updates the
PID controller and reads in the parameter estimates, which is a futile exercise as the
simulation has already been terminated. Various methods were experimented with
including the use of if/else statements, trigger blocks and time related variables in the
simulink file to try to overcome this simulation difficulty. None of these methods
proved successful and it was decided to proceed and test the online genetic algorithm
as fully as possible by working around this simulation difficulty.
From the testing of the RLS estimator carried out in section 8.12 it may be
assumed that the RLS s-function performs adequately in a simulation environment.
This section will focus on analysing the PID controllers evaluated by the genetic
algorithm Selftuning_RLS_GA.m
To ensure that the GA tuned controller produces a stable overall system
additional code was added that analysed the stability of the controlled system. The
stability of the system was examined by accessing the magnitude of the real and
imaginary parts of the discrete poles using code similar to that in Figure 9. 5.
65

Figure 9.5 Code used to Analyse the Stability of the Discrete Controlled System

With this code in place, if a controller designed by the genetic algorithm
produces an unstable overall system then it is indicated on the Matlab command
screen.
The genetic algorithm, Selftuning_RLS_GA.m, was iterated one hundred times
to monitor the PID controllers evaluated by the genetic algorithm for the ball and
hoop system. It was discovered that around one in ten GA tuned PID controllers
resulted in an unstable system. (Appendix C.1 shows the command screen output for
the first ten iterations. Note that iteration 4 resulted in an unstable system.)
The fact that the genetic algorithm designs a PID controller that will produce
an unstable system is surprising considering that the GA evaluates functional
controllers for the remainder of the time, as illustrated in Figure 9.6. One possible
reason for this may be found by analysing the initial population of the genetic
algorithm. Theoretically, if the population of the genetic algorithm were initialised to
PID gain values that all produce unstable controllers then it would be difficult for the
algorithm to converge to a stable controller, particularly with this genetic algorithm as
there are only 80 generations produced per population. This limited number of
generations would make it difficult for the GA to converge to a stable controller if the
population is initialised to unstable controllers.


66
Figure 9.6 Step Response Using Controller Evaluated in Iteration 1 of the GA

The population analysed for the fourth iteration of the genetic algorithm to see if any
of the population resulted in a controller that produced a stable system. The code
segment in Figure 9.7 was inserted into the objective function to record the population
that produced stale controllers during the fourth iteration of the genetic algorithm.
Figure 9.7 Code to Record the Population of the Genetic Algorithm

It was discovered that 409 members of the population produced stable
controllers during the unstable fourth iteration (Appendix C.2). This is compared with
435 stable controllers being produced during the first iteration of the genetic
algorithm. The number of stable controllers produced during each iteration of the
genetic algorithm were found to be similar.
67
The cause for the genetic algorithm producing an unstable controller could not
be established. To prevent an unstable controller being implemented by the genetic
algorithm, the code in Figure 9.8 was added.

Figure 9.8 Code to Prevent an Unstable Controller Being Implemented

If a PID controller evaluated by the genetic algorithm was established as being
unstable, the code in Figure 9.8 will disregard the controller and implement the last
stable controller derived by the GA. If the first controller derived by the genetic
algorithm were to be established as being unstable, the Ziegler-Nichols PID gain
values would be implemented instead.
To confirm that this code does work, the genetic algorithm was performed for
4 iterations. The fourth iteration is the one were the GA evaluated controller is
unstable. From Figure 9.9, it can be seen that the PID values for the third and fourth
iteration are the same. This is because the controller evaluated during the fourth
iteration was established as being unstable, the code in Figure 9.8 disregarded this
controller and then implemented the last stable controller, i.e. the controller evaluated
during iteration 3, in its place.


Figure 9.9 Screen-grab of GA Implemented PID Values

68

Figure 9.10 Screen-grab of GA Evaluated PID Values

Adding the extra functionality provided by the code in Figure 9.8 negates the
rational for using genetic algorithms to derive an optimal controller. Genetic
algorithms have been shown to reliably evaluate PID controllers that outperform
standard tuning methods, as shown in section 6.3. The fact that the genetic algorithm
described in Selftuning_RLS_GA.m produces an unstable controller at regular
intervals is more than likely a coding error or a bug in the Genetic Algorithm
Optimisation Toolbox.
The overall testing of the online tuned PID controller was impossible due to
the lack of real-time simulation facilities provided by the Simulink software package.
The testing of the online tuned PID controller on the physical ball and hoop system
was hampered by the RLS estimator not converging to the correct coefficients when
tested on the actual rig. As a result of this conclusive testing of the ball and hoop
system could not be achieved.


















69
10.0 Conclusions
It was established, by comparison of their steady state characteristics that GAs
outperformed standard tuning practices, e.g. Ziegler Nichols, when designing a PID
controller. It was determined that the Mean Square Error (MSE) performance criterion
based objective function produced the most effective PID controllers when compared
with other performance criterion i.e. IAE, ITAE and ISE.
When the transfer function for the hoop was derived experimentally, a
discrepancy was found between the actual output and the simulated output of the hoop
to a step input of 4V. This discrepancy was overcome by adjusting the gain manually
until the two outputs matched. The difference in gains between the simulated and real
system may have occurred due to the misreading of the voltage from the voltmeter.
When the experiments were being carried out the voltage reading on the voltmeter
was constantly changing, a mean value was taken but this leave scope for error that
may emerge in the form of a gain error.
The hoop position, ) (s , is the input to the ball transfer function as shown in
Figure 7.12. The simulated output of the hoop position, ) (s , is a ramp output
whereas the output of ) (s in the physical ball and hoop system is a saw tooth
function. This may account for the difference in outputs between the physical rig and
the simulated system. A function was created that converted the ramp output in the
simulated system into a saw tooth output but this still resulted in a mismatch between
the simulated system and the physical system. Since there is no mention of the
requirement for this function in the ball and hoop manual it was omitted.
The sample time of the system was calculated as 0.2635 sec using the
bandwidth of the system. This was discovered to be too slow a sample time for a ball
and hoop system so a sample time of 0.01 sec was used instead.
The RLS s-function performed well in simulation, accurately predicting the
parameter estimates of the ball and hoop system. When the RLS estimator was
applied to the ball and hoop rig it failed to correctly identify the systems parameters.
One possible reason for this is due to the paint on the hoop being chipped. When the
hoop is rotating, the uneven surface causes the ball to vibrate up and down. This
reduces the force of friction acting on the ball and leads to the difference in predicted
output and actual output.
70
Considering, the error in the hoop transfer function, the failure of the RLS
estimator to function correctly when used with the physical rig and the difference in
outputs between the physical ball and hoop system and the simulated one, it may be
concluded that the derived transfer function of the ball and hoop system may be
somewhat erroneous. If this is true, there are two possible explanations:
1. The transfer functions/descriptions of experiments in the manual are wrong.
2. The experiments undertaken to derive the various parameters produces false
results.
The testing of an online tuned PID controller for the ball and hoop system in
simulation proved to be difficult due to the lack of real-time simulation facilities in
Simulink. The individual components of the online tuned controller were tested to
evaluate if the overall controller was effective.
When testing the genetic algorithm component, it was discovered to frequently
produce controllers that made the overall controlled system unstable. The exact cause
for this could not be determined. To rectify this problem, the genetic algorithm was
modified so it would analyze the controller it evaluates. If the controller produces an
unstable system, it is replaced with the last stable controller evaluated by the genetic
algorithm.
The genetic algorithm online tuned PID controller proved to be a capable
controller. Adequate testing of the controller could not be performed due to the
simulation difficulties mentioned previously.
Recommendations for a continuation of this project would include; designing a
more robust RLS estimator that will estimate any system and does not have to be
manually tailored to the system it is estimating. Test the genetic algorithm used to
tune the PID controller online i.e. Selftuning_RLS_GA.m using a different toolbox
than GAOT. This will evaluate if it is the GAOT toolbox that is causing the genetic
algorithm to produce controllers that make the overall system unstable.






71
11.0 References
[1] O Mahony, T., Downing,C.J. and Klaudiuz, F., Genetic Algorithms for PID
Parameter Optimisation: Minimising Error Criteria, [online], URL:
http://www.pwr.wroc.pl/~i-8zas/kf_glas00.pdf

[2] Linkens, D.A., & H.O. Nyongesa, Genetic algorithms for fuzzy control, IEE
Proc. Control Theory Appl., Vol. 142, No. 3, pp.161-185

[3] Online, Ball and Hoop White Paper, URL: http://www.control-systems-
principles.co.uk

[4] Whitley, A Genetic Algorithm Tutorial, Technical Report CS-93-103, Dept. of
Computer Science, Colorado State University, 1993

[5] D. E. Goldberg, Genetic Algorithms in Search, Optimization, and Machine
Learning, Addison-Wesley Publishing Co., Inc., 1989

[6] C. R. Houck, J. Joines. and M.Kay. A genetic algotithm for function
optimisation: A Matlab implementation. ACM Transactions on Mathematical
Software, 1996, [Online], URL:
http://www.eos.ncsu.edu/eos/service/ie/research/kay_res/GAToolBox/gaot

[7] G.J. Battaglia and J.M. Maynard, Mean square Error: A Useful Tool for
Statistical Process Management,AMP J. Technol. 2, 47-55 (1992).

[8] SELF TUNING SYSTEMS Control and Signal Processing, P.E. Wellstead
and M.B Zarrop (Publishers(WILEY))1991 pp 140-150

[9] Online, URL:
http://www.mathworks.com/access/helpdesk_r12p1/help/pdf_doc/simulink/sfu
nctions.pdf

[3] Online, URL: www-ccec.ece.ucsb.edu/people/smith/classnotes/147b/part4.ps
72








Appendix A



Matlab Script and Function
Files

















73
Appendix A.1 Initial_PID_GA.m
%Initial_PID_GA.m
%Written by Ian Griffin July 2003
%Last Modified 20-08-03
%____________________________________________________________________
clc
clear
close all
global sys_controlled
global time
global sysrl
%____________________________________________________________________
%Defining sysrl
den1=[1 6 11 6 0];
num1=[1];
sysrl=tf(num1,den1);
%____________________________________________________________________
%Initialising the genetic algorithm
populationSize=80;
variableBounds=[-100 100;-100 100;-100 100];
evalFN='PID_objfun_MSE';
%Change this to relevant object function
evalOps=[];
options=[1e-6 1];
initPop=initializega(populationSize,variableBounds,evalFN,...
evalOps,options);
%____________________________________________________________________
%Setting the parameters for the genetic algorithm
bounds=[-100 100;-100 100;-100 100];
evalFN='PID_objfun_MSE';%change this to relevant object function
evalOps=[];
startPop=initPop;
opts=[1e-6 1 0];
termFN='maxGenTerm';
termOps=100;
selectFN='normGeomSelect';
selectOps=0.08;
xOverFNs='arithXover';
xOverOps=4;
mutFNs='unifMutation';
mutOps=8;
%____________________________________________________________________
%Iterating the genetic algorithm
[x,endPop,bPop,traceInfo]=ga(bounds,evalFN,evalOps,startPop,opts,...
termFN,termOps,selectFN,selectOps,xOverFNs,xOverOps,mutFNs,mutOps);
%____________________________________________________________________
%Plotting Genetic algorithm controller Vs Root locus controller
den1=[1 6 11 6 0];
num1=[1];
sysrl=tf(num1,den1);

%Transfer function of the Root Locus PID controller
den_pid=[1 0];
num_pid=[4.74 6 1.91]; %Kd Kp Ki
rl_pid=tf(num_pid,den_pid);

%Placing PID controller in unity feedback system with 'sysrl'
sys1=series(rl_pid,sysrl);
rl_sys=feedback(sys1,[1]);

74
%Creating the optimal PID controller from GA results
ga_pid=tf([x(1) x(2) x(3)],[1 0]);
ga_sys=feedback(series(ga_pid,sysrl),1);
figure(1)
hold on;
step(ga_sys,time,'g');%Green-genetic algorithm
step(time,rl_sys,'r');%Red-Root locus
legend('ZN Controlled Sys','GA Controlled Sys',0);
%____________________________________________________________________
%Printing to screen the PID values and
%comparing them to the Zeigler Nichols values

disp(' Kd Kp Ki');
disp('Z-N: 4.74 6 1.91');
disp( x );
%____________________________________________________________________
%Plotting best population progress
figure(2)
subplot(3,1,1),plot(bPop(:,1),bPop(:,3)),...
title('Kp Value'),, ylabel('Gain');
subplot(3,1,2),plot(bPop(:,1),bPop(:,4)),...
title('Ki Value'),, ylabel('Gain');
subplot(3,1,3),plot(bPop(:,1),bPop(:,2)),...
title('Kd Value'),xlabel('Generations'), ylabel('Gain');
%____________________________________________________________________


Appendix A.2 PID_objfun_ITAE.m
%PID_objfun_ITAE.m
%Written by Ian Griffin July 2003
%Last Modified 20-08-03
%____________________________________________________________________
function [x_pop, fx_val]=PID_objfun_ITAE(x_pop,options)
global sys_controlled
global time
global sysrl
%____________________________________________________________________
Kp=x_pop(2);
Ki=x_pop(3);
Kd=x_pop(1);

%Creating the PID controller from current values
pid_den=[1 0];
pid_num=[Kd Kp Ki];
pid_sys=tf(pid_num,pid_den); %overall PID controller

%Creating PID feedback loop
sys_series=series(pid_sys,sysrl);
sys_controlled=feedback(sys_series,1);
%____________________________________________________________________
time =0:0.1:30;
[y t] = step(sys_controlled,time); % Step response of closed-loop
system

for i=1:301
error(i) = (abs(1-y(i)))*t(i);
end
%Integral of Squared Error
ITAE=sum(error);
75
%____________________________________________________________________
%to make sure controlled system is stable
poles=pole(sys_controlled);
if poles(1)>0
ITAE=100e300;
elseif poles(2)>0
ITAE=100e300;
elseif poles(3)>0
ITAE=100e300;
elseif poles(4)>0
ITAE=100e300;
elseif poles(5)>0
ITAE=100e300;
end
fx_val=1/ITAE;
%____________________________________________________________________


Appendix A.3 PID_objfun_IAE.m
%PID_objfun_IAE.m
%Written by Ian Griffin July 2003
%Last Modified 20-08-03
%____________________________________________________________________
function [x_pop, fx_val]=PID_objfun_IAE(x_pop,options)
global sys_controlled
global time
global sysrl
%____________________________________________________________________
Kp=x_pop(2);
Ki=x_pop(3);
Kd=x_pop(1);

%Creating the PID controller from current values
pid_den=[1 0];
pid_num=[Kd Kp Ki];
pid_sys=tf(pid_num,pid_den); %overall PID controller

%Creating PID feedback loop
sys_series=series(pid_sys,sysrl);
sys_controlled=feedback(sys_series,1);

time =0:0.1:30;
[y t] = step(sys_controlled,time); % Step response of closed-loop
system
%____________________________________________________________________
for i=1:301
error(i) = 1-y(i);
end
IAE=sum(abs(error));%Integral of absolute error
%____________________________________________________________________
%to make sure controlled system is stable
poles=pole(sys_controlled);
if poles(1)>0
IAE=100e300;
elseif poles(2)>0
IAE=100e300;
elseif poles(3)>0
IAE=100e300;
elseif poles(4)>0
76
IAE=100e300;
elseif poles(5)>0
IAE=100e300;
end
fx_val=1/IAE;
%____________________________________________________________________


Appendix A.4 PID_objfun_ISE.m
%PID_objfun_ISE.m
%Written by Ian Griffin July 2003
%Last Modified 20-08-03
%____________________________________________________________________
function [x_pop, fx_val]=PID_objfun_ISE(x_pop,options)
global sys_controlled
global time
global sysrl
%____________________________________________________________________
Kp=x_pop(2);
Ki=x_pop(3);
Kd=x_pop(1);

%Creating the PID controller from current values
pid_den=[1 0];
pid_num=[Kd Kp Ki];
pid_sys=tf(pid_num,pid_den); %overall PID controller

%Creating PID feedback loop
sys_series=series(pid_sys,sysrl);
sys_controlled=feedback(sys_series,1);
%____________________________________________________________________
time =0:0.1:30;
[y t] = step(sys_controlled,time); % Step response of closed-loop
system

for i=1:301
error(i) = 1-y(i);
end

error=error*error';
ISE=sum(error); %Integral of Squared Error
%____________________________________________________________________
%to make sure controlled system is stable
poles=pole(sys_controlled);
if poles(1)>0
ISE=100e300;
elseif poles(2)>0
ISE=100e300;
elseif poles(3)>0
ISE=100e300;
elseif poles(4)>0
ISE=100e300;
elseif poles(5)>0
ISE=100e300;
end
fx_val=1/ISE;
%____________________________________________________________________
77
Appendix A.5 PID_objfun_mse.m
%Initial_PID_objfun_MSE.m
%Written by Ian Griffin July 2003
%Last Modified 20-08-03
%____________________________________________________________________
function [x_pop, fx_val]=PID_objfun_MSE(x_pop,options)
global sys_controlled
global time
global sysrl
%____________________________________________________________________
Kp=x_pop(2);
Ki=x_pop(3);
Kd=x_pop(1);
%____________________________________________________________________
%creating the PID controller from current values
pid_den=[1 0];
pid_num=[Kd Kp Ki];
pid_sys=tf(pid_num,pid_den); %overall PID controller

%Placing PID controller in unity feedback system with 'sysrl'
sys_series=series(pid_sys,sysrl);
sys_controlled=feedback(sys_series,1);
%____________________________________________________________________
time =0:0.1:30;
[y t] = step(sys_controlled,time); % Step response of closed-loop
system
%____________________________________________________________________
%Calculating the error
for i=1:301
error(i) = 1-y(i);
end

%Calculating the MSE
error_sq = error*error';
MSE=error_sq/max(size(error));
%____________________________________________________________________
%Ensuring controlled system is stable
poles=pole(sys_controlled);
if poles(1)>0
MSE=100e300;
elseif poles(2)>0
MSE=100e300;
elseif poles(3)>0
MSE=100e300;
elseif poles(4)>0
MSE=100e300;
elseif poles(5)>0
MSE=100e300;
end
fx_val=1/MSE;
%____________________________________________________________________







78
Appendix A.6 m_prbs.m
%Initial_PID_objfun_MSE.m
%Written by Ian Griffin July 2003
%Last Modified 29-07-03
%____________________________________________________________________
function y=prbs(u)
%This prbs file is used to provide a small noise signal to the system
%so that the RLS estimator values may be calculated.

if u<.5
y=-.01;
else y=.01;
end



Appendix A.7 rls.m
%Initial_PID_objfun_MSE.m
%Written by Ian Griffin July 2003
%Last Modified 20-08-03
%____________________________________________________________________
function[sys,x0,str,ts]=...
rls(t,x,u,flag,n,theta_init,P_init,lambda,samp_t)
% RLS S-function
% Discrete-time recursive least-squares estimator
% for the Ball and Hoop system
%
% y = x'*theta
%
% Inputs:
% phi - regressor vector,
% y - output.
% Outputs:
% theta - parameter vector,
% P - covariance matrix.
% Parameters:
% n - number of parameters,
% theta_init - initial parameter estimates,
% P_init - initial covariance matrix,
% lambda - forgetting factor,
% samp_t - sampling interval.
%____________________________________________________________________
switch flag,

%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts] = mdlInitializeSizes(n,theta_init,P_init,samp_t);

%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys = mdlUpdate(x,u,n,lambda);

%%%%%%%%%%
% Output %
%%%%%%%%%%
79
case 3,
sys = mdlOutputs(x,n);

%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
sys = [];
end

%____________________________________________________________________
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-
function.
%____________________________________________________________________
function [sys,x0,str,ts] =
mdlInitializeSizes(n,theta_init,P_init,samp_t)


sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = n+n^2;
sizes.NumOutputs = n;
sizes.NumInputs = n+1;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;

sys = simsizes(sizes);

x0 = mdlPack(theta_init,P_init,n);
str = [];
ts = [samp_t 0];

%____________________________________________________________________
% mdlUpdate
% Update theta and P
%____________________________________________________________________
function sys = mdlUpdate(x,u,n,lambda)

% unpack theta,P, phi, and y
[theta,P] = mdlUnpack(x,n);
phi = u(1:n);
y = u(n+1);

% compute new estimate and update covariance matrix
K = P*phi/(lambda + phi'*P*phi);
new_theta = theta + K*(y - phi'*theta);
new_P = (eye(n) - K*phi')*P/lambda;
new_P = (new_P + new_P')/2;

% repack theta and P in x
x = mdlPack(new_theta,new_P,n);

sys = x;



%____________________________________________________________________
% mdlOutputs
% Return theta and P
%____________________________________________________________________
80
function sys = mdlOutputs(x,n)
sys=x(1:n);
sys=sys(:);

%____________________________________________________________________
% mdlPack
% Pack theta and P in x
%____________________________________________________________________
function x = mdlPack(theta,P,n)

P_vec = [];
for j = 1:n
P_vec = [P_vec;P(:,j)];
end
x = [theta;P_vec];


%____________________________________________________________________
% mdlUnpack
% Unpack theta and P from x
%____________________________________________________________________
function [theta,P] = mdlUnpack(x,n)

theta = x(1:n,1);
P = [];
for j = 1:n
P = [P,x(j*n+1:(j+1)*n,1)];
End
%____________________________________________________________________



Appendix A.8 Model_Sample_Time.m
sys_hoop1=tf([1.63],[.66 1]);
H=tf([67.5],[1 0]);
sys_ball=tf([.42 1.873 0],[1.42 1.873 112.11]);
sys_hoop=series(sys_hoop1,H);
Ball_Hoop=series(sys_hoop,sys_ball);
sys=feedback(Ball_Hoop,1);
t=0:.01:50;
figure(1)
plot(t,nb_out,'r');
hold on;
[y,t]=step(sys,t);
plot(t,y)

%Finding the sample time using bandwidth
figure(2)
bode(Ball_Hoop);
[mag,phase,w]=bode(Ball_Hoop);
mag_db=20*log10(mag);
ind_wb=min(find(mag_db<=mag_db(1)-3));
wb=w(ind_wb);
ws=10*wb;
ts=(2*pi)/ws

rlocus(Ball_Hoop);
81
Appendix A.9 Ultimate_PID_GA.m

%Ultimate_PID_GA.m
%Written by Ian Griffin July 2003
%Last Modified 20-08-03
%____________________________________________________________________
clc
clear
close all
%global sys_controlled
%global time
global Ball_Hoop_d
rand('state',0);
%____________________________________________________________________
%Defining the ball and hoop system
hoop=tf([1.63],[.66 1]);
H=tf([67.5],[1 0]);
sys_ball=tf([.42 1.873 0],[1.42 1.873 112.11]);
sys_hoop=series(hoop,H);
Ball_Hoop=series(sys_hoop,sys_ball);
Ball_Hoop_d=c2d(Ball_Hoop,.01,'zoh');
%____________________________________________________________________
%Initialising the genetic algorithm
populationSize=3000;
variableBounds=[-10000 10000;-10000 10000;-10000 10000];
evalFN='Ultimate_PID_objfun_mse';%Change this to relevant object
function
evalOps=[];
options=[1e-6 1];
initPop=initializega(populationSize,variableBounds,evalFN,evalOps,opt
ions);
%____________________________________________________________________
%Setting the parameters for the genetic algorithm
bounds=[-10000 10000;-10000 10000;-10000 10000];
evalFN='Ultimate_PID_objfun_mse';%change this to relevant object
function
evalOps=[];
startPop=initPop;
opts=[1e-6 1 0];
termFN='maxGenTerm';
termOps=300;
selectFN='normGeomSelect';
selectOps=0.08;
xOverFNs='arithXover';
xOverOps=4;
mutFNs='unifMutation';
mutOps=500;
%____________________________________________________________________
%Iterating the genetic algorithm
[x,endPop,bPop,traceInfo]=ga(bounds,evalFN,evalOps,startPop,opts,...

termFN,termOps,selectFN,selectOps,xOverFNs,xOverOps,mutFNs,mutOps);
%____________________________________________________________________
%Generating the Continuous PID Controller
den_pid=[1 0];
num_pid=[x(1) x(2) x(3)]; %Kd Kp Ki
sys_pid=tf(num_pid,den_pid);

%Discretizing the Continuous PID Controller
disp('PID controller')
82
sysd_pid=c2d(sys_pid,.01,'tustin')
%____________________________________________________________________
%Creating the controlled System
sys_controlled=feedback(series(sysd_pid,Ball_Hoop_d),1);
figure(1)
time =0:0.01:10;
u=.4*ones(size(time));
lsim(sys_controlled,u,time);
%____________________________________________________________________
%Printing to screen the PID values
%x
disp('_________________________________')
disp('| PID GAIN VALUES |')
disp('|________________________________|')
disp('| Kd Kp Ki |');
disp([x(1) x(2) x(3)]);
disp('|________________________________|')
%____________________________________________________________________
%Printing to screen the PID values
%x
%disp(' Kd Kp Ki');
%disp('ZN: 4.74 6 1.91');
%disp( x );
%____________________________________________________________________
%Plotting best population progress
figure(2)
subplot(3,1,1),plot(bPop(:,1),bPop(:,3)),...
title('Kp Value'),, ylabel('Gain');
subplot(3,1,2),plot(bPop(:,1),bPop(:,4)),...
title('Ki Value'),, ylabel('Gain');
subplot(3,1,3),plot(bPop(:,1),bPop(:,2)),...
title('Kd Value'),xlabel('Generations'), ylabel('Gain');
%____________________________________________________________________
%Informing user if the system is unstable
poles=pole(sys_controlled);
if abs(real(poles(1)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 1%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('REAL POLE VALUE')
disp(poles(1))
elseif abs(imag(poles(1)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 1%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('IMAGINARY POLE VALUE')
disp(poles(1))
elseif abs(real(poles(2)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 2%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('REAL POLE VALUE')
disp(poles(2))
elseif abs(imag(poles(2)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 2%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('IMAGINARY POLE VALUE')
disp(poles(2))
elseif abs(real(poles(3)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
83
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 3%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('REAL POLE VALUE')
disp(poles(3))
elseif abs(imag(poles(3)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 3%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('IMAGINARY POLE VALUE')
disp(poles(3))
elseif abs(real(poles(4)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 4%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('REAL POLE VALUE')
disp(poles(4))
elseif abs(imag(poles(4)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 4%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('IMAGINARY POLE VALUE')
disp(poles(4))
elseif abs(real(poles(5)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 5%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('REAL POLE VALUE')
disp(poles(5))
elseif abs(imag(poles(5)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 5%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('IMAGINARY POLE VALUE')
disp(poles(5))
elseif abs(imag(poles))<1
disp('This system is stable');
elseif abs(real(poles))<1
disp('This system is stable');
end
%____________________________________________________________________



Appendix A.10 Ultimate_PID_objfun_mse.m

%Ultimate_PID_objfun_mse.m
%Written by Ian Griffin July 2003
%Last Modified 20-08-03
%____________________________________________________________________
function [x_pop, fx_val]=Ultimate_PID_objfun_mse(x_pop,options)
%global sys_controlled
global time
global Ball_Hoop_d

Kp=x_pop(2);
Ki=x_pop(3);
Kd=x_pop(1);

%creating the PID controller from current values
pid_den=[1 0];
84
pid_num=[Kd Kp Ki];
pid_sys=tf(pid_num,pid_den); %overall PID controller

%discretising the pid controller
pid_sysd=c2d(pid_sys,.01,'tustin');

%Placing discrete PID controller in unity feedback system with
'sysrl'
sys_series=pid_sysd*Ball_Hoop_d;%series(pid_sys,Ball_Hoop_rls);
sys_controlled=feedback(sys_series,1);

time =0:0.01:8;
u=.4*ones(size(time));
[y t] = lsim(sys_controlled,u,time); % Step response of closed-
loop system to
% an input of 0.4.
for i=1:801
error(i) = 0.4-y(i);
end

error_sq = error*error';
MSE=error_sq/max(size(error));
%____________________________________________________________________
%Making sure overall system is stable
poles=pole(sys_controlled);
if abs(real(poles(1)))>1
MSE=100e306;
elseif abs(imag(poles(1)))>1
MSE=100e306;
elseif abs(real(poles(2)))>1
MSE=100e306;
elseif abs(imag(poles(2)))>1
MSE=100e306;
elseif abs(real(poles(3)))>1
MSE=100e306;
elseif abs(imag(poles(3)))>1
MSE=100e306;
elseif abs(real(poles(4)))>1
MSE=100e306;
elseif abs(imag(poles(4)))>1
MSE=100e306;
elseif abs(real(poles(5)))>1
MSE=100e306;
elseif abs(imag(poles(5)))>1
MSE=100e306;
end

fx_val=1/MSE;
%____________________________________________________________________












85
Appendix A.11 Selftuning_RLS_GA.m
%Selftuning_RLS_GA.m
%Written by Ian Griffin July 2003
%Last Modified 20-08-03
%____________________________________________________________________
clc
clear
global sys_controlled
global time
global Ball_Hoop
global u
global time
global Ball_Hoop_rls
global z%remove
global ROW
global observe_pop
ROW=1;
close all
last_stable=1;
rand('state',0);%keeps using the same initial values
%____________________________________________________________________
%Initalising the PID parameters to ones found in root locus as a
backup
%incase the GA doesn't compile before the step signal initiates.
Discrete_PID_num=[12.97 -23.96 11.07];
Discrete_PID_den=[1 0 -1];
%____________________________________________________________________
%Simulating the Adaptive_GA_RLS_rls simulink file
sim('Adaptive_GA_RLS_rls');
%____________________________________________________________________
%Creating a while loop so the Genetic Algorithm will compute PID
gains indefinately
z=1;
while z<5
sys_unstable=0;
%if z==2
% co=100;
%elseif z==4
%co=50;
%end
%____________________________________________________________________
%Displaying the Iteration number on screen
disp('ITERATION')
disp(z)
%____________________________________________________________________
%Getting the most recent estimates from the RLS estimator
B0=b0(max(size(b0)));
B1=b1(max(size(b1)));
B2=b2(max(size(b2)));
A1=a1(max(size(a1)));
A2=a2(max(size(a2)));
A3=a3(max(size(a3)));
%____________________________________________________________________
%Discrete Ball and Hoop system from RLS estimates
rls_discrete_num=[B0 B1 B2];
rls_discrete_den=[1 -A1 -A2 -A3]; %Multiplying by a minus to make
signs match
disp('RLS Estimation Of Plant')
Ball_Hoop_rls=tf(rls_discrete_num,rls_discrete_den,.01)
disp('')
86
%rls_continuous_tf=d2c(rls_discrete_tf)
%____________________________________________________________________
%Initialising the genetic algorithm
populationSize=30;
variableBounds=[-5 10;-5 10;100 200];
evalFN='Selftuning_RLS_GA_OBJFUN';%Change this to relevant object
function
evalOps=[];
options=[1e-6 1];
initPop=initializega(populationSize,variableBounds,evalFN,evalOps,opt
ions);
%____________________________________________________________________
%Setting the parameters for the genetic algorithm
bounds=[-5 10;-5 10;100 200];
evalFN='Selftuning_RLS_GA_OBJFUN';%change this to relevant object
function
evalOps=[];
startPop=initPop;
opts=[1e-6 1 0];
termFN='maxGenTerm';
termOps=80;
selectFN='normGeomSelect';
selectOps=0.08;
xOverFNs='arithXover';
xOverOps=4;
mutFNs='unifMutation';
mutOps=2;%one thousanth of the (population size x maxGenTerm)
%____________________________________________________________________
%Iterating the genetic algorithm
[x,endPop,bPop,traceInfo]=ga(bounds,evalFN,evalOps,startPop,opts,...

termFN,termOps,selectFN,selectOps,xOverFNs,xOverOps,mutFNs,mutOps);
%____________________________________________________________________
%Printing to screen the PID values
%x
disp('_________________________________')
disp('| PID GAIN VALUES |')
disp('|________________________________|')
disp('| Kd Kp Ki |');
disp([x(1) x(2) x(3)]);
disp('|________________________________|')
%____________________________________________________________________
%Plotting best population progress
figure(z)
subplot(3,1,1),plot(bPop(:,1),bPop(:,3)),...
title('Kp Value'),, ylabel('Gain');
subplot(3,1,2),plot(bPop(:,1),bPop(:,4)),...
title('Ki Value'),, ylabel('Gain');
subplot(3,1,3),plot(bPop(:,1),bPop(:,2)),...
title('Kd Value'),xlabel('Generations'), ylabel('Gain');
%____________________________________________________________________
%Generating the Continuous PID Controller
den_pid=[1 0];
num_pid=[x(1) x(2) x(3)]; %Kd Kp Ki
sys_pid=tf(num_pid,den_pid);

%Discretizing the Continuous PID Controller
disp('PID controller')
sysd_pid=c2d(sys_pid,.01,'tustin')

%Getting the Numerator from the Discrete PID Controller
87
[Discrete_PID_num,Discrete_PID_den]=tfdata(sysd_pid,'v');

%PID Controlled System using genetic algorithm results
controlled_sys=feedback(series(sysd_pid,Ball_Hoop_rls),1);
%lsim(sys_controlled,u,time);%Plot of new PID controller
%____________________________________________________________________
%Informing user if the system is unstable
poles=pole(sys_controlled);
if abs(real(poles(1)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 1%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('REAL POLE VALUE')
disp(poles(1));
sys_unstable=1;
%break
elseif abs(imag(poles(1)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 1%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('IMAGINARY POLE VALUE')
disp(poles(1))
sys_unstable=1;
%break
elseif abs(real(poles(2)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 2%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('REAL POLE VALUE')
disp(poles(2))
sys_unstable=1;
%break
elseif abs(imag(poles(2)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 2%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('IMAGINARY POLE VALUE')
disp(poles(2))
sys_unstable=1;
%break
elseif abs(real(poles(3)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 3%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('REAL POLE VALUE')
disp(poles(3))
sys_unstable=1;
%break
elseif abs(imag(poles(3)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 3%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('IMAGINARY POLE VALUE')
disp(poles(3))
sys_unstable=1;
%break
elseif abs(real(poles(4)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 4%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('REAL POLE VALUE')
88
disp(poles(4))
sys_unstable=1;
%break
elseif abs(imag(poles(4)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 4%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('IMAGINARY POLE VALUE')
disp(poles(4))
sys_unstable=1;
%break
elseif abs(real(poles(5)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 5%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('REAL POLE VALUE')
disp(poles(5))
sys_unstable=1;
%break
elseif abs(imag(poles(5)))>1
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('%THIS SYSTEM IS UNSTABLE DUE TO POLE 5%')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
disp('IMAGINARY POLE VALUE')
disp(poles(5))
sys_unstable=1;
%break
end
%____________________________________________________________________
%creating a matrix to store the PID values
pid_trace(z,:)=x;
%____________________________________________________________________
%if the GA designed system is Unstable use the Last stable controller
if sys_unstable==1
x=pid_trace(last_stable,:);
if z==1
x=Discrete_PID_num;
end
else
last_stable=z;
end
stable_pid_trace(z,:)=x;

%____________________________________________________________________
%Generating the Continuous PID Controller
den_pid=[1 0];
num_pid=[x(1) x(2) x(3)]; %Kd Kp Ki
sys_pid=tf(num_pid,den_pid);

%Discretizing the Continuous PID Controller
disp('PID controller')
sysd_pid=c2d(sys_pid,.01,'tustin')

%Getting the Numerator from the Discrete PID Controller
[Discrete_PID_num,Discrete_PID_den]=tfdata(sysd_pid,'v');

%PID Controlled System using genetic algorithm results
controlled_sys=feedback(series(sysd_pid,Ball_Hoop_rls),1);
%lsim(sys_controlled,u,time);%Plot of new PID controller
%____________________________________________________________________
z=z+1;
89
end

Appendix A.12 Selftuning_RLS_GA_OBJFUN.m
%Selftuning_RLS_GA_OBJFUN.m
%Written by Ian Griffin July 2003
%Last Modified 20-08-03
%____________________________________________________________________
function [x_pop, fx_val]=Selftuning_RLS_GA_OBJFUN(x_pop,options)
global sys_controlled
global time
global Ball_Hoop
global u
global time
global Ball_Hoop_rls
global z
global ROW
global observe_pop

outside_system_limits_flag=0;% flag to ensure control signal is below
1
Kp=x_pop(2);
Ki=x_pop(3);
Kd=x_pop(1);
%____________________________________________________________________
%creating the PID controller from current values
pid_den=[1 0];
pid_num=[Kd Kp Ki];
pid_sys=tf(pid_num,pid_den); %overall PID controller

%discretising the pid controller
pid_sysd=c2d(pid_sys,.01,'tustin');

%Placing discrete PID controller in unity feedback system with
'sysrl'
sys_series=pid_sysd*Ball_Hoop_rls;%series(pid_sys,Ball_Hoop_rls);
sys_controlled=feedback(sys_series,1);
%____________________________________________________________________
time =0:0.01:8;
u=.4*ones(size(time));
[y t] = lsim(sys_controlled,u,time); % Step response of closed-
loop system to
% an input of 0.4.
for i=1:801
error(i) = 0.4-y(i);
if error(i)>1
outside_system_limits_flag=1;
end
end

error_sq = error*error';
MSE=error_sq/max(size(error));
%____________________________________________________________________
%Making sure overall system is stable
poles=pole(sys_controlled);
if abs(real(poles(1)))>1
MSE=100e306;
elseif abs(imag(poles(1)))>1
MSE=100e306;
elseif abs(real(poles(2)))>1
MSE=100e306;
90
elseif abs(imag(poles(2)))>1
MSE=100e306;
elseif abs(real(poles(3)))>1
MSE=100e306;
elseif abs(imag(poles(3)))>1
MSE=100e306;
elseif abs(real(poles(4)))>1
MSE=100e306;
elseif abs(imag(poles(4)))>1
MSE=100e306;
elseif abs(real(poles(5)))>1
MSE=100e306;
elseif abs(imag(poles(5)))>1
MSE=100e306;
elseif outside_system_limits_flag==1
MSE=100e306;
end

fx_val=1/MSE;
%____________________________________________________________________























91




Appendix B



RLS Derivation























92
Appendix B.1 Derivation of Recursive Least Squares
Using least squares, Equation (8.5), as a starting point and defining:
1
1
1
]
1

+
+
) 1 (
....
) (
) 1 (
t x
t X
t X
T
And,
1
1
1
]
1

+
+
) 1 (
...
) (
) 1 (
t t
t y
t y
Gives,
) 1 ( ) 1 ( )] 1 ( ) 1 ( [ ) 1 (

1
+ + + + +

t y t X t X t X t
T T

Where,
) 1 ( ) 1 ( ) ( ) ( ) 1 ( ) 1 ( + + + + + t x t x t X t X t X t X
T T T

) 1 ( ) 1 ( ) ( ) ( ) 1 ( ) 1 ( + + + + + t y t x t y t X t y t X
T T
(B.1)
Defining Shorthand Notation
1
)] ( ) ( [ ) (

t X t X t P
T

) ( ) ( ) ( t y t X t B
T

) 1 ( ) 1 ( ) ( ) 1 (
1 1
+ + + +

t x t x t P t P
T

) 1 ( ) 1 ( ) ( ) 1 ( + + + + t y t x t B t B
Using this shorthand
) ( ) ( ) (

) 1 ( ) 1 ( ) 1 (

t B t P t
t B t P t

+ + +

} (B.2)
In order to directly update P(t) to P(t+1) the Matrix Inversion Lemma must be used.
The Matrix Inversion Lemma is defined as:
1 1 1 1 1 1 1
) ( ) (

+ + DA B DA C B A A BCD A
Assigning
) (
1
t P A

, , 1 C ) 1 ( + t x B , ) 1 ( + t x D
T

Gives
( ) [ ] ) ( ) 1 ( ) 1 ( ) ( ) 1 ( 1 ) 1 ( ) ( ) 1 (
1
t P t x t x t P t x t x I t P t P
T T
m
+ + + + + +

(B.3)
Using Equation (B.3), it is possible to update from P(t) to P(t+1) without inverting a
matrix. The only term that needs to be inverted is a scalar.
Defining the error, , as:
93
) (

) 1 ( ) 1 ( ) 1 ( t t x t y t
T
+ + +
And substituting for y(t+1) into Equation (B.1) gives:
) 1 ( ) 1 ( ) (

) 1 ( ) 1 ( ) ( ) 1 ( + + + + + + + t t x t t x t x t B t B
T

Substituting for ) 1 ( ), ( + t B t B using Equations (8.7) gives:
) 1 ( ) 1 ( ) 1 ( ) (

) 1 (

+ + + + + t t x t P t t



























94



Appendix C



Genetic Algorithm Tuned Controller
Results

















95
Appendix C.1 First Ten GA Results

ITERATION
1

_________________________________
| PID GAIN VALUES |
|________________________________|
| Kd Kp Ki |
1.8869 2.6542 136.9328

|________________________________|
PID controller

Transfer function:
380.7 z^2 - 753.4 z + 375.4
---------------------------
z^2 - 1

Sampling time: 0.01
ITERATION
2

_________________________________
| PID GAIN VALUES |
|________________________________|
| Kd Kp Ki |
2.0278 2.4886 149.9009

|________________________________|
PID controller

Transfer function:
408.8 z^2 - 809.6 z + 403.8
---------------------------
z^2 - 1

Sampling time: 0.01
ITERATION
3

_________________________________
| PID GAIN VALUES |
|________________________________|
| Kd Kp Ki |
2.0352 2.7816 149.6656

|________________________________|
PID controller

Transfer function:
410.6 z^2 - 812.6 z + 405
-------------------------
z^2 - 1

Sampling time: 0.01
ITERATION
4

_________________________________
96
| PID GAIN VALUES |
|________________________________|
| Kd Kp Ki |
2.0039 2.7325 147.9990

|________________________________|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%THIS SYSTEM IS UNSTABLE DUE TO POLE 1%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
REAL POLE VALUE
-1.0289 + 0.1000i

PID controller

Transfer function:
410.6 z^2 - 812.6 z + 405
-------------------------
z^2 - 1

Sampling time: 0.01
ITERATION
5

_________________________________
| PID GAIN VALUES |
|________________________________|
| Kd Kp Ki |
2.0322 2.4364 153.1424

|________________________________|
PID controller

Transfer function:
409.6 z^2 - 811.4 z + 404.8
---------------------------
z^2 - 1

Sampling time: 0.01
ITERATION
6

_________________________________
| PID GAIN VALUES |
|________________________________|
| Kd Kp Ki |
2.0614 2.5629 152.9685

|________________________________|
PID controller

Transfer function:
415.6 z^2 - 823 z + 410.5
-------------------------
z^2 - 1

Sampling time: 0.01
ITERATION
7

_________________________________
| PID GAIN VALUES |
97
|________________________________|
| Kd Kp Ki |
2.0109 2.4026 149.7018

|________________________________|
PID controller

Transfer function:
405.3 z^2 - 802.9 z + 400.5
---------------------------
z^2 - 1

Sampling time: 0.01
ITERATION
8

_________________________________
| PID GAIN VALUES |
|________________________________|
| Kd Kp Ki |
1.9977 2.6486 143.5183

|________________________________|
PID controller

Transfer function:
402.9 z^2 - 797.7 z + 397.6
---------------------------
z^2 - 1

Sampling time: 0.01
ITERATION
9

_________________________________
| PID GAIN VALUES |
|________________________________|
| Kd Kp Ki |
2.0008 2.4663 147.9964

|________________________________|
PID controller

Transfer function:
403.4 z^2 - 798.8 z + 398.4
---------------------------
z^2 - 1

Sampling time: 0.01
ITERATION
10

_________________________________
| PID GAIN VALUES |
|________________________________|
| Kd Kp Ki |
2.0547 2.4698 152.8903

|________________________________|
PID controller

98
Transfer function:
414.2 z^2 - 820.4 z + 409.2
---------------------------
z^2 - 1

Sampling time: 0.01



Appendix C.2 Population Producing Stable Controllers during the
Fourth Iteration of the Genetic Algorithm

Array Size = 409x3

3.3442 0.0703 110.0309
0.6903 1.9343 116.7392
1.2983 0.3629 144.9941
1.9355 -0.1327 107.0292
1.8249 -0.0466 106.7154
2.3144 1.3565 104.9917
2.1603 -0.3075 107.6663
2.2374 -0.3674 107.8848
1.6503 0.0891 133.9615
2.1100 -0.2684 119.5545
2.3327 1.1212 105.4291
2.4438 -0.3070 108.0846
1.4072 0.2782 114.1132
1.5414 0.1738 125.0709
2.1603 -0.0279 107.6663
1.9049 0.8697 109.1095
1.8168 0.7650 109.9954
2.3321 1.1288 105.4151
2.3150 1.3489 105.0058
1.2983 9.4637 144.9941
1.7081 0.6358 111.0883
2.0136 0.9989 108.0167
2.0990 1.1459 105.0407
1.5137 0.5735 105.1737
1.3382 0.3319 108.4774
1.3674 0.3092 110.8585
1.9049 0.8697 172.5383
1.7030 0.6309 111.0849
1.3724 0.3141 110.8619
2.0185 1.0048 107.9668
2.0039 0.9875 108.1133
1.4403 0.3899 110.4066
2.2415 1.2758 105.4436
2.3144 1.3565 182.3066
2.0990 5.6024 105.0407
2.0987 1.1454 105.0507
2.0138 0.9994 108.0067
2.0544 4.8374 105.8242
1.8614 1.5300 109.2119
2.1935 2.9752 146.7402
2.1753 3.2186 141.3907
2.1655 4.2917 105.0256
2.2479 2.6671 105.0068
1.9873 2.8785 143.8886
99
2.0166 3.5936 133.6904
1.8243 0.8581 111.4890
1.9798 2.7854 142.3950
2.0144 2.1172 127.2980
1.9777 1.8664 124.0881
2.2479 2.6671 171.0242
1.8168 8.6768 109.9954
1.8961 1.9911 114.6813
1.9819 3.1325 128.2210
2.2279 2.8195 162.8366
2.1954 3.0663 149.5784
1.9944 3.2977 130.1814
1.9183 2.2869 118.1903
2.0911 2.9304 146.1030
2.0841 2.9213 145.8704
1.8168 8.6768 109.9954
1.8168 8.6768 109.9954
1.9944 3.2977 130.1814
1.9944 3.2977 130.1814
2.0179 5.6148 127.6079
1.9742 6.2806 123.7782
1.8935 1.9574 114.2817
1.8862 1.8595 113.1205
2.1655 4.2917 167.5272
3.0164 4.2917 167.5272
1.9864 3.0180 136.8499
1.9877 3.0651 135.7265
1.9802 2.8607 139.3185
1.9815 3.0571 131.2975
2.0896 2.9436 145.8555
2.0181 3.5803 133.9380
1.9871 3.0415 136.2893
1.9804 2.8090 141.8323
1.9798 6.8626 142.3950
2.0166 4.9898 133.6904
1.9867 3.0272 136.6300
1.9802 2.7997 142.0544
2.0232 2.8420 143.8423
2.0476 2.8738 144.6558
2.0376 2.8607 144.3210
1.9898 2.7985 142.7298
1.9798 2.7854 142.3950
1.9798 2.7854 142.3950
1.9798 3.9154 142.3950
1.9814 2.8815 142.0155
2.0150 4.8937 134.0700
1.9975 2.8085 142.9873
2.0054 2.8188 143.2500
1.9810 2.8564 142.1148
1.9802 2.8105 142.2958
1.9798 2.7854 144.0886
1.9953 2.8057 142.9137
1.9899 2.7985 142.7314
1.9875 2.7954 142.6521
1.9821 2.7884 142.4727
1.9934 2.8031 142.8482
1.9918 2.8010 142.7952
1.9798 2.7854 143.3680
1.9798 2.7854 143.1157
1.9798 2.7854 120.9368
2.0196 2.8373 143.7219
100
1.9935 2.8032 142.8518
2.0039 2.8168 143.4835
1.9954 2.8058 143.3541
1.9839 2.7908 142.5328
1.9893 2.7978 142.7141
2.0017 2.8139 143.1247
1.9971 2.8080 142.9735
1.9918 2.8010 153.4055
1.9954 6.4597 143.3541
2.0037 2.8165 143.4692
1.9896 2.7982 142.7284
2.0011 2.8131 143.1045
1.9977 2.8088 142.9937
1.9993 2.8108 143.1232
2.0019 2.8143 143.3333
1.9920 2.8013 142.8025
1.9894 2.7980 142.7176
1.9798 1.7905 144.0886
2.0013 2.8135 143.1732
2.0017 2.8139 143.2647
2.0034 2.8162 143.4053
2.0022 2.8145 143.2029
2.0032 2.8159 143.3941
2.0022 2.8146 143.3445
2.0022 4.9674 143.3445
2.0022 2.8146 143.3540
2.0037 2.8165 143.4628
1.9999 2.8116 143.1694
2.0033 2.8161 143.4373
2.0039 2.8168 143.4835
2.0039 2.8168 143.4835
2.0017 7.0385 143.2647
2.0039 2.8168 143.4835
2.0039 2.8168 143.4835
1.9998 2.8114 143.1235
2.0012 2.8132 143.1244
2.0039 1.2050 143.4835
2.0039 2.8168 106.6067
2.0036 2.8165 143.4395
2.0019 2.8143 143.1688
2.0026 2.8151 143.2749
2.0033 2.8160 143.3773
2.0039 9.5754 143.4835
2.0039 9.9465 143.4835
2.0012 2.8133 143.2741
2.0020 2.8143 143.3325
2.0031 2.8158 143.3536
2.0034 2.8162 143.4048
1.5595 2.8168 143.4835
2.0039 2.8168 143.4835
2.0039 2.8168 143.4835
2.0039 2.8168 143.4835
2.0039 2.8168 143.4835
2.0039 5.3826 143.4835
2.0039 2.8168 106.3944
2.0012 2.8133 143.2751
2.0039 2.8168 143.4825
2.0039 2.8168 143.4835
2.0039 2.8168 143.4835
2.0036 2.8165 143.4361
2.0037 2.8166 143.4522
101
2.0037 2.8166 182.6622
2.0039 2.8168 144.4339
2.0039 2.8168 143.4835
2.0039 2.8168 143.4835
2.9758 2.8168 143.4835
2.0039 2.8168 143.4835
2.0039 2.8168 111.8495
0.9865 2.8168 143.4835
2.0039 2.8168 143.9347
2.0039 2.8168 143.9826
2.0039 2.8168 143.9081
2.0039 2.8168 144.0093
2.0039 -0.5434 144.4339
2.0039 6.4263 144.4339
2.0039 2.8168 143.8665
2.0039 2.8168 144.0508
2.0039 2.8168 144.0896
2.0039 2.8168 143.8277
2.0039 2.6629 143.4835
2.0039 9.3111 143.9081
2.0039 2.7821 144.2194
2.0039 2.6977 143.6979
2.0039 2.8129 143.5673
2.0039 2.7861 144.1356
2.0039 2.8097 144.3646
2.0039 2.7932 144.2048
2.0039 2.8168 144.4339
2.0039 2.8168 144.4339
2.0039 2.7932 152.9392
2.0039 2.8168 177.9213
2.0039 2.8168 144.4339
2.0039 2.8168 144.4339
2.0039 2.8168 137.6735
2.0039 2.8168 140.5360
2.0039 3.2198 144.4339
2.0039 9.3131 144.4339
2.0039 6.3250 144.4339
2.0039 1.9149 144.4339
2.0039 0.1423 144.4339
2.0039 2.8168 191.9369
2.0039 2.8168 196.4608
2.0039 5.8517 144.4339
2.0039 2.8168 157.0043
2.0039 7.5586 144.4339
2.0039 2.8168 137.7765
2.0039 0.1982 144.4339
2.0039 2.7325 144.4339
2.0039 2.8168 144.4339
2.0039 2.8168 144.4339
2.0039 2.7534 144.4339
2.0039 2.7959 144.4339
2.0039 1.5929 144.4339
2.0039 2.8168 144.4339
2.0039 2.8168 144.4339
2.0039 2.8093 144.4339
2.0039 2.8035 144.4339
2.0039 2.8168 127.5816
2.0039 2.8133 144.4339
2.0039 2.8071 144.4339
2.0039 2.8117 144.4339
2.0039 2.8011 144.4339
102
2.0039 2.8155 133.9194
2.0039 2.8146 138.0960
2.0039 2.7413 143.3223
2.0039 2.8067 135.0310
2.0039 5.6952 144.4339
2.0039 9.2374 144.4339
2.0039 2.7731 144.4339
2.0039 2.7664 144.4339
2.0039 2.8059 144.4339
2.0039 2.8069 144.4339
2.0039 2.8014 144.4339
2.0039 2.7981 144.4339
2.0039 2.8033 143.5034
2.0039 2.8127 139.0265
2.0039 2.6436 144.4339
2.0039 3.4725 144.4339
2.0039 2.7516 144.4339
2.0039 2.7541 144.4339
2.0039 2.7135 144.4339
2.0039 2.7470 144.4339
2.0039 2.7430 144.4339
2.0039 2.7411 144.4339
2.0039 0.6288 144.4339
2.0039 2.6572 144.4339
2.0039 2.7189 144.4339
2.0039 2.6936 144.4339
2.0039 2.6825 144.4339
2.0039 2.6821 144.4339
2.0039 2.6550 144.4339
2.0039 2.6853 144.4339
2.0039 2.7297 144.4339
2.0039 8.9536 144.4339
2.0039 2.7325 145.2633
2.0039 2.7029 144.4339
2.0039 2.6868 144.4339
2.0039 2.6859 144.4339
2.0039 2.6862 144.4339
2.0039 2.7321 145.1480
2.0039 2.7301 144.5492
2.0039 2.7168 145.1171
2.0039 2.6592 144.5800
1.8028 2.6550 144.4339
2.0039 2.7024 144.9827
2.0039 2.6893 144.8606
2.0039 2.7199 145.1457
2.0039 2.7019 144.9782
2.0039 2.6953 144.8611
2.0039 2.6961 144.8669
2.0039 2.7322 145.1825
2.0039 2.7324 145.2288
2.0039 2.7024 123.6254
2.0039 6.4623 145.2288
2.0039 2.6630 144.6153
2.0039 2.7130 145.0818
2.0039 2.7078 145.0328
2.0039 2.6683 144.6644
2.0039 2.6439 144.4366
2.0039 2.7165 145.1144
2.0039 2.7307 145.1477
2.0039 2.7213 145.1460
2.0039 2.7199 163.3547
103
2.0039 2.6692 144.6731
2.0039 2.6942 144.9064
2.0039 2.7278 145.1414
2.0039 2.7197 145.1234
2.0039 2.7226 145.1550
2.0039 2.7296 145.2317
2.0039 2.7206 145.1481
2.0039 2.7219 145.1526
2.0039 5.6964 145.2633
2.0039 2.6663 144.6456
2.0039 2.6972 144.9339
2.0039 2.7219 145.1646
2.0039 2.7305 145.2444
2.0039 2.7275 145.1480
2.0039 2.7252 145.1481
2.0039 2.7325 130.5211
2.0039 2.7325 131.4483
2.0039 2.7325 144.3362
2.0039 2.7325 145.2633
2.0039 2.7325 145.2633
2.0039 2.7274 145.2158
2.0039 2.7250 145.1932
2.0039 2.7325 132.3852
2.0039 2.7325 144.3264
2.0039 0.2690 145.2633
2.0039 2.7325 199.8797
2.0039 7.6152 145.2633
2.0039 1.0859 145.2633
2.0039 2.7325 145.2633
2.0039 2.7325 145.2633
2.0039 2.7325 104.9362
2.0039 7.6306 145.2633
2.0039 2.7325 145.2633
2.0039 2.7325 145.2633
2.0039 7.9217 145.2633
2.0039 2.7325 139.1215
2.0039 6.4211 145.2633
2.0039 6.9893 145.2633
2.0039 2.7325 145.2633
2.0039 2.7325 145.2633
2.0039 2.7325 117.8089
2.0039 2.7325 115.5249
2.0039 2.7325 145.2633
2.0039 2.7325 145.2633
2.0039 2.7325 115.2115
2.0039 1.7807 145.2633
2.0039 2.7325 145.2633
2.0039 2.7325 145.2633
2.0039 8.3708 145.2633
2.0039 0.2513 145.2633
2.0039 0.7131 145.2633
2.0039 2.5962 145.2633
2.0039 2.7325 147.9990
2.0039 2.7325 145.2633
2.0039 2.7325 145.2633
2.0039 2.7325 145.2633
2.0039 2.7325 145.2633
2.0039 2.7325 147.3924
2.0039 2.7325 145.8698
2.0039 7.3083 145.2633
2.0039 2.7325 107.4221
104
2.0039 2.7325 146.8061
2.0039 2.7325 146.4562
2.0039 2.7325 145.4347
2.0039 2.7325 147.8276
2.0039 2.7325 146.3969
2.0039 2.7325 145.6725
2.0039 2.7325 145.3083
2.0039 2.7325 147.7825
2.0039 2.7325 147.1364
2.0039 2.7325 147.3187
2.0039 2.7325 147.7066
2.0039 2.7325 147.6848
1.3319 2.7325 147.7825
2.0039 -1.3865 147.9990
2.0039 2.7325 147.0808
2.0039 2.7325 145.8673
2.0039 2.7325 147.4499
2.0039 2.7325 146.4163
2.0039 2.7325 178.5742
2.0039 5.9737 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 198.1139
2.0039 2.7325 117.0134
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 135.3905
2.0039 2.7325 155.3785
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 150.1005
2.0039 2.7325 153.2770
2.0039 2.7325 107.2023
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 175.0642
2.0039 6.6883 147.9990
2.0039 9.7951 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 7.5702 147.9990
2.0039 2.7528 147.9990
2.0039 -1.0850 147.9990
2.0039 2.7325 132.6889
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.0039 2.7325 147.9990
2.39 2.7325 147.9990

105

You might also like