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
1
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. GA’s 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 don’t 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.
2
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
3
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
4
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.
5
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. Pterm = K p × Error
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.
I tetm = K I × ∫ Errordt 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. Dterm = K D ×
d ( Error ) dt
3.4 Continuous PID Controller The three types of control are combined together to form a PID controller with the transfer function:
C PID ( s) =
KD s2 + KP s + KI s
6
(3.1)
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 s =
2 z −1 is used to T z +1
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');
7
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.
8
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.
9
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.
10
5.0 Genetic Algorithms Genetic Algorithms (GA’s) 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
11
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 individual’s 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:
12
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.
13
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 14
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. 15
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.
16
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
17
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
18
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.
19
•
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 GA’s final population. bestPop = The GA’s 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
20
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 chromosome’s fitness value to create a new population consisting of the fittest members.
21
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).
C PID =
KD s2 + KP s + KI s
(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.
22
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.
23
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) =
1 s + 6s + 11s 2 + 6 s 4
3
(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 Tc is calculated as:
Tc =
2π = 6.28 sec ωc
24
Placing the values of K c and Tc into Table 6.1 Controller PID
TI
Kp
0.6 K C TC / 2 Table 6.1 Ziegler-Nichols PID tuning parameters
TD TC / 8
Gives Controller PID
6 3.14 Table 6.2 Ziegler-Nichols PID Tuning Values
Using the relationship K I = Controller PID
TI
Kp
TD 0.79
KP and K D = K P TD , the PID gains can be evaluated. TI
KI
Kp
6 1.91 Table 6.3 Ziegler-Nichols PID Gain values
KD 4.74
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 0 ≤ T ≤ t s where t s is the settling time of the system. The performance indices used were:
6.2.1 Integral of Time multiplied by Absolute Error (ITAE) T
I ITAE = ∫ t e(t ) dt 0
25
(6.2)
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) T
I IAE = ∫ e(t ) dt
(6.3)
0
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
I ISE = ∫ e 2 (t )dt
(6.3)
0
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
26
6.2.4 Mean of the Square of the Error (MSE)
I MSE =
1 n ( e(t )) 2 ∑ n i =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 . To ensure that all of the genetic algorithms had the ’ was used.
exact same initial conditions the matlab command ‘
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. 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
Table 6.4 Comparisons of Steady State Responses
27
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.
28
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.
29
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, ∆ω = g .∆vi
(6.1)
Figure 7.3 Change of Motor Speed in Time [3] Where, ∆ω = 4.55V − 2.34V = 2.21V (As read from voltmeter)
∆Vi = 2V G=
2.21 2 G = 1.105
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 ∆Vi in the drive voltage Vi . The drive voltage was chosen to be 4V, as this will give an output of around 3000RPM. The 30
step increase was added in the form of a ± 1V 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 0.632∆ω 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. τ = 0.66 sec
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
Frequency
Period
Amplitude
Frequency X
Output (V)
(Hz)
(Seconds)
(V)
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
31
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; H=
135 = 67.5 2
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.
32
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
33
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 40o 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: − πξ FO = exp 1 − ξ 2
Figure 7.11 Illustration of Actual Oscillations
34
(7.2)
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.
ξ = 0.066 Time to the first peak overshoot ( t p ) is defined as:
tp =
π ωd
(7.3)
A time to first peak value of t p = 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: ωn =
ωd
(7.4)
1−ξ 2
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)
2 rb 2 b s s + b 2 5 r mr
ψ ( s) = θ ( s ) 2 rb 2 2 s + bb s + g 5 r R mr 2 Where: rb = 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) bb = Coefficient of Rolling Friction
35
(7.5)
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: 2 rb 2 2 b g + 1 s + b 2 s + = 0 5 r R mr
⇒ s2 +
bb 2 r mr 2 b + 1 5 r 2
s+
g 2 r 2 R b + 1 5 r
(7.6)
=0
Using the standard characteristic equation for a second order system: s 2 + 2ξω n s + ω n = 0 2
And equating the coefficients of the ‘s’ terms to solve for bb : 2ξω n =
bb 2 r 2 mr 2 b + 1 5 r
Rearranging, 2 r 2 bb = 2ξω n mr 2 b + 1 5 r Where:
ξ = 0.066 ω n = 9.987 rad/sec. m = 28.2g rb = 9.53mm r = 9.3mm Substituting these values into Equation (7.7) gives: 2 9.53 2 bb = 2(0.066)(9.987)(.0282)(.0093) + 1 5 9.3 2
bb = 4.57 × 10 −6
36
(7.7)
Now that the coefficient of rolling friction is known, the transfer function shown in Equation (7.5) can be evaluated as:
ψ ( s) 0.42s 2 + 1.873s = θ ( s ) 1.42 s 2 + 1.873s + 112.11 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
37
With a frequency ( ω c ) of 1 rad/s, the period Tc is calculated as
2π = 0.5 sec. ωc
Placing the values of K c and Tc into Table 6.1 gives: Controller PID
.9478 0.25 Table 7.2 Ziegler-Nichols PID Tuning Values
Using the relationship K I = Controller PID
TI
Kp
TD .0625
KP and K D = K P TD the PID gains can be evaluated. TI
KI
Kp
.9478 3.7912 Table 7.3 Ziegler-Nichols PID Gain values
KD .06
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
206.1 = 1.84 . This gain is shown in Figure 7.15 when the open 112.1
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
38
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: y (t ) = x T .θ + e(t )
(8.2)
Where θ is a group of unknown vectors defined by: θ T = [− a1 ,...,− a na , b0 ,..., bnb , c1 ,..., c cc , d 0 , d1 ,..., d nd ]
And the regression vector, x(t), is a matrix of input and output variables in the form: x T (t ) = [ y (t − 1),..., y (t − na ), u (t − 1),..., u (t − nb − 1), e(t − 1),..., e(t − nc ),1, t ,..., t nd ]
e(t ) 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: eˆ = y − Xθˆ
(8.3)
x T (1) T x ( 2) Where, X = : T x ( N )
To find θˆ , minimise the Error Performance Index, J, where J is the sum of the squares of the error. N
J = ∑ eˆ 2 (t ) = eˆT eˆ t −1
39
(8.4)
To find the least squares estimate, insert Equation (8.3) into Equation (8.4). J = ( y − Xθˆ) T ( y − Xθˆ) J = y T y − θˆ T X T y − y T Xθˆ + θˆX T Xθˆ
Taking the derivative of J with respect to θˆ and setting it equal to zero: ∂J = −2 X T y + 2 X T Xθˆ = 0 ˆ ∂θ
Taking the transpose: X T y = X T yθˆ
Rearranging produces the least squares estimate for the parameter vector: θˆ = [ X T X ]−1[ X T y ]
(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 θ (t + 1) 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 θˆ(t − 1) ,
40
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 t + 1 : (i)
Form x (t + 1) using the new data.
(ii)
Form ε (t + 1)
ε (t + 1) = y (t + 1) − x T (t + 1)θˆ( t )
using
(iii)
Form P(t + 1) using x (t + 1) x T (t + 1) P (t ) P (t + 1) = P (t ) I m − 1 + x T (t + 1) P (t ) x (t + 1)
(iv)
(8.6)
Update θˆ(t ) θˆ(t + 1) = θˆ(t ) + P (t + 1) x (t + 1)ε (t + 1)
(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.
41
Laplace Transform z-transform G(s)
G(z)
1 s
τs z −1
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) 2.964 − 2.936 0.9721 θ (0) = 0.002477 0.0001215 − 0.002382 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].
42
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 43
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].
44
The least squares approach, Equation (8.5), to minimising the cost function at each time t implies that all the values of eˆ(i ) from i = 1 to i = t carry an equal weighting. t
J t = ∑ eˆ(i)
(8.7)
i =1
The forgetting factor approach applies a differential weighting to the data by use of a modified cost function (1.2). t
J t = ∑ λt −i eˆ 2 (i )
(8.8)
i =1
The discounting effect of λ on past errors can be seen by writing (8.8) in the form: J t = λJ t −1 + eˆ 2 (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:
45
P (t + 1) =
1 P (t ) x (t + 1) x T (t + 1) P (t ) P ( t ) − λ λ + x T (t + 1) P (t ) x (t + 1)
(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 RealTime toolbox in Simulink. To this end, the RLS estimator must be written as an SFunction 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.
46
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-pertime-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.
47
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.
48
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 ZeroOrder Hold.
8.11.1 System Sample Time According to Shannon’s 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 Shannon’s 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.
49
Figure 8.7 Graph of Bode Plot of System
Figure 8.8 Step Response of Discrete System using Different Sample Times
50
Continuous Ball and Hoop Transfer Function:
Y (s) 46.21s 2 + 206.1s = U ( s ) 0.9372 s 4 + 2.656 s 3 + 75.87 s 2 + 112.1s Discrete Ball and Hoop Transfer Function (Using ZOH):
Y ( z ) 0.002477 z 2 + 0.0001215 z − 0.002382 = U ( z) z 3 − 2.964 z 2 + 2.936 z − 0.9721 Converting to the form of z −1 : Y ( z −1 ) 0.002477 z −1 + 0.0001215 z −2 − 0.002382 z −3 = U ( z −1 ) 1 − 2.964 z −1 + 2.936 z −2 − 0.9721−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) 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 ) = X T θ (k ) 2.964 − 2.936 0.9721 y(k ) = [ y(k − 1) y(k − 2) y(k − 3) u(k − 1) u(k − 2) u(k − 3)] (8.11) 0 . 002477 0.0001215 − 0.002382 The regression vector, X T , 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.
51
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 Sfunction. 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. 2.964 10 0 0 0 0 0 − 2.936 0 10 0 0 0 0 0.9721 0 0 10 0 0 0 θ (0) = P(0) = 0.002477 0 0 0 10 0 0 0.0001215 0 0 0 0 10 0 − 0.002382 0 0 0 0 0 10 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
52
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
53
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
54
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.
55
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 13, the estimates are still incorrect and indicate that the RLS estimator doesn’t 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.
56
Figure 8.14 RLS estimator working on the Ball and Hoop system
.
57
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 doesn’t 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.
58
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:
K P = 2.7407 K I = 145.0226 K D = 2.0208
59
Performing a continuous to discrete transformation on a PID controller with these gain values using the trapezoidal difference method yields the discrete controller:
C PID ( z ) =
407.6 z 2 - 806.9 z + 402.1 z2 −1
(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.
60
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.
61
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.
62
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 aren’t instantaneous and won’t 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. 63
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 don’t 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.
64
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.
65
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.
66
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
67
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.
68
10.0 Conclusions It was established, by comparison of their steady state characteristics that GA’s 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.
69
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.
70
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-systemsprinciples.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
71
Appendix A Matlab Script and Function Files
72
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]);
73
%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);
74
%____________________________________________________________________ %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
75
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; %____________________________________________________________________
76
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; %____________________________________________________________________
77
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 % %%%%%%%%%%
78
case 3, sys = mdlOutputs(x,n); %%%%%%%%%%%%%%%%%%%% % Unexpected flags % %%%%%%%%%%%%%%%%%%%% otherwise sys = []; end %____________________________________________________________________ % mdlInitializeSizes % Return the sizes, initial conditions, and sample times for the Sfunction. %____________________________________________________________________ function [sys,x0,str,ts] = mdlInitializeSizes(n,theta_init,P_init,samp_t)
sizes = simsizes; sizes.NumContStates sizes.NumDiscStates sizes.NumOutputs sizes.NumInputs sizes.DirFeedthrough sizes.NumSampleTimes
= = = = = =
0; n+n^2; n; n+1; 0; 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 %____________________________________________________________________
79
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);
80
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')
81
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('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
82
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];
83
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); loop system to
% Step response of closed% 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; %____________________________________________________________________
84
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('')
85
%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
86
[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')
87
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;
88
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 closedloop 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;
89
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; %____________________________________________________________________
90
Appendix B RLS Derivation
91
Appendix B.1 Derivation of Recursive Least Squares Using least squares, Equation (8.5), as a starting point and defining: X (t ) y (t ) X (t + 1) = .... And, y (t + 1) = ... x T (t + 1) t (t + 1)
Gives, θˆ(t + 1) = [ X T (t + 1) X (t + 1)]−1 X T (t + 1) y (t + 1)
Where, X T (t + 1) X (t + 1) = X T (t ) X (t ) + x(t + 1) x T (t + 1) X T (t + 1) y (t + 1) = X T (t ) y (t ) + x (t + 1) y (t + 1)
(B.1)
Defining Shorthand Notation P(t ) = [ X T (t ) X (t )]−1 B(t ) = X T (t ) y (t ) P −1 (t + 1) = P −1 (t ) + x(t + 1) x T (t + 1)
B(t + 1) = B(t ) + x(t + 1) y (t + 1) Using this shorthand
θˆ(t + 1) = P(t + 1) B(t + 1) θˆ(t ) = P(t ) B(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: ( A + BCD) −1 = A −1 − A −1 B(C −1 + DA −1 B) −1 DA −1 Assigning A = P −1 (t ) , C = 1, B = x(t + 1) , D = x T (t + 1) Gives
[
(
)
−1
]
P(t +1) = P(t ) I m − x(t +1) 1+ xT (t +1)P(t) x(t +1) xT (t +1)P(t)
(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:
92
ε (t + 1) = y (t + 1) − x T (t + 1)θˆ(t )
And substituting for y(t+1) into Equation (B.1) gives: B (t + 1) = B (t ) + x(t + 1) x T (t + 1)θˆ(t ) + x(t + 1)ε (t + 1)
Substituting for B(t ), B(t + 1) using Equations (8.7) gives: θˆ(t + 1) = ϑˆ (t ) + P (t + 1) x(t + 1)ε (t + 1)
93
Appendix C Genetic Algorithm Tuned Controller Results
94
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 _________________________________
95
| 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 |
96
|________________________________| | 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
97
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.6903 1.2983 1.9355 1.8249 2.3144 2.1603 2.2374 1.6503 2.1100 2.3327 2.4438 1.4072 1.5414 2.1603 1.9049 1.8168 2.3321 2.3150 1.2983 1.7081 2.0136 2.0990 1.5137 1.3382 1.3674 1.9049 1.7030 1.3724 2.0185 2.0039 1.4403 2.2415 2.3144 2.0990 2.0987 2.0138 2.0544 1.8614 2.1935 2.1753 2.1655 2.2479 1.9873
0.0703 1.9343 0.3629 -0.1327 -0.0466 1.3565 -0.3075 -0.3674 0.0891 -0.2684 1.1212 -0.3070 0.2782 0.1738 -0.0279 0.8697 0.7650 1.1288 1.3489 9.4637 0.6358 0.9989 1.1459 0.5735 0.3319 0.3092 0.8697 0.6309 0.3141 1.0048 0.9875 0.3899 1.2758 1.3565 5.6024 1.1454 0.9994 4.8374 1.5300 2.9752 3.2186 4.2917 2.6671 2.8785
110.0309 116.7392 144.9941 107.0292 106.7154 104.9917 107.6663 107.8848 133.9615 119.5545 105.4291 108.0846 114.1132 125.0709 107.6663 109.1095 109.9954 105.4151 105.0058 144.9941 111.0883 108.0167 105.0407 105.1737 108.4774 110.8585 172.5383 111.0849 110.8619 107.9668 108.1133 110.4066 105.4436 182.3066 105.0407 105.0507 108.0067 105.8242 109.2119 146.7402 141.3907 105.0256 105.0068 143.8886
98
2.0166 1.8243 1.9798 2.0144 1.9777 2.2479 1.8168 1.8961 1.9819 2.2279 2.1954 1.9944 1.9183 2.0911 2.0841 1.8168 1.8168 1.9944 1.9944 2.0179 1.9742 1.8935 1.8862 2.1655 3.0164 1.9864 1.9877 1.9802 1.9815 2.0896 2.0181 1.9871 1.9804 1.9798 2.0166 1.9867 1.9802 2.0232 2.0476 2.0376 1.9898 1.9798 1.9798 1.9798 1.9814 2.0150 1.9975 2.0054 1.9810 1.9802 1.9798 1.9953 1.9899 1.9875 1.9821 1.9934 1.9918 1.9798 1.9798 1.9798 2.0196
3.5936 0.8581 2.7854 2.1172 1.8664 2.6671 8.6768 1.9911 3.1325 2.8195 3.0663 3.2977 2.2869 2.9304 2.9213 8.6768 8.6768 3.2977 3.2977 5.6148 6.2806 1.9574 1.8595 4.2917 4.2917 3.0180 3.0651 2.8607 3.0571 2.9436 3.5803 3.0415 2.8090 6.8626 4.9898 3.0272 2.7997 2.8420 2.8738 2.8607 2.7985 2.7854 2.7854 3.9154 2.8815 4.8937 2.8085 2.8188 2.8564 2.8105 2.7854 2.8057 2.7985 2.7954 2.7884 2.8031 2.8010 2.7854 2.7854 2.7854 2.8373
133.6904 111.4890 142.3950 127.2980 124.0881 171.0242 109.9954 114.6813 128.2210 162.8366 149.5784 130.1814 118.1903 146.1030 145.8704 109.9954 109.9954 130.1814 130.1814 127.6079 123.7782 114.2817 113.1205 167.5272 167.5272 136.8499 135.7265 139.3185 131.2975 145.8555 133.9380 136.2893 141.8323 142.3950 133.6904 136.6300 142.0544 143.8423 144.6558 144.3210 142.7298 142.3950 142.3950 142.3950 142.0155 134.0700 142.9873 143.2500 142.1148 142.2958 144.0886 142.9137 142.7314 142.6521 142.4727 142.8482 142.7952 143.3680 143.1157 120.9368 143.7219
99
1.9935 2.0039 1.9954 1.9839 1.9893 2.0017 1.9971 1.9918 1.9954 2.0037 1.9896 2.0011 1.9977 1.9993 2.0019 1.9920 1.9894 1.9798 2.0013 2.0017 2.0034 2.0022 2.0032 2.0022 2.0022 2.0022 2.0037 1.9999 2.0033 2.0039 2.0039 2.0017 2.0039 2.0039 1.9998 2.0012 2.0039 2.0039 2.0036 2.0019 2.0026 2.0033 2.0039 2.0039 2.0012 2.0020 2.0031 2.0034 1.5595 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0012 2.0039 2.0039 2.0039 2.0036 2.0037
2.8032 2.8168 2.8058 2.7908 2.7978 2.8139 2.8080 2.8010 6.4597 2.8165 2.7982 2.8131 2.8088 2.8108 2.8143 2.8013 2.7980 1.7905 2.8135 2.8139 2.8162 2.8145 2.8159 2.8146 4.9674 2.8146 2.8165 2.8116 2.8161 2.8168 2.8168 7.0385 2.8168 2.8168 2.8114 2.8132 1.2050 2.8168 2.8165 2.8143 2.8151 2.8160 9.5754 9.9465 2.8133 2.8143 2.8158 2.8162 2.8168 2.8168 2.8168 2.8168 2.8168 5.3826 2.8168 2.8133 2.8168 2.8168 2.8168 2.8165 2.8166
142.8518 143.4835 143.3541 142.5328 142.7141 143.1247 142.9735 153.4055 143.3541 143.4692 142.7284 143.1045 142.9937 143.1232 143.3333 142.8025 142.7176 144.0886 143.1732 143.2647 143.4053 143.2029 143.3941 143.3445 143.3445 143.3540 143.4628 143.1694 143.4373 143.4835 143.4835 143.2647 143.4835 143.4835 143.1235 143.1244 143.4835 106.6067 143.4395 143.1688 143.2749 143.3773 143.4835 143.4835 143.2741 143.3325 143.3536 143.4048 143.4835 143.4835 143.4835 143.4835 143.4835 143.4835 106.3944 143.2751 143.4825 143.4835 143.4835 143.4361 143.4522
100
2.0037 2.0039 2.0039 2.0039 2.9758 2.0039 2.0039 0.9865 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039
2.8166 2.8168 2.8168 2.8168 2.8168 2.8168 2.8168 2.8168 2.8168 2.8168 2.8168 2.8168 -0.5434 6.4263 2.8168 2.8168 2.8168 2.8168 2.6629 9.3111 2.7821 2.6977 2.8129 2.7861 2.8097 2.7932 2.8168 2.8168 2.7932 2.8168 2.8168 2.8168 2.8168 2.8168 3.2198 9.3131 6.3250 1.9149 0.1423 2.8168 2.8168 5.8517 2.8168 7.5586 2.8168 0.1982 2.7325 2.8168 2.8168 2.7534 2.7959 1.5929 2.8168 2.8168 2.8093 2.8035 2.8168 2.8133 2.8071 2.8117 2.8011
182.6622 144.4339 143.4835 143.4835 143.4835 143.4835 111.8495 143.4835 143.9347 143.9826 143.9081 144.0093 144.4339 144.4339 143.8665 144.0508 144.0896 143.8277 143.4835 143.9081 144.2194 143.6979 143.5673 144.1356 144.3646 144.2048 144.4339 144.4339 152.9392 177.9213 144.4339 144.4339 137.6735 140.5360 144.4339 144.4339 144.4339 144.4339 144.4339 191.9369 196.4608 144.4339 157.0043 144.4339 137.7765 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 127.5816 144.4339 144.4339 144.4339 144.4339
101
2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 1.8028 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039
2.8155 2.8146 2.7413 2.8067 5.6952 9.2374 2.7731 2.7664 2.8059 2.8069 2.8014 2.7981 2.8033 2.8127 2.6436 3.4725 2.7516 2.7541 2.7135 2.7470 2.7430 2.7411 0.6288 2.6572 2.7189 2.6936 2.6825 2.6821 2.6550 2.6853 2.7297 8.9536 2.7325 2.7029 2.6868 2.6859 2.6862 2.7321 2.7301 2.7168 2.6592 2.6550 2.7024 2.6893 2.7199 2.7019 2.6953 2.6961 2.7322 2.7324 2.7024 6.4623 2.6630 2.7130 2.7078 2.6683 2.6439 2.7165 2.7307 2.7213 2.7199
133.9194 138.0960 143.3223 135.0310 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 143.5034 139.0265 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 144.4339 145.2633 144.4339 144.4339 144.4339 144.4339 145.1480 144.5492 145.1171 144.5800 144.4339 144.9827 144.8606 145.1457 144.9782 144.8611 144.8669 145.1825 145.2288 123.6254 145.2288 144.6153 145.0818 145.0328 144.6644 144.4366 145.1144 145.1477 145.1460 163.3547
102
2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039
2.6692 2.6942 2.7278 2.7197 2.7226 2.7296 2.7206 2.7219 5.6964 2.6663 2.6972 2.7219 2.7305 2.7275 2.7252 2.7325 2.7325 2.7325 2.7325 2.7325 2.7274 2.7250 2.7325 2.7325 0.2690 2.7325 7.6152 1.0859 2.7325 2.7325 2.7325 7.6306 2.7325 2.7325 7.9217 2.7325 6.4211 6.9893 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 1.7807 2.7325 2.7325 8.3708 0.2513 0.7131 2.5962 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 7.3083 2.7325
144.6731 144.9064 145.1414 145.1234 145.1550 145.2317 145.1481 145.1526 145.2633 144.6456 144.9339 145.1646 145.2444 145.1480 145.1481 130.5211 131.4483 144.3362 145.2633 145.2633 145.2158 145.1932 132.3852 144.3264 145.2633 199.8797 145.2633 145.2633 145.2633 145.2633 104.9362 145.2633 145.2633 145.2633 145.2633 139.1215 145.2633 145.2633 145.2633 145.2633 117.8089 115.5249 145.2633 145.2633 115.2115 145.2633 145.2633 145.2633 145.2633 145.2633 145.2633 145.2633 147.9990 145.2633 145.2633 145.2633 145.2633 147.3924 145.8698 145.2633 107.4221
103
2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 1.3319 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.0039 2.39
2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 -1.3865 2.7325 2.7325 2.7325 2.7325 2.7325 5.9737 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 6.6883 9.7951 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 2.7325 7.5702 2.7528 -1.0850 2.7325 2.7325 2.7325 2.7325 2.7325
146.8061 146.4562 145.4347 147.8276 146.3969 145.6725 145.3083 147.7825 147.1364 147.3187 147.7066 147.6848 147.7825 147.9990 147.0808 145.8673 147.4499 146.4163 178.5742 147.9990 147.9990 147.9990 198.1139 117.0134 147.9990 147.9990 147.9990 147.9990 147.9990 147.9990 135.3905 155.3785 147.9990 147.9990 150.1005 153.2770 107.2023 147.9990 147.9990 147.9990 147.9990 175.0642 147.9990 147.9990 147.9990 147.9990 147.9990 147.9990 147.9990 147.9990 147.9990 147.9990 147.9990 147.9990 147.9990 132.6889 147.9990 147.9990 147.9990 147.9990
104
105