Desgn and Optmzaton of Fuzzy Controller for Inverse Pendulum System Usng Genetc Algorthm H. Mehraban A. Ashoor Unversty of Tehran Unversty of Tehran h.mehraban@ece.ut.ac.r a.ashoor@ece.ut.ac.r Abstract: The reverse movng pendulum system, because of ts nonlnear unstable and non-mnmum phase dynamcs has always been a good crteron for testng and evaluatng control methods. In ths paper, a new method based on fuzzy controllng of the system s presented. Several methods are suggested for optmzng the fuzzy controllers such as, genetc algorthm and neural network. We have used genetc algorthm to fnd the optmum set of fuzzy rules among all possble rules to control the system. Ths controller not only decreases the settlng tme, but also elmnates the fluctuatons of steady state response acceptably and leads to an even moton of the pendulum, whch results n a better controllng of the system n comparson wth the exstng classc methods. KeyWords: Fuzzy Controller, Inverse Pendulum System, Rules Base, Genetc Algorthm (GA), optmzaton. INTRODUCTION A fuzzy controller s based on human logc and attempts to behave lke a human who controls a system. A fuzzy controller for a desred functon requres correct adustment. The number, shape and operatonal range of nput and output membershp functons, table of rules, etc are the parameters that should be adusted accordng to the system specfcatons. Adustng these parameters for a smple system mght be done easly, but for a complcated system t s usually a challenge task, therefore some ntellgent methods such as neural network, that has a hgh level of learnng ablty and Genetc Algorthm that s a powerful searchng method for desgnng a fuzzy controller are appled. In ths document desgn of fuzzy controller based on adustng the rule base usng genetc algorthm s presented. Three methods are usually appled n adustng rule base usng Genetc Algorthm[0] Mchgan method, Pttsburgh method teratve learnng rules In Mchgan method each rule s consdered as a chromosome and populaton conssts of a number of rules. In Pttsburgh method the rule base s consdered as a chromosome. In the thrd method chromosomes consst of a group of rules that each rule enters the chromosome after a large number of teratons. In ths paper Pttsburgh method has been appled to desgn a fuzzy controller for nverse pendulum system based on the two methods presented n [,3]. In part 2 the nverse pendulum system has been descrbed. In part 3 Genetc Algorthm structure s gven. Part 4 explans the procedure of provdng Genetc Algorthm to acheve approprate rule base for the fuzzy controller. Fnally n part 5 Fuzzy controller desgn, the Genetc Algorthm optmzaton and smulatons were done usng MATLAB software. The smulaton results verfy successful applcaton of our method to real moton stuatons. 2 THE INVERSE PENDULUM SYSTEM To solve the problem of nverse pendulum system t s requred to get famlar wth Lagrange Formula n order to be able to formulate the operaton of the system. Therefore we frst descrbe the Lagrange Formula and then usng ths formula we formulate the movement of the nverse pendulum 2. Lagrange Formula q = ( q q,..., q ) Suppose that, 2 n are ndcatons of orthonormal vectors of the space. If T s the Knetc Energy of the system and V s the Potental Energy
of the system, then L = T V s called Lagrangan. In ths case the equatons of the moblty of the system can be acheved from the followng equatons. d L L dt q q =,2,..., n = F For the nverse pendulum system whch s shown n fgure () q = x and q 2 = θ (where x s poston and θ s angle of the pendulum). x p = x + l snθ = l cosθ T = 2 y p 2 ( J + ml ) θ + 2( M + m) + ml xθ cosθ L = T V d L L dt x x = F x ( ) (2) d dt L L θ θ = 0 (3) Fgure : the parameters x, tetta defnton T = J θ + 2 m x p + y p + 2 M x 2 (,2,3 ) ( m+ M) x+ mlθ cosθ mlθ snθ = F 2 ( J + ml ) θ+ mlx cosθ mgl snθ = 0 The system model s also provded n fgure (2) V = mgl cosθ Fgure 2: the nverse pendulum system model
3 GENETIC ALGORITHM Genetc Algorthm (GA) s a powerful searchng method that operates based on selectng and producng generaton n nature. GA deals wth a populaton of chromosomes and s n search of the one that has the best characterstcs. The effcency of each chromosome s evaluated wth a functon that ndcates ts goodness (cost functon). In fact n an optmzaton we are lookng for a chromosome that has the best performance. Each chromosome s constructed from a number of smaller parts called genes. Intally, GA chooses some chromosomes randomly and generates the frst populaton. The cost functon (how good and effcent the chromosome s) s calculated for each of these chromosomes. To produce next generaton, the chromosomes that have bgger cost functon values have hgher probablty to be chosen and GA operators are appled to them n order to produce new chromosomes. GA operators are crossover and mutaton. In crossover a number of genes are two chromosomes are selected and exchanged to generate new chromosomes that make next generaton and replace the prevous generaton. In mutaton a gene of a chromosome wll be selected and replaced by another gene that s produced randomly. Cost functon s calculated for these chromosomes and other generatons are produced accordng to ts value. 4 PROVIDING GENETIC ALGORITHM In ths part a genetc algorthm for optmzng the rule base wll be provded. Accurate preparaton of ths algorthm for a problem s an mportant part of solvng t, and naccurate adustment of ths algorthm may yeld dvergence n optmum response or may lead us to locally optmum responses. The goal s to get an optmum rule base. Therefore, wth a genetc algorthm approach, an optmum rule base should be found. To do ths, each rule base s consdered as a chromosome, the tnest fracture of a rule base s a rule that descrbes the output membershp functon for a specfc state of the angle and ts dervatve (angular velocty). So each rule can be consdered as a gene. A rule can be defned as follows: If angle belongs to the membershp functon and angular velocty belongs to the membershp functon, then the control sgnal belongs to the membershp functon k. Regardng ths defnton each rule can be descrbed as a three dgt number of k. Intal generaton conssts of a number of chromosomes that there genes are produced randomly. Genes of a chromosome may be repeated, whch means havng dentcal rules n rule base s allowed. Also some rules have dentcal f parts but dfferent then parts, lke 566 and 567, n ths case there fuzzy or combnaton wll be appear n the output. Cost functon should be defned accordng to what s as sutable and unsutablty of a chromosome (rule base). The better the rule base s, the better the system wll be controlled and the output wll follow the nput suffcently. Cost functons may be t t 2 2 I = ( e + u )dt and I = 0 ( e + u )dt for 0 contnues sgnals and I = e + u and 2 2 I = ( e + u ) for dscrete sgnals. To defne cost functon frst each chromosome (rule base)and then the lnear model of the nverse pendulum system together wth the Fuzzy controller are put n a loop and are evaluated for several states of the nput and output, after that the weghted summaton of the obtaned errors are calculated due to ths equaton: f ( RB ). In ths = equaton th α α I I s the performance of the system for rule base for th ntal and fnal state, n whch s the weght of each I regardng the ntal and fnal values. In ths case the cost functon wll be maxmzed. Now the genetc algorthm operatons can be exerted on chromosomes. Choosng operaton s done accordng to the cost functon and wth a rotary method. In the mutaton operaton, frst a gene wll be chosen randomly and another gene that s randomly produced wll replace t n the chromosome. Therefore mutaton changes a rule n the rule base. Fuzzy controller has two nputs (error and ts dervatve) and one output sgnals. In the fuzzy controller Mamdan method and also operand MIN for AND and operand MAX for OR have been used.
Snce 5 membershp functons have been chosen for error and dervatve of error, length of a chromosome that s the number of genes s assumed 25. Consderng the 7 membershp functons for the output, all of the forms that a rule can have are equal to 5 5 7 = 75, therefore t s better to choose the number of populaton about 75. As descrbed above, each rule (gene) can be represented n 75 forms, snce each chromosome has 25 genes and dentcal rules are allowed, all of the forms that a chromosome may be represented s 7525. 5 PROVIDING THE OPTIMAL RULE BASE In ths part we perform GA wth populaton number of 50, crossover probablty of, mutaton probablty of 0.5 and smulaton tme of 5 seconds, for 200 generaton, and analyze the results. Step response of the nverse pendulum system wth a fuzzy controller and the best acheved rule base for a number of generatons s provded and depcted n fgure 4. As can be seen n the fgure, the response does not have overshoot and ts steady state error s zero. As t s obvous from fgure 5, t s probable that we don t get the best response n the last generaton. The best response (maxmum cost functon value) s gven n fgure 5. Although there are some fluctuatons n t, but t s ncreasng whch means better responses wll be obtaned n newer generatons. The rule base correspondent to the best answer s provded n table (). In ths table the output membershp functons are as follows. PL (stands for Postve Large), PM (stands for Postve Medum), PS (stands for Postve Small), Z (stands for zero), NL (stands for Negatve Large), NM (stands for Negatve Medum), NS (stands for Negatve Small). It can be seen that some boxes of the table are empty that occurs under three crcumstances: The nverse pendulum system does not nclude such error and error dot, so the fuzzy controller doesn t need to ths type of rule. Because of the overlap of the membershp functons, ths box s affected by the neghbors boxes rules. The dynamc of system orders that under ths condton t doesn t requre a rule and wats untl the condton changes. Fgure 3: the optmum rule base
Fgure 4: the step response for the optmum rule base By omttng the repeated rules we can acheve a table, whch s optmzed regardng number of rules too. The fuzzy controller used n ths system has two nputs and one output, so the plot of the graph (rules surface) can be shown n a three dmensonal space. Fgure (3) ndcates the relatonshp between the error, the error dot and the output control sgnal. Fgure 5: the cost functon for the optmum response(rule base) n each generaton As t can be seen t has a small steady state error, whch s because of the format of the cost functon. As can be seen n these fgures the step response of the system has small overshoot when the error s bg and the controller can control the pendulum wth a very small overshoot whle the error s small. Also the system has a small settlng tme. error NL NS Z PS PL error-dot NL NL NM NS NS - NS NM NS - - PS Z NM - - - PM PS NS - - PS PM PL - PS PS PM PL Table : optmum rule base Fgure 6: step response for ntal state [error, error-dot]= [0.2, 0.05] 6 IMPLEMENTING THE RESULTS ON THE SYSTEM The optmum fuzzy controller explaned n the prevous part s appled to the nverse pendulum n ths secton n real tme mode. The results usng Smulnk Toolbox of MATLAB software for some ntal condtons are shown n fgure 6 and fgure7.
Usng Genetc Algorthms, Dept. of computer scence and AI, Unversty of Granada, Techncal Report, #DECSAI-9508, February,995. Fgure 7: step response for ntal state 2 [error, error-dot]= [0.5, 0.05] 7 CONCLUSION In ths paper a fuzzy controller s desgned for the system of the nverse pendulum system. To optmze the fuzzy controller we used Genetc Algorthm. In ths method not only the rules, but also the number of rules s optmzed. The results showed small overshoot and also small settlng tme whch ndcates the good performance of the desgned system. The Genetc Algorthm succeeded to fnd the desred chromosome n 90th generaton between 7525 chromosomes (after searchng 2750 chromosomes) that shows the power of genetc algorthm. 8 REFERENCES [] A.Fateh, C.Lucas, Optmzaton of the Rule Base and Parameters of a Fuzzy Logc Controller by Genetc Algorthms, Proc.Int.Conf Applcaton of Fuzzy systems (ICAFS), Tabrz, Iran, pp236-240, 994. [2] O.Cordon, F.Herrera, M.Lozano, Genetc Algorthms and Fuzzy Logc n Control Processors, Unversty of Granada, Techncal Report #DECSAI-9807, July, 998. [3] R.Schleffer, H.J.Sebastan, E.K.Antonsson, Genetc Algorthms n Fuzzy Engneerng Desgn, 999 ASME Desgn Engneerng Techncal Conferences, Las Vegas, Nevada, USA. [4] O.Cordon, F.Herrera, F.Gomde, F.Hoffmann, L.Magdalena, Ten Years of Genetc Fuzzy Systems: Current Framework and New Trends, Unversdad de Granada. [5] F.Herrera, M.Lozano, J.L.Verdegay, A Learnng Process for Fuzzy Control Rules