# HG changeset patch # User hodelas # Date 948302205 0 # Node ID 04aef7306dca14e1fcd0b333974f916243aa2dba # Parent 1f2ce6b49c572e512602e0e519f6a06b0cf84342 [project @ 2000-01-19 17:16:43 by hodelas] Updated to accept signal names or signal indices as inputs (calls to either sysidx or listidx) diff --git a/scripts/control/base/__bodquist__.m b/scripts/control/base/__bodquist__.m --- a/scripts/control/base/__bodquist__.m +++ b/scripts/control/base/__bodquist__.m @@ -27,9 +27,8 @@ ## @item w ## range of frequencies; empty if user wants default ## @item out_idx -## vector output indices or list of output signal names; empty if user wants all -## @item in_idx -## vector of input indices of list of input signal names; empty if user wants all +## @itemx in_idx +## names or indices of output/input signal names; empty if user wants all ## @item rname ## name of routine that called __bodquist__ ("bode", "nyquist", or "nichols") ## @end table diff --git a/scripts/control/base/bode.m b/scripts/control/base/bode.m --- a/scripts/control/base/bode.m +++ b/scripts/control/base/bode.m @@ -65,6 +65,7 @@ ## The names or indices of outputs and inputs to be used in the frequency ## response. See @code{sysprune}. ## +## @strong{Example} ## @example ## bode(sys,[],"y_3",list("u_1","u_4"); ## @end example @@ -132,6 +133,8 @@ endif [f, w, sys] = __bodquist__ (sys, w, outputs, inputs, "bode"); + bode_nin = sysdimensions(sys,"in"); + bode_nout = sysdimensions(sys,"out"); [stname,inname,outname] = sysgetsignals(sys); systsam = sysgettsam(sys); diff --git a/scripts/control/base/lqg.m b/scripts/control/base/lqg.m --- a/scripts/control/base/lqg.m +++ b/scripts/control/base/lqg.m @@ -40,7 +40,7 @@ ## @itemx R ## state, control weighting respectively. Control ARE is ## @item in_idx -## indices of controlled inputs +## names or indices of controlled inputs (see @code{sysidx}, @code{listidx}) ## ## default: last dim(R) inputs are assumed to be controlled inputs, all ## others are assumed to be noise inputs. @@ -94,7 +94,14 @@ elseif(nout != columns(Sigv)) error(["lqg: sys has ",num2str(nout)," outputs, dim(Sigv)=", ... num2str(columns(Sigv)),")"]) - elseif(length(input_list) != columns(R)) + endif + + ## check for names of signals + if(is_signal_list(input_list) | isstr(input_list)) + input_list = sysidx(sys,"in",input_list); + endif + + if(length(input_list) != columns(R)) error(["lqg: length(input_list)=",num2str(length(input_list)), ... ", columns(R)=", num2str(columns(R))]); endif diff --git a/scripts/control/base/nyquist.m b/scripts/control/base/nyquist.m --- a/scripts/control/base/nyquist.m +++ b/scripts/control/base/nyquist.m @@ -53,8 +53,8 @@ ## not change excessively from point to point and that singular ## points (e.g., crossovers from +/- 180) are accurately shown. ## @end enumerate -## outputs, inputs: the indices of the output(s) and input(s) to be used in -## the frequency response; see sysprune. +## outputs, inputs: names or indices of the output(s) and input(s) to be +## used in the frequency response; see sysprune. ## ## @strong{Inputs} (pass as empty to get default values) ## @table @var diff --git a/scripts/control/system/dmr2d.m b/scripts/control/system/dmr2d.m --- a/scripts/control/system/dmr2d.m +++ b/scripts/control/system/dmr2d.m @@ -28,12 +28,11 @@ ## discrete time system; ## @code{dmr2d} exits with an error if @var{sys} is not discrete ## @item idx -## list of states with sampling time @code{sysgettsam(@var{sys})} (may -## be empty) +## indices or names of states with sampling time +## @code{sysgettsam(@var{sys})} (may be empty); see @code{listidx} ## @item sprefix ## list of string prefixes of states with sampling time -## @code{sysgettsam(@var{sys})} -## (may be empty) +## @code{sysgettsam(@var{sys})} (may be empty) ## @item Ts2 ## sampling time of states not specified by @var{idx}, @var{sprefix} ## must be an integer multiple of @code{sysgettsam(@var{sys})} @@ -84,6 +83,11 @@ elseif(!is_digital(sys)) error("sys must be discrete-time; continuous time passed"); + + endif + + if(is_signal_list(idx) | isstr(idx)) + idx = sysidx(sys,"st",idx); elseif (!(is_vector(idx) | isempty(idx))) error(["idx(",num2str(rows(idx)),"x",num2str(columns(idx)), ... @@ -117,7 +121,7 @@ ## compute number of steps if(Ts1 > Ts2) - error(["Current sampling time=",num2str(Ts1),"< Ts2=",num2str(Ts2)]); + error(["Current sampling time=",num2str(Ts1)," > Ts2=",num2str(Ts2)]); endif nstp = floor(Ts2/Ts1+0.5); if(abs((Ts2 - Ts1*nstp)/Ts1) > 1e-12) @@ -172,7 +176,7 @@ ## permute A, B (stname permuted for debugging only) da = da(pv,pv); db = db(pv,:); - stname = stname(pv,:); + stname = stname(pv); ## partition A, B: lfidx = length(fidx); @@ -251,7 +255,7 @@ da = da(pvi,pvi); db = db(pvi,:); - stname = stname(pvi,:); + stname = stname(pvi); ## construct new system and return dsys = ss2sys(da,db,dc,dd,Ts2,0,nz,stname,inname,outname,find(yd == 1)); diff --git a/scripts/control/system/sysconnect.m b/scripts/control/system/sysconnect.m --- a/scripts/control/system/sysconnect.m +++ b/scripts/control/system/sysconnect.m @@ -26,8 +26,9 @@ ## system data structure ## @item out_idx ## @itemx in_idx -## list of connections indices; @math{y(out_idx(ii))} -## is connected to @math{u(in_idx(ii))}. +## names or indices of signals to connect (see @code{sysidx}). +## The output specified by @math{out_idx(ii)} is connected to the input +## specified by @math{in_idx(ii)}. ## @item order ## logical flag (default = 0) ## @table @code @@ -89,6 +90,14 @@ ", eps=",num2str(eps)]) endif + ## convert signal names to indices + if(is_signal_list(input_list) | isstr(input_list)) + input_list = sysidx(sys,"in",input_list); + endif + if(is_signal_list(output_list) | isstr(output_list)) + output_list = sysidx(sys,"out",output_list); + endif + ## verify sizes,format of input, output lists if( min(size(output_list))*min(size(input_list)) != 1) error("output_list and input_list must be vectors"); diff --git a/scripts/control/system/sysdup.m b/scripts/control/system/sysdup.m --- a/scripts/control/system/sysdup.m +++ b/scripts/control/system/sysdup.m @@ -26,7 +26,7 @@ ## system data structure ## @item out_idx ## @itemx in_idx -## list of connections indices; +## indices or names of desired signals (see @code{sigidx}). ## duplicates are made of @code{y(out_idx(ii))} and @code{u(in_idx(ii))}. ## @end table ## @@ -69,6 +69,14 @@ [nn,nz,mm,pp] = sysdimensions(Asys); [aa,bb,cc,dd] = sys2ss(Asys); + ## check for signal names + if(is_signal_list(input_list) | isstr(input_list)) + input_list = sysidx(Asys,"in",input_list); + endif + if(is_signal_list(output_list) | isstr(output_list)) + output_list = sysidx(Asys,"out",output_list); + endif + ## first duplicate inputs if(is_vector(input_list)) for ii=1:length(input_list); diff --git a/scripts/control/system/sysgetsignals.m b/scripts/control/system/sysgetsignals.m --- a/scripts/control/system/sysgetsignals.m +++ b/scripts/control/system/sysgetsignals.m @@ -41,16 +41,17 @@ ## @end table ## ## @item signum -## Index of signal (or indices of signals if signum is a vector) +## index(indices) or name(s) or signals; see @code{sysidx} ## ## @item strflg ## flag to return a string instead of a list; Values: ## @table @code ## @item 0 -## (default) return a list (even if signum is a scalar) +## (default) return a list (even if signum specifies an individual signal) ## ## @item 1 -## return a string. Exits with an error if signum is not a scalar. +## return a string. Exits with an error if signum does not specify an +## individual signal. ## @end table ## ## @end table @@ -166,7 +167,10 @@ sigid)); endif if(nargin >= 3) - if(signum > length(stname)) + if( is_signal_list(signum) | isstr(signum) ) + signum = listidx(stname,signum); + end + if(max(signum) > length(stname)) error(sprintf("sysgetsignals(sys,\"%s\",%d):only %d entries.\n", ... sigid,signum, rows(stname))); else diff --git a/scripts/control/system/syssetsignals.m b/scripts/control/system/syssetsignals.m --- a/scripts/control/system/syssetsignals.m +++ b/scripts/control/system/syssetsignals.m @@ -47,9 +47,9 @@ ## To desired output continuous/discrete flag. ## Set name to 0 for continuous, or 1 for discrete. ## @end table -## @item list -## vector of indices of outputs, yd, inputs, or -## states whose respective names should be changed. +## @item sig_idx +## indices or names of outputs, yd, inputs, or +## states whose respective names/values should be changed. ## ## Default: replace entire list of names/entire yd vector. ## @end table @@ -101,6 +101,16 @@ strcmp(opt,"in") + strcmp(opt,"st") ) ) error("opt must be one of [], ""out"", ""yd"", ""in"", or ""st"""); elseif(nargin == 4) + if(is_signal_list(sig_idx) | isstr(sig_idx)) + ## convert to vector of indices + if(opt == "yd") + sig_idx = sysidx(sys,"out",sig_idx); + else + sig_idx = sysidx(sys,opt,sig_idx); + endif + endif + + ## check index vector if(min(size(sig_idx)) > 1) disp("syssetsignals: sig_idx=") disp(sig_idx);