Anda di halaman 1dari 9

# INTELLIGENT DECISION AND CONTROL

## MatLab Fuzzy Toolbox

Safe distance

1. A car A is driving on a highway. This can wants to keep a safe distance to car B in its front. Design a (simplified) fuzzy-logic system which satisfies this requirement. a) Determine the required fuzzy variables (input/output) and their ranges. b) Form the rule base. c) Use fuzzy reasoning to check the operability of the rule base.

Solution: a) Fuzzy variables. Consider the simple case: INPUT: distance d, range [0,30]m OUTPUT: brake b, range [0,100]% Three membership functions are chosen for both input and output: distance d: short, medium, long brake b: soft, medium, hard MATLAB fuzzy toolbox is used to define the system by giving numerical values for the variables. To open the Fuzzy Inference System GUI, in MATLAB type: >> fuzzy The input and output windows are activated by clicking on them (a red frame appears). Switching between the input and output windows, name the corresponding variables as shown in Fig. 1.

Fig. 1 Name the input and output variables. To open the membership function (MF) editor window, click twice on the input/output windows. Change the range of the variable as in Fig. 2.

Fig. 2 Set the range of the input and output variables. The default MF can be kept or deleted (EDIT REMOVE ALL MFs). To add new MF use (EDIT ADD MFs). Fig. 3 shows the MF window where the type and number of the MF can be chosen. Example: choose 3 triangular membership functions (trimf) and click CLOSE.

Fig. 3 Set membership functions. Back in the MF editor window, we can select each of the MF and name them (see Fig. 4).

Fig. 4 Name membership functions. Repeat the procedure for the MF of the output brake. b) Rule base. Edit the rule editor window (Fig. 5) using EDIT RULES. The left-hand side contains the MF of the input distance. The right-hand side has the MF of the output brake. If the input side has several variables, connected either by and or or, the Connection block in the lower left corner is used. In this case it is not necessary. The weight factor (default value = 1) indicates the importance of the rule in question. The construction of the rule base is the hardest part of the design task. Here a simple-minded rule base is constructed based on driving experience. Typical rules are: If distance is short then brake is hard. If distance is medium then brake is medium. If distance is long then brake is soft. With the mouse select the MF short for the distance and hard for the brake and then click Add rule. This procedure is shown in Fig. 5 for the second rule. The design of the fuzzy system is complete. The Toolbox provides two more interesting ways of expressing the rule base. Check under OPTIONS FORMAT. Under that you can see that the rules are shown in VERBOSE. The

other formats are SYMBOLIC and INDEXED. Check in what form the rule base is given in each case. After finishing click CLOSE.

Fig. 5 Rule editor. Viewing the rules gives the overall picture of the developed fuzzy system. From the main FIS editor choose VIEW RULES to open the rule viewer represented in Fig. 6. On the left-hand side is the input distance, with the corresponding MF, and on the right-hand side is the output brake. In the lower right corner is the result of fuzzy reasoning or defuzzification.

## Fig. 6 The rule viewer.

Different input values can be tried by moving the distance red vertical line. Fig. 7 represents the brake result for maximum distance input.

Fig. 7 Brake result for maximum distance input. Notice that maximum distance does not correspond to minimum brake. This is due to the defuzzification method used. By default it is centroid. This can be changed in the main FIS editor window (Fig. 8).

## Fig. 8 Changing the defuzzification method.

Finally, the input-output mapping can be observed by choosing VIEW SURFACE (Fig. 9). It is clear that the mapping is nonlinear. This is where the power of fuzzy is strong. Try seeing what happens to the mapping when you change between the different defuzzification methods. You may save your model for future use by choosing FILE EXPORT TO FILE.

## Relative speed! Safe distance

Correct the previous fuzzy system to take into account the relative speed of the vehicles. Solution: Set up a new rule base with two inputs, distance and speed, and one output, brake (only the main steps will be shown here). Add the second input, speed, by choosing EDIT ADD VARIABLE INPUT. Call it speed (Fig. 10). Define the range of the relative speed as [-40,40] km/h and 3 triangular membership functions: slow,medium,fast (Fig. 11).

Define the new base rule considering now the 2 inputs, distance and speed, and one output, brake.

## Fig. 10 Add new input variable, speed.

Fig. 11 Add range and membership functions for relative speed. Nine rules may be constructed (Fig. 12). You may either change the existing ones or delete them and add new ones. Obviously, the rules are not unique. You may consider different ones. The rule base must be viewed and tested to see its effectiveness and how well the system specifications are satisfied (Fig. 13). Again the system may be tested by choosing different values for the two inputs. If the result is not satisfactory, then refine the system. For instance, it seems that the area of short distance and fast speed does not give hard enough brake response.
7

## Fig. 12 New rule base.

Fig. 13 Rule base viewer with the new input, speed. The input-output mapping may be viewed in Fig. 14. You may change the grid points of the graphic changing the X grids and Y grids numbers. You may also change the view point of the graphic by clicking on it and rotating it. Note that the right side corner is practically flat, with small brake value over a fairly large area. You can change that by introducing a new MF little for brake and changing the rule base.