Anda di halaman 1dari 7

VHDL PACKAGE FOR DESCRIPTION OF FUZZY LOGIC CONTROLLERS

D. Galán, C. J. Jiménez, A. Barriga, S. Sánchez Solano

Instituto de Microelectrónica de Sevilla - Centro Nacional de Microelectrónica


Avda. Reina Mercedes s/n, (Edif. CICA)
E-41012, Sevilla, Spain

European Design Automation Conference (EURO-VHDL’95),


pp. 528-533, Brighton - Great Britain, September 18-22, 1995.

© 1995 IEEE. Personal use of this material is permitted. However, permission to reprint/republish this material for adver-
tising or promotional purposes or for creating new collective works for resale or redistribution to servers or lists, or to reuse
any copyrighted component of this work in other works must be obtained from the IEEE.

This material is presented to ensure timely dissemination of scholarly and technical work. Copyright and all rights therein
are retained by authors or by other copyright holders. All persons copying this information are expected to adhere to the terms
and constraints invoked by each author’s copyright. In most cases, these works may not be reposted without the explicit per-
mission of the copyright holder.
VHDL Package for Description of Fuzzy Logic Controllers

D. Galán, C. J. Jiménez, A. Barriga and S. Sánchez-Solano

Dpto. de Diseño de Circuitos Analógicos. Centro Nacional de Microelectrónica,


Edificio CICA, Avda. Reina Mercedes s/n, 41012-Sevilla, SPAIN.

Abstract tions to any of the market-available VHDL simulators) and


second, its integration into VHDL-based design environ-
The particular architecture of fuzzy systems has led to ments (in such a way that simulation results at circuit and
the introduction of specific simulators on the market, usu- algorithmic levels can be compared immediately).
ally isolated from design environments. This article pre-
sents a VHDL package that allows high level descriptions 2: Basic concepts of fuzzy logic
and simulations of fuzzy controllers. The importance of this
package to fuzzy hardware design lies not only in its porta- The application of approximate reasoning techniques
bility to any VHDL simulator, but also in that it allows ver- has emerged as a valid alternative in control problems
ification of the simulation results of a particular system in where the system is not easily described by an analytic
a unique and standard simulation environment, from algo- model [4]. In an inference system based on fuzzy logic, the
rithm description level to RTL level (synthesizable) or logic knowledge base is structured as a group of IF-THEN rules:
gates. Finally, an example is included to demonstrate the
package functionality. IF X1 is A1r and X2 is A2r and... Xp is Apr THEN Yk is Bkr

where X1, ..., Xp and Yk represent the system inputs and out-
1: Introduction put, and A1r, ..., Apr and Bkr are linguistic labels defined by
means of fuzzy sets. These fuzzy sets are characterized by
Hardware implementation of electronic systems membership functions which may assume different shapes
requires the extensive use of verification stages throughout depending on the problem, though in practice, the use of
the design process to guarantee correct functionality of the piecewise linear functions is usually sufficient [5] [6].
final product. The use of VHDL for modeling and simula- Figure 1 shows the structure of a fuzzy controller
tion is especially appealing since it provides a formal together with the controlled system. An FLC consists of a
description of the system and allows the use of specific group of rules and an inference mechanism capable of pro-
description styles to cover the different abstraction levels cessing such information. In addition to these basic ele-
used in the design (architectural, algorithmic, RT and logic
level).
FUZZY CONTROLLER
As consequence of its adaptability to complex control
problems, the interest in fuzzy logic controllers (FLCs) has Rule
grown in the last years. As yet, these systems have been Memory
Fuzzifier Defuzzifier
simulated using specific CAD tools, independent of the Inference
design environment. However, some authors have investi- Engine
gated the possibility of using VHDL as a language to sup- Antecedents Consequents
port the data structures and functions required for fuzzy
system simulation [1] [2]. CONTROLLED
This communication presents a VHDL package which SYSTEM
allows formal description and simulation of fuzzy control-
lers. The advantages of this approach derive from first, the
use of a standard [3] (enabling portability of the descrip- Figure 1: Fuzzy control system.
ments, two interface blocks are needed to perform the
transformation between fuzzy values used in the controller input_array
and deterministic values that make up the input and output
of the controlled system (fuzzifier and defuzzifier). X 1 X2 ... X I
Input/Output
The most widely used inference mechanism is that a) interface
proposed by Mamdani, which uses the maximum and min- output_array
imum as basic operators [7]. Figure 2 presents an example Y Y ... Y
1 2 k
of FLC operation showing the case of two rules whose
antecedents are symmetric triangles. The membership
degree of the input to the antecedents is determined in the
fuzzification stage. The activation degree of the rule is name [STRING]
obtained as the minimum of the membership degrees. The data [ID_ARRAY]
fuzzy set resulting from truncating the consequent of each b) mfc centr [REAL]
rule to the value of its activation degree determines the par- area [REAL]
tial conclusion given by this rule. Finally, the rules are shape [NATURAL]
aggregated to obtain the controller output. Since the result
of the inference process is a fuzzy set, a defuzzification
stage must be included to obtain a concrete output value num_gra [STRING]
(Y) [8]. c) goa_ goa [REAL[1:N]]
record
consec [ID_ARRAY[1:M]]
3: VHDL package for FLCs.
To extend the capabilities of VHDL to support descrip- N = Number of Inputs.
tion and simulation of FLCs, our package includes defini- M = Number of Rules + 1.
tions of data structures that store fuzzy information, and
several functions to describe fuzzy inference algorithms. Figure 3: Basic data types.
The different elements are defined for integer and real
types, that allow modelling digital and analog controller
realizations. The interface between the FLC and the process under
control is characterized using the “input_array” and
3.1: Data structures. “output_array” types. Both correspond to arrays whose ele-
ments contain the input and output values. A membership
Basic data structures have been defined to store the function is described by the record (“mfc”) formed by five
values of the input and output variables, the membership fields: “name”, “data”, “centr”, “area”, and “shape”. The
function descriptions, and the activation degrees of the dif- first field stores the linguistic label that identifies the mem-
ferent rules. Figure 3 presents a schematic of these data bership function. The second notes its description. The
structures. third and fourth fields refer to its centroid and area, and the
last one represents its function’s format, which can be one
of the following: Triangular, Trapezoidal, Gaussian, or
Antecedents Partial Conclusions Cauchy. Finally, the activation degrees of the rules are
stored in another record-type object named “goa-record”,
MIN composed by three fields: “goa”, “consec”, and “num_gra”.
Aggregation
The first and the second are arrays where the activation
degree and the label of the affected output variable’s mem-
R1 bership function are stored, respectively. The number of
Inference
MAX pairs (goa-consec) located on these two arrays is stored in
the last field.
Y Using these types, the package includes another set of
MIN
more complex definitions which enable grouping the data
X1 R2 X2 corresponding to the different linguistic variables appear-
from other rules ing in the rules (Figure 5). The “mfc_set” groups the defi-
nitions of the membership functions associated with a
Figure 2: Symbolic representation of fuzzy inference. variable, while “mfc_all_sets” defines the complete data-
the pairs goa-consequent_label obtained from the rule base
mfc_all_sets inference); “def_method” (where the defuzzification
method is chosen); “psi_value” (parameter used in the psi-
mfc_set quality defuzzification method); “agr_method” (where the
a)
aggregation function is selected); and “imp_method”
(where the implication method is chosen). Implication
mfc functions are Minimum, Product, Boundary Product, and
Drastic Product. Aggregation functions are Maximum and
name [STRING] Sum.
num_mfc [NATURAL]
Input variables are jointly associated in a variable
“input_var” and the output in “output_var”. In both cases,
mfcs [MFC_SET]
these are arrays whose elements are “L_var” and
min_value [REAL] “Out_L_var” types, respectively.
b) L_var max_value [REAL]
int_step [REAL] 3.2: Functions.
discret [REAL]
actual_value [REAL] Once the available data structures are introduced, we
will describe the functions that handle them. First, there are
initialization functions that allow describing the system's
database. “init_all_mfc” and “init_all_vars“are functions
ling_var [L_VAR] which use data files to initialize all the membership func-
GradeOfActiv [GOA_RECORD] tions and all the linguistic variables, respectively.
def_method [NATURAL] “init_mfc”, “init_inputs”, and “init_outputs” are other ini-
c) tialization functions to initialize the membership functions
Out_L_var psi_value [REAL]
and the linguistic variables with data inside the VHDL
agr_method [NATURAL]
code.
imp_method [NATURAL] The next group of functions implements the inference
mechanism. “fzis” performs the fuzzification, that is, it
returns the membership degree of the input variable to a lin-
input_var output_var
guistic label. “fzand” and “fzor” are the connectives of the
d)
different rules. Lastly, “fzthen” performs the fuzzy implica-
tion function and the aggregation of the conclusions of the
L_var Out_L_var different rules.
Several defuzzification methods are provided by the
“defuzzifier” function, which evaluates the controller out-
Figure 5: Complex data types. put according to the values stored in the “def_method” field
of the output variables, returning a single, crisp value.
base of membership functions used in the fuzzy controller. Defuzzification strategies considered in this VHDL pack-
Linguistic variables are defined using “L_var”. This is age include both conventional (Center of Area, Mean of
a record consisting of the following fields: “name” (vari- Maximum, etc.) and simplified (Fuzzy Mean, Weighty
able name); “num_mfc” (number of membership func- Fuzzy Mean, Level Grading Method, Yager, etc.) methods
tions); “mfcs” (array with the definition of membership [8].
functions); “min_value” and “max_value” (minimum and The “defuzzifier_all” function can be used when sev-
maximum values of the variable’s universe of discourse); eral output variables are needed. It returns an array-type
“int_step” (value used for the numerical integration in the object with the defuzzification’s crisp values of each output
defuzzification); “discret” (discretization of membership variable, ordered by the initialization sequence.
degrees); and “actual_value” (actual value of the variable).
Output variables are described by “Out_L_var” which, 4: Application to an example.
in addition to including “L_var”, contains information
about the activation degree of the rules, the defuzzification This section demonstrates the use of the proposed
mechanism, and the aggregation and implication functions. package, applying it to a typical example of fuzzy control
It can be described using a record with six fields: found in literature [9]. The purpose is to control the trajec-
“ling_var” (“L_var” type); “GradeOfActiv” (which stores tory of a truck as it backs to a loading dock (Figure 6). The
The VHDL description of the FLC is shown in Figure
Y Load Point. (100,50) 9. Basically, it contains a process which describes the algo-
rithm of the system operation. The specification of the FLC
architecture includes the following steps: 1) initialization
of membership functions, and input and output variables;
2) description of the rulebase and execution of the infer-
ence process; and 3) defuzzification and assignment of
X results to output.
An “input_var” variable is defined in the declarative
Operation site part of the FLC process to represent the controller input and
an “output_var” to identify the output. In addition, three
rear
(x,y)
RB RU RV VE LV LU LB
1.0
phi
0.8
front
0.6
psi
0.4
Meaning of the variables
0.2
Figure 6: Graphic description. 0.0
-90.0 10.0 110.0 210.0
aim is that the truck arrive to the platform at a 90o angle and Input 1: Angle between the truck
in such a manner that its position locks into the space pro- and the horizontal line (PHI)
vided for such purpose. Let us assume that there is suffi-
cient distance in the Y-axis between the initial position of LE LC CE RC RI
1.0
the truck and the destination so as to reject the coordinate
Y, thus the truck movement depends exclusively on its X- 0.8
coordinate and the angle (PHI) formed by the longitudinal
axis of the truck with the horizontal axis. These two vari- 0.6
ables are the input of the fuzzy controller which, according
0.4
to the rules shown in Figure 7, supply as output the new
direction which the truck wheels should assume (PSI). Fig- 0.2
ure 8 shows the membership functions used for antecedents
0.0
and consequents. 0.0 20.0 40.0 60.0 80.0 100.0
Input 2: Horizontal position (X)
X
PHI LE LC CE RC RI
PS PM PM PB PB NB NM NS ZE PS PM PB
RB 1.0
RU NS PS PM PB PB
0.8
RV NM NS PS PM PB
0.6
VE NM NM ZE PM PM
0.4
LV NB NM NS PS PM
0.2
LU NB NB NM NS PS
0.0
LB NB NB NM NM NS -30.0 -10.0 10.0 30.0
Output: Angle of the wheel (PSI)
PSI

Figure 7: Rulebase. Figure 8: Memberchip function definition.


use work.FUZZY4.all; -- Initialize the inputs and output variables.
--
entity FLC is vars_IN(1):=init_inputs(“M(PHI)”,-90.0,
port ( FLC_input : in input_array; 270.0,-90.0,0.05,0.0,7,mfc_set_PHI);
FLC_output: out output_array);
end FLC; vars_IN(2):=init_inputs(“M(X)”,0.0,100.0,
25.0,0.05,0.0,5,mfc_set_X);
architecture FLC_arch of FLC is
begin vars_OUT(1):=init_outputs(init_inputs
FLC:process (“M(PSI)”,-30.0,30.0,0.0,0.05,0.0,7,
variable mfc_set_PHI : mfc_set; mfc_set_PSI),IMP_MIN,AGR_MAX,COA_CRIT,0.0);
variable mfc_set_X : mfc_set; --
variable mfc_set_PSI : mfc_set; -- Rules setting and inference mechanism
variable vars_IN : input_var; --
variable vars_OUT : output_var; while (1=1) loop
begin --
-- -- Turns to zero the Grade of Activity array
-- Initialize the membership funcions groups -- places in the output record.
-- --
mfc_set_PHI:=( vars_OUT(1).GradeOfActiv:=ini_grade_activ;
init_mfc(“RB”,-45.0,56.0,0.0,55.0,0.0,0.0),
init_mfc(“RU”,30.0,40.0,0.0,30.0,0.0,0.0), fzthen(fzand(fzis(“RB”,vars_IN(1)),
init_mfc(“RV”,70.0,20.0,0.0,20.0,0.0,0.0), fzis(“LE”,vars_IN(2))),
init_mfc(“VE”,90.0,10.0,0.0,10.0,0.0,0.0), “PS”,vars_OUT(1));
init_mfc(“LV”,110.0,20.0,0.0,20.0,0.0,0.0),
init_mfc(“LU”,150.0,30.0,0.0,40.0,0.0,0.0), fzthen(fzand(fzis(“RB”,vars_IN(1)),
init_mfc(“LB”,225.0,55.0,0.0,56.0,0.0,0.0), fzis(“LC”,vars_IN(2))),
others=>NIL); “PM”,”vars_OUT(1));

mfc_set_X:=(
init_mfc(“LE”,5.0,0.0,10.0,25.0,0.0,0.0), ........................
init_mfc(“LC”,40.0,10.0,0.0,10.0,0.0,0.0),
init_mfc(“CE”,50.0,5.0,0.0,5.0,0.0,0.0),
init_mfc(“RC”,60.0,10.0,0.0,10.0,0.0,0.0), fzthen(fzand(fzis(“LB”,vars_IN(1)),
init_mfc(“RI”,95.0,25.0,10.0,0.0,0.0,0.0), fzis(“RI”,vars_IN(2))),
others=>NIL); “NS”,vars_OUT(1));

mfc_set_PSI:=( FLC_output(1) <= defuzzifier(vars_OUT(1));


init_mfc(“NB”,-30.0, 0.0,0.0,13.0,0.0,0.0),
init_mfc(“NM”,-15.0,10.0,0.0,9.0,0.0,0.0), wait on FLC_input;
init_mfc(“NS”,-6.0,6.0,0.0,6.0,0.0,0.0),
init_mfc(“ZE”,0.0,6.0,0.0,6.0,0.0,0.0), data_assign(2, FLC_input, vars_IN);
init_mfc(“PS”,6.0,6.0,0.0,6.0,0.0,0.0),
init_mfc(“PM”,15.0,9.0,0.0,10.0,0.0,0.0), end loop;
init_mfc(“PB”,30.0,13.0,0.0,0.0,0.0,0.0), end process FLC;
others=>NIL); end FLC_arch;
--

Figure 9: VHDL description of the example FLC.

“mfc_set” variables are defined to store the descriptions of Lastly, “fzthen” applies this activation degree to the lin-
the different membership functions (“mfc_set_PHI”, guistic label of the consequent to evaluate the partial con-
“mfc_set_X”, and “mfc_set_PSI”). clusion of the rule. Before ending the cycle, defuzzification
The body of the process starts assigning values to the is performed using the function “defuzzifier” and the
membership functions through the function “init_mfc”. resulting value is assigned to the FLC output.
Then the linguistic variables are initialized using the func-
tions “init_inputs” and “init_outputs”, assigning PHI to 5: Simulation results.
“vars_IN(1)”, X to “vars_IN(2)”, and PSI to “vars_OUT
(1)”. VHDL descriptions of the fuzzy controllers can be val-
The descriptions of the control rules and defuzzifica- idated with any VHDL simulator, using a “test_bench”. To
tion are inserted in an endless cycle that includes a “wait” simulate the pair consisting of the controller and system
sentence, so that the system will apply the inference mech- under control, the test_bench must include, in addition to
anism each time any of the input are modified. The specifi- the FLC description, a second VHDL unit which models
cation of each rule uses the “fzis”, “fzand”, and “fzthen” the controlled system behavior.
functions. “fzis” calculates the membership degree of the This example considers a very simple model of the
input to the linguistic label passed as argument. “fzand” controlled system that can be described with functions
implements the linking connective between the two ante- given by VHDL mathematical packages. Assuming that the
cedents and returns the activation degree of that link. truck moves a fixed distance “d” in each inference step, the
new coordinates are calculated as a function of the former 7: References
coordinates and the angle determined by the fuzzy control-
ler output, according to the following equations: [1] A. Zamfirescu, “Logic and Arithmetic in Hardware De-
scription Languages”, “Fundamentals and Standards in
Hardware Description Languages” Edited by Jean P. Mer-
phit = phit - 1 + psi
met, NATO ASI Series, pp. 109-151, 1993.
xt = xt - 1 + d * cos(phit)
[2] A. Zamfirescu and C. Ussery, “VHDL and Fuzzy Logic If-
yt = xt - 1 + d * sin(phit)
Then Rules”, Proc. of Euro-VHDL’92, pp. 636-641, Ham-
burg.
The code describing the system under control includes
[3] “IEEE Standard VHDL Language Reference Manual”,
a series of sentences that send to a file the data needed to IEEE std 1076-1987.
obtain a graphic representation of the trajectory followed
[4] L.A. Zadeh, “Fuzzy Sets”, Inform. Control, vol. 8, pp. 338-
by the truck for different starting points. Figure 10 shows 353, 1965.
some of the results obtained using different defuzzification
[5] C. C. Lee: “Fuzzy Logic in Control Systems: Fuzzy Logic
methods. As can be observed in the figures, the target is Controller - Parts I and II”, IEEE Transactions on Systems,
always reached, regardless of the method employed. How- Man and Cybernetics, vol 20, num 2, pp. 404-435, March/
ever, from a microelectronic point of view, the use of sim- April, 1990.
plified methods eases the hardware realization of fuzzy [6] M. Mizumoto and H. Zimmermann, “Comparison of fuzzy
controller, as indicated by the authors in [10]. In fact, our reasoning methods”, Fuzzy Sets and Systems, vol. 8 pp.
future work will focus on the automatic synthesis of fuzzy 253-283, 1982,
controllers from their VHDL description. [7] E. H. Mamdani, “Application of Fuzzy Logic to Approxi-
mate Reasoning Using Linguistic Synthesis”, IEEE Trans.
Computer, Vol. C-26, N. 12, pp. 1182-1191, 1977.
6: Conclusions.
[8] H. Hellendoorn and C. Thomas, “Defuzzification in Fuzzy
Controllers”, Journal of Intelligent and Fuzzy Systems,
A VHDL package has been presented which permits
vol. 1, pp. 109-123, 1993.
describing control systems based on fuzzy logic. In addi-
[9] B. Kosko, “Neural Network and Fuzzy Systems”, Prentice
tion to the inherent advantages of using standard descrip-
Hall, 1992.
tion language, this approximation allows reducing the gap
[10]Jiménez, C.J., Sánchez-Solano, S. y Barriga, A.: “Hard-
found between specific simulation tools for fuzzy systems
ware Implementation of a General Purpose Fuzzy Control-
and VHDL-based tools for hardware development. The ler”. Proc. 6th IFSA World Congress, (to be published) Sao
viability of the proposed method is shown through its prac- Paulo, Jul. 1995.
tical application.

40.0 40.0

-10.00.0 20.0 40.0 60.0 80.0 100.0 -10.00.0 20.0 40.0 60.0 80.0 100.0

(a) (b)

Figure 10: Simulation results with different defuzzification methods: a) Center of Area; b) Fuzzy Mean.

Anda mungkin juga menyukai