Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added gtm_design/FlightCockpit_GUI.mlapp
Binary file not shown.
Binary file added gtm_design/Oscillatory Spin Trajectory.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
237 changes: 237 additions & 0 deletions gtm_design/OscillatorySpin.asv
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
%% --------------------- Oscillatory Trajectory Simulation --------------------------
%
% This MATLAB script models a targeted oscillatory spin condition for a GTM_T2 aircraft,
% simulates the trajectory from that condition, and plots various flight
% parameters over time.
%
% Simulation Details:
% - The script begins by initializing the simulation with nominal design conditions for
% a GTM_T2 aircraft.
% - It then proceeds to set up conditions for an oscillatory spin as specified in
% init_spin_design function.
% - The trajectory is simulated for a duration of 100 seconds.
% - The resulting trajectory is plotted, showing the behavior of key flight parameters
% such as alpha, beta, flight path angle, airspeed, angular rates, and Euler angles
% over time.
% - The trajectory is also visualized in a 3D plot with an orientated aircraft shape.
%
%
%% About
%
% Author: Omar Mourad
% Email: <mailto: st181901@stud.uni-stuttgart.de>
% Created: 20.03.2024


%% Conditions

% Start with some altitude,otherwise nominal init
MWS = init_design('GTM_T2');
loadmws(MWS,'gtm_design');
printStates(MWS);

% Proceed with the oscillatory spin conditions
MWS = init_spin_design('GTM_T2');
printStates(MWS);
loadmws(MWS,'gtm_design');

%% Simulate
%Determine the Simulation time (in Secs)
time_of_simulation = 10;
[t,x,y]=sim('gtm_design',[0 time_of_simulation]);

%% Convert from lat/lon to ft
Xeom=y(:,7:18);
dist_lat=(Xeom(:,7)-Xeom(1,7)) * 180/pi*364100.79;
dist_lon=(Xeom(:,8)-Xeom(1,8)) * 180/pi*291925.24;
alt=Xeom(:,9);
tplot=[0:.1:max(t)];

%% Save the data to file
save('simulationData.mat', 't', 'y', 'Xeom', 'dist_lat', 'dist_lon', 'alt');

%% Define simple airplane shape
scale=1;
x1=scale*([0.0,-.5, -2.0, -3.0,-4.0, -3.25, -5.5, -6.0, -6.0]+3.0);
y1=scale*[0.0, 0.5, 0.5, 4.25, 4.5, 0.5, 0.5, 1.5, 0.0];
Vehicletop=[ [x1,fliplr(x1)]; [y1,fliplr(-y1)]; -.01*ones(1,2*length(x1))];
Vehiclebot=[ [x1,fliplr(x1)]; [y1,fliplr(-y1)]; .01*ones(1,2*length(x1))];


%%NEW PLOTS
% Interpolate data to match the tplot timeline
X_ani = interp1(t, Xeom, tplot);
Y_ani = interp1(t, y(:,1:5), tplot);
lat_ani = interp1(t, dist_lat, tplot);
lon_ani = interp1(t, dist_lon, tplot);
alt_ani = interp1(t, alt, tplot);

%% Setup Dynamic Plots
h = figure(1);
set(h, 'Position', [20, 20, 1200, 800]);
clf;

% Alpha/Beta Plot Initialization
%hAlphaBeta = subplot(4, 2, 1);
axes('position',[.1 .75 .23 .13])
pAlpha = plot(tplot(1), X_ani(1, 3), 'r', 'LineWidth', 1.5); % Alpha
hold on;
pBeta = plot(hAlphaBeta, tplot(1), X_ani(1, 4), 'b', 'LineWidth', 1.5); % Beta
grid on;
legend({'\alpha', '\beta'}, 'Location', 'SouthEast');
xlabel('Time (sec)');
ylabel('\alpha (deg), \beta (deg)');
title('Alpha/Beta');
ylim([-50 50]);

% Flight Path and Airspeed Initialization
%hFlightPath = subplot(4, 2, 2);
axes('position',[.1 .55 .23 .13])
hGamma = plot(tplot(1), Y_ani(1, 5), 'r', 'LineWidth', 1.5); % Gamma
hold on;
hEAS = plot(hFlightPath, tplot(1), Y_ani(1, 1), 'b', 'LineWidth', 1.5); % Air-Speed
grid on;
legend({'\gamma', 'EAS'}, 'Location', 'SouthEast');
xlabel('Time (sec)');
ylabel('\gamma (deg), Equivalent Airspeed (knots)');
title('Flight Path Angle and Airspeed');

% Angular Rates Plot Initialization
hAngularRates = subplot(4, 2, 3);
axes('position',[.1 .35 .23 .13])
pP = plot(hAngularRates, tplot(1), X_ani(1, 4) * 180 / pi, 'r', 'LineWidth', 1.5); % p
hold on;
pQ = plot(hAngularRates, tplot(1), X_ani(1, 5) * 180 / pi, 'g', 'LineWidth', 1.5); % q
pR = plot(hAngularRates, tplot(1), X_ani(1, 6) * 180 / pi, 'b', 'LineWidth', 1.5); % r
legend({'p', 'q', 'r'}, 'Location', 'SouthEast');
xlabel('Time (sec)');
ylabel('Angular Rates (deg/sec)');
title('Angular Rates');
grid on;

% Euler Angles Plot Initialization
hEulerAngles = subplot(4, 2, 4);
pRoll = plot(hEulerAngles, tplot(1), X_ani(1, 10) * 180 / pi, 'r', 'LineWidth', 1.5); % Roll (phi)
hold on;
pPitch = plot(hEulerAngles, tplot(1), X_ani(1, 11) * 180 / pi, 'g', 'LineWidth', 1.5); % Pitch (theta)
pYaw = plot(hEulerAngles, tplot(1), X_ani(1, 12) * 180 / pi, 'b', 'LineWidth', 1.5); % Yaw (psi)
legend({'Roll', 'Pitch', 'Yaw'}, 'Location', 'NorthEast');
xlabel('Time (sec)');
ylabel('\phi (deg), \theta (deg), \psi (deg)');
title('Euler Angles');
grid on;

% 3D Trajectory Plot Initialization
hTrajectory = subplot(4, 2, [6 7]);
plot3(hTrajectory, dist_lat, dist_lon, alt, 'k', 'LineWidth', 1.5); % Entire Trajectory
hold on;
h3DAircraft = plot3(hTrajectory, lat_ani(1), lon_ani(1), alt_ani(1), 'ro', 'MarkerSize', 8, 'MarkerFaceColor', 'r');
grid on;
xlabel('Lat. Crossrange (ft)');
ylabel('Long. Crossrange (ft)');
zlabel('Altitude (ft)');
title('3D Oscillatory Spin Trajectory');
view([25, 10]);

%% Start Dynamic Plot Updates
for i = 1:length(tplot)
% Update Alpha/Beta plot
set(pAlpha, 'XData', tplot(1:i), 'YData', X_ani(1:i, 3));
set(pBeta, 'XData', tplot(1:i), 'YData', X_ani(1:i, 4));

% Update Flight Path and Airspeed plot
set(hGamma, 'XData', tplot(1:i), 'YData', Y_ani(1:i, 5));
set(hEAS, 'XData', tplot(1:i), 'YData', Y_ani(1:i, 1));

% Update Angular Rates plot
set(pP, 'XData', tplot(1:i), 'YData', X_ani(1:i, 4) * 180 / pi);
set(pQ, 'XData', tplot(1:i), 'YData', X_ani(1:i, 5) * 180 / pi);
set(pR, 'XData', tplot(1:i), 'YData', X_ani(1:i, 6) * 180 / pi);

% Update Euler Angles plot
set(pRoll, 'XData', tplot(1:i), 'YData', X_ani(1:i, 10) * 180 / pi);
set(pPitch, 'XData', tplot(1:i), 'YData', X_ani(1:i, 11) * 180 / pi);
set(pYaw, 'XData', tplot(1:i), 'YData', X_ani(1:i, 12) * 180 / pi);

% Update 3D Trajectory plot
set(h3DAircraft, 'XData', lat_ani(i), 'YData', lon_ani(i), 'ZData', alt_ani(i));

% Plot Aircraft Shape at Current Position
% Top View
fill3(Vehicletop(1,:) + lat_ani(i), Vehicletop(2,:) + lon_ani(i), Vehicletop(3,:) + alt_ani(i), 'r', 'FaceAlpha', 0.5);
% Bottom View
fill3(Vehiclebot(1,:) + lat_ani(i), Vehiclebot(2,:) + lon_ani(i), Vehiclebot(3,:) + alt_ani(i), 'b', 'FaceAlpha', 0.5);

% Pause for animation effect
pause(0.1);
end



% %% ------------------------Plots---------------------------
% h=figure(1);,set(h,'Position',[20,20,1200,800]);clf
%
% % Alpha/Beta
% axes('position',[.1 .75 .23 .13])
% plot(t,[y(:,3),y(:,4)]); % y(:,3) ----> Alphas // y(:,4) ----> Betas
% legend({'\alpha','\beta'},'Location','SouthEast');,grid on
% xlabel('time (sec)'),
% ylabel('\alpha (deg), \beta (deg)');
% title('Alpha/Beta');
%
% % Flight Path Angle and Airspeed
% axes('position',[.1 .55 .23 .13])
% [ax,h1,h2]=plotyy(t,y(:,5),t,y(:,1));grid on % y(:,5) ----> Gammas //
% xlabel('time (sec)'), % %y(:,1) ----> Airspeeds
% ylabel(ax(1),'Flight Path, \gamma (deg)');
% ylabel(ax(2),'Equivalent Airspeed (konts)')
% legend([h1;h2],{'\gamma','eas'},'Location','SouthEast');
% title('Flight Path Angle and Airspeed');
%
% % Angular Rates
% axes('position',[.1 .35 .23 .13])
% plot(t,Xeom(:,4:6)*180/pi);grid on
% legend({ 'p','q','r'},'Location','SouthEast');
% xlabel('time (sec)'),ylabel('angular rates (deg/sec)')
% title('Angular Rates');
%
% % Euler Angles
% axes('position',[.1 .15 .23 .13]);
% plot(t,[y(:,16)*180/pi, y(:,17)*180/pi, y(:,18)*180/pi]);
% % y(:,16) ---> Phi // y(:,17) ---> Theta // y(:,18) ---> Psi
% legend({'roll','pitch','yaw'},'Location','NorthEast');,grid on
% xlabel('time (sec)');
% ylabel('\phi (deg), \theta (deg), \psi (deg)');
% title('Euler Angles');
%
% % Trajectory: 3D plot with orientated vehicle
% axes('position',[.45,.15,.5,.7])
% plot3(dist_lat,dist_lon,alt);grid on, axset=axis; % Just get axis limits
% %cnt=0;
% % resample at equally spaced points for animation plot
% tplot=[0:.1:max(t)];
% X_ani=interp1(t,Xeom,tplot);
% lat_ani=interp1(t,dist_lat,tplot);
% lon_ani=interp1(t,dist_lon,tplot);
% alt_ani=interp1(t,alt,tplot);
% tic
% for i=[1:length(tplot)]
% plot3(dist_lat,dist_lon,alt);grid on
% Offset=repmat([lat_ani(i);lon_ani(i);alt_ani(i)],1,size(Vehicletop,2));
% Ptmp=diag([1,1,-1])*transpose(euler321(X_ani(i,10:12)))*Vehicletop + Offset;
% patch(Ptmp(1,:),Ptmp(2,:),Ptmp(3,:),'g');
% Ptmp=diag([1,1,-1])*transpose(euler321(X_ani(i,10:12)))*Vehiclebot + Offset;
% patch(Ptmp(1,:),Ptmp(2,:),Ptmp(3,:),'c');
% view(25,10),axis(axset),hold off
% xlabel('Lat. Crossrange(ft)');
% ylabel('Long. Crossrange(ft)');
% zlabel('Altitude(ft)');
% title('Simulation of Oscillatory Spin Trajectory');
% pause(.1);
% end
% toc
% if(exist('AutoRun','var'))
% pause(.2);
% orient portrait; print -dpng OscillatorySpin;
% end
%
51 changes: 51 additions & 0 deletions gtm_design/OscillatorySpin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
%% --------------------- Oscillatory Trajectory Simulation --------------------------
%
% This MATLAB script models a targeted oscillatory spin condition for a GTM_T2 aircraft,
% simulates the trajectory from that condition, and plots various flight
% parameters over time.
%
% Simulation Details:
% - The script begins by initializing the simulation with nominal design conditions for
% a GTM_T2 aircraft.
% - It then proceeds to set up conditions for an oscillatory spin as specified in
% init_spin_design function.
% - The trajectory is simulated for a duration of 100 seconds.
% - The resulting trajectory is plotted, showing the behavior of key flight parameters
% such as alpha, beta, flight path angle, airspeed, angular rates, and Euler angles
% over time.
% - The trajectory is also visualized in a 3D plot with an orientated aircraft shape.
%
%
%% About
%
% Author: Omar Mourad
% Email: <mailto: st181901@stud.uni-stuttgart.de>
% Created: 20.03.2024


%% Conditions

% Start with some altitude,otherwise nominal init
MWS = init_design('GTM_T2');
loadmws(MWS,'gtm_design');
printStates(MWS);

% Proceed with the oscillatory spin conditions
MWS = init_spin_design('GTM_T2');
printStates(MWS);
loadmws(MWS,'gtm_design');

%% Simulate
%Determine the Simulation time (in Secs)
time_of_simulation = 100;
[t,x,y]=sim('gtm_design',[0 time_of_simulation]);

%% Convert from lat/lon to ft
Xeom=y(:,7:18);
dist_lat=(Xeom(:,7)-Xeom(1,7)) * 180/pi*364100.79;
dist_lon=(Xeom(:,8)-Xeom(1,8)) * 180/pi*291925.24;
alt=Xeom(:,9);
tplot=0:.1:max(t);

%% Save the data to file
save('OscillatorySpinData.mat','t', 'tplot' , 'y', 'Xeom', 'dist_lat', 'dist_lon', 'alt');
Binary file added gtm_design/OscillatorySpinData.mat
Binary file not shown.
Binary file added gtm_design/Steep Spiral Trajectory.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions gtm_design/SteepSpiral.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
%% --------------------- Steep Spiral Trajectory Simulation --------------------------
%
% This MATLAB script models a targeted steep spiral condition for a GTM_T2 aircraft,
% simulates the trajectory from that condition, and plots various flight
% parameters over time.
%
% Simulation Details:
% - The script begins by initializing the simulation with nominal design conditions for
% a GTM_T2 aircraft.
% - It then proceeds to set up conditions for a steep spiral as specified in
% init_spiral_design function.
% - The trajectory is simulated for a duration of 100 seconds.
% - The resulting trajectory is plotted, showing the behavior of key flight parameters
% such as alpha, beta, flight path angle, airspeed, angular rates, and Euler angles
% over time.
% - The trajectory is also visualized in a 3D plot with an orientated aircraft shape.
%
%
%% About
%
% Author: Omar Mourad
% Email: <mailto: st181901@stud.uni-stuttgart.de>
% Created: 15.03.2024


%% Conditions

% Start with some altitude,otherwise nominal init
MWS = init_design('GTM_T2');
loadmws(MWS,'gtm_design');
printStates(MWS);

% Proceed with the steep spiral conditions
MWS = init_spiral_design('GTM_T2');
printStates(MWS);
loadmws(MWS,'gtm_design');

%% Simulate
%Determine the Simulation time (in Secs)
time_of_simulation = 100;
[t,x,y]=sim('gtm_design',[0 time_of_simulation]);
intermediate = y;
%% Convert from lat/lon to ft
Xeom=y(:,7:18);
dist_lat=(Xeom(:,7)-Xeom(1,7)) * 180/pi*364100.79;
dist_lon=(Xeom(:,8)-Xeom(1,8)) * 180/pi*291925.24;
alt=Xeom(:,9);
tplot=0:.1:max(t);

%% Save the data to file
save('SteepSpiralData.mat','t', 'tplot' , 'y', 'Xeom', 'dist_lat', 'dist_lon', 'alt');
Binary file added gtm_design/SteepSpiralData.mat
Binary file not shown.
Loading