From: <par...@us...> - 2012-09-14 14:31:31
|
Revision: 11015 http://octave.svn.sourceforge.net/octave/?rev=11015&view=rev Author: paramaniac Date: 2012-09-14 14:31:20 +0000 (Fri, 14 Sep 2012) Log Message: ----------- control: quicksave work on further multiplot features Modified Paths: -------------- trunk/octave-forge/main/control/inst/__frequency_response__.m trunk/octave-forge/main/control/inst/bode.m trunk/octave-forge/main/control/inst/sigma.m Added Paths: ----------- trunk/octave-forge/main/control/devel/MDSSystem2.m Added: trunk/octave-forge/main/control/devel/MDSSystem2.m =================================================================== --- trunk/octave-forge/main/control/devel/MDSSystem2.m (rev 0) +++ trunk/octave-forge/main/control/devel/MDSSystem2.m 2012-09-14 14:31:20 UTC (rev 11015) @@ -0,0 +1,154 @@ +%% -*- texinfo -*- +%% Robust control of a mass-damper-spring system. +%% Type @code{which MDSSystem} to locate, +%% @code{edit MDSSystem} to open and simply +%% @code{MDSSystem} to run the example file. + +% =============================================================================== +% Robust Control of a Mass-Damper-Spring System Lukas Reichlin August 2011 +% =============================================================================== +% Reference: Gu, D.W., Petkov, P.Hr. and Konstantinov, M.M. +% Robust Control Design with Matlab, Springer 2005 +% =============================================================================== + +% Tabula Rasa +clear all, close all, clc + +% =============================================================================== +% System Model +% =============================================================================== +% +---------------+ +% | d_m 0 0 | +% +-----| 0 d_c 0 |<----+ +% u_m | | 0 0 d_k | | y_m +% u_c | +---------------+ | y_c +% u_k | | y_k +% | +---------------+ | +% +---->| |-----+ +% | G_nom | +% u ----->| |-----> y +% +---------------+ + +% Nominal Values +m_nom = 3; % mass +c_nom = 1; % damping coefficient +k_nom = 2; % spring stiffness + +% Perturbations +p_m = 0.4; % 40% uncertainty in the mass +p_c = 0.2; % 20% uncertainty in the damping coefficient +p_k = 0.3; % 30% uncertainty in the spring stiffness + +% State-Space Representation +A = [ 0, 1 + -k_nom/m_nom, -c_nom/m_nom ]; + +B1 = [ 0, 0, 0 + -p_m, -p_c/m_nom, -p_k/m_nom ]; + +B2 = [ 0 + 1/m_nom ]; + +C1 = [ -k_nom/m_nom, -c_nom/m_nom + 0, c_nom + k_nom, 0 ]; + +C2 = [ 1, 0 ]; + +D11 = [ -p_m, -p_c/m_nom, -p_k/m_nom + 0, 0, 0 + 0, 0, 0 ]; + +D12 = [ 1/m_nom + 0 + 0 ]; + +D21 = [ 0, 0, 0 ]; + +D22 = [ 0 ]; + +inname = {'u_m', 'u_c', 'u_k', 'u'}; % input names +outname = {'y_m', 'y_c', 'y_k', 'y'}; % output names + +G_nom = ss (A, [B1, B2], [C1; C2], [D11, D12; D21, D22], ... + 'inputname', inname, 'outputname', outname); + +G = G_nom(4, 4); % extract output y and input u + + +% =============================================================================== +% Frequency Analysis of Uncertain System +% =============================================================================== + +% Uncertainties: -1 <= delta_m, delta_c, delta_k <= 1 +[delta_m, delta_c, delta_k] = ndgrid ([-1, 0, 1], [-1, 0, 1], [-1, 0, 1]); + +% Bode Plots of Perturbed Plants +w = logspace (-1, 1, 100); % frequency vector +Delta = arrayfun (@(m, c, k) diag ([m, c, k]), delta_m(:), delta_c(:), delta_k(:), 'uniformoutput', false); +G_per = cellfun (@lft, Delta, {G_nom}, 'uniformoutput', false); + +figure (1) +bode (G_per{:}, w); + + +% =============================================================================== +% Mixed Sensitivity H-infinity Controller Design (S over KS Method) +% =============================================================================== +% +-------+ +% +--------------------->| W_p |----------> e_p +% | +-------+ +% | +-------+ +% | +---->| W_u |----------> e_u +% | | +-------+ +% | | +---------+ +% | | ->| |-> +% r + e | +-------+ u | | G_nom | +% ----->(+)---+-->| K |----+--->| |----+----> y +% ^ - +-------+ +---------+ | +% | | +% +-----------------------------------------+ + +% Weighting Functions +s = tf ('s'); % transfer function variable +W_p = 0.95 * (s^2 + 1.8*s + 10) / (s^2 + 8.0*s + 0.01); % performance weighting +W_u = 10^-2; % control weighting + +% Synthesis +K_mix = mixsyn (G, W_p, W_u); % mixed-sensitivity H-infinity synthesis + +% Interconnections +L_mix = G * K_mix; % open loop +T_mix = feedback (L_mix); % closed loop + + +% =============================================================================== +% H-infinity Loop-Shaping Design (Normalized Coprime Factor Perturbations) +% =============================================================================== + +% Settings +W1 = 8 * (2*s + 1) / (0.9*s); % precompensator +W2 = 1; % postcompensator +factor = 1.1; % suboptimal controller + +% Synthesis +K_ncf = ncfsyn (G, W1, W2, factor); % positive feedback controller + +% Interconnections +K_ncf = -K_ncf; % negative feedback controller +L_ncf = G * K_ncf; % open loop +T_ncf = feedback (L_ncf); % closed loop + +% =============================================================================== + +% Plotting +figure (2) +bode (K_mix, K_ncf) % bode plot + +figure (3) +step (T_mix, 10) % step response for 10 seconds + +figure (4) +step (T_ncf, 10) % step response for 10 seconds + +% =============================================================================== Modified: trunk/octave-forge/main/control/inst/__frequency_response__.m =================================================================== --- trunk/octave-forge/main/control/inst/__frequency_response__.m 2012-09-14 12:02:15 UTC (rev 11014) +++ trunk/octave-forge/main/control/inst/__frequency_response__.m 2012-09-14 14:31:20 UTC (rev 11015) @@ -30,7 +30,7 @@ %endif sys_idx = cellfun (@isa, args, {"lti"}); # look for LTI models - w_idx = cellfun (@is_real_vector, args); # look for frequency vectors + w_idx = cellfun (@(x) is_real_vector (x) && length (x) > 1, args); # look for frequency vectors r_idx = cellfun (@iscell, args); # look for frequency ranges {wmin, wmax} sys_cell = args(sys_idx); # extract LTI models @@ -50,7 +50,8 @@ error ("frequency_response: invalid cell"); endif elseif (any (w_idx)) # are there any frequency vectors? - w = args(w_idx)(end); + w = args(w_idx){end}; + w = repmat ({w}, 1, numel (sys_cell)); else # there are neither frequency ranges nor vectors w = __frequency_vector__ (sys_cell, wbounds); endif Modified: trunk/octave-forge/main/control/inst/bode.m =================================================================== --- trunk/octave-forge/main/control/inst/bode.m 2012-09-14 12:02:15 UTC (rev 11014) +++ trunk/octave-forge/main/control/inst/bode.m 2012-09-14 14:31:20 UTC (rev 11015) @@ -84,7 +84,7 @@ style = varargin(style_idx(style_idx > sys_idx(k) & style_idx <= lim)); mag_args = cat (2, mag_args, w(k), mag_db(k), style); pha_args = cat (2, pha_args, w(k), pha(k), style); - legend_args{k} = inputname(sys_idx(k)); + legend_args{k} = inputname(sys_idx(k)); # watch out for bode (lticell{:}) endfor subplot (2, 1, 1) Modified: trunk/octave-forge/main/control/inst/sigma.m =================================================================== --- trunk/octave-forge/main/control/inst/sigma.m 2012-09-14 12:02:15 UTC (rev 11014) +++ trunk/octave-forge/main/control/inst/sigma.m 2012-09-14 14:31:20 UTC (rev 11015) @@ -60,44 +60,56 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: May 2009 -## Version: 0.6 +## Version: 0.7 -function [sv_r, w_r] = sigma (sys, w = [], resptype = 0) +function [sv_r, w_r] = sigma (varargin) - ## TODO: multiplot feature: sigma (sys1, "b", sys2, "r", ...) - - if (nargin == 0 || nargin > 3) + if (nargin == 0) print_usage (); endif +resptype = 0; + [H, w] = __frequency_response__ (varargin, true, resptype, "std", true); - [H, w] = __frequency_response__ (sys, w, true, resptype, "std", true); + sv = cellfun (@(H) cellfun (@svd, H, "uniformoutput", false), H, "uniformoutput", false); + sv = cellfun (@(sv) horzcat (sv{:}), sv, "uniformoutput", false); - sv = cellfun (@svd, H, "uniformoutput", false); - sv = horzcat (sv{:}); - if (! nargout) # plot the information ## convert to dB for plotting - sv_db = 20 * log10 (sv); + sv_db = cellfun (@(sv) 20 * log10 (sv), sv, "uniformoutput", false); - ## determine xlabel - if (isct (sys)) - xl_str = "Frequency [rad/s]"; - else - xl_str = sprintf ("Frequency [rad/s] w_N = %g", pi / get (sys, "tsam")); - endif + tmp = cellfun (@isa, varargin, {"lti"}); + sys_idx = find (tmp); + tmp = cellfun (@ischar, varargin); + style_idx = find (tmp); + len = numel (H); + plot_args = {}; + legend_args = cell (len, 1); + + for k = 1:len + if (k == len) + lim = nargin; + else + lim = sys_idx(k+1); + endif + style = varargin(style_idx(style_idx > sys_idx(k) & style_idx <= lim)); + plot_args = cat (2, plot_args, w(k), sv_db(k), style); + legend_args{k} = inputname(sys_idx(k)); # watch out for sigma (lticell{:}) + endfor + ## plot results - semilogx (w, sv_db, "b") + semilogx (plot_args{:}) axis ("tight") ylim (__axis_margin__ (ylim)) grid ("on") - title (["Singular Values of ", inputname(1)]) - xlabel (xl_str) + title ("Singular Values") + xlabel ("Frequency [rad/s]") ylabel ("Singular Values [dB]") + legend (legend_args) else # return values - sv_r = sv; - w_r = reshape (w, [], 1); + sv_r = sv{1}; + w_r = reshape (w{1}, [], 1); endif endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |