Creating a Fuzzy Logic Controller in MATLAB

Creating a Fuzzy Logic Controller in MATLAB

So recently I have been dabbling a bit with Fuzzy Logic in MATLAB. This is a short tutorial or guide as to how to use the FIS Editor in MATLAB. First, we start by opening said editor and its whereabouts are found in the below screenshot.

FIS

We will be working on a Fuzzy Logic controller for a simple washing machine. Our washing machine will use four variables. The typical washing machine has a fuzzy logic engine which allows it to take into account a few variables as it relates to the laundry, and conjure a suitable washing cycle to best cater for the load. In this case, I have designed a fuzzy logic engine to simulate that of a state of the art washing machine which evaluates the size of the load, the amount of dirt present and the texture of the fabric to be washed. This simulation is designed with three variables load_size, level_of_dirt and fabric_texture. These three variable are used to ultimately determine the washing_time. Below are screen shots of each variable and its range and shape as used in the inferencing engine.

The FIS Editor looks like this originally:

Capture

It boasts one input variable, The inferencing engine type (mamdani is the default and seemingly preferred one) and the output variable. By using the Edit command in the context menu, you can Add/Remove Variable (Edit -> Add Variable/Remove Selected Variable),  Modify Membership Functions or change Rules. Each of these has a bearing on how your control system will function. Below is a screen shot of the completed FIS Editor after adding the three input variables and the rules to govern the inferencing.

Capture

and the rules…

Capture

 

In setting up the intricacies of the membership functions of each input variable, it is important to take into consideration, the nature of the functions and appropriate value ranges for each. Below is the breakdown of the membership functions of each variable.

Capture

 

load_size has a range which ends at 50, indicating the maximum number of pounds worth of laundry.

Capture

level_of_dirt is used to ascertain a rough estimate of how soiled the fabric may be, out of 10.

Capture

fabric_texture takes a rough estimation as to how tough the fabric might be, out of 10.

Capture

washing_time is the amount of time that will be allotted, in terms of minutes (60 is max), to the wash cycle given the unique combinations of the variables, relative to the laundry load. Using the rules that were inserted into the inferencing system, the different combinations of values will be the determinants of how long a wash cycle will last.

This table shows some test values used to test the system.

Inputs

Output

load_size(lbs)

level_of­_dirt(%)

fabric_texture(%)

washing_time(mins)

25

50

50

30

10.9

11.6

13.6

10.7

37.1

74.2

100

35.7

50

100

100

37.5

31.7

80

20

29.1

32.6

80

80

36.8

50

0

100

37.5

50

50

100

37.5

5

100

100

24.9

27

25

10

21.8

The rules used to govern the inferencing system puts the main emphasis on the size of the load. If the load is big, it will wash for long and if it is small, it will wash for a short period of time. At those points, the level of dirt and texture of the fabric is of little consequence. If the load size is medium, it will then go on to evaluate the level of dirt and set a medium or long time accordingly. The texture of the fabric also has high bearing on the outcome of the washing cycle, regardless of the dirt present and/or size of the load. If the fabric is tough, it will wash for long, if delicate, it will wash for short.

To play with the different combinations of the input variables, you go to View -> Rules in the context menu which will give you a tool looking like the screen shot below. By moving the red markers, the values will change and the output value will be calculated according to the rules.

Capture

Of course, these outcomes are relative to my rules. By tweaking the rules, you determine how your fuzzy controller will work and you have greater control of the outcomes.