function flight = flight_6DOF(time) % This is the Y-motion component to a general 6-DOF flight simulator package. % It is in the SECOND ORDER stage of development. % THIRD ORDER would need polar coordinates in order to simulate being on the earth % VARIABLES and UNITS % % conventions: Large arrays are in all caps % Vectors and other variables are in mixed case, as appropriate % % +y is North, -y is South % +x is East, -x is West % +z is up, -z is down. % % TIME :ODE array in seconds. % OPT :Options array for the ODE. % dt :Delta t, differential step time for the TIME array. % Controlls the precision of the overall simulation. % IC :Initial conditions for the ODE to start wtih: [v, xyz, o, m] % where: v = [vx vy vz] (velocity) % xyz = [x y z] (position) % o = [ox oy oz] (orientation) % mf = fuel mass. % theta :Launch azimuth angle (90 = straight up), in deg. % gamma :Launch rotation angle (0 = North), in deg. % CONSTANTS % INITIAL CONDITIONS %load parameter file %load specs.txt; %load fuel.txt; %load aerodynamics; %load guidance; % for ODE45 IC = [0 0 0 0 0 300 0 0 0 9]; % [vx vy vz x y z ox oy oz mf] OPT = odeset('RelTol',1e-4); % options % initial orientation theta = 20 *(pi/180); % degrees gamma = 0 *(pi/180); % degrees (0 < gamma < 90) IC(7) = cos(theta)*sin(gamma); IC(8) = cos(theta)*sin(pi/2-gamma); IC(9) = sin(theta); %dt = .1; %TIME = [0:dt:time]; % SOLVE THE SIMULATION [t,x]=ode45('rocket_6DOF',[0 time],IC,OPT); flight = [t x]; % mach number column %for i = 1:time+1 %flight(i,12) = sqrt(x(i,2)^2+x(i,3)^2+x(i,4)^2)/(sqrt(1.4*287*temperature(x(i,6)))); %end % PLOTS figure(1) subplot(411) plot(t,sqrt(x(:,1).^2+x(:,2).^2+x(:,3).^2)) ylabel('velocity (m/s)') grid on subplot(412) plot(t,x(:,6)/1000) ylabel('Altitude (km)') grid on subplot(413) plot(x(:,5)/1000,x(:,6)) ylabel('Profile (km)') grid on subplot(414) plot(t,x(:,10)) ylabel('Fuel Mass (kg)') xlabel('time, [sec]') grid on figure(2) subplot(331) plot(t,x(:,1)) ylabel('velocity (m/s)') subplot(332) plot(t,x(:,2)) subplot(333) plot(t,x(:,3)) subplot(334) plot(t,x(:,4)) ylabel('position (m)') subplot(335) plot(t,x(:,5)) subplot(336) plot(t,x(:,6)) subplot(337) plot(t,x(:,7)) xlabel('x') ylabel('orientation') subplot(338) plot(t,x(:,8)) xlabel('y') subplot(339) plot(t,x(:,9)) xlabel('z') figure(3) subplot(111) plot3(x(:,4)/1000,x(:,5)/1000,x(:,6)/1000) xlabel('x (km)') ylabel('y (km)') zlabel('z (km)') grid on