Files
2025-06-04 14:13:22 +08:00

120 lines
3.6 KiB
Matlab

load('trimgrid_20250126_2.mat');
trimgrid1 = trim_grid(trimgrid, H_lst, TAS_lst, mass);
trimgrid = trimgrid1;
save('trimgrid_20250126_3.mat', 'H_lst', 'TAS_lst', 'mass', 'trimgrid');
function rslt = trim_grid(rslt_ori, H_lst, TAS_lst, mass0)
mdl = evalin('base', 'mdl_name');
fcn = [mdl, '_an'];
opts = trimoptions(fcn);
opts.v0_type = uint8(0);
opts.max_alpha = 10/57.3;
opts.max_alpha_pullup = 5/57.3;
opts.min_alpha = -1/57.3;
opts.max_beta = 6/57.3;
opts.min_beta = -6/57.3;
opts.max_de = 20/57.3;
opts.min_de = -20/57.3;
opts.max_da = 10/57.3;
opts.min_da = -10/57.3;
opts.max_dr = 10/57.3;
opts.min_dr = -10/57.3;
opts.max_throttle = 1;
opts.max_power = 46000;
% opts.de = -4/57.3;
% opts.dr = 0/57.3;
% opts.throttle = 0.6;
% opts.de = -7.5/57.3;
load_system(fcn);
mdlWks = get_param(fcn,'ModelWorkspace');
assignin(mdlWks,'mass0',mass0);
opts.TrimOptions.OptimizationOptions.Display = 'iter';
opts.TrimOptions.DisplayReport = 'on';
opts.TrimOptions.OptimizationOptions.MaxIter = 100;
opts.TrimOptions.OptimizationOptions.MaxFunEvals = 300;
opts.TrimOptions.OptimizationOptions.TolX = 1e-6;
n_TAS = length(TAS_lst);
n_H = length(H_lst);
rslt = cell(n_H,n_TAS);
for h_idx=1:length(H_lst)
h0 = H_lst(h_idx);
[~, ~, ~, rho] = atmoscoesa(h0);
for tas_idx=1:n_TAS
rslt{h_idx,tas_idx} = amend(rslt_ori{h_idx,tas_idx}, opts, H_lst(h_idx),TAS_lst(tas_idx));
end
end
close_system(fcn, 0); % close without saving
end
function rslt = amend(rslt_ori, opts, h0, tas0)
% rslt = [];
rslt = rslt_ori;
if ~isempty(rslt_ori)
rslt = rslt_ori;
% if ~isfield(rslt_ori, 'cruise')
% [success,opts1] = trimLon( opts, h0, tas0, 0);
% if success&&(opts1.power < opts.max_power)
% rslt.cruise = opts1;
% rslt.cruise.opsec = [];
% rslt.cruise.TrimOptions = [];
% end
% end
% if ~isfield(rslt_ori, 'climb')
% [success,opts2] = trimGamma( opts, h0, tas0, opts.max_throttle);
%
% if success
% hdot = sin(opts2.gamma)*opts2.TAS;
% if hdot>0.5
% rslt.climb = opts2;
% rslt.climb.opsec = [];
% rslt.climb.TrimOptions = [];
% else
% rslt = [];
% end
% end
% end
% if ~isfield(rslt_ori, 'glide')
% [success,opts3] = trimGamma( opts, h0, tas0, 0);
% if success
% rslt.glide = opts3;
% rslt.glide.opsec = [];
% rslt.glide.TrimOptions = [];
% end
% end
%
% if ~isfield(rslt_ori, 'glide_idle')
% [success,opts4] = trimGamma( opts, h0, tas0, 0.08);
% if success
% rslt.glide_idle = opts4;
% rslt.glide_idle.opsec = [];
% rslt.glide_idle.TrimOptions = [];
% end
% end
if ~isfield(rslt_ori, 'pullup')
[success,opts5] = trimPullupThr( opts, h0, tas0, opts.max_throttle );
if ~success
[success,opts5] = trimPullupAoA( opts, h0, tas0, opts.max_alpha);
if ~success
[success,opts5] = trimPullupDe( opts, h0, tas0, opts.min_de );
end
end
if success && opts5.Nn > 1
rslt.pullup = opts5;
rslt.pullup.opsec = [];
rslt.pullup.TrimOptions = [];
end
end
end
end