⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 truck_a.m

📁 FISMAT accommodates different arithmetic operators, fuzzification and defuzzification algorithm, imp
💻 M
字号:
echo off% truck_a.m%% This script runs in conjunction with the model file truck_s and the script% truck_d.% This script runs the simulation from workspace and analysis the results.%% FSTB - Fuzzy Systems Toolbox for MATLAB% Copyright (c) 1993-1996 by Olaf Wolkenhauer% Control Systems Centre at UMIST% Manchester M60 1QD, UK%% 28-May-1994 echo offtstart=0;tfinal=150;tol=1e-3;minstep=0.01;maxstep=1;clcdec=input('Sequence of runs ? y/n [n]: ','s');if isempty(dec), dec='n'; end;if dec=='y',  dec2=input('Saving data in files ? (overwrites previous files) y/n [n]: ','s');  ip=[20 20;30 20;45 20;50 20;55 20;70 20;80 20]; % initial positions (x,y).  % number of initial positions:  nu_of_ip=length(ip);      an=[-60 40 140 190 240];       % change of angle phi for each initial position.  nu_of_an=length(an);  dec3=input('Using initial positions and angles from script file ? y/n [n]: ','s');  if isempty(dec3), dec3='n'; end;  if dec3=='n',    nu_of_ip=input('Number of initial positions ? : '); disp('');    disp('Type in a vector with angles, for which each initial ');    an=input('position is starting. Example: [-60 140 220] : ');    nu_of_an=length(an);    ip=zeros(nu_of_ip,2);    for i=1:nu_of_ip,      ip(i,1)=input('initial x-position : ');      ip(i,2)=input('initial y-position : ');    end;  end;  % Run script for preparing the controller:  truck_d  echo off  lcount=zeros(nu_of_ip*nu_of_an,1); % counter for the number of samples per run  sco=0;                  % simulation counter.  if dec2=='y',    [infid,message]=fopen('truck.inf','w');    if infid==-1, disp(['Error: ',message]); end;    fprintf(infid,'%g\n',tol);    fprintf(infid,'%g\n',tfinal);    fprintf(infid,'%g\n',minstep);    fprintf(infid,'%g\n',maxstep);    [datfid,message]=fopen('truck.dat','w');    if datfid==-1, disp(['Error: ',message]); end;  end;  clf  for i=1:nu_of_ip,    IXPOS=ip(i,1);    IYPOS=ip(i,2);    for j=1:nu_of_an,      IPHI=an(j);      x0=[];      [t,x,y]=rk45('truck_s',[tstart,tfinal],x0,[tol,minstep,maxstep]);      % Analysis of the results: y(1) = x-position y(2) = y-position      % y(3) = phi y(4) = theta      if dec2=='y',        fprintf(datfid,'%g %g %g %g %g\n',[t';y(:,1)';y(:,2)';y(:,3)';y(:,4)']);        spl=length(y);        sco=sco+1;        lcount(sco)=spl;        fprintf(infid,'%g  %g  %g  %g\n',IXPOS,IYPOS,IPHI,spl);      end;      spl=length(y);      % docking error:       dockerr=sqrt((90-y(spl,3))^2+(50-y(spl,1))^2+(100-y(spl,2))^2);      trajlen=(t(spl)/Ts)*MOVDIS;      shortdi=sqrt((IXPOS-50)^2+(IYPOS-100)^2);      % trajectory error =       % length of truck trajectory/distance(initial position,desired final pos.)      trajerr=trajlen/shortdi;       hold on      plot(y(:,1),y(:,2)); title('loading dock'); axis([0 100 0 100]);      xlabel(['docking error: ',num2str(dockerr),'     trajectory error: ',num2str(trajerr)]);      drawnow      echo on      disp(['ip ',num2str(i),'  angle ',num2str(j)]);      echo off    end; % of loop for different angle with the same initial position.  end;   % of loop for initial positions.  hold off  if dec2=='y',    fprintf(infid,'%g  %g\n',sco,sum(lcount));    status=fclose('all');    if status==-1, disp('Error closing all files. '); end;    disp('The data file is: truck.dat ');    disp('Information to these files are in truck.inf')  end;  clear x0 nu_of_ip nu_of_an message status datfid trajlen dockerr shortdi  clear sco spl i j ip an infid lcount t x y dec2 dec3 trajerrend;                                       % of simulation sequence.dec=input('Single run ? y/n [n]: ','s');if isempty(dec)  dec='n';end;if dec=='y',  % Run script for preparing the controller:  truck_d  echo off  disp(['current initial position: x=',num2str(IXPOS),'  y=',num2str(IYPOS),...  '  phi=',num2str(IPHI)]);  IXPOS=input(' x-position : ');  IYPOS=input(' y-position : ');  IPHI=input(' phi : ');  x0=[];  [t,x,y]=rk45('truck_s',[tstart,tfinal],x0,[tol,minstep,maxstep]);  % Analysis of the results: y(1) = x-position y(2) = y-position  % y(3) = phi y(4) = theta  spl=length(y);  % docking error:   dockerr=sqrt((90-y(spl,3))^2+(50-y(spl,1))^2+(100-y(spl,2))^2);  trajlen=(t(spl)/Ts)*MOVDIS;  shortdi=sqrt((IXPOS-50)^2+(IYPOS-100)^2);  % trajectory error =   % length of truck trajectory/distance(initial position,desired final pos.)  trajerr=trajlen/shortdi;  clf,plot(y(:,1),y(:,2)); title('loading dock'); axis([0 100 0 100]);  xlabel(['docking error: ',num2str(dockerr),'     trajectory error: ',num2str(trajerr)]);  dec=input('Time plot ? y/n [n] : ','s');  if isempty(dec),    dec=='n';  end;  if dec=='y',    figure    subplot(3,1,1),plot(t,y(:,1)),title('controller input x position:'),grid on    subplot(3,1,2),plot(t,y(:,2)),title('controller input angle phi:'),grid on    subplot(3,1,3),plot(t,y(:,4)),title('steering angle signal theta:'),grid on    xlabel(['traveltime : ',num2str(t(spl))]);  end;  clear trajerr trajlen shortdi dockerr spl x0end;               % of single simulation run.dec=input('Loading sample data in workspace (from files) ? y/n [n]: ','s');if isempty(dec)  dec='n';end;if dec=='y',  % The file containing all sample vectors is called: truck.dat .  [datfid,message]=fopen('truck.dat');  if datfid==-1, disp(['Error: ',message]); end;  samples=fscanf(datfid,'%g %g %g %g %g',[5 inf]);  samples=samples';  status=fclose(datfid);  if status==-1,    [message]=ferror(datfid);    disp(['Error: ',message]);  end;  disp('The sample vectors are now stored in "samples" .');  clear message datfid statusend; % of loading sample data from files to workspace.disp(' ');disp(['There are ',num2str(length(samples)), ' sample vectors.']);dec=input('Plotting the input data distribution ? y/n [n]: ','s');if isempty(dec), dec='n'; end;if dec=='y',  figure  axis([-100 250 0 100]); plot(samples(:,4),samples(:,2),'.');  title('Input data distribution'); xlabel('phi'); ylabel('x');  figure  axis([-100 250 0 100 -30 30]);   plot3(samples(:,4),samples(:,2),samples(:,5),'.'); grid on  title('Input data distribution'); xlabel('phi'); ylabel('x'); zlabel('theta');end;echo offdec=input('Product space clustering ? y/n [n]: ','s');if isempty(dec), dec='n'; end;if dec=='y',  nos=input(['Number of training pattern ? [',num2str(length(samples)),'] : ']);  if isempty(nos), nos=length(samples); end;  p=input('Number of synaptic vectors ? [245] : ');  if isempty(p), p=245; end;  N=input('Number of nearest synaptic vectors or "winners" ? [35] : ');  if isempty(N), N=35; end;  wii=input('wii (positive) ? [1] : ');  if isempty(wii), wii=1; end;  wij=input('wij (negative) ? [-1] : ');  if isempty(wij), wij=-1; end;  c=input('c (c>0) ? [1] : ');  if isempty(c), c=1; end;  vectors=[samples(:,2) samples(:,4) samples(:,5)];  xsec=[0 32.5; 32.5 47.5; 47.5 52.5; 52.5 67.5; 67.5 100];  phisec=[-90 0; 0 66.5; 66.5 86; 86 94; 94 113.5; 113.5 182.5; 182.5 270];  thetasec=[-30 -20; -20 -7.5; -7.5 -2.5; -2.5 2.5; 2.5 7.5; 7.5 20; 20 30];  dec=input('random mix of sample pattern ? y/n [y] : ','s');  if isempty(dec), dec='y'; end;  if dec=='y',    rands=randperm(nos);  end;  [FAMbank,msum,y2,m2x,m2p,M,mdens]=truckpsc(xsec,phisec,thetasec,vectors(1:nos,:),N,p,wii,wij,c,rands);  FAMbank,msum  figure  subplot(2,2,1),plot(y2); ylabel('y2');xlabel('training time');  subplot(2,2,2),plot(m2x); ylabel('M(2,1) = x');  subplot(2,2,4),plot(m2p); ylabel('M(2,2) = phi'); xlabel('training time');  subplot(2,2,3),axis([0 1 0 1]);set(gca,'Visible','off');   text(0,0,['wii = ',num2str(wii)]);  text(0,0.25,['wij = ',num2str(wij)]);  text(0,.5,['pattern = ',num2str(nos)]);  text(0,0.75,'ct = 0.1(1-t/pattern)');    mdens=mdens(:).*100./p;  figure  subplot(2,2,1); bar(mdens);  xlabel('cell number'); ylabel('% classification');  title('synaptic vector histogram');    subplot(2,2,2);   axis([xsec(1,1) xsec(length(xsec),2) phisec(1,1) phisec(length(phisec),2)]);  hold on  plot(vectors(1:nos,1),vectors(1:nos,2),'.');  title('pattern distribution'); ylabel('phi');      subplot(2,2,3); axis([0 1 0 1]); set(gca,'Visible','off');   text(0,0.5,['c = ',num2str(c)]);  text(0,0.75,['p = ',num2str(p)]);  text(0,0.25,[num2str(N),'  "winner"']);  subplot(2,2,4);   axis([xsec(1,1) xsec(length(xsec),2) phisec(1,1) phisec(length(phisec),2)]);  set(gca,'XTick',[xsec(:,1);xsec(length(xsec),2)]);   set(gca,'XGrid','on');  set(gca,'YTick',[phisec(:,1);phisec(length(phisec),2)]);   set(gca,'YGrid','on');  hold on; xlabel('x'); ylabel('phi');  title('Synaptic vectors M'); xlabel('x');ylabel('phi');  plot(M(1,:),M(2,:),'.');   clear xsec phisec thetasec vectors mdens nos N wii wij c p y2 m2x m2p M msumend;clear dec tstart tfinal tol minstep maxstep echo on

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -