Fuzzy Logic Controller - IIT Kgp

Transcription

Fuzzy Logic ControllerDebasis SamantaIIT Kharagpurdsamanta@iitkgp.ac.in12.02.2018Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.20181 / 34

Applications of Fuzzy LogicDebasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.20182 / 34

Fuzzy Systems : Fuzzy Logic ControllerConcept of fuzzy theory can be applied in many applications, suchas fuzzy reasoning, fuzzy clustering, fuzzy programming etc.Out of all these applications, fuzzy reasoning, also called ”fuzzylogic controller (FLC)” is an important application.Fuzzy logic controllers are special expert systems. In general, aFLC employs a knowledge base expressed in terms of a fuzzyinference rules and a fuzzy inference engine to solve a problem.We use FLC where an exact mathematical formulation of theproblem is not possible or very difficult.These difficulties are due to non-linearities, time-varying nature ofthe process, large unpredictable environment disturbances etc.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.20183 / 34

Fuzzy Systems : Fuzzy Logic ControllerA general scheme of a fuzzy controller is shown in the following figure.Fuzzy ControllerDefuzzificationmoduleFuzzy rulebaseFuzzy inferenceengine(IIT Kharagpur)InputProcess to becontrolledFuzzificationmoduleFigure1Debasis SamantaactionsSoft Computing ApplicationsOutputConditions12.02.20184 / 34

Fuzzy Systems : Fuzzy Logic ControllerA general fuzzy controller consists of four modules:1a fuzzy rule base,2a fuzzy inference engine,3a fuzzification module, and4a defuzzification module.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.20185 / 34

Fuzzy Systems : Fuzzy Logic ControllerAs shown in Figure 1, a fuzzy controller operates by repeating a cycleof the following four steps :1Measurements (inputs) are taken of all variables that representrelevant condition of controller process.2These measurements are converted into appropriate fuzzy sets toexpress measurements uncertainties. This step is calledfuzzification.3The fuzzified measurements are then used by the inferenceengine to evaluate the control rules stroed in the fuzzy rule base.The result of this evaluation is a fuzzy set (or several fuzzy sets)defined on the universe of possible actions.4This output fuzzy set is then converted into a single (crisp) value(or a vector of values). This is the final step called defuzzification.The defuzzified values represent actions to be taken by the fuzzycontoller.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.20186 / 34

Fuzzy Systems : Fuzzy Logic ControllerThere are two approaches of FLC known.1Mamdani approach2Takagi and sugeno’s approachMamdani approach follows linguistic fuzzy modeling andcharacterized by its high interpretability and low accuracy.On the other hand, Takagi and Sugeno’s approach follows precisefuzzy modeling and obtains high accuracy but at the cost of lowinterpretabily.We illustrate the above two approaches with two examples.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.20187 / 34

Mamdani approach : Mobile RobotConsider the control of navigation of a mobile robot in thepresence of a number of moving objects.To make the problem simple, consider only four moving objects,each of equal size and moving with the same speed.A typical scenario is shown in Figure 2.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.20188 / 34

Mamdani approach : Mobile RobotO2O3D O4O1RDebasis Samanta (IIT Kharagpur)SSoft Computing Applications12.02.20189 / 34

Mamdani approach : Mobile RobotWe consider two parameters : D, the distance from the robot to anobject and θ the angle of motion of an object with respect to therobot.The value of these parameters with respect to the most criticalobject will decide an output called deviation (δ).We assume the range of values of D is [0.1, . 2.2] in meter and θis [-90, . , 0, . 90] in degree.After identifying the relevant input and output variables of thecontroller and their range of values, the Mamdani approach is toselect some meaningful states called ”linguistic states” for eachvariable and express them by appropriate fuzzy sets.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201810 / 34

Linguistic StatesFor the current example, we consider the following linguistic states forthe three parameters.Distance is represented using four linguistic states:1VN : Very Near2NR : Near3VF : Very FarFR : FarAngle (for both angular direction (θ) and deviation (δ)) are representedusing five linguistic states:1LT : Left42AL : Ahead Left3AA: Ahead4AR : Ahead Right5RT : RightDebasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201811 / 34

Linguistic StatesThree different fuzzy sets for the three different parameters are givenbelow (Figure 3). D1.0VNNRFRVF1.52.21.00.01.040.10.8Distance D in mt 1.0LTALAAARRT 1.00.0LTALAAAR045RT0.0-90-4504590Angle ɵ in degreeDebasis Samanta (IIT Kharagpur)-90-45DeviationSoft Computing Applications90 in degree12.02.201812 / 34

Fuzzy rule baseOnce the fuzzy sets of all parameters are worked out, our next step inFLC design is to decide fuzzy rule base of the FLC.The rule base for the FLC of mobile robot is shown in the form of atable below.LTVNNRFRVFDebasis Samanta (IIT Kharagpur) AA AA AAAAALAAARRT AR AL AL AAAA RT AA AA AA AR AA AA AA AA AA AASoft Computing Applications12.02.201813 / 34

Fuzzy rule base for the mobile robotNote that this rule base defines 20 rules for all possible instances.These rules are simple rules and take in the following forms.Rule 1: If (distance is VN ) and (angle is LT) Then (deviation is AA).Rule 13: If (distance is FR ) and (angle is AA) Then (deviation isAR).Rule 20: Rule 1: If (distance is VF ) and (angle is RT) Then(deviation is AA)Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201814 / 34

Fuzzification of inputsThe next step is the fuzzification of inputs. Let us consider, at anyinstante, the object O3 is critical to the Mobile Robot and distanceD 1.04 m and angle θ 30o (see Figure 2).For this input, we are to decide the deviation δ of the robot asoutput.From the given fuzzy sets and input parameters’ values, we saythat the distance D 1.04m may be called as either NR (near) orFR (far).Similarly, the input angle θ 30o can be declared as either AA(ahead) or AR(ahead right).Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201815 / 34

Fuzzification of inputsHence, we are to determine the membership values corresponding tothese values, which is as follows.x 1.04mµNR (x) 0.6571µFR (x) 0.3429y 30oµAA (y) 0.3333µAR (y ) 0.6667FRNR1.00.00.1ARAA1.00.00.81.52.2xDebasis Samanta (IIT Kharagpur)-45045y301.04Soft Computing Applications12.02.201816 / 34

Fuzzification of inputsHint : Use the principle of similarity.xy δ1δ2FRNR1.00.00.00.10.81.52.2-45xx1 1.5 1.041.5 0.8 ,045y301.04Thus,ARAA1.0that is, x 0.6571yx 1 2Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201817 / 34

Rule strength computationThere are many rules in the rule base and all rules may not beapplicable.For the given x 1.04 and θ 30o , only following four rules out of 20rules are firable.R1: If (distance is NR) and (angle is AA) Then (deviation is RT)R2: If (distance is NR) and (angle is AR) Then (deviation is AA)R3: If (distance is FR) and (angle is AA) Then (deviation is AR)R4: If (distance is FR) and (angle is AR) Then (deviation is AA)Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201818 / 34

Rule strength computationThe strength (also called α values) of the firable rules are calculated asfollows.α(R1) min(µNR (x), µAA (y)) min(0.6571, 0.3333) 0.3333α(R2) min(µNR (x), µAR (y)) min(0.6571, 0.6667) 0.6571α(R3) min(µFR (x), µAA (y )) min(0.3429, 0.3333) 0.3333α(R4) min(µFR (x), µAR (y)) min(0.3429, 0.6667) 0.3429In practice, all rules which are above certain threshold value of rulestrngth are selected for the output computation.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201819 / 34

Fuzzy outputThe next step is to determine the fuzzified outputs corresponding toeach fired rules.The working principle of doing this is first discussed and then weillustrate with the running example.Suppose, only two fuzzy rules, R1 and R2, for which we are to decidefuzzy output.R1: IF (s1 is A1 ) AND (s2 is B1 ) THEN (f is C1 )R2: IF (s1 is A2 ) AND (s2 is B2 ) THEN (f is C2 )Suppose, s1 and s2 are the inputs for fuzzy variables s1 and s2 . µA1 ,µA2 , µB1 , µB2 , µC1 and µC2 are the membership values for differentfuzzy sets.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201820 / 34

Fuzzy outputThe fuzzy output computation is graphically shows in the followingfigure. A1 B1 C1 A2 B2 C 2s1*Debasis Samanta (IIT Kharagpur) CCombine outputs2*Soft Computing Applications12.02.201821 / 34

Fuzzy outputNote:We take min of membership function values for each rule.Output membership function is obtained by aggregating themembership function of result of each rule.Fuzzy output is nothing but fuzzy OR of all output of rules.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201822 / 34

Illustration : Mobile RobotFor four rules, we find the following results.NRAART1.0R1 :0.33330.00.81.01.50NR4545AR90AAR2 :0.65710.00.81.5045-45AA1.0045ARR3 :0.33330.00.81.50045AR1.04590045AAR4 :0.33330.00.81.5D 1.04Debasis Samanta (IIT Kharagpur)045-45Ɵ 30Soft Computing Applications12.02.201823 / 34

Illustration : Mobile RobotARAART0.6571 0.34-450.333304590Aggregation of all resultsDebasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201824 / 34

DefuzzificationThe fuzzy output needs to be defuzzified and its crisp value has to bedetermined for the output to take decision.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201825 / 34

Illustration : Mobile RobotFrom the combined fuzzified output for all four fired rules, we get thecrisp value using Center of Sum method as follows.v 12.5 71 25 45 25.56 0 25.56 012.5 39.79 25 25.5639.7/0 19.59ARAART1.0A30.50.6571 0.34A2A4-459045025.56 / 00.3333A125/4512.5 / 71Conclusion : Therefore, the robot should deviate by 19.58089 degreetowards the right with respect to the line joining to the move of directionto avoid collision with the obstacle O3 .Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201826 / 34

Takagi and Sugeno’s approachIn this approach, a rule is composed of fuzzy antecedent andfunctional consequent parts.Thus, any i-th rule, in this approach is represented byIf (x1 is Ai1 ) and (x2 is Ai2 ) . and (xn is Ain )Then, y i a0i a1i x1 a2i x2 . ani xnwhere, a0 , a1 , a2 , . an are the co-efficients.The weight of i-th rule can be determined for a set of inputs x1 , x2 ,. xn as follows.w i µiA1 (x1 ) µiA2 (x2 ) . µiAn (xn )where A1 , A2 , . , An indicates membership function distributionsof the linguistic hedges used to represent the input variables andµ denotes membership function value.The combinedaction then can be obtained asPk i ii w yy Pk i ; where k denotes the total number of rules.iwDebasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201827 / 34

Illustration:Consider two inputs I1 and I2 . These two inputs have the followinglinguistic states :I1 : L(low), M(Medium), H(High)I2 : NR(Near), FR (Far), VF(Very Far)Note:The rule base of such as system is decided by a maximum of3 3 9 feasible rules.Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201828 / 34

Illustration:The output of any i-th rule can be expressed by the following.y i f (I1 , I2 ) aji I1 bki I2 ; where, j,k 1,2,3.Suppose : a1i 1, a2i 2, a3i 3 if I1 L, M and H, respectively.b1i 1, b2i 2, b3i 3 if I2 NR, FR, and VF , respectively.We have to calculate the output of FLC for I1 6.0 and I2 2.2Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201829 / 34

Illustration:Given the distribution functions for I1 and I2 as below. I11.00.0L5.0M10.0H15.0 I21.00.0I1Debasis Samanta (IIT Kharagpur)NR1.0FRVF2.03.0I2Soft Computing Applications12.02.201830 / 34

Solutiona) The input I1 6.0 can be called either L or M. Similarly, the inputI2 2.2 can be declared either FR or VF.b) Using the principal of similarity of triangle, we have the following.µL (I1 ) 0.8µM (I1 ) 0.2µFR (I2 ) 0.8µVF (I2 ) 0.2c) For the input set, following four rules can be fired out of all 9 rules.R1: I1 is L and I2 is FRR2: I1 is L and I2 is VFR3: I1 is M and I2 is FRR4: I1 is M and I2 is VFDebasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201831 / 34

Solutiond) Now, the weights for each of the above rules can be determined asfollows.R1: w 1 µL µFR 0.8 0.8 0.6R2: w 2 µL µVF 0.8 0.2 0.16R3: w 3 µM µFR 0.2 0.8 0.16R4: w 4 µM µVF 0.2 0.2 0.6e) The functional consequent values for each rules can be calculatedas below.y 1 I1 2I2 6.0 2 2.2 10.4y 2 I1 3I2 6.0 3 2.2 12.6y 3 2I1 2I2 2 6.0 2 2.2 16.4y 4 2I1 3I2 2 6.0 3 2.2 18.6Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201832 / 34

Solutionf) Therefore, the output y of the controller can be determined asfollows.1 12 y 2 w 3 y 3 w 4 y 4y w y w w 12.041 w 2 w 3 w 4Debasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201833 / 34

Happy LearningDebasis Samanta (IIT Kharagpur)Soft Computing Applications12.02.201834 / 34

Fuzzy Systems : Fuzzy Logic Controller There are two approaches of FLC known. 1 Mamdani approach 2 Takagi and sugeno's approach Mamdani approach follows linguistic fuzzy modeling and characterized by its high interpretability and low accuracy.