%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % This program implements the indirect neural controller % for the surge tank example. % % Kevin Passino % Version: 3/25/99 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Initialize variables clear % We assume that the parameters of the tank are: abar=0.01; % Parameter characterizing tank shape (nominal value is 0.01) bbar=0.2; % Parameter characterizing tank shape (nominal value is 0.2) cbar=1; % Clogging factor representing dirty filter in pump (nominally, 1) dbar=1; % Related to diameter of output pipe g=9.8; % Gravity T=0.1; % Sampling rate beta0=0.25; % Set known lower bound on betahat beta1=0.5; % and the upper bound % Set the length of the simulation Nnc=1000; % As a reference input, we use a square wave (define one extra % point since at the last time we need the reference value at % the last time plus one) timeref=1:Nnc+1; %r(timeref)=3.25-3*square((2*pi/150)*timeref); % A square wave input r(timeref)=3.25*ones(1,Nnc+1)-3*(2*rand(1,Nnc+1)-ones(1,Nnc+1)); % A noise input ref=r(1:Nnc); % Then, use this one for plotting time=1:Nnc; time=T*time; % Next, make the vector real time % Next, set plant initial conditions h(1)=1; % Initial liquid level e(1)=r(1)-h(1); % Initial error A(1)=abs(abar*h(1)+bbar); alpha(1)=h(1)-T*dbar*sqrt(2*g*h(1))/A(1); beta(1)=T*cbar/A(1); % Define the parameters for the gradient adaptation method eta=1.25; gamma=1; Walpha=0.01; Wbeta=0.01; epsilon(1)=Walpha; % Just pick this to be something reasonable % Define parameters of the approximators nR=50; % The number of receptive field units in the RBF theta(:,1)=ones(2*nR,1); thetabeta(:,1)=(beta0+0.5*(beta1-beta0))*theta(nR+1:2*nR,1); % Set initial thetabeta value % (the middle of the range) thetaalpha(:,1)=0*theta(1:nR,1); % Set initial thetaalpha value (not a good guess) paramerrornorm(1)=0; n=1; % The number of inputs (since 1, use c(1,..) below) c(1,1)=0; % Next, initialize the centers - just make them uniform sigma=0.2; % Next, form the phih vector for i=2:nR c(1,i)=c(1,i-1)+0.2; end for i=1:nR phih(i,1)=exp(-(h(1)-c(1,i))^2/sigma^2); end % Next, find the initial estimates of the plant dynamics betahat(1)=thetabeta(:,1)'*phih(:,1); alphahat(1)=thetaalpha(:,1)'*phih(:,1); % Next, define the intial controller output u(1)=(1/(betahat(1)))*(-alphahat(1)+r(1+1)); % Next, form the phi vector phi(:,1)=[phih(:,1)', u(1)*phih(:,1)']'; % Initialize estimate of the plant dynamics (note that the % time indices are not properly aligned but this is just an estimate hhat(1)=alphahat(1)+betahat(1)*u(1); % Estimate to be the same as at % the first time step %%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Next, start the main loop: %%%%%%%%%%%%%%%%%%%%%%%%%%%%% for k=2:Nnc % Define the plant % In implementation, the input flow is restricted % by some physical contraints. So we have to put a % limit for the input flow that is chosen as 50. if u(k-1)>50 u(k-1)=50; end if u(k-1)<-50 u(k-1)=-50; end h(k)=alpha(k-1)+beta(k-1)*u(k-1); h(k)=max([0.001,h(k)]); % Constraint liquid not to go % negative % Define the controller e(k)=r(k)-h(k); % Define the deadzone size and its output: epsilon(k)=Walpha+Wbeta*abs(u(k-1)); if e(k)>epsilon(k) eepsilon(k)=e(k)-epsilon(k); end if abs(e(k))<=epsilon(k) eepsilon(k)=0; end if e(k)<-epsilon(k) eepsilon(k)=e(k)+epsilon(k); end % Next, perform the parameter update with the normalized gradient method: theta(:,k)=theta(:,k-1)-... (eta*phi(:,k-1)*eepsilon(k))/(1+gamma*phi(:,k-1)'*phi(:,k-1)); thetabeta(:,k)=theta(nR+1:2*nR,k); thetaalpha(:,k)=theta(1:nR,k); % Perform projection for betahat(k) so that the control input % is well-defined for i=1:nR if thetabeta(i,k)