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

📄 overrun.m

📁 jitterbug是基于matlab的工具箱
💻 M
字号:
% Jitterbug example% =================% Compare three overrun handling methods for a control system with% delayed samples. The plant to be controlled is an integrator with% a resonance (3:rd order system). The controller is an LQG% controller, designed for the mean time delay. The delay for the% sample from the plant is uniformly distributed between 0 and% tau_max, which varies between 0 and 2h.%% When a sample is delayed more than one period,% the controller will:% Case a) Not be updated at all% Case b) Let its observer run without input% Case c) Extend the period until the sample arrives (aperiodic system).%% The last case is very computationally intensive as it requires an% iterative solver. The resulting cost plot can be seen in % figure "overrun.eps"addpath('../');% 1 = No control update, 2 = Control update without input, % 3 = period overruns = tf('s');zeta = 0.2;omega = 1;G = 1/s/(s^2+2*zeta*omega*s+omega^2); % The process          h = 0.25;delta = h/10;Q = diag([1 1]);R1 = 300;R2 = 0.1;delays = (1:round(2*h/delta))/round(h/delta);slots = round(h/delta);Samp = tf(1,1,-1);                 % Sampler systemJvec = [];clf;hold on;for mode = 1:3  for delay = delays;    % All three modes do the same thing for delay < 1.    if (mode < 2 | delay >= 1)       Ptau = ones(1,delay*slots+1); % Uniform delay      Ptau = Ptau/sum(Ptau);      if (mode == 2)	if (size(Ptau,2) > slots+1)	  Ptau = [Ptau(1:slots) sum(Ptau(1,slots+1:end))];	end      end      Pwait = zeros(slots*delay+1,slots+1);      for d = 1:(slots*delay+1)	if (d > slots+1)	  Pwait(d,1) = 1;	else	  Pwait(d,slots-d+2) = 1;	end      end            % Create optimal controller based on mean delay      [C,L,Obs,K,Kbar,Gd] = lqgdesign(G,Q,R1,R2,h,delay*h/2);      % Create optimal controller based on observer with no input      Cnodata = ss(Gd.A-Gd.B*L,Gd.B*0,-L,Gd.D*0,h);                  % Add different timing nodes depending on mode.      if (mode == 3)	N = initjitterbug(delta,0);      else	N = initjitterbug(delta,h);      end       if (mode == 2)	N = addtimingnode(N,1,Ptau, [2*ones(1,round(h/delta)) 3]);      else	N = addtimingnode(N,1,Ptau, 2);      end      if (mode == 3)	N = addtimingnode(N,2,Pwait,1);      else	N = addtimingnode(N,2);      end      if (mode == 2)	N = addtimingnode(N,3);      end            N = addcontsys(N,1,G,3,Q,R1,R2);        % Cont. sys with output noise      N = adddiscsys(N,2,Samp,1,1);           % Sampler      N = adddiscsys(N,3,C,2,2);              % Controller      if (mode == 2)	N = adddiscexec(N,3,Cnodata,2,3);     % Time-out controller      end      N = calcdynamics(N);      delay      J = calccost(N)      Jvec = [Jvec J];    end  end  if (mode == 1)    plot(delays,Jvec,'b');    Jvec1 = Jvec;  elseif (mode == 2)    plot(delays(find(delays >= 1)),Jvec,'g');    Jvec2 = Jvec;  else    plot(delays(find(delays >= 1)),Jvec,'r');    Jvec3 = Jvec;  end  Jvec = [];  pause(0);endhold off;legend('Skip sample', 'Update controller without sample', 'Extend period');xlabel('Maximum delay relative to h');ylabel('Cost');title('Comparison of costs for different overrun handling methods.');

⌨️ 快捷键说明

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