DYN_SIM - Dynamic control allocation simulation. [u,W,time,iter] = dyn_sim(B,v,plim,[rlim,T,Wv,W1,W2,S],options) Performs dynamic control allocation for a sequence of virtual control commands stored in v. For each value of v, the control signal u is determined by solving min ||W1(u(t)-Sv(t))||^2 + ||W2(u(t)-u(t-T))||^2 u in M where M is the set of control signals solving min ||Wv(Bu-v)|| u in U where U is the set of feasible control signals with respect to position and, possibly, rate limits. Inputs: ------- B control effectiveness matrix (k x m) v commanded virtual control trajectory (k x N) plim position limits [min max] (m x 2) rlim rate limits [min max] (m x 2) ([] --> no rate limits) T sampling time [1] Wv virtual control weighting matrix (k x k) [I] W1 control position weighting matrix (m x m) [I] W2 control rate weighting matrix (m x m) [0] S steady state control distribution (m x k) [0] Options: See QP_SIM -------- Outputs: ------- u optimal control W active constraints in u (+/- : max/min, 1/2 : position/rate) time average computation time per sample iter no. of iterations Step response example: B = [2 1]; t = 0:.2:10; v = 1*(t>1); plim = [-1 1;-1 1]; W1 = eye(2); W2 = diag([5 0]); S = pinv(B); u = dyn_sim(B,v,plim,[],.2,1,W1,W2,S); figure(1),bodemag(dca(B,S,W1,W2,.2)) figure(2),stairs(t,[u' v']),legend('u_1','u_2','v=2u_1+u_2') See also: DCA, QP_SIM, DIR_SIM.
0001 function [u,W,time,iter] = dyn_sim(B,v,plim,varargin) 0002 0003 % DYN_SIM - Dynamic control allocation simulation. 0004 % 0005 % [u,W,time,iter] = dyn_sim(B,v,plim,[rlim,T,Wv,W1,W2,S],options) 0006 % 0007 % Performs dynamic control allocation for a sequence of virtual 0008 % control commands stored in v. For each value of v, the control 0009 % signal u is determined by solving 0010 % 0011 % min ||W1(u(t)-Sv(t))||^2 + ||W2(u(t)-u(t-T))||^2 0012 % u in M 0013 % 0014 % where M is the set of control signals solving 0015 % 0016 % min ||Wv(Bu-v)|| 0017 % u in U 0018 % 0019 % where U is the set of feasible control signals with respect to 0020 % position and, possibly, rate limits. 0021 % 0022 % Inputs: 0023 % ------- 0024 % B control effectiveness matrix (k x m) 0025 % v commanded virtual control trajectory (k x N) 0026 % plim position limits [min max] (m x 2) 0027 % rlim rate limits [min max] (m x 2) ([] --> no rate limits) 0028 % T sampling time [1] 0029 % Wv virtual control weighting matrix (k x k) [I] 0030 % W1 control position weighting matrix (m x m) [I] 0031 % W2 control rate weighting matrix (m x m) [0] 0032 % S steady state control distribution (m x k) [0] 0033 % 0034 % Options: See QP_SIM 0035 % -------- 0036 % 0037 % Outputs: 0038 % ------- 0039 % u optimal control 0040 % W active constraints in u (+/- : max/min, 1/2 : position/rate) 0041 % time average computation time per sample 0042 % iter no. of iterations 0043 % 0044 % Step response example: 0045 % 0046 % B = [2 1]; t = 0:.2:10; v = 1*(t>1); plim = [-1 1;-1 1]; 0047 % W1 = eye(2); W2 = diag([5 0]); S = pinv(B); 0048 % u = dyn_sim(B,v,plim,[],.2,1,W1,W2,S); 0049 % figure(1),bodemag(dca(B,S,W1,W2,.2)) 0050 % figure(2),stairs(t,[u' v']),legend('u_1','u_2','v=2u_1+u_2') 0051 % 0052 % See also: DCA, QP_SIM, DIR_SIM. 0053 0054 % Number of variables 0055 [k,m] = size(B); 0056 0057 % Find no. of optional arguments (excluding options) 0058 iopt = length(varargin)+1; 0059 for i = 1:length(varargin) 0060 if ischar(varargin{i}) 0061 iopt = i; % index of first option string 0062 break; 0063 end 0064 end 0065 narg = iopt-1; 0066 0067 % Set default values of optional arguments 0068 rlim = []; 0069 T = 1; 0070 Wv = eye(k); 0071 W1 = eye(m); 0072 W2 = zeros(m); 0073 S = zeros(m,k); 0074 0075 % Set values of submitted optional arguments 0076 for i=1:narg 0077 switch i 0078 case 1, rlim = varargin{i}; 0079 case 2, T = varargin{i}; 0080 case 3, Wv = varargin{i}; 0081 case 4, W1 = varargin{i}; 0082 case 5, W2 = varargin{i}; 0083 case 6, S = varargin{i}; 0084 end 0085 end 0086 0087 % Call generic control allocation simulation subroutine. 0088 [u,W,time,iter] = alloc_sim('dyn',B,v,plim,rlim,T,'Wv',Wv,'W1', ... 0089 W1,'W2',W2,'S',S,varargin{iopt:end}); 0090