diff options
Diffstat (limited to '')
-rw-r--r-- | uav.m | 108 |
1 files changed, 51 insertions, 57 deletions
@@ -12,39 +12,27 @@ fprintf('Generating system parameters...\n') params = uav_params(); ctrl = struct(); +% Flags to speed up running for debugging do_plots = true; +do_lqr = false; % unused +do_hinf = false; % midterm +do_musyn = true; % endterm % ------------------------------------------------------------------------ %% Define performance requirements -fprintf('Generating performance requirements...\n') -perf = uav_requirements(params, do_plots); +if do_hinf | do_musyn + fprintf('Generating performance requirements...\n') + perf = uav_performance(params, do_plots); +end % ------------------------------------------------------------------------ %% Define stability requirements -W_malpha = tf(1,1); -W_momega = tf(1,1); -W_mState = tf(1,1); - -% if do_plots -% figure; hold on; -% -% bodemag(W_malpha); -% bodemag(W_momega); -% bodemag(W_mState); -% -% grid on; -% legend('$W_{m,\alpha}$', '$W_{m,\omega}$', ... -% '$W_{m,\Theta}$', '$W_{m,\Omega}$', ... -% 'Interpreter', 'latex', 'fontSize', 8); -% title('Uncertainties') -% end - -uncert = struct(... - 'FlapAngle', W_malpha * eye(4), ... - 'Thrust', W_momega, ... - 'StateLinApprox', W_mState * eye(12)); +if do_musyn + fprintf('Generating stability requirements...\n') + uncert = uav_uncertainty(params, do_plots); +end % ------------------------------------------------------------------------ %% Create UAV model @@ -55,52 +43,61 @@ model = uav_model(params, perf, uncert); % ------------------------------------------------------------------------ %% Perform LQR design -% fprintf('Performing LQR controller design...\n') -% ctrl.lqr = uav_ctrl_lqr(params, model); +if do_lqr + fprintf('Performing LQR controller design...\n') + ctrl.lqr = uav_ctrl_lqr(params, model); +end % ------------------------------------------------------------------------ %% Perform H-infinity design -fprintf('Performing H-infinty controller design...\n') +if do_hinf + fprintf('Performing H-infinty controller design...\n') -idx = model.uncertain.index; -P = model.uncertain.StateSpace; + idx = model.uncertain.index; + P = model.uncertain.StateSpace; -% Get nominal system without uncertainty (for lower LFT) -P_nom = minreal(P([idx.OutputError; idx.OutputNominal], ... - [idx.InputExogenous; idx.InputNominal])); + % Get nominal system without uncertainty (for lower LFT) + P_nom = minreal(P([idx.OutputError; idx.OutputNominal], ... + [idx.InputExogenous; idx.InputNominal])); -nmeas = max(size(idx.OutputNominal)); % size of y -nctrl = max(size(idx.InputNominal)); % size of u + nmeas = max(size(idx.OutputNominal)); % size of y + nctrl = max(size(idx.InputNominal)); % size of u -hinfopt = hinfsynOptions('Display', 'on', 'Method', 'RIC', ... - 'AutoScale', 'off', 'RelTol', 1e-3); -[K_inf, ~, gamma, info] = hinfsyn(P_nom, nmeas, nctrl, hinfopt); -ctrl.hinf = struct('Name', '$\mathcal{H}_{\infty}$', 'K', K_inf); + hinfopt = hinfsynOptions('Display', 'on', 'Method', 'RIC', ... + 'AutoScale', 'off', 'RelTol', 1e-3); + [K_inf, ~, gamma, info] = hinfsyn(P_nom, nmeas, nctrl, hinfopt); + ctrl.hinf = struct('Name', '$\mathcal{H}_{\infty}$', 'K', K_inf); -if gamma >= 1 - fprintf('Failed to syntesize controller (closed loop is unstable).\n') -end + if gamma >= 1 + fprintf('Failed to syntesize controller (closed loop is unstable).\n') + end % ------------------------------------------------------------------------ -%% Measure Performance +%% Measure Performance of H-infinity design -fprintf('Simulating closed loop...\n'); + fprintf('Simulating closed loop...\n'); -nsamples = 500; -do_noise = true; -% uav_sim_step(params, model, ctrl.lqr, nsamples, do_plots); + nsamples = 500; + do_noise = true; + simout = uav_sim_step_hinf(params, model, ctrl.hinf, nsamples, do_plots, do_noise); -simout = uav_sim_step_hinf(params, model, ctrl.hinf, nsamples, do_plots, do_noise); + fprintf('Writing simulation results...\n'); + cols = [ + simout.StepX(:, simout.index.Position), ... + simout.StepX(:, simout.index.Velocity), ... + simout.StepX(:, simout.index.FlapAngles) * 180 / pi, ... + simout.StepX(:, simout.index.Angles) * 180 / pi]; -fprintf('Writing simulation results...\n'); -cols = [ - simout.StepX(:, simout.index.Position), ... - simout.StepX(:, simout.index.Velocity), ... - simout.StepX(:, simout.index.FlapAngles) * 180 / pi, ... - simout.StepX(:, simout.index.Angles) * 180 / pi]; + writematrix([simout.TimeXY', cols], 'fig/stepsim.dat', 'Delimiter', 'tab') +end + +% ------------------------------------------------------------------------ +%% Perform mu-Analysis & DK iteration -writematrix([simout.TimeXY', cols], 'fig/stepsim.dat', 'Delimiter', 'tab') +if do_musyn + +end % ------------------------------------------------------------------------ %% Verify performance satisfaction via mu-analysis @@ -134,7 +131,4 @@ writematrix([simout.TimeXY', cols], 'fig/stepsim.dat', 'Delimiter', 'tab') % title('$\mu_\Delta(N)$', 'Interpreter', 'latex'); % end -% ------------------------------------------------------------------------ -% Perform mu-Analysis & DK iteration - % vim: ts=2 sw=2 et: |