NEESgrid logo

An Introduction to Fuzzy Logic Controllers in the LabView Environment.

 

William Green

Argonne National Laboratory

Mathematics and Computer Science Division

 

 

I:  Background

 

Fuzzy Logic is a variation on set theory where a variable can partially be an element of a set.  Fuzzy Logic was first developed in the state we know of now by Lofti Zadeh in the 1960’s.  Fuzzy Logic Controllers are intended to “think” like humans do, in this way they are helpful for problems that can not easily be set up mathematically, but can easily be expressed in words.

 

In traditional set theory, a variable is either an element of a set or it isn’t, essentially a Boolean 1/0 classification.  However, in Fuzzy Logic, a variable can partially exist in sets.  For instance, in the following picture, x is wholly in the sets A, B, and C in the traditional set theory.  However, in Fuzzy Logic, we can say x is in A to a degree of 0.7, 0.4 in B and 0.5 in C.  (Or essentially an value on [0,1].)

 

Fuzzy Logic thus allows a degree of set membership.  For instance, say we have created a feedback controller that is based on the error of control.  An error value of +8mm can exist partially in the set “Over Target”, partially in the set “Close to target”, and partially in the set “Slightly Over Target.”

Text Box: Membership in Set

 

 

 

This should suffice to introduce the ideas behind Fuzzy Logic necessary to writing a LabView Fuzzy Logic Controller.  For more information on Fuzzy Logic see:

 

[1]        http://www.ni.com/pdf/manuals/321511a.pdf

 

 

 

 

 

II:  Designing a Simple Fuzzy Logic Controller

 

First, one must determine the input variables and the desired output.  The input variables are often referred to by “linguistic terms,” a way in which to describe the meaning of the variables.  For instance, Error and Actual Position are two easily defined linguistic terms for use as input variables.  The fuzzy output must then be utilized to control the system.

 

Now, we go to the LabView Fuzzy Logic Toolkit which is located in the Tools menu of the LabView programming environment.  In true LabView style, the Fuzzy Logic Toolkit is a GUI, a Graphical User Interface.  We must first open a new Controller from the File menu and select New.  We name and define our variables by going to the Edit menu and selecting Set Editor. 

 

 

                     

 

 

 

For example, the first Fuzzy Logic Controller I designed was a simple controller to trace the data I collected of an analog channel on the DAQ box connected to my computer.  I read the voltage off of a function generator that was generating either sine, square or triangle waveforms. 

 

The output of the Fuzzy Controller I named “Fuzzy Position” and plotted versus “Wave Position,” the analog input.  I then took the difference of the two and named it “Error” and made it the first Fuzzy Controller input variable.  This controller would essentially only consider the Error term in calculating its output, though considering multiple terms is possible.

 

Next I had to define my Fuzzy Sets.  You can define a maximum of 9 sets for each variable.  For Error, I designated the sets “Far Under,” “Under,” “Mid Under,” “Slightly Under,” “Close,” “Slightly Over,” “Mid Over,” “Over,” and “Far Over.”  Now, I had to decide the range of these variables.  Since I was using a function generator whose waveforms spanned the range of ±1 volt, the maximum magnitude of error would be 2.  Thus, I made the range of the error variable to be ±2. 

 

Similarly, I defined the response variable.  The sets were named “Down Hard,” “Down,” “Slight Down,” “No Move,” “Slight Up,” “Up,” and “Up Hard.”  I also used ±2 as the range of this variable as any correction to the error would have to lie in this range.

 

 

 

            

 

 

Next, I had to designate the rules by which the Fuzzy Logic Controller would take in inputs “fuzzify” them, determine their set memberships,defuzzify” them and determine the appropriate response.  Complete step-by-step details for the LabView Fuzzy Logic Controller Design environment can be found in [1] Chapter 5.

 

 

 

 

      

 

 

Essentially, you pick a response for each combination of inputs.  Here, Wave Position was a non-factor in how the Controller should respond to the waveform.  Notice the column labeled “DoS,” this is the weighting factor.  This will modify how the Defuzzification process will work, it will weight responses to give you slightly better results if used properly.

 

The Fuzzy Logic Controller will then take in the input variables match them up with your linguistic variables, and determine how the input should be converted to the appropriate output.  It can do this by one of three “Defuzzification” methods, Center-of-Gravity, Center-of-Maximum or Mean-of-Maximum.

 

The different Defuzzification methods produce different results, but for now, we don’t need to worry about these differences.  It suffices to say that for simple controllers the outputs from the different controllers are similar enough that simply trying out the three methods and determining which one best suits your needs is the most effective way to choose a Defuzzification method.

 

Next I set up the VI to properly handle the data and the built-in capabilities of LabView did the rest of the work.  The following trace is the result of the Fuzzy Controller responding to an inputted analog sine wave.  The white line is the analog input while the red is the fuzzy logic output.

 

 

 

 

 

 

 

 

 

III:  Designing a More Complicted Fuzzy Logic Controller

 

To design a more complicated Fuzzy Logic Controller, one simply has to generalize the ideas from setting up a simple controller to a more complicated system.  Probably the most difficult part will be incorporating multiple variables.  There is a wonderful example of a 2 variable Fuzzy Logic Controller that is included with the PID control toolset of LabView, for more details see [1] Chapter 5 and the VI included in the PID toolset.

 

When controlling actual instruments, one must first test how the Fuzzy Logic Response generalizes to your specific equipment.  For instance, a fuzzy logic response of 20 is how much you want to change a given parameter, not necessarily the voltage or amperage you want to output to the instrument.  Test the response to a small test step increase in voltage and determine the necessary output levels and avoid instrument damage.  It is always a good idea to have a simulation to test your controller and controller software on before using your actual equipment.  Errors in software are easier to rectify if you’ve damaged a simulator program rather than an expensive instrument.

 

When creating more complicated VIs that utilize the Fuzzy Logic Controller be sure to have routines that will stop the VI if an error occurs.  The Fuzzy Logic Controller does not always respond well to errors in other parts of the VI, this can easily cause instrument damage.

 

IV:  Summary

 

The Fuzzy Logic Controller is a powerful tool in controlling instruments and equipment.  Using Fuzzy Logic can quickly lead to more efficient, precise and accurate controls.  For instance, the Fuzzy Logic Waveform Tracer described in Section II has since been modified to create a control for an ANCO shake table located in Argonne National Laboratory.  The Fuzzy Logic Controllers are easily adapted, a few slight changes in range of the variables and finding a conversion factor appropriate for the equipment and I was ready to write software to control the table.

 

The benefits of Fuzzy Logic Controllers are simple; they can be more accurate and more precise than their PID counterparts.  For example, the Fuzzy Logic controller on the ANCO shake table was used in a program to simulate a trace of the Sylmar earthquake of 1971.  The Fuzzy Logic Controller cut down the effective error by nearly half compared to the PID control, but more impressively cut down the standard deviation of the error by 60-70%, thus creating a far more precise control.  Further, there is better control on the overshoot that often occurs on large jumps in the earthquake trace as well as considerably less “ringing.”

 

LabView provides a powerful toolkit for setting up these Fuzzy Logic Controllers.  Essentially all the hard work of Fuzzy Logic is done internally by the LabView program, the user merely needs to go through a Graphical Interface and set up a few picture guided screens to create a powerful, highly effective tool for controlling instruments.  The Fuzzy Logic Controllers are more precise and accurate than their PID predecessors, and are actually easier to learn to a beginner.

Navigation links

  • Back to NEESGrid page
  • Back to home page
  • Support

    This work was supported primarily by the George E. Brown, Jr. Network for Earthquake Engineering Simulation (NEES) Program of the National Science Foundation under Award Number CMS-0117853.