-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrajectory_analysis_F50.m~
151 lines (128 loc) · 6.99 KB
/
Trajectory_analysis_F50.m~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Prescott Rynewicz
% 504288967
% MAE 157A Trajectory Analysis Code
% Team SpaceY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all; clear all; clc;
%% Constants
Oz_kg = 0.0283; % [kg/oz]
in_m = 0.0254; % [m/in]
g = 9.81; % [m/s]
Re = 3.67e6; % []
%% Total Vehicle Input Parameters
total_mass = 0.7; % [kg]
CD_coast_recovery = [0.75 1.5]; % [ ]
original_D = 1.33*in_m; % [m]
recovery_D = 18*in_m; % [m]
launch_angle = 5; % [deg]
%% Motor Inputs
prop_mass = 37.9/1000; % [kg]
total_mass_motor = 83.9/1000; % [kg]
final_motor_mass = 38.4/1000; % [kg]
total_impulse = 76.83; % [N-s]
deploy_time = 6.05;
Thrust_curve = dlmread('Thrust_curve.pol'); % [N]
%% Interpolate Thrust curve for high accuracy in numerical integration.
t_simple = Thrust_curve(:,1); % [t]
t_total = []; % [t]
T_simple = Thrust_curve(:,2); % [N]
T_total = []; % [N]
for i = 1:length(t_simple)-1
expanded_array_t = linspace(t_simple(i),t_simple(i+1),100);
expanded_array_T = linspace(T_simple(i),T_simple(i+1),100);
t_total = cat(2,t_total,expanded_array_t);
T_total = cat(2,T_total,expanded_array_T);
end
%% Vehicle Calcs
final_mass = total_mass-total_mass_motor ... % [ ]
+ final_motor_mass; % [kg]
Isp = total_impulse/(prop_mass*g); % [sec]
m_dot = T_total./g./Isp; % [kg/s]
prop_mass_profile = linspace(0,0,length(t_total)); % [kg]
prop_mass_profile(1)=prop_mass; % [kg]
total_mass = linspace(total_mass,total_mass,... % [kg]
length(t_total)); % [kg]
%% Setup variables for all numerical calcs.
burn_length = length(t_total); % [vec_length]
a = linspace(0,0,burn_length); % [m/s^2]
u = linspace(0,0,burn_length); % [m/s]
h = linspace(0,0,burn_length); % [m]
Af = pi*(original_D/2)^2; % [m^s]
theta = deg2rad(launch_angle); % [rad]
ge = 9.81; % [m/s]
h = linspace(0,0,burn_length); % [m]
g = linspace(0,0,burn_length); % [m/s^2]
g(1) = 9.81; % [m/s]
rho = linspace(0,0,burn_length); % [kg/m^3]
rho(1) = 1.225; % [kg/m^3]
CD = 0.8; % Initial Estimate from Stine
D = linspace(0,0,burn_length); % [N]
D(1) = 0.5*rho(1)*u(1)^2*CD*Af; % [N]
dt_avg = 0;
for index = 2:length(T_total)
prop_mass_profile(index) = prop_mass_profile(index-1) - m_dot(index)*(t_total(index)-t_total(index-1));
total_mass(index) = total_mass(index-1) - m_dot(index)*(t_total(index)-t_total(index-1));
end
for index = 1:(burn_length-1)
dt = (t_total(index+1)-t_total(index));
dt_avg = dt_avg + dt;
a(index+1) = (T_total(index) - D(index))/total_mass(index) - g(index)*cos(theta);
u(index+1) = u(index) + (T_total(index)/total_mass(index) - D(index)/total_mass(index) ...
- g(index)*cos(theta))*dt;
h(index+1) = h(index) + u(index)*dt*cos(theta);
g(index+1) = ge*(Re/(Re+h(index+1)));
rho(index+1) = real(1.2*exp(-2.9*10^-5*h(index+1)^1.15));
D(index+1) = 0.5*rho(index+1)*u(index+1)^2*CD*Af;
end
dt = dt_avg/burn_length; % [s] New Time step from average thrust dt.
for index = burn_length:10000000
total_mass(index)= total_mass(index-1);
a(index+1) = -D(index)/total_mass(index) - g(index)*cos(theta);
u(index+1) = u(index) + (-D(index)/total_mass(index)*dt ...
- g(index)*cos(theta)*dt);
h(index+1) = h(index) + u(index)*dt*cos(theta);
g(index+1) = ge*(Re/(Re+h(index+1)));
rho(index+1) = real(1.2*exp(-2.9*10^-5*h(index+1)^1.15));
D(index+1) = 0.5*rho(index+1)*u(index+1)^2*CD*Af;
t_total(index+1)= t_total(index)+dt;
if t_total(index) >= deploy_time
index = index+1;
break;
end
end
total_mass(index) = final_mass;
CD = 2.0; % Will be determined from drop tests with parachute.
Af = pi*(recovery_D/2)^2; % [m^2]r
D(index) = 0.5*rho(index)*u(index)^2*CD*Af;
for index = index:100000000
total_mass(index)= total_mass(index-1);
u(index+1) = u(index) + (-D(index)/total_mass(index)*dt ...
- g(index)*dt);
h(index+1) = h(index) + u(index)*dt*cos(theta);
g(index+1) = ge*(Re/(Re+h(index+1)));
rho(index+1) = real(1.2*exp(-2.9*10^-5*h(index+1)^1.15));
D(index+1) = 0.5*rho(index+1)*u(index+1)^2*CD*Af;
t_total(index+1)= t_total(index)+dt;
if u(index+1) <= 0
break;
end
end
for index = index:100000000
total_mass(index)= total_mass(index-1);
u(index+1) = u(index) + (D(index)/total_mass(index)*dt ...
- g(index)*dt);
h(index+1) = h(index) + u(index)*dt*cos(theta);
g(index+1) = ge*(Re/(Re+h(index+1)));
rho(index+1) = real(1.2*exp(-2.9*10^-5*h(index+1)^1.15));
D(index+1) = 0.5*rho(index+1)*u(index+1)^2*CD*Af;
t_total(index+1)= t_total(index)+dt;
if h(index+1) <= 0
break;
end
end
figure; plot(t_total,u); title('Velocity vs. Time', 'Fontsize', 16); xlabel('Time [s]'); ylabel('Velocity [m/s]');
figure; plot(t_total,h); title('Altitude vs. Time', 'Fontsize', 16); xlabel('Time [s]'); ylabel('Altitude [m]');
% figure; plot(t_total,D); title('Drag vs. Time', 'Fontsize', 16); xlabel('Time [s]'); ylabel('Drag [N]');
% figure; plot(t_total,g); title('Gravity vs. Time', 'Fontsize', 16); xlabel('Time [s]'); ylabel('Gravity [m/s]');
% figure; plot(t_total,rho); title('Density vs. Time', 'Fontsize', 16); xlabel('Time [s]'); ylabel('Density [kg/m^3]');