dir_alloc

PURPOSE ^

DIR_ALLOC - Direct control allocation.

SYNOPSIS ^

function [u,a] = dir_alloc(B,v,umin,umax)

DESCRIPTION ^

 DIR_ALLOC - Direct control allocation.

  [u,a] = dir_alloc(B,v,umin,umax)

 Performs direct control allocation by solving the LP

   max a   subj. to  Bu = av
   a,u               umin <= u <= umax

 If a > 1, set u = u/a.

 Note: This function has not been optimized for speed.

  Inputs:
  -------
 B     control effectiveness matrix (k x m)
 v     commanded virtual control (k x 1)
 umin  lower position limits (m x 1)
 umax  upper position limits (m x 1)
 
  Outputs:
  -------
 u     optimal control
 a     scaling factor

 See also: DIR_SIM.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [u,a] = dir_alloc(B,v,umin,umax)
0002   
0003 % DIR_ALLOC - Direct control allocation.
0004 %
0005 %  [u,a] = dir_alloc(B,v,umin,umax)
0006 %
0007 % Performs direct control allocation by solving the LP
0008 %
0009 %   max a   subj. to  Bu = av
0010 %   a,u               umin <= u <= umax
0011 %
0012 % If a > 1, set u = u/a.
0013 %
0014 % Note: This function has not been optimized for speed.
0015 %
0016 %  Inputs:
0017 %  -------
0018 % B     control effectiveness matrix (k x m)
0019 % v     commanded virtual control (k x 1)
0020 % umin  lower position limits (m x 1)
0021 % umax  upper position limits (m x 1)
0022 %
0023 %  Outputs:
0024 %  -------
0025 % u     optimal control
0026 % a     scaling factor
0027 %
0028 % See also: DIR_SIM.
0029     
0030 % Number of variables
0031   [k,m] = size(B);
0032   
0033   % Reformulate problem to fit linprog format:
0034   %
0035   % min f'x subj. to A*x <=b
0036   %                  Aeq*b = beq
0037   %             lb <= x <= ub
0038   
0039   % x = [a ; u]
0040   % f' = [-1 0 ... 0] (min -a <-> max a)
0041   f = [-1 zeros(1,m)]';
0042   % A, b empty
0043   A = [];
0044   b = [];
0045   % Bu = av <=> [-v B]x = 0
0046   Aeq = [-v B];
0047   beq = zeros(k,1);
0048   % a >= 0, umin <= u <= umax
0049   lb = [0 umin']';
0050   ub = [1e4 umax']'; % 1e4 should be infty but error if too large.
0051   
0052   % Solve linear program
0053   options = optimset('Display', 'off');
0054   x = linprog(f,A,b,Aeq,beq,lb,ub,[],options);
0055   a = x(1);
0056   u = x(2:end);
0057   
0058   % Scale down u if a>1
0059   if a>1
0060     u = u/a;
0061   end

Generated on Wed 25-Aug-2004 14:38:35 by m2html © 2003