jFuzzyLogic/html/html_old/fcl_content.html

93 lines
3.7 KiB
HTML
Raw Normal View History

2014-12-19 14:30:46 +01:00
<center><h3> FCL example explained </h3></center>
Fuzzy Control Langage <i><b>FCL</b></i> is defined by IEC 1331 part 7.
It's a simple language to define a fuzzy inferece system.
We'll take a look at an example, for a more detailed explanation, please read the spec.
<p>
Keep in mind that FCL is defined as a 'Control language', so the main concept is a 'control block' which has some input and output variables (it's not a 'programm' in the usual way).<br>
We'll be using this <a href=example_fcl.html>example</a>, first take a look at it.
<p>
Ok, let's try to annalize each line:
<ul>
<li>First you define each <i><b>FUNCTION_BLOCK</b></i> (there may be more than one in each file)
<table border=0 bgcolor=#ccfccc><tr><td><pre> FUNCTION_BLOCK tipper </pre></td></tr></table>
<p>
<li> Then input and output variable/s are defined (variable type is only <i><b>REAL</b></i>, integer is not implemented yet)
<table border=0 bgcolor=#ccfccc><tr><td><pre>
VAR_INPUT
service : REAL;
food : REAL;
END_VAR
VAR_OUTPUT
tip : REAL;
END_VAR
</pre></td></tr></table>
<p>
<li> How each input variable is fuzzified is defined in <i><b>FUZZIFY</b></i> block. In each block we define one or more <i><b>TERMs</b></i> (also called LinguisticTerms). Each term is composed by a name and a membership function. E.g.:
<table border=0 bgcolor=#ccfccc><tr><td><pre>
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
</pre></td></tr></table>
In this lines we define how variable <i><b>service</b></i> will be fuzzified. Three terms are used, for instance term <i><b>poor</b></i> uses a piece-wise linear membership function defined by points x_0 = 0, y_0 = 1 and x_1 = 4, y_1 = 0<br>
<img src=images/service.png><p>
<i><b>food</b></i> variable fuzzify block is define likewise:<p>
<table border=0 bgcolor=#ccfccc><tr><td><pre>
FUZZIFY food
TERM rancid := (0, 1) (1, 1) (3,0) ;
TERM delicious := (7,0) (9,1);
END_FUZZIFY
</pre></td></tr></table><p>
<img src=images/food.png><br>
<p>
<li> Output variables are defuzzified to get a 'real' output number, this is defined in <i><b>DEFUZZIFY</b></i> block. Like FUZZIFY block, linguistic terms (or TERMs) are defined:
<table border=0 bgcolor=#ccfccc><tr><td><pre>
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);
</pre></td></tr></table><p>
<img src=images/tip.png><p>
Then we may define some other parameters:
<table border=0 bgcolor=#ccfccc><tr><td><pre> METHOD : COG; </pre></td></tr></table>
Use 'Center of gravity' as defuzzifier's method.<p>
<table border=0 bgcolor=#ccfccc><tr><td><pre> DEFAULT := 0; </pre></td></tr></table>
Use '0' as default value (if no rule actuvates this variable).<p>
</pre></td></tr></table>
<li> We can define now the rules. This is done using a <i><b>RULEBLOCK</b></i>. First we define some parameters:
<table border=0 bgcolor=#ccfccc><tr><td><pre>
RULEBLOCK No1
AND : MIN;
</pre></td></tr></table>
Use 'min' for 'and' (also implicit use 'max' for 'or' to fulfill DeMorgan's Law) <p>
<table border=0 bgcolor=#ccfccc><tr><td><pre> ACT : MIN; </pre></td></tr></table>
Use 'min' activation method<p>
<table border=0 bgcolor=#ccfccc><tr><td><pre> ACCU : MAX; </pre></td></tr></table>
Use 'maximum' as accumulation method.<p>
And now define some rules (3 in this case)
<table border=0 bgcolor=#ccfccc><tr><td><pre>
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
</pre></td></tr></table>
Ok, that's it, you've got a fuzzy controller.