Genetic Algorithm Tuned Fuzzy Logic Controller for Rotary Inverted Pendulum

In this study, a Genetic Algorithm (GA) is proposed to search for the optimal input membership functions of the fuzzy logic controller. With the optimal membership function, the fuzzy logic controller can efficiently control a rotary inverted pendulum. The advantage of the proposed method is tuning the parameters of membership functions automatically rather than tuning them manually. In genetic algorithm, these parameters are converted to a chromosome which is encoded into a binary string. Because the membership functions are symmetric to zero, the length of each chromosome could be reduced by half. The computation time will also be shorter with the shorter chromosomes. Moreover, the roulette wheel selection is chosen as reproduction operator and one-point crossover operator and random mutation operator are also used. After the genetic algorithm completes searching for optimal parameters, the optimal membership function will be introduced to the fuzzy logic controller. Finally, simulation results show that the proposed GA-tuned fuzzy logic controller is effective for the rotary inverted pendulum control system with robust stabilization capability.


INTRODUCTION
Fuzzy logic controllers have been operated successfully in many un-modeled or nonlinear systems that conventional control theories, like PID controllers, have difficulties to deal with (Klir and Yuan, 1995;Wang, 1996;Tao and Taur, 2000;Zidani et al., 2008;Wang and Nie, 2011).Experts use fuzzy logic controller with their own knowledge which is often coached in vague or linguistic statements in the form of IF-THEN rules.These linguistic statements are converted to precise numeric values by using input and output membership functions.This kind of control method has more simple calculation than other intelligent controllers, such as neural network controller.Moreover, fuzzy logic control is suitable for nonlinear systems because it is able to control without exact system transfer functions.
The first genetic algorithm was developed by Holland in 1975 (Goldberg, 1989).Many researches have been extended the application in search, optimization and machine learning.Genetic algorithms are global and robust over a wide range of problems.The searching procedures depend on the mechanics of natural genetics.According to the principle of Darwinian, survival-of-the-fittest, all natural species will survive by adaptation which is the fundamental power of genetic algorithm.A genetic algorithm usually adopts a fitness function to evaluate which chromosomes are worthy to reserve for next generation.

By
solving a polynomial, a chromosome mathematically stands for a set of roots.Chromosomes are operated by three operations, such as reproduction, crossover and mutation, to generate new offspring for next generation.These three operations make chromosomes to reveal the whole possible solution sets.
A lot of researches on rotary inverted pendulum controller have been proposed.For example, the model predictive control was a feedback control scheme.Further, a gain-scheduling control was proposed which is an effective method when the dynamics of the controlled plants changes critically due to the operating point.After achieving the requirements of every operating point, the gain-scheduling method will control the rotary inverted pendulum effectively.
Genetic algorithms are modern heuristic algorithms, which use natural population genetics to evolve solutions.Based on fuzzy logic control, we developed the genetic algorithm to obtain better parameters of the fuzzy controller to stabilize the rotary inverted pendulum.Membership functions of the proposed fuzzy logic controller will be tuned by genetic algorithms.

ROTARY INVERTED PENDULUM DYNAMICS
The structure of rotary inverted pendulum is shown in Fig. 1.The rotary inverted pendulum is operated by a rigid rod pendulum rotating in a vertical plane.The rigid rod is attached to a pivot arm that is mounted on Fig. 1: Sketch of the rotary inverted pendulum the shaft of the servo-motor.The pivot arm can be rotated in the horizontal plane by the servo-motor.The pendulum hangs downwards at a standstill situation.The goal here is to swing up the pendulum from the downward position and then to balance the pendulum in the vertical-upright position.
The system variables and parameters are defined as follows: m 1 is the mass of the rotary arm, m 2 is the mass of the inverted pendulum, l 1 is the length of the rotary arm, l 2 is the length of the inverted pendulum, l c1 is the distance of mass of the rotary arm to the extreme point, l c2 is the distance of mass of the inverted pendulum to the extreme point, J 1 is the inertia pendulum, θ 1 is the angle of the rotary arm, θ 2 is the angle of the inverted pendulum, ߠ ሶ ଵ is the angle velocity of the rotary arm, ߠ ሶ ଶ is the angle velocity of the inverted pendulum and g is the gravitational constant.
Applying the Lagrange equation to derive the dynamic equations of the rotary inverted pendulum yields: where, T = The kinetic energy V = The potential energy ߠ = The included angle of link i ߬ = The moment of force of link i For this rotary inverted pendulum, one can get kinetic energy and potential energy as follows: where, ϕ is defined as గ ଶ − ߠ ଶ .Substituting (2) and ( 3) into (1) yields the following expression: where, ߠ ∈ ܴ ଶ : Vector respecting to angle ߠ ሶ ∈ ܴ ଶ : Vector respecting to angle velocity ߠ ሷ ∈ ܴ ଶ : Vector respecting to angle acceleration M (θ) ∈R 2×2 : The inertial matrix C (θ,θ ሶ ) ∈R 2×2 : A matrix which is relative to centripetal force and Coriolis force G (θ) ∈R 2 : A vector of gravity term τ∈R 2 : A vector of control input torque The form of these matrices and vectors can be completely presented as follows: where, The input signal is the voltage feeding into the rotary inverted pendulum.A voltage signal is supplied to a PWM driver amplifier which drives the servo- motor to control the pendulum.The relationship of the control input ߬ ଵ and the voltage v is: where, ܴ : The armature resistance ݇ : Is the back-emf constant Recalling ( 6) and (10), the system dynamic equation is presented as: where, u = [v 0] and each element in above can be described in detail as follows:

FUZZY LOGIC CONTROLLER
The proposed fuzzy logic controller consists of four components including fuzzification, fuzzy rule base, fuzzy inference engine and defuzzification.The fuzzification converts a crisp value into a suitable linguistic value within a certain universe of discourse.The Gaussian-type membership functions are used in the fuzzification process: where, p : The input variable of fuzzy logic controller m 1 : The center of membership function ߪ : The dispersion of membership function Define the tracking error dynamics as: e = y d -y ( 13) where y d = [y d1 y d2 ] T consists of the desired output of each joint and denotes the practical output of each joint: Let the error e and the error differential ݁ሶ be the input linguistic variables of the fuzzy logic and the control force u be the output linguistic variable and the associated fuzzy sets for e, ݁ሶ and u are expressed as follows: • Table 1 shows twenty-five linguistic rules.The universes of the input and output variables are [-30, 30] and [-8, 8], respectively.In this study, Gaussian-type input membership functions, singleton output membership functions and center average defuzzification method are adopted as they are computationally simple and easy for implementation.
Then, the control force can be obtained by the fuzzy inference mechanism as follows: The block diagram of the proposed computation structure is shown in Fig. 4. Based on each fitness values of each chromosome in a generation, the genetic algorithm selects the best set of means for input membership functions.Further, the rotary inverted pendulum system is controlled by fuzzy logic controller according to the means of input membership functions selected by genetic algorithm.

GENNTIC ALGORITHM
The use of genetic algorithms is widespread in applications to engineering, scientific and business fields.Before genetic algorithms are applied, the optimization problem should be converted to a suitably described function which is usually called fitness function that may consist of one or more variables.The fitness function represents a performance index.If a genetic algorithm is applied to a control problem, the higher the fitness value is, the better the system performance will be.Genetic algorithms are to imitate the genetic operation processes, e.g., reproduction, crossover, or mutation, to obtain a solution corresponding to the fitness value.The flowchart of the genetic algorithm is shown in Fig. 5.Each block of the proposed genetic algorithm in the flowchart is described as follows.
Define a string of a chromosome: According to the accuracy and the range of parameter, one is able to determine the number of segments.Note that each factor may have different number of bits according to its range.The number of segments is the bit length.Define a fitness function which is a kind of index to evaluate how good a chromosome is.One has to determine the population size and the number of generation.
Assume the variable x i are located on the interval [a j , b j ] and the numbers are accurate to ten-thousandths.Thus, the variable should be at least divided into (b j -a j ) ×10 4 parts.The required bit length m j of the variable x i could be obtained: Moreover, the real value could be obtained: 1 2 where, decimal (substring j ) is simply converting binary to decimal integer and it can be evaluated with MTALAB command bin2dec.

Generate an initial population:
Generate an initial population.N sets of chromosomes should be randomly generated before using a Genetic Algorithm (GA) operation.These chromosomes are called the initial population.Generally, larger population size requires fewer generations to come to an optimal solution.Moreover, the total computation time counts on N times the generation numbers.To create an initial population, the MATLAB command randint is adopted to generate matrix of uniformly distributed random binary numbers.However, randint generates numbers not strings.

Define the fitness function:
Define the fitness function: The fitness function is the performance index of a GA to resolve the viability of each chromosome.The design of the fitness function is according to the performance requirements, e.g., convergence value, error, rise time 17 .In this study, the control objective is to achieve the stability as well as the robustness of the rotary inverted pendulum.We also expect the control force is small after achieving the objective.Thus, Due to the fitness function is related to control force and error, the fitness function is defined as: Evaluation: Calculate the fitness value of each chromosome after converting the string to the real value through Eq. ( 18).According to the fitness values of chromosomes, the proper chromosomes will be selected for further reproduction, crossover and mutation.
Reproduction: By the performance of index (the fitness value), better chromosomes will be selected from preceding population to generate offspring.Reproduction is the operator carrying old strings through into a new population, depending on the fitness value.Chromosomes with high fitness values obtain a high possibility of copies in the next generation.In this study, we choose roulette wheel selection as reproduction operator.In roulette wheel selection, the expected value of an individual is that fitness divided by the actual fitness of the population.Each individual can be assigned as a slice of the roulette wheel and the size of the slice being proportional to the individual's fitness.The wheel is spun N times, where N is the number of individuals in the population.On each spin, the individual under the wheel's marker is selected to be in the pool of parents for the next generation.If the population has N individuals, the fitness value of the i th individual is f (C i ).Therefore, the probability for the individual being selected is: After evaluating the probability of each individual, we randomly produce N numbers between 0 and 1 for determining which individuals are available to make their next offspring.These chromosomes are applied to further crossover and mutation operations.

Crossover operator:
In this study, one-point crossover operator is adopted.The crossover operator exchanges the chromosome string of two selected parent chromosomes starting from a random index.It is an effective way of exchanging information and recombining segments from high-fitness chromosomes.The crossover procedure is to randomly select a pair of strings from the mating pool, then randomly determine the crossover position.Note that the randomly selection is the roulette wheel selection.There is also an example.The parent chromosomes are C 1 = 11011 and C 2 = 01100.There are only four crossover positions, because the length of each chromosome is five.If the crossover position is 3, then the offspring chromosomes are 11000 and 01111.

Mutation operator:
The mutation operator is used to avoid the possibility of mistaking a local optimum for a global one.The local optimum implies premature convergence of the population.It is an occasional random change at some string position based on the mutation probability.Mutation of a bit involves flipping a bit, changing 0 to 1 and vice versa.It is worthy to mention that mutation operation is performed to produce new offspring after crossover operation.Different from crossover operator, the mutation operator has five mutation positions if the length of each chromosome is five.For example, if the parent chromosome is 11011 and the mutation position is 5, then the fifth bit will be switched.Thus the offspring chromosome is 11010.

Generate next generation or stop:
The genetic algorithm uses the operations of reproduction, crossover and mutation to generate the next generation until the number of generation is satisfied.

SIMULATION RESULTS
The proposed fuzzy logic controller has five membership functions for each input.The initial means of the Gaussian-type input membership functions in (12) are -30, -15, 0, 15 and 30, respectively.Therefore, these ten membership functions have to be initialized since the fuzzy logic controller has two inputs, e and ݁ሶ .All the standard deviations of the Gaussian-type input membership functions are 7.5.The fuzzy logic inference engine utilizes the product inference engine.The center average defuzzification method is adopted.Since the input membership functions are formulated to be symmetric to zero, the number of optimal mean values could be reduced from 5 to 2, which are both positive.Putting negative sign to the two mean values turns out another five input membership functions.The initial positions of the rotary arm and the inverted pendulum are both located at 0.5 rad.Let the tracking command be y d [0 0] T .In other words, the rotary arm and the inverted pendulum will be driven toward zero.
Firstly, the fuzzy controller without genetic algorithm is adopted.Figure 6 and 7 show the tracking performances of the rotary arm and the inverted pendulum, respectively.If the proposed genetic algorithm is involved, the corresponding results are shown in Fig. 8 and 9. Comparing Fig. 6 with Fig. 8, it is obvious that the rotary arm with GA-tuned fuzzy controller converged to zero after 10 sec, which is much better than that without GA-tuned controller.As for the inverted pendulum, Fig. 7 demonstrates that it was not stable to zero in 25 sec.Yet, the performance with GAtuned controller is better.Figure 9 shows the inverted pendulum completely converged to zero after 13 sec.

CONCLUSION
In this study, a GA-tuned fuzzy logic controller for nonlinear model of the rotary inverted pendulum system has been presented.The mathematical model of the rotary inverted pendulum system has been driven.The proposed fuzzy logic controller adopted Gaussiantype input membership functions, singleton output membership functions and center average defuzzification method.The fitness function is the performance index of the genetic algorithm, which is with respect to tracking error and control force.We used genetic algorithm to automatically tune the membership functions of the fuzzy logic controller.Note that Roulette wheel selection was adopted as the reproduction operator.The crossover operator, a recombination operator, is applied to the mating pool to create a better offspring.
Simulation results demonstrate that the proposed controller for rotary inverted pendulum is effective in searching for optimal membership functions rather than trial and error method.It is worth to be mentioned, the length of each chromosome could be reduced by half because the membership functions are symmetric to zero.With the shorter chromosomes, the computation time will also be shorter.It is clear that the performance of the proposed fuzzy logic controller with genetic algorithm is better than that of fuzzy logic controller without GA.
For e, ሶ [the antecedent part]: Negative Big (NB), Negative Small (NS), Zero (ZE), Positive Small (PS) and Positive Big (PB).• For u [the consequent part]: Negative Big (NB), Negative Small (NS), Zero (ZE), Positive Small (PS) and Positive Big (PB).The fuzzy rule base consists of a set of fuzzy IF-THEN rules: Rule 1: IF e is NB and ݁ሶ is NB, THEN u is NB Rule 2: IF e is NS and ݁ሶ is NB, THEN u is NS ⋮ Rule 25: IF e is PB and ݁ሶ is PB, THEN u is PB Fig. 4: Structure of the GA-tuned fuzzy logic controller