Fuzzy Logic#
Block appearance in REPEAT VISION#
Fuzzy Logic is a unit that implements operation with fuzzy logic. When one selects a unit, initialization takes place (Fig. 1) where one needs to load a file with the extension .fcl - Fuzzy Contol Language.
Important
The number and names of ports are determined by the contents of the downloaded file.
Fig. 1 Initialization of Fuzzy Logic unit#
A signal is issued at the output of the unit, which is generated based on the rules specified in the file.
Example file: tipper.fcl
FUNCTION_BLOCK tipper
VAR_INPUT
service : REAL;
food : REAL;
END_VAR
VAR_OUTPUT
tip : REAL;
END_VAR
FUZZIFY service
TERM poor := (0, 1) (4, 0) ;
TERM good := (1, 0) (4,1) (6,1) (9,0);
TERM excellent := (6, 0) (9, 1);
END_FUZZIFY
FUZZIFY food
TERM rancid := (0, 1) (1, 1) (3,0) ;
TERM delicious := (7,0) (9,1);
END_FUZZIFY
DEFUZZIFY tip
TERM cheap := (0,0) (5,1) (10,0);
TERM average := (10,0) (15,1) (20,0);
TERM generous := (20,0) (25,1) (30,0);
METHOD : COG;
DEFAULT := 0;
END_DEFUZZIFY
RULEBLOCK No1
AND : MIN;
ACT : MIN;
ACCU : MAX;
RULE 1 : IF service IS poor OR food IS rancid THEN tip IS cheap;
RULE 2 : IF service IS good THEN tip IS average;
RULE 3 : IF service IS excellent AND food IS delicious THEN tip IS generous;
END_RULEBLOCK
END_FUNCTION_BLOCK
1. File type record .fcl#
One shall specify a name for the unit function:
FUNCTION_BLOCK tipper
The input and output variables are defined. The supported data type is REAL. The number of ports with their names is determined by the number of variables and their name:
VAR_INPUT
service : REAL;
food : REAL;
END_VAR
VAR_OUTPUT
tip : REAL;
END_VAR
Each input parameter shall undergo a phasing process. One shall define ownership boundaries and functions for each characteristic:
FUZZIFY service
TERM poor := (0, 1) (4, 0) ;
TERM good := (1, 0) (4,1) (6,1) (9,0);
TERM excellent := (6, 0) (9, 1);
END_FUZZIFY
The output variable shall be defuzzified. One shall define ownership boundaries and functions for each characteristic:
DEFUZZIFY tip
TERM cheap := (0,0) (5,1) (10,0);
TERM average := (10,0) (15,1) (20,0);
TERM generous := (20,0) (25,1) (30,0);
It is necessary to select the defuzzification method: COG (center of gravity), COGS (centroid of points), COA (bisector), SM (smallest maximum), GM (greatest maximum), AM (average maximum):
METHOD : COG;
DEFAULT := 0;
END_DEFUZZIFY
One needs to select the principle of operation:
RULEBLOCK No1
AND : MIN;
ACT : MIN;
ACCU : MAX;
Set rules from input variables using the standard AND, OR, NOT operations:
RULE 1 : IF service IS poor OR food IS rancid THEN tip IS cheap;
RULE 2 : IF service IS good THEN tip IS average;
RULE 3 : IF service IS excellent AND food IS delicious THEN tip IS generous;
END_RULEBLOCK
END_FUNCTION_BLOCK
2. Membership functions#
Triangular (first x coordinate, second x coordinate (vertex), third x coordinate).
TERM test := trian 0 5 10;
Trapezoidal (first x-coordinate of lower base, first x-coordinate of upper base, second x-coordinate of upper base, second x-coordinate of lower base).
TERM test := trape 0 2 3 4;
Gauss (expectation, root mean square deviation)
TERM test := gauss 5 2;
Bell function (x descent distance, top length, value)
TERM test := gbell 2 4 2;
S and Z shaped (amplifier, center)
TERM test := sigm -4 3;
Point (point coordinate)
TERM test := 5;
Piecewise linear ((x1,y1) (x1,y1)… (xn,yn))
TERM test := (0,1) (2,1) (4,0).
3. Properties#
Property |
Default Value |
Description |
Units of measurement |
|---|---|---|---|
Number of input ports |
- |
The number of inputs and outputs depends on the content of the loaded file |
– |
Number of output ports |
- |
The number of inputs and outputs depends on the content of the loaded file |
– |
4. Inputs and outputs#
Parameters |
Input/Output |
Description |
Units of measurement |
Port type |
|---|---|---|---|---|
- |
Input |
Determined by the content of the downloaded file |
– |
Automation |
- |
Output |
Determined by the content of the downloaded |
– |
Automation |
In order to see the connection capabilities of the block, you need to go to page Description of blocks ports
See also
An example of using this block can be found in section Control systems practical guide Fuzzy logic control for valve of water supply to tank