Download presentation

Presentation is loading. Please wait.

Published byIgnacio Chaffey Modified over 2 years ago

1
Implementation of Fuzzy Controllers u The first hardware approaches that implemented fuzzy logic inference engine were the digital circuits designed by Togai (1986, 1987) and Watanabe (1990). They designed ASIC's implementing specific architectures and specialized instructions (MIN & MAX) exhibiting enhanced processing speed relatively to regular microprocessors that time. u There was a trend in the market, ten years ago, to establish dedicated have fuzzy/neural processor chips (NeuraLogix, Intel). u Such vanguard work has not flourished. The advent of powerful and fast microcontrollers and the availability of advanced tools like FuzzyTech, TILShell, OInca generating efficient software algorithms for executing fuzzy logic faded away the emergence of dedicated hardware.

2
u Motorola, Intel, TI and Microchip have some sort of programming environment for their microcontrollers, with ability of generating code, or interfacing directly with fuzzy controllers. u Even PLCs (AEG, Siemens, Klockner-Moeller, OMRON, Foxboro, Allen-Bradley) can have fuzzy controllers embedded on their system. u For sure, writing fuzzy algorithm code in C language is still one of the the best ways to have it linked to real-time applications. A brief discussion will be made on using C for such development u FUZZ-C generates C code that may be cross-compiled to the 6805, Z8C and COP8C microprocessors using separate compilers. FUZZ-C was reviewed in the March 1993 issue of AI Expert. u In order to have a didactic learning and integration into dynamical systems we will take more time explaining the use of Matlab and Simulink to design and evaluate fuzzy controllers.

3
IMPLENTING FUZZY CONTROL IN C-LANGUAGE

4
Building Fuzzy Systems with C Language u C language is the straightforward choice of a language to implement a fuzzy controller. u It is a very powerful language and the existing compilers allow the generation of highly optimized code to most hardware systems, which are very important features to real-time applications. u Following, it is shown an implementation of a fuzzy logic controller using C language. u The first part of the code defines structures to support the fuzzy inference process. After, the whole fuzzy inference process is depicted into several steps, and a C function is implemented to perform each one of these steps. Finally, a simple control loop function is presented, which can regulate a physical or simulated process by means of the implemented fuzzy controller.

5
Defining support structures typedef struct { int Tnum, Point1, Point2; double Value, Slope1, Slope2; struct mf_type *Next; } mf_type; // Used to store fuzzy membership functions // parameters, in a linked list fashion typedef struct { int Vnum, Type, Atuation, Mode, RefConn, ConnR, ConnS, Resol; double Gain, Value, LastV, DeltaV, LastDV, MinVal, MaxVal; mf_type *MembershipFunction; struct io_type *Next; } io_type; // Used to store information about the inputs // and outputs of a fuzzy system, in a linked list fashion typedef struct { double *Value; struct rule_element_type *Next; } rule_element_type; // Defines a fuzzy evaluation, present at IF and THEN // parts of a fuzzy rule typedef struct { rule_element_type *IfSide; rule_element_type *ThenSide; struct rule_type *Next; } rule_type; // Used to store rule base information (IF and THEN parts) // in a linked list fashion

6
Defining support functions… /* ***** Function used to Calculate fuzzy strengths of inputs into each membership function */ void ComputeDegreeOfMembership(Mf, Input) mf_type *Mf; double Input; { double Delta1, Delta2; /* ***** Begin ComputeDegreeOfMembership */ Delta1 = Input - (double) Mf->Point1; Delta2 = (double) Mf->Point2 - Input; if((Delta1 >= 0.0) && (Delta2 >= 0.0)) if( (Mf->Slope1 != 0.0) && (Mf->Slope2 != 0.0) ) Mf->Value = MIN( (Mf->Slope1 * Delta1), (Mf->Slope2 * Delta2) ); else if(Mf->Slope1 == 0.0) Mf->Value = MIN( UPPER_LIMIT, (Mf->Slope2 * Delta2) ); else Mf->Value = MIN( (Mf->Slope1 * Delta1), UPPER_LIMIT ); else Mf->Value = 0.0; Mf->Value = MIN(Mf->Value, UPPER_LIMIT); /* ***** End ComputeDegreeOfMembership */ }

7
/* ***** Function used to Calculate the area of a trapezoid object */ double TrapezoidArea(Mf) mf_type *Mf; { double Run1 = 0, Run2 = 0, Base, Top, Area; /* ***** Begin TrapezoidArea */ Base = (double) Mf->Point2 - Mf->Point1; if(fabs(Mf->Slope1 - 0.0) > EPS) Run1 = Mf->Value / Mf->Slope1; if(fabs(Mf->Slope2 - 0.0) > EPS) Run2 = Mf->Value / Mf->Slope2; Top = Base - Run1 - Run2; Area = Mf->Value * (Top + Base) / 2; return( Area ); /* ***** End TrapezoidArea */ } Defining support functions…

8
/* ***** Function used to Calculate the Center of Gravity of an object */ double CentroidPoint(Mf) mf_type *Mf; { double a1, a2, a3, b, c, Point; /* ***** Begin CentroidPoint */ if( fabs(Mf->Value - 0.0) > EPS ) { if(Mf->Slope1 != 0.0) b = (double)Mf->Point1 + Mf->Value / Mf ->Slope1; else b = (double)Mf->Point1; if(Mf->Slope2 != 0.0) c = (double)Mf->Point2 - Mf->Value / Mf ->Slope2; else c = (double)Mf->Point2; a1 = (b - (double)Mf->Point1) * Mf->Value / 2; a2 = (c - b) * Mf->Value; a3 = ((double)Mf->Point2 - c) * Mf->Value / 2; Point = ( a1 * ((double)Mf->Point1 + (b - (double)Mf->Point1) * 2/3) + a2 * (b + (c - b) * 1/2) + a3 * (c + ((double)Mf->Point2 - c) * 1/3) ) / ( a1 + a2 + a3 ); return(Point); } else return(0.0);} /* ***** End CentroidPoint */ Defining support functions…

9
Defining fuzzy inference functions… /* ***** Function used to transform crisp input values into fuzzy inputs */ void Fuzzification() { io_type *Si; mf_type *Mf; /* ***** Begin Fuzzification */ for(Si = SystemInput; Si != NULL; Si = Si->Next) // For each input, for(Mf = Si->MembershipFunction; Mf != NULL; Mf = Mf->Next) ComputeDegreeOfMembership(Mf, Si->Value); // Process Degree of Membership /* ***** End Fuzzification */ }

10
Defining fuzzy inference functions… /* ***** Function used to evaluate a fuzzy rule base, given the fuzzy inputs */ void RuleEvaluation() { double Strength; int i; rule_type *Rule; rule_element_type *IfPtr; rule_element_type *ThenPtr; io_type *So; mf_type *Mf; /* ***** Begin RuleEvaluation */ for(So = SystemOutput; So != NULL; So = So->Next) for(Mf = So->MembershipFunction; Mf != NULL; Mf = Mf->Next) Mf->Value = 0.0; // for all outputs, clear "Value" fields i = 0; for(Rule = RuleBase; Rule != NULL; Rule = Rule->Next) // For each rule Rule, { i++; Strength = UPPER_LIMIT; /* ***** process IF side of the rule (MIN or PROD operations) */ for(IfPtr = Rule->IfSide; IfPtr != NULL; IfPtr = IfPtr->Next) if(DefuzzyMaxMin == YES) Strength = MIN( Strength, *(IfPtr->Value) ); else Strength = Strength * *(IfPtr->Value); /* ***** process THEN side of the rule (MAX operations) */ for(ThenPtr = Rule->ThenSide; ThenPtr != NULL; ThenPtr = ThenPtr->Next) *(ThenPtr->Value) = MAX( Strength, *(ThenPtr->Value) ); } /* ***** End RuleEvaluation */ }

11
Defining fuzzy inference functions /* ***** Function used to transform fuzzy sets into crisp output values */ void Defuzzification() { io_type *So; mf_type *Mf; double SumProducts, SumAreas, Area, Centroid, Result; /* ***** Begin Defuzzification */ for(So = SystemOutput; So != NULL; So = So->Next) // for each output, { SumProducts = 0.0; // initialize variables SumAreas = 0.0; for(Mf = So->MembershipFunction; Mf != NULL; Mf = Mf->Next) // calculate fuzzy output { Area = TrapezoidArea(Mf); Centroid = CentroidPoint(Mf); SumProducts += Area * Centroid; SumAreas += Area; } if(fabs(SumAreas - 0.0) > EPS) Result = SumProducts / SumAreas; // calculate centroid area else Result = 0.0; So->Value = Result; // store on Value field } /* ***** End Defuzzification */ }

12
Defining fuzzy execution functions /********************************************************************************** **************************** Fuzzy Execution Functions **************************** **********************************************************************************/ /* ***** Execution of the Fuzzy Controller */ void FuzzyController() { Fuzzification(); RuleEvaluation(); Defuzzification(); } /* ***** Example of a Control Loop Routine */ void ControlLoop() { SystemInitialize(); while(Run == YES) { GetSystemInputs(); FuzzyController(); PutSystemOutputs(); } SystemShutDown(); }

13
MATLAB, SIMULINK AND FIS

14
Constructing Fuzzy Systems with Matlab/Simulink u FIS Editor permit building up rules and constructing membership functions that will be part of a fuzzy inference system. u There is a diagram that shows the names of each input variable on the left, and those of each output variable on the right. u Below the diagram is the name of the system and the type of inference used. The are two inference machines (1) Mamdani- type inference (rule based) and (2) Sugeno-type inference (parametric based) u Pop-up menus allow you to modify the various pieces of the inference process. u When you save your fuzzy structure, a file with extension.fis is created which can be used inside your Simulink simulation.

15
u You can start from scratch by typing at the Matlab prompt >> fuzzy u A generic FIS Editor opens, with one input, labeled input1, and one output, labeled output1. 3 1 4 2 6 5 8 7

16
1. This edit field is used to name and edit the names of the input and output variable. 2. Double-click on the icon for the output variable to open the Membership Function Editor. 3. Double-click on the system diagram to open the Rule Editor. 4. Double-click on an input variable icon to open the Membership Function Editor. 5. These menu items allow you to save, open, or edit a fuzzy system using any of the five basic GU I tools. 6. The name of the system is displayed here. It can be changed using the Save… as menu option 7. These pop-up menus are used to adjust the fuzzy inference functions, such as the defuzzification method. 8. This status line describes the most recent operation.

17
Example of a Project u Using the previous project constructed inside Matlab, we will determine fuel consumption with FIS. u The left block set-ups the m.f. for velocity, the right block the m.f. for consumption, the middle block defines the rules.

18
u You can click on the inflection points defined in the membership functions to change the shape. u Typing Edit => Add you can change the # of m.f. or have customized ones. u On the right you can see the m.f. for input and output of our system.

19
u Double-click on the Rule Editor. u You can select the rules aggregation, the weight, negation of rule u After you finish setting up the system, save as a *.fis u This example has been saved as VelCons.fis

20
u Inside Simulink you can integrate your block to fit your dynamical simulation. u Here, just for example, time (clock) is being used to generate the evaluation of velocity (just to illustrate) u The Scope generates the Consumption in terms of Velocity u The button Variable Initialization runs the script file VelC_ini to load the fuzzy structure into memory.

21
If Velocity is Low Then Consumption is High If Vel. is Medium Then Consumption is Medium If Velocity is High Then Consumption is High If Velocity is Low Then Consumption is High If Vel. is Medium Then Consumption is Medium If Velocity is High Then Consumption is Medium The rules can be changed by using FIS and saving a new *.fis structure to run in Simulink

22
Activities u Play with the current system to understand how to operate it u Incorporate a second input, Power u Rebuild your rule base, including rules containing the new input variable. u Observe the new optimum point after the inference execution of your new fuzzy system.

23
INTERACTIVE TANKS SYSTEM

24
u An interactive tank system is very instructive to model. u It has storage capacity limits, coupling and clamping effects. u Some non-linearities are found in the real implementation. u The dynamics are given by the interaction of Tank 02 and Tank 03. Tank 01 is acting as a sump in the system, providing continuous flow for the experimental set-up.

25
u Tank-02 and Tank-03 can be equated based on balance of mass: where m 2 e m 3 are the mass of liquid in both tanks, and IN, 23 and OUT are the mass flow. Considering both tanks with same dimensions area (A) and height (h), constant liquid density ( ) : m = A h = q

26
u One obtains the flow rate determining the dynamics of the height. The flow from Tank 02 to Tank 03 is determined by Bernoulli law, relating the pressure difference and load loss where u P atm is the local atmospheric pressure, g is the gravity acceleration. Thus, P n = P atm +. g. h n, and :

27
u Pneumatic valves present exponential characteristic relating their command to the flow. u One can neglect the valve dynamic response u But still needs to consider the resistive effects of a valve normally open and a valve normally closed where q in and q out represent the input and output flow Q in MAX and Q out MAX are the clamped values for input and output R 1 and R 2 are the range of control (FCV-01 and FCV-02) u 1 and u 2 are the input command for the valves.

28
Dynamic System x 1 and x 2 are the tank levels y 2 is the output flow controlled by valve FCV-02

29
A PI based closed system can control both loops

30
A supervisory control system can manage the setting-points in order to decouple the tanks interaction

31
u Following is shown a Simulink diagram containing a model of the interactive tanks system previously described (non-linearities in orange).

32
u Now, the tanks system is regulated by two PID controllers and supervised by a Fuzzy System. u The goal of the supervisor system here is to modify the set- points of the regulated variables and minimize the existing interaction between them.

33
u The supervisor Fuzzy System uses 6 rules to optimize the operation of the coupled system. These rules correspond to the supervision surface shown on the bottom.

34
u The time response for the system just described is shown below. u The first graphic shows TQ3 level control and the second one below shows TQ3 outflow control. u Set-points are shown in pink, actual variables in green and control signals in light blue. u The action of the fuzzy supervisor is visible at the instants of changing in the set-point of output flow from the tank 3, at times 3000s, 7000s and 11000s.

35
FUZZY PI CONTROLLER FOR A DC-MACHINE

36
Design of a Fuzzy-PI Controller u You are given a dc-machine model in Simulink like the block diagram below u The system is running with the provided PI. However, one can see that the PI generates the armature voltage. u We know that there is an inner current loop control that should be implemented to improve the transient response ! u However, most of people try to avoid that. Thus, using a PI controller like this actually does not optimize the transient response… u Let us try to design a fuzzy controller to replace that PI ?

37
Simulink based control of a dc-machine

38
Implement the following fuzzy controller to replace your PI

39
Use the following rules for your fuzzy controller

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google