-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVScript.py
More file actions
210 lines (203 loc) · 6.37 KB
/
VScript.py
File metadata and controls
210 lines (203 loc) · 6.37 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import math
from matplotlib import pyplot as plt
def Simulation(self):
#Get Variables
try:
mass = float(self.M.toPlainText())
drag_coef = float(self.C.toPlainText())
surface_area = float(self.A.toPlainText())
lift_coef = float(self.L.toPlainText())
initial_alt = float(self.h.toPlainText())
initial_vel = float(self.v.toPlainText())
initial_angle = math.radians(float(self.gam.toPlainText()))
except ValueError:
import Launcher
Launcher.Ui_MainWindow.err0()
Launcher.Ui_MainWindow.restart()
exit()
#Check states
At = self.At.checkState()
Act = self.Act.checkState()
Vt = self.Vt.checkState()
ht = self.ht.checkState()
rant = self.rant.checkState()
rana = self.rana.checkState()
err1 = [At,Act,Vt,ht,rant,rana]
ii = 0
for i in range(6):
if err1[i] == 0:
ii += 1
if ii == 6 or (ii == 5 and At == 2):
import Launcher
Launcher.Ui_MainWindow.err1()
Launcher.Ui_MainWindow.restart()
exit()
#Preliminary Calculations
gravity_accel = 8.87
weight = mass*gravity_accel
lift = lift_coef/drag_coef
bal_coef = weight/(drag_coef*surface_area)
dt = 0.1
t = 0
time = [0]
down = [0]
alt = [initial_alt]
vel = [initial_vel]
accel = [0]
AoA = [initial_angle]
curr_alt = initial_alt
curr_vel = initial_vel
curr_angle = initial_angle
curr_range = 0
plt.rcParams["figure.figsize"] = [14.00, 8.00]
plt.rcParams["figure.autolayout"] = True
while curr_alt >= 0.1 :
#Clock
t = t + dt
time.append(t)
#Atmos Sim (High Density Min Solar Activity Used)
if curr_alt >= 0:
p = 112
if curr_alt >= 5000:
p = 87.1
if curr_alt >= 10000:
p = 66.8
if curr_alt >= 15000:
p = 50.6
if curr_alt >= 20000:
p = 37.9
if curr_alt >= 25000:
p = 27.8
if curr_alt >= 30000:
p = 20
if curr_alt >= 35000:
p = 14.2
if curr_alt >= 40000:
p = 9.72
if curr_alt >= 45000:
p = 6.4
if curr_alt >= 50000:
p = 4.01
if curr_alt >= 55000:
p = 2.36
if curr_alt >= 60000:
p = 1.25
if curr_alt >= 65000:
p = 0.564
if curr_alt >= 70000:
p = 0.25
if curr_alt >= 75000:
p = 0.108
if curr_alt >= 80000:
p = 0.0451
if curr_alt >= 85000:
p = 0.0179
if curr_alt >= 90000:
p = 0.0067
if curr_alt >= 95000:
p = 0.00239
if curr_alt >= 100000:
p = 0.000804
if curr_alt >= 110000:
p = 0.0000737
if curr_alt >= 120000:
p = 0.0000056
if curr_alt >= 130000:
p = 0.000000676
if curr_alt >= 140000:
p = 0.0000000838
if curr_alt >= 150000:
p = 0.000000015
if curr_alt >= 160000:
p = 0.00000000415
if curr_alt >= 180000:
p = 0.0000000000692
if curr_alt >= 200000:
p = 0.0000000000164
if curr_alt >= 210000:
p = 0
#Dynamic Pressure Sim
Q = (p*(curr_vel**2))/2
#Velocity Sim
past_vel = curr_vel
curr_vel = (dt*gravity_accel*((-Q/bal_coef)+math.sin(initial_angle))) + past_vel
vel.append(curr_vel)
curr_accel = (curr_vel-past_vel)/dt
accel.append(curr_accel)
#Angle Sim
past_angle = curr_angle
curr_angle = dt*((((-(Q*gravity_accel)/bal_coef)*(lift))+(math.cos(curr_angle)*(gravity_accel-((curr_vel**2)/(6051800+curr_alt)))))/curr_vel) + past_angle
AoA.append(math.degrees(curr_angle))
#Altitude Sim
past_alt = curr_alt
curr_alt = dt*(-curr_vel)*math.sin(curr_angle) + past_alt
alt.append(curr_alt)
#Range Sim
past_range = curr_range
curr_range = dt*((6051800*curr_vel*math.cos(curr_angle))/(6051800+curr_alt)) + past_range
down.append(curr_range)
if At == 2:
plt.subplot(2, 3, 6)
plt.plot(time,AoA,color='yellow')
plt.xlabel("time / s")
plt.ylabel("AoA / deg")
plt.grid()
if rant == 2:
plt.subplot(2, 3, 1)
plt.plot(time,down, color = 'purple')
plt.xlabel("time / s")
plt.ylabel("Downrange / m")
plt.grid()
if ht == 2:
plt.subplot(2, 3, 2)
plt.plot(time,alt, color = 'blue')
plt.xlabel("time / s")
plt.ylabel("Altitude / m")
plt.grid()
if Vt == 2:
plt.subplot(2, 3, 3)
plt.plot(time, vel, color='red')
plt.xlabel("time / s")
plt.ylabel("Velocity / ms^-1")
plt.grid()
if Act == 2:
plt.subplot(2, 3, 4)
plt.plot(time,accel, color='green')
plt.xlabel("time / s")
plt.ylabel("acceleration / ms^-2")
plt.grid()
if rana == 2:
plt.subplot(2, 3, 5)
plt.plot(down,alt,color='purple')
plt.xlabel("Downrange / m")
plt.ylabel("Altitude / m")
plt.grid()
else:
if rant == 2:
plt.plot(time,down, color = 'purple')
plt.xlabel("time / s")
plt.ylabel("Downrange / m")
plt.grid()
if ht == 2:
plt.plot(time,alt, color = 'blue')
plt.xlabel("time / s")
plt.ylabel("Altitude / m")
plt.grid()
if Vt == 2:
plt.plot(time, vel, color='red')
plt.xlabel("time / s")
plt.ylabel("Velocity / ms^-1")
plt.grid()
if Act == 2:
plt.plot(time,accel, color='green')
plt.xlabel("time / s")
plt.ylabel("acceleration / ms^-2")
plt.grid()
if rana == 2:
plt.plot(down,alt,color='purple')
plt.xlabel("Downrange / m")
plt.ylabel("Altitude / m")
plt.grid()
plt.xlim()
plt.ylim()
plt.show()