fuzdemo4.m
来自「FISMAT accommodates different arithmetic」· M 代码 · 共 175 行
M
175 行
function fuzdemo4
%# call tr_dem_c
echo on
clc
% fuzdemo4.m
%
% FSTB - Fuzzy Systems Toolbox for MATLAB
% Copyright (c) 1993-1996 by Olaf Wolkenhauer
% Control Systems Centre at UMIST
% Manchester M60 1QD, UK
%
% See the READ.ME file for more information.
pause % Strike any key to continue.
clc
% The example is taken from the paper S.G.Kong, B.Kosko: 'Adaptive Fuzzy
% Systems for Backing up a Truck-and-Trailer', IEEE Transactions on Neural
% Networks, Vol.3, No.2, March 1992, pp.211-223.
%
% As far as possible we use the notation from this paper.
%
% This demo develops the fuzzy control system for backing up a simulated
% truck to a loading dock in a parking lot, as described in the paper.
%
% There are three state variables determining the truck position:
% phi = specifing the angle of the truck with the horizontal.
% x,y = specifing the position of the rear centre of the truck.
%
% The objective is to reverse the truck to the loading dock at a right
% angle (phif=90 degrees) and to allign the position (x,y) of the truck with
% the desired loading dock (xf,yf). The truck moves backward a fixed dis-
% tance at every stage until the truck hits the border of the loading zone.
% The loading zone corresponds to the plane [0,100]x[0,100], and (xf,yf)
% equals (50,100). At every stage the fuzzy controller should produce the
% steering angle, theta, that backs up the truck to the loading dock from
% any initial position and from any angle in the loading zone.
%
pause % Strike any key to continue...
clc
% The input variables of the fuzzy-controller are the truck angle phi and
% the truck x-position coordinate x. The output or control variable is the
% steering angle theta.
% The ranges for the variables are: x ranges from 0 to 100, phi ranges from
% -90 to 270 degrees and theta ranges from -30 to 30 degrees.
% The resolution of phi and theta is 1 degree each and the resolution of x
% is 0.1.
%
% Fuzzy set values of the fuzzy variables phi, x, and theta:
%
% phi: x: theta:
% RB Right Below LE Left NB Negative Big
% RU Right Upper LC Left Center NM Negative Medium
% RV Right Vertical CE Center NS Negative Small
% VE Vertical RC Right Center ZE Zero
% LV Left Vertical RI Right PS Positive Small
% LU Left Upper PM Positive Medium
% LB Left Below PB Positive Big
pause % Strike any key to continue...
clc
% Defining the fuzzy membership functions for each linguistic fuzzy-set
% value. A graphical - mouse supported - way to create the sets is the
% function modtrset(). This function gives the compact trapezoidal form
% which we could also code directly: Each column describes one general
% trapezoidal set characterized by four points:
% LE LC CE RC RI RB RU RV VE LV LU LB
% XPOS=[-inf 30 45 50 65 ; PHI=[ -95 -5 45 80 95 115 175 ;
% 0 40 50 60 90 ; -45 30 65 90 115 150 225 ;
% 10 40 50 60 100 ; -45 30 65 90 115 150 225 ;
% 35 50 55 70 inf]; 5 65 85 100 135 185 275];
% NB NM NS ZE PS PM PB
% THETA=[-45 -25 -10 -5 0 5 15 ;
% -30 -15 -5 0 5 15 30 ;
% -30 -15 -5 0 5 15 30 ;
% -15 -5 0 5 10 25 45];
% In the next step we delineate the sets using con2dis(). This is now done
% by executing the script file tr_dat.m.
% (PC user - be patient...)
pause % Press any key after plot...
echo off
clc
% Specifying the libraries of fuzzy-sets for the controller variables:
XPOS=[-inf 30 45 50 65; 0 40 50 60 90; 10 40 50 60 100; 35 50 55 70 inf];
PHI=[-95 -5 45 80 95 115 175 ;-45 30 65 90 115 150 225;...
-45 30 65 90 115 150 225; 5 65 85 100 135 185 275];
THETA=[-45 -25 -10 -5 0 5 15;-30 -15 -5 0 5 15 30 ;...
-30 -15 -5 0 5 15 30 ;-15 -5 0 5 10 25 45];
subplot(3,1,1),plot_set(XPOS),grid on,title('Input variable x - position');
subplot(3,1,2),plot_set(PHI),grid on,
title('Input variable phi - angle of truck with horizontal');
subplot(3,1,3),plot_set(THETA), grid on,
title('Output variable theta - stearing angle signal')
grid off
% Running the script file, where also other parameters for the simulation
% are specified:
tr_dat
echo on
% Now we specify the fuzzy rule base, also known as bank of FAM-rules. In
% Kosko's approach fuzzy rules are viewed as associations between input and
% output. Instead of writing the fuzzy associations in the "IF .. THEN .."
% form, we code these rules in a FAM-bank matrix. This matrix is imple-
% mented in the controller file tr_dem_c.m which looks as follows:
% function do = tr_dem_c(e,x,Ts)
%
% global X XPOS P PHI MOMENTS AREAS
%
% Fuzzification: (e(1)=x e(2)=phi
% mx = match(X,e(1),XPOS);
% mp = match(P,e(2),PHI);
%
% NB=1; NM=2; NS=3; ZE=4; PS=5; PM=6; PB=7;
%
% x -> LE LC CE RC RI
%FAMbank= [PS PM PM PB PB ; % RB | phi
% NS PS PM PB PB ; % RU v
% NM NS PS PM PB ; % RV
% NM NM ZE PM PM ; % VE
% NB NM NS PS PM ; % LV
% NB NB NM NS PS ; % LU
% NB NB NM NM NS ]; % LB
%
% aggop='t3mi'; % minimum operator
%
% A=aggregat(mx,mp,FAMbank,aggop);
% A = [a1, a2,...,aj,...,am] with aj=aggop(aj1,aj2,...,aji,...,ajn).
%
% Using the algebraic-product for the inference and a summation of the
% outputs. Centre of Gravity (COG) method:
%
% do = apsumcog(FAMbank,A,MOMENTS,AREAS);
% Alternative - Height Method:
% do=apsumhei(FAMbank,A,MOMENTS,AREAS);
pause % Strike any key to continue...
clc
% Displaying the control surface of the fuzzy controller with the toolbox
% function ctr_surf. The result can also be used to implement the controller
% specified before, as a look-up table.
% If you are a PC user - be patient...
[xpos,phi,theta]=ctr_surf('tr_dem_c',1,[0 100 -90 270],25);
clf,surf(xpos,phi,theta),view([-130,30]),xlabel('x'),ylabel('phi'),
zlabel('theta'),pause
clc
% The simulation can be started from SIMULINK opening the model-file
% tr_dem_s.m.
% After executing this file, the simulation can be started directly.
pause % Press any key to continue ...
clc
% Any constructive feedback would be most welcome.
% Please feel free to criticize and comment upon this toolbox.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?