📄 aclin.m
字号:
if exist('xinco') == 0 | exist('uaero0') == 0 | exist('uprop0') == 0
disp(' ');
disp('No operating point defined!');
disp(' ');
disp(' ');
disp('<<< Press a key to return to main menu >>>');
pause
else
ok = 1;
end
else % QUIT
% ----
ok = 1;
skip = 1; % Return to end of program rightaway when quitting.
end
end % of operating-point definition.
clear ok
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if skip ~= 1 % If not quitting from ACLIN, proceed with program.
% Else, go to end of program rightaway!
disp(' ');
disp('<<< Press a key to proceed with model definition >>>');
pause
% Define parameters for aircraft model:
% =====================================
%
% AM, EM, GM1, and GM2: matrices, containing parameters for the aircraft
% model. See also the help text and source code for
% MODBUILD.M (contained in the directory AIRCRAFT).
%
% The other variables will either be explained when they are used, or are
% self-explaining (at least if you know something about aircraft stabi-
% lity and control).
%
% Check if these variables already have been defined in the Matlab work-
% space (by ACTRIM). If not, run LOADER to retrieve them from file.
% -----------------------------------------------------------------------
if exist('AM')==0 | exist('EM')==0 | exist('GM1')==0 | exist('GM2')==0
loader
end
% The systems BEAVER and BEAVER1 use a gain block for arbitrarily setting
% time-derivatives of the state variables to zero. This may be useful for
% some purposes, for instance to eliminate longitudinal-lateral cross-
% coupling, or to fix the airspeed to its initial value if an altitude
% controller is to be evaluated, but no autothrottle is available yet.
% The gain value is xfix, which is set to 1 if all states may vary, i.e.,
% if the complete six degree-of-freedom model is used without restric-
% tions. When states have to be fixed, the routine FIXSTATE.M can be
% called (type HELP FIXSTATE for more info).
%
% Here, all state variables are allowed to vary, so xfix will be set to
% one. Replace this line by:
%
% fixstate;
%
% if you want to set some time-derivatives to zero, even when linearizing
% the aircraft model.
%-------------------------------------------------------------------------
xfix = 1;
%%%% fixstate;
disp(' ');
disp('<<< Press a key to proceed with linearization >>>');
pause
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Proceed with linearization.
% ===========================
% Build initial inputvector to the system (contains both aerodynamic
% and engine inputs). Note: wind velocities and accelerations (inclu-
% ding atmospheric turbulence) have been set to zero!!!
% -------------------------------------------------------------------
uinco = [uaero0; uprop0; 0; 0; 0; 0; 0; 0];
clc
disp(['Now linearizing S-function ',sysname]);
disp(' ');
disp('Wait a moment, please...');
home
% Apply Simulink routine LINMOD to nonlinear aircraft model, contained
% in the S-function sysname. Note: contrary to the routine ACTRIM, the
% linearization tool LINMOD is a standard Simulink function. Hence, it
% is not necessary to initialize the system at this place by calling
% it once with [sys,x0] = sysname([],[],[],0)!
% --------------------------------------------------------------------
[Aac, Bac, Cac, Dac] = linmod(sysname,xinco,uinco);
disp(' ');
disp('Linearization succeeded.');
disp(' ');
disp('<<< Press a key to continue >>>');
pause
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Select a subset of the states and inputs. Note: the remaining states
% and inputs are omitted from the state equation by simply eliminating
% the corresponding elements from the state matrices. The more elements
% you neglect, the larger the resulting error will be.
%
% ACLIN doesn't provide the option to choose a subset of the output
% equations, because the exact definition of the outputvector from the
% Simulink system which contains the nonlinear aircraft model is not
% known (in general). The full twelfth-order linear aircraft model
% does include the output equations y = Cac*x + Dac*u, but the exact
% definition of the matrices Cac and Dac, and the outputvector y can be
% determined only by checking the corresponding nonlinear Simulink
% model!
% =====================================================================
% While-loop in which the user must specify the element numbers of the
% STATES that should be used for the linear model. These element num-
% bers are stored in the vector xdef (state definition).
%
% The flag 'allstates' is set to one if user wants to maintain defini-
% tion of state vector. If not, allstates = 0.
% --------------------------------------------------------------------
allstates = 0;
ok = 0;
while ok ~= 1
clc
disp('Select states');
disp('-------------');
disp(' ');
disp('The current state vector is: ');
disp(' ');
disp('x = [ V alpha beta p q r psi theta phi xe ye H ]''');
disp(' ');
disp(' 1 2 3 4 5 6 7 8 9 10 11 12');
disp(' ');
disp(' ');
disp('Enter vector with element numbers of states you want to use');
disp('(enter = use all states):');
xdef = input('> ');
if isempty(xdef) % Use all states.
xdef = [1 2 3 4 5 6 7 8 9 10 11 12];
allstates = 1; % Set all states flag.
end
% Check if no illegal numbers have been specified.
% ------------------------------------------------
if min(xdef) < 1 | max(xdef) > 12 % state numbers outside allowable
% region...
disp(' ');
disp('Use element numbers from {1,2,3,4,5,6,7,8,9,10,11,12}!');
disp(' ');
disp('<<< Press a key >>>');
pause
ok = 0;
else
ok = 1;
end
end
% While-loop in which the user must specify the element numbers of the
% INPUTS that should be used for the linear model. These element num-
% bers are stored in the vector udef (input definition). Note: wind
% and turbulence inputs (disturbances) are selected separately.
%
% The flag 'allinputs' is set to one if the user wants to maintain
% the full inputvector, INCLUDING atmospheric disturbances. If not,
% allinputs = 0.
% --------------------------------------------------------------------
allinputs = 0;
ok = 0;
while ok ~= 1
clc
disp('Select inputs');
disp('-------------');
disp(' ')
disp('The current control-input vector is: ');
disp(' ');
disp('u = [ deltae deltaa deltar deltaf n pz ]''');
disp(' ');
disp(' 1 2 3 4 5 6');
disp(' ');
disp(' ');
disp('Enter vector with element numbers of control inputs that you want');
disp('to use (enter = use all control inputs):');
udef = input('> ');
if isempty(udef) % use all control inputs.
udef = [1 2 3 4 5 6];
allinputs = 1; % set all inputs flag (will be
% reset to 0 if influence of wind
% & turbulence is neglected later).
end
% Check if no illegal numbers have been specified.
% ------------------------------------------------
if min(udef) < 1 | max(udef) > 6 % input numbers outside allowable
% region...
disp(' ');
disp('Use element numbers from {1,2,3,4,5,6}!');
disp(' ');
disp('<<< Press a key >>>');
pause
ok = 0;
else
ok = 1;
end
end
clear ok
% Include wind and turbulence inputs (disturbances) to inputvector?
% -----------------------------------------------------------------
disp(' ');
answ = input('Include wind & turbulence inputs (y/n)? ','s');
if answ == 'y'
udef = [udef 7 8 9 10 11 12];
else
allinputs = 0; % Reset all inputs flag. Wind and turbulence are
% neglected, so user does NOT want to consider
% full inputvector!
end
clear answ
% If user has selected all states AND all outputs, including the
% atmospheric disturbances (wind & turbulence), there is no need
% to determine new, simplified matrices for the linearized model,
% because Aac_s == Aac and Bac_s == Bac in that case. If the user
% has selected a subset of x and u, or if he has defined the vectors
% xdef and udef such that the order of the states and/or inputs is
% shuffled, simplified versions of Aac and Bac will be created.
%
% First check if user has specified full state and inputvector
% (unshuffled) for linearized model. If not, define Aac_s and Bac_s.
% ------------------------------------------------------------------
if allstates ~= 1 | allinputs ~= 1
% Determine new state matrix Aac_s, depending upon element numbers
% selected above.
% ----------------------------------------------------------------
for ii = 1:length(xdef) % ii = row number
for jj = 1:length(xdef) % jj = column number
Aac_s(ii,jj) = Aac(xdef(ii),xdef(jj));
end
end
% Determine new state matrix Bac_s, depending upon element numbers
% selected above.
% ----------------------------------------------------------------
for ii = 1:length(xdef) % ii = row number
for jj = 1:length(udef) % jj = column number
Bac_s(ii,jj) = Bac(xdef(ii),udef(jj));
end
end
clear ii jj
end
clc;
disp('State-space matrices of complete 12th-order system:');
disp('Aac, Bac, Cac, and Dac.');
disp(' ');
if allstates ~= 1 & allinputs ~= 1
disp('State-space matrices of simplified model (state equation only):');
disp('Aac_s and Bac_s');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -