% FLCLI.M %-------------------------------------------------------------- % File name "flcli.m" % An illustrative program for the design of % Fuzzy Logic Controller. %-------------------------------------------------------------- clear; % clear all variables dt=0.01;tf=2; % sampling period, final time r=1; % command input x0=[0 0]; % initial conditions wn=40; % natural frequency damp=0.3; % damping ratio A=[0 1;0 -2*damp*wn]; % SYSTEM MATRICES B=[0;wn.^2]; C=[1 0]; D=0; u=[0 0]'; % initial control input t=(0:dt:dt)'; iter=tf/dt; % iteration %------------------------------------------------------------- for i=1:iter [y,x]=lsim(A,B,C,D,u,t,x0); % LINEAR PLANT x0=x(2,:); % continue conditions Y1(i,1)=y(2,1); % record output for PLOT % PERFORM CONTROL LAW u(1,1)=r-y(2,1); % u(2,1)=u(1,1); % GAIN=1 end; %--------------------------------------------------------------- x0=[0 0];u=[0 0]'; % RESET INITIAL CONDITIONS for i=1:iter [y,x]=lsim(A,B,C,D,u,t,x0); % LINEAR PLANT x0=x(2,:); % continue condition Y2(i,1)=y(2,1); % record output for PLOT u(1,1)=fuzzy(Y2,r); % fuzzy logic control u(2,1)=u(1,1); % control input for PLANT end; %--------------------------------------------------------------- % PLOT RESULTS %--------------------------------------------------------------- subplot(211);plot(Y1);title('Response of GAIN=1'); ylabel('OUTPUT');grid; subplot(212);plot(Y2);title('Response of FUZZY CONTROL'); ylabel('OUTPUT');xlabel('TIME (unit=0.01second)');grid