Escolar Documentos
Profissional Documentos
Cultura Documentos
To Fuzz-C
If youre using the C language, the facilities
of FCL (and more) are available through
Byte Crafts Fuzz-C.
Kirk Zurell, Byte Craft Limited
IEC 61131 (previously named IEC 1131) is a standard that formalizes the programming
of Programmable Logic Controllers. It details a block-structured language called ST
that is suitable for processing into a control program.
Section IEC 61131-7 is concerned with Fuzzy Logic and its use in PLCs. It specifies ST
language constructs for describing linguistic and consequence variables and fuzzy rules.
This language is called FCL (Fuzzy Control Language).
Fuzz-C is Byte Craft Limiteds fuzzy logic preprocessor for C. It accepts fuzzy logic
statements embedded within a C program, and generates pure C code suitable for any
ISO-compliant C compiler.
IEC 61131-7 ST code and Fuzz-C source programs are similar in many respects. Moving
fuzzy logic code from a PLC to a custom microprocessor system programmed in C is
straightforward.
FCL
Fuzz-C
FUNCTION_BLOCK function_block_name
(C module)
VAR_INPUT
variable_name: data_type;
END_VAR
FUZZIFY variable_name
TERM term_name := (pair), (pair)
END_FUZZIFY
VAR_OUTPUT Output
variable_name: data_type;
END_VAR
DEFUZZIFY variable_name
TERM term_name := crisp;
METHOD method;
END_DEFUZZIFY
RULEBLOCK block_name
(operator definition; see below)
(activation method; see below)
(accumulation method; see below)
RULE number: IF condition THEN
conclusion
[WITH weight];
END_RULEBLOCK
FUZZY block_name
{
IF condition THEN conclusion;
VAR
variable_name: data_type;
END_VAR
END_FUNCTION_BLOCK
(C module)
The following sections give details about the differences between FCL and Fuzz-C
notation.
Values
Envelope
Example
Diagram
Fuzzy 1
Threshold
"Threshold
member"
Fuzzy 0
MEMBER { 30 }
0x20 - - - 0x 30 - - - 0x40
"Range
member"
Fuzzy 1
Range
Fuzzy 0
MEMBER { 25, 35 }
0x20 - - - 0x 30 - - - 0x40
"Triangl e
member"
Fuzzy 1
Triangle
Fuzzy 0
0x20 - - - 0x 30 - - - 0x40
"Trapezoid
member"
Fuzzy 1
Trapezoid
Fuzzy 0
0x20 - - - 0x 30 - - - 0x40
2+
Table
"Tabl e
member"
Fuzzy 1
MEMBER { (10,0),
(20, 0.25),
(30, 0.77),
(40, 0), }
Fuzzy 0
0x20 - - - 0x 30 - - - 0x40
A singleton envelope can be specified using a range envelope, with the two crisp values
set to be the same. Most fuzzy sets are triangular or trapezoidal, having three or four
important points, so this notation reduces code size.
Fuzzy sets more complex than these can be specified using a pair notation very similar to
FCL.
Key.
AND
Key.
OR
Zadeh Operators
MIN
min(x, y)
MAX
max(x, y)
Probabilistic Product/Sum
PROD
x y
ASUM
x + y x y
Bounded
Intersection/Union
BDIF
max(0, x + y - 1)
BSUM
min(1, x + y)
In Fuzz-C, fuzzy AND and OR are defined as macros in a standard header file (fuzz-c.h):
By default, the Zadeh operators are compiled in. We have found the
overwhelming majority of fuzzy logic programs use the Zadeh operators.
fm
// Code to be executed each time a consequence function is called
/* fm section */
fc_@CONSNAME += @CONSVOL;
fa_@CONSNAME += (@CONSVOL * (@CONSPOINT));
;;
Weighting (the FCL WITH clause) is accomplished differently as well. Where in FCL
explicit weights are assigned to the action of different rules and activate them, in
Fuzz-C weighting can be accomplished more naturally through the crisp values given in
CONSEQUENCE members. Adding a rule multiple times to give it extra weight is a quick but
unattractive alternative and suggests a design problem.
Even when there are only two possible outcomes, it is useful to declare many different
consequence members. Doing so allows the fuzzy rules to be more intuitive and makes
the effect of combining several rules more pronounced. Weighting the output
CONSEQUENCE members in effect weights the rules, but within the concepts expressed
through linguistic variables (and not as arbitrary values).
In the following PID controller process, the manipulated variable (the output) is likely a
single port bit, to be taken from the MSB of ManVar. With the CONSEQUENCE range centered
on 0, this is a direct copying operation, but in the fuzzy system the rules are weighted by
large and small positive and negative values. With a large result, it is far more likely that
the bit will be switched; this is useful behaviour for large errors.
CONSEQUENCE ManVar
{
MEMBER LNegative
MEMBER SNegative
MEMBER SPositive
MEMBER LPositive
}
-18 }
-6 }
6 }
18 }
FUZZY pid
{
Defuzzification Methods
/* large moves for large proportional errors */
IF Error IS LNegative THEN ManVar IS LPositive
IF Error IS LPositive THEN ManVar IS LNegative
/* small moves for changes in error */
IF Error IS normal AND DeltaError IS Positive
THEN ManVar IS SNegative
IF Error IS normal AND DeltaError IS Negative
THEN ManVar IS SPositive
/* small moves for large sums of accumulated error */
IF Error IS close AND SumError IS LPos
THEN ManVar IS SNegative
IF Error IS close AND SumError IS LNeg
THEN ManVar IS SPositive
}
Defuzzification Methods
Defuzzification methods are pre-defined in the FCL standard. In contrast, Fuzz-C uses a
user-defined defuzzification template that allows any type of defuzzification. Several prewritten templates ship with Fuzz-C.
Defuzzification Technique
Centre of Gravity
COG
CG
COGS
CG
Centre of Area
COA
Maximum
MAX
Maximum Average
MAXAVE
LM
MAXLEFT
RM
MAXRIGHT
MIDMAX
Additional Features
Fuzz-C includes some features not reflected in FCL:
Summary
Hedge functions. Functions like NEARLY or ROUGHLY can add extra detail to a fuzzy
condition, effectively adding an additional transformation to the membership
function.
Summary
Translating FCL fuzzy logic code to Fuzz-C source is straightforward; there is an almost
one-to-one correspondence between the two for the most commonly used fuzzy logic
constructions.
References
IEC: International Electrotechnical Commission, http://www.iec.ch/index.html.
IEC 61131-7: International Electrotechnical Commission (IEC). Technical committee no.
65: Industrial process measurement and control. Sub-committee 65b: Devices. IEC 61131
Programmable ControllersPart 7: Fuzzy control programming.
Fuzz-C: Byte Craft Limited, http://www.bytecraft.com/Fuzz-C.
Byte Craft Limited
A2-490 Dutton Drive
Waterloo, Ontario, Canada
N2L 6H7
sales@bytecraft.com
www.bytecraft.com