% cont.m % to find controller by solving mixed sensitivity problem clear all; sample = 0.00025; % sampling time for discretized controller load nominal.mat; load weight.mat; % weight function for S(s) s = tf('s'); ks = 50; % larger value means better performance ws1 = 2*pi*0.1; WS = ks*ws1/(s+ws1); systemnames = 'P0 WT WS'; inputvar = '[ w; u ]'; outputvar = '[ WT; WS; P0 + w ]'; input_to_P0 = '[ u ]'; input_to_WT = '[ P0 ]'; input_to_WS = '[ P0 + w ]'; cleanupsysic = 'yes'; G = sysic; G = balreal(G); %[K, clp, gam] = hinfsyn(G, 1, 1, 'DISPLAY', 'on', 'GMAX', 1, 'GMIN', 1); [K, clp, gopt] = hinfsyn(G, 1, 1, 'DISPLAY', 'on'); %[K, clp, gopt] = hinfsyn(G, 1, 1, 'DISPLAY', 'on', 'METHOD', 'lmi'); % gopt should be less than 1 so that closed-loop system is robustly stable against modeling error norm(clp, 'inf') figure(5); bode(K); h = get(5); set(h.Children(1), 'XLim', [1 2000]); S = 1/(1 - P0*K); T = 1 - S; figure(6); bodemag(S, 'r', gopt/WS, 'r--', T, 'b', gopt/WT, 'b--'); legend('S', 'gamma/WS', 'T', 'gamma/WT', 'Location', 'SouthEast'); h = get(6); set(h.Children(2), 'XLim', [1 2000]); Kd = c2d(K, sample); tmp = [Kd.a, Kd.b; Kd.c, Kd.d]; save cont.dat sample tmp -ascii -double; n = size(K.a, 1); fid = fopen('cont_order.dat', 'w'); fprintf(fid, '%d\n', n); fclose(fid); save cont.mat K Kd S T G;