📄 aclin.m
字号:
% ----------------------------------------------------------------
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
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');
disp(' ');
end
disp('<<< Press a key >>>');
pause
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create a text matrix with information about the linearized model.
% Note: the function NUM2STR2 is just a slightly changed version
% of NUM2STR. Type HELP NUM2STR2 at the Matlab command line for
% more info.
% =================================================================
line1 = ['Linearized aircraft model of the system ' sysname ':'];
line2 = '';
line3 = ['User-specified operating point:'];
line4 = '';
line5 = ['Airspeed: V = ' num2str2(xinco(1),10) ' [m/s]' ];
line6 = ['Angle of attack: alpha = ' num2str2(xinco(2),10) ' [rad]' ];
line7 = ['Sideslip angle: beta = ' num2str2(xinco(3),10) ' [rad]' ];
line8 = ['Roll-rate: p = ' num2str2(xinco(4),10) ' [rad/s]'];
line9 = ['Pitch-rate: q = ' num2str2(xinco(5),10) ' [rad/s]'];
line10 = ['Yaw-rate: r = ' num2str2(xinco(6),10) ' [rad/s]'];
line11 = ['Yaw-angle: psi = ' num2str2(xinco(7),10) ' [rad] '];
line12 = ['Pitch-angle: theta = ' num2str2(xinco(8),10) ' [rad] '];
line13 = ['Roll-angle: phi = ' num2str2(xinco(9),10) ' [rad] '];
line14 = ['X-coordinate: xe = ' num2str2(xinco(10),10) ' [m] '];
line15 = ['Y-coordinate: ye = ' num2str2(xinco(11),10) ' [m] '];
line16 = ['Altitude: H = ' num2str2(xinco(12),10) ' [m] '];
line17 = '';
line18 = ['Elevator angle: deltae = ' num2str2(uaero0(1),10) ' [rad] '];
line19 = ['Aileron angle: deltaa = ' num2str2(uaero0(2),10) ' [rad] '];
line20 = ['Rudder angle: deltar = ' num2str2(uaero0(3),10) ' [rad] '];
line21 = ['Flap angle: deltaf = ' num2str2(uaero0(4),10) ' [rad] '];
line22 = '';
line23 = ['Engine speed: n = ' num2str2(uprop0(1),10) ' [RPM] '];
line24 = ['Manifold pressure: pz = ' num2str2(uprop0(2),10) ' ["Hg] '];
line25 = '';
line26 = ['Full state space model: Aac, Bac, Cac, Dac.'];
line27 = '';
% Add definition of Aac_s and Bac_s to text matrix.
% -------------------------------------------------
if allstates == 1 & allinputs == 1 % all states and all outputs selected,
% so no model simplifications...
line28 = ['No simplified model available.'];
line29 = '';
line30 = ['x = [V alpha beta p q r psi theta phi xe ye H]'''];
line31 = ['u = [ua'' ut'' uwind'']'''];
line32 = '';
line33 = ['ua = [deltae deltaa deltar deltaf]'''];
line34 = ['ut = [n pz]'','];
line35 = ['uwind = [uw vw ww uwdot vwdot wwdot]'''];
line36 = '';
else % simplified model has been determined
line28 = ['Aac_s and Bac_s contain simplified model (state eqs. only!)'];
line29 = '';
line30 = ['State and input vectors of the simplified model:'];
line31 = ['x_s=['];
for ii = 1:length(xdef)
line31 = [line31 'x(' num2str(xdef(ii)) ') '];
end
line31 = [line31(1:length(line31)-1) ']'];
line32 = ['u_s=['];
for jj = 1:length(udef)
line32 = [line32 'u(' num2str(udef(jj)) ') '];
end
line32 = [line32(1:length(line32)-1) ']'];
line33 = '';
line34 = ['where: x = [V alpha beta p q r psi theta phi xe ye H]'''];
line35 = [' u = [deltae deltaa deltar deltaf n pz ...'];
line36 = [' ... uw vw ww uwdot vwdot wwdot]'''];
end
% Include default output definition (ACLIN will also work when the output
% definition is altered in the nonlinear model, hence the caution)
% -----------------------------------------------------------------------
line37 = '';
line38 = 'For the default system BEAVER, the output vector is equal to:';
line39 = '';
line40 = 'y = [x'' dH/dt pb/2V qc/V rb/2V]''';
line41 = '';
line42 = 'If you are not sure of the current output definition, please';
line43 = 'verify the nonlinear Simulink model that was used to obtain';
line44 = 'the linearized system.';
line45 = '';
% Add time and date to text matrix.
% ---------------------------------
t = clock;
t1 = num2str(t(4));
t2 = num2str(t(5));
t3 = num2str(t(6));
line46 = ['date: ', date, ' time: ', t1, ':', t2, ':', t3];
% Enhance explanatory lines to 80 characters and collect the results in the
% string matrix 'lindef'. Clear the individual line variables.
% -------------------------------------------------------------------------
lindef = [];
for ii = 1:46
linestr = ['line' num2str(ii)];
eval([linestr '= [' linestr ' blanks(79-length(' linestr '))];']);
eval(['lindef = [lindef; ' linestr '];']);
eval(['clear ' linestr ]);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Results can now be saved to a file, which will be filled with the
% state space matrices Aac, Bac, Cac, Dac of the linearized aircraft
% model, and the information matrix lindef. Moreover, the user will
% be asked if the operating point, defined by xinco, uaero0, and uprop0
% must be saved to the same file too. In that case, the information
% matrix trimdef will be saved too if it exists (see ACTRIM for more
% info).
%
% Note: files with linearized aircraft model have extension .LIN!
% ==================================================================
clc
answ = input('Save linear state-space model to file (y/[n])? ','s');
if isempty(answ)
answ = 'n';
end
if answ == 'y'
% Destination directory for storing the results is the default FDC
% data-directory, which is obtained from the function DATADIR.M.
% If that directory does not exist, the current directory will be
% used instead.
% ----------------------------------------------------------------
defdir = datadir;
currentdir = chdir;
% Go to default directory if that directory exists (if not, start
% save-routine from the current directory).
% ---------------------------------------------------------------
try
chdir(defdir);
catch
chdir(currentdir);
end
% Obtain filename and path
% ------------------------
[filename,dirname] = uiputfile('*.lin','Save linearized model');
% Save results to the specified file
% ----------------------------------
save([dirname,filename],'Aac','Bac','Cac','Dac','lindef');
% If simplified matrices exist, append them to the saved file
% -----------------------------------------------------------
if allstates ~= 1 | allinputs ~= 1
save([dirname,filename],'Aac_s','Bac_s','-append');
end
% Ask if operating point needs to be included to the .LIN file.
% If it does, append xinco, uaero0, uprop0 and (if present)
% trimdef to the saved file.
% -------------------------------------------------------------
disp(' ');
answ = input('Include operating point {xinco,uaero0,uprop0} to file ([y]/n)? ','s');
if isempty(answ)
answ = 'y';
end
if answ == 'y'
save([dirname,filename],'xinco','uaero0','uprop0','-append');
% If operating point has been loaded from .TRI file or computed by
% directly calling ACTRIM, the definition of the trimmed flight-
% condition is stored in the text-matrix trimdef. If the operating
% point is defined in another way, this matrix does not exist. If
% trimdef exists, it will be saved along with the trimmed flight-
% condition itself.
% -----------------------------------------------------------------
if exist('trimdef') == 1
save([dirname,filename],'trimdef','-append');
end
end
% Display file location
% ---------------------
clc
disp('The linear state-space model was saved to the file:');
disp(' ');
disp([' ',dirname,filename]);
disp(' ');
disp('<<< Press a key >>>');
pause
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Display results for user.
% =========================
clc
disp('State-space matrices of linearized aircraft model: Aac, Bac, Cac,');
disp('and Dac (ac = aircraft). Operating point is defined by the vectors');
disp('xinco, uaero0, and uprop0.');
disp(' ');
disp('The default output definition used by the system BEAVER equals:');
disp(' ');
disp(' y = [x'' dH/dt pb/2V qc/V rb/2V]''');
disp(' ');
disp('which contains all relevant information for the autopilot simu-');
disp('lation model APILOT. Notice that this includes four additional');
disp('output trajectories, when compared with the state vector. Since');
disp('ACLIN will also work when the output definition in the nonlinear');
disp('model is altered, it is recommended always to verify the current');
disp('output definition when using a different aircraft model that is');
disp('based on the system BEAVER.');
disp(' ');
if allstates ~= 1 | allinputs ~= 1
disp('Simplified state model available in matrices Aac_s and Bac_s');
disp('(state equations only!).');
disp(' ');
end
disp('See matrix lindef for more details!');
end % of the part of the program in which the actual linearization takes
% place, and which contains the save routines (skipped if the option
% QUIT is selected from the main menu).
disp(' ');
disp('Ready.');
disp(' ');
% Clear variables which are not needed anymore
% --------------------------------------------
clear V alpha beta p q r psi theta phi xe ye H deltae deltaa deltar
clear deltaf n pz ok ok1 ok2 proceed answ answ1
clear opt skip sysname uinco udef xdef allstates allinputs ii jj h
clear t t1 t2 t3 dirname filename savecmmnd defdir currentdir
%-----------------------------------------------------------------------
% The Flight Dynamics and Control Toolbox version 1.4.0.
% (c) Copyright Marc Rauw, 1994-2005. Licensed under the Open Software
% License version 2.1; see COPYING.TXT and LICENSE.TXT for more details.
% Last revision of this file: December 31, 2004.
%-----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -