ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 14.06.2025
Просмотров: 3110
Скачиваний: 0
186 15 Fuzzy Logic Temperature Controller
cold |
warm |
|
1 |
||
0.6 |
||
t |
||
10 |
15 |
25 |
Fig. 15.2. Example of membership functions
This means that it is possible to associate to any fuzzy set A, a function f : A → [0, 1] called the membership function. Figure 15.2 shows a possible shape of the membership functions associated with the fuzzy sets “cold” and “warm” defined in the above example.
In practice, it is not very useful to know the absolute temperature of the controlled system – it is more important to know how warm the controlled system is with respect to the set-point temperature. In other words, it is more convenient to use the calculated error e(t) = Ts − Tm , instead of the measured temperature T m.
The domain of variation of e(t) can be divided in three fuzzy subsets: a subset N for the negative values, a subset Z for the values near zero, and another subset P for positive values. Figure 15.3 shows the graphic shape of the three membership functions associated with these fuzzy subsets of values of e(t).
But, as mentioned in the previous chapter, the information provided by the error function e(t) describes only the present status of the system, and it is not enough for efficient control action. The information about the tendency of evolution of the system is contained in the derivative of the function e(t), d(t) = dedt(t) . d(t) is also called the error dot. The possible values of d(t) can be described as having a certain degree of membership to fuzzy subsets ND, Z D, PD similar to those related to e(t).
The domain of variation of the output can also be divided in three fuzzy subsets of values: Low (L), Medium (M), and High (H). To make things simpler, these subsets are singletons, i.e. a single numeric value is assigned to represent the whole range of low values of the output, another single value represents the medium range of values, etc. For example, if Vout [0, 255], it is possible to define the singleton subsets L, M, H as L = {15}, M = {125}, and H = {250}.
Having the fuzzy subsets associated with each input and the output defined, it becomes possible to describe the behavior of the system through a number of sentences (or “rules”) similar to this: “If the error is positive and the derivative of the
Z |
||||
N |
1 |
P |
||
-4 |
-2 |
0 |
2 |
e(t) |
4 |
Fig. 15.3. Membership functions for the subdomains N, Z, and P of e(t)
15.2 The Principles of Fuzzy Control |
187 |
error (the error dot) is positive, then the output is high.” This translates to: “If the temperature of the controlled system is lower than the set-point temperature, and the difference between the two values tends to become bigger, then the output must be high.” Which is pretty close to the natural human language.
The general structure of these rules is: “If (A and B), then C”, where A, B, and C are logic sentences referring to the inputs e(t), d(t) and the output Vout(t), respectively.
(A and B) is called the antecedent of the proposition, and C is the consequent.
Note that in fuzzy logic the truth value of a proposition is not 0 or 1, but a number in the interval [0, 1]. A, B, C and the proposition “If (A and B) then C” are all fuzzy logic propositions.
The total number of rules that describe the behavior of the system is K = N M, where N is the number of fuzzy subsets associated with the input e(t), and M is the number of subsets associated with d(t). In the example presented in this chapter, N = 3 and M = 3, which leads to a total of K = 9 rules.
For maximum clarity, the nine rules can be presented in two tables (Tables 15.1 and 15.2): one containing the values for the antecedent, the other for consequent.
The antecedent table and the consequent table define the rule matrix. The whole system of rules defines the rule base.
Knowing the membership functions for x = e(t) and y = d(t), it is possible to determine at any moment the truth value of the sentences Ai and Bi corresponding to the antecedent of each rule. In fuzzy logic, if ( Ai ), (Bi ) are the truth values of the sentences Ai , Bi , then the truth value of the sentence Ai and Bi is zi = ( Ai and Bi ) = min(( Ai ), (Bi )).
One possible way to obtain the crisp output Vout is by combining all the rules in the rule matrix, according to the following formula:
K
Vout = |
i=1 |
zi × Si |
(15.1) |
|
K |
||||
zi |
||||
i=1 |
||||
Table 15.1. The antecedent table |
||||
x = e(t) |
N |
Z |
P |
|
y = de(t)/dt |
||||
N |
x = N and y = N |
x = Z and y = N |
x = P and y = N |
|
Z |
x = N and y = Z |
x = Z and y = Z |
x = P and y = Z |
|
P |
x = N and y = P |
x = Z and y = P |
x = P and y = P |
|
Table 15.2. The consequent table |
||||
z = Vout(t) |
N |
Z |
P |
|
N |
L |
L |
M |
|
Z |
L |
L |
M |
|
P |
L |
M |
H |
|
188 15 Fuzzy Logic Temperature Controller
Where zi = min(( Ai ), (Bi )), Si is the corresponding singleton value of the fuzzy output, and K is the total number of rules in the rule base.
The process of computing the crisp value of the output of the fuzzy controller is called defuzzyfication.
Example
Consider a fuzzy temperature controller having the membership functions for e(t) = Ts −Tm defined in Fig. 15.4, and for d(t) = de(t)/dt defined in Fig. 15.5. The singleton values of the output are Low = 10, Medium = 125, and High = 250. Compute the crisp output for a time moment when e(t) = 3 ◦C, and d(t) = 1 ◦C/s.
Z |
|||
N |
1 |
P |
|
0.75 |
|||
0.25 |
|||
-12 |
0 |
3 |
e(t) |
12 |
Z |
|||
N |
1 |
P |
|
0.5 |
|||
-2 |
0 |
1 |
d(t) |
2 |
Fig. 15.4. Sample membership functions |
Fig. 15.5. Sample membership functions |
for e(t) |
for d(t) |
Solution
The first step in solving this problem is to create the antecedent table, starting from the data provided in Figs. 15.4 and 15.5 (see Table 15.3). In this table, the notation x = N indicates the truth value of the position “x = N” (“x is negative”).
Each cell of Table 15.3 contains two numeric values, the first of which represents the degree of membership of e(t) to the sets N, Z, and P (extracted from Fig. 15.4), and the second represents the degree of membership of d(t) to the sets N, Z, and P (as results from Fig. 15.5).
By selecting the minimum of the two values, the antecedent table becomes Table 15.4 and, after filling the values of singletons for each situation, the consequent table becomes Table 15.5.
Table 15.3. Sample antecedent table
x = e(t) |
N |
Z |
P |
y = de(t)/dt |
N |
(x = N) = 0 |
(y = N) = 0 |
|
Z |
(x = N) = 0 |
(y = Z) = 0.5 |
|
P |
(x = N) = 0 |
(y = P) = 0.5 |
(x = Z) = 0.75 (y = N) = 0
(x = Z) = 0.75 (y = Z) = 0.5 (x = Z) = 0.75 (y = P) = 0.5
(x = P) = 0.25 (y = N) = 0
(x = P) = 0.25 (y = Z) = 0.5 (x = P) = 0.25 (y = P) = 0.5
15.3 |
A Microcontroller Implementation of a Fuzzy Controller |
189 |
||
Table 15.4. Sample antecedent table |
||||
x = e(t) |
N |
Z |
P |
|
y = de(t)/dt |
||||
N |
0 |
0 |
0 |
|
Z |
0 |
0.5 |
0.25 |
|
P |
0 |
0.5 |
0.25 |
|
Table 15.5. Sample consequent table |
||||
z = Vout(t) |
N |
Z |
P |
|
N |
10 |
10 |
125 |
|
Z |
10 |
10 |
125 |
|
P |
10 |
125 |
250 |
|
It is now possible to compute the crisp value of Vout, according to the formula (15.1), which is a weighted average of the values in the consequent table, with the weights extracted from the corresponding cells of the antecedent table.
V |
0.5 × 10 + 0.25 |
× 125 + 0.5 × 125 + 0.25 × 250 |
= |
107 . |
|||||
0.5 |
|||||||||
out = |
+ |
0.25 |
+ |
0.5 |
+ |
0.75 |
|||
15.3 A Microcontroller Implementation of a Fuzzy Controller
From a hardware perspective, nothing distinguishes a fuzzy controller from a micro- controller-based PID controller. It’s the software that makes the difference. The project described in this chapter uses exactly the same hardware as that used for the PI temperature controller described in the previous chapter.
The key element in designing the software for this application is the way of representing the membership functions, The simplest solution to do this is to use the values of e(t) and d(t) as the offset in ROM tables associated with every function. In this case, obtaining the degree of membership for any value of the variable ERR = e(t) is as simple as this:
* HC11 code |
||
LDX |
#MFTAB |
;load X with the starting address |
LDAB |
ERR |
;load current value of e(t) in B |
ABX |
;adjust index |
|
LDAA |
0,X |
;get the value from table |
.... |
||
.... |
||
MFTAB DB |
$00 |
|
DB |
$01 |
|
.... |
190 15 Fuzzy Logic Temperature Controller
This fragment of code assumes that ERR is an 8-bit unsigned integer. In practice, things are a bit more complicated because e(t) and d(t) can take values in the range [−255, 255]. To cover this range, the variables associated with e(t) and d(t), called ERR and DERIV, must be 16-bit signed integers.
To avoid working with negative offsets in a table, a simple solution is to split the table associated with a membership function in two distinct tables: one for the positive values of the variable, the other for the negative values. Here is an example of code that uses this artifice:
LDD |
ERR |
;ERR is now a 16-bit signed INT |
BMI |
NEGVAL |
;check sign of D |
LDX |
#MFTAB1 |
;one table for positive values |
ABX |
;id D>=0, B contains the offset |
|
LDAA |
0,X |
;get value from table |
.... |
||
NEGVAL LDX |
#MFTAB2 |
;table for negative values |
COMA |
;compute 2’s complement |
|
COMB |
;of the negative value in D |
|
ADDD |
#1 |
;B contains now abs(ERR) |
ABX |
||
LDAA |
0,X |
;get the value from table |
.... |
||
MFTAB1 DB |
$00 |
;table for positive values |
DB |
$01 |
|
.... |
||
.... |
||
MFTAB2 DB |
$00 |
;table for negative values |
.... |
||
.... |
Besides the obvious simplicity of the program, defining membership functions as tables has another important advantage: it allows the use of any shape for the membership functions without the need to change anything in the code, only the tables.
The general structure of the software application, defined in MAIN.ASM, is very similar to the implementation of the PI temperature controller, described in the previous chapter.
INCLUDE 68HC11F1.DEF
INCLUDE AS11.MAC
INCLUDE MAP.ASM
CODE
VECTOR_RESET
RESET EQU |
* |
INCLUDE |
INIT.ASM |