You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: campyros/main.py
+56-50Lines changed: 56 additions & 50 deletions
Original file line number
Diff line number
Diff line change
@@ -1,33 +1,25 @@
1
1
"""
2
2
Contains the classes and functions for the core trajectory simulation. SI units unless stated otherwise.
3
-
4
3
Notes
5
4
-----
6
-
7
5
Known issues:
8
-
9
6
- Unsure about the use of "dx" in "scipy.misc.derivative(self.mass_model.mass, time, dx=1)" when calculating mdot
10
7
- Possible inconsistency in the definition of the launch site coordinate system, and whether the origin is at alt=0 or alt=launch_site.alt. I haven't thoroughly checked for this inconsistency yet.
11
-
12
8
Coordinate systems:
13
-
14
9
- Body (x_b, y_b, z_b)
15
10
- Origin on rocket
16
11
- Rotates with the rocket.
17
-
18
12
- y points east and z north at take off (before rail alignment is accounted for) x up.
19
13
- x is along the "long" axis of the rocket.
20
14
- Launch site (x_l, y_l, z_l):
21
15
- Origin has the launch site's longitude and latitude, but is at altitude = 0.
22
16
- Rotates with the Earth.
23
-
24
17
- z points up (normal to the surface of the Earth).
25
18
- y points East (tangentially to the surface of the Earth).
26
19
- x points South (tangentially to the surface of the Earth).
27
20
- Inertial (x_i, y_i, z_i):
28
21
- Origin at centre of the Earth.
29
22
- Does not rotate.
30
-
31
23
- z points to North from the centre of Earth.
32
24
- x aligned with launch site at start .
33
25
- y defined from x and z (so it is a right hand coordinate system).
@@ -46,7 +38,8 @@
46
38
importpandasaspd
47
39
frommetpy.unitsimportunits
48
40
49
-
importscipy.interpolate, scipy.misc
41
+
importscipy.interpolateasinterpolate
42
+
importscipy.misc
50
43
importscipy.integrateasintegrate
51
44
fromscipy.spatial.transformimportRotation
52
45
importnumexprasne
@@ -70,22 +63,20 @@
70
63
from .windimportWind
71
64
72
65
__copyright__="""
73
-
74
66
Copyright 2021 Jago Strong-Wright & Daniel Gibbons
75
-
76
67
This program is free software: you can redistribute it and/or modify
77
68
it under the terms of the GNU General Public License as published by
78
69
the Free Software Foundation, either version 3 of the License, or
79
70
(at your option) any later version.
80
-
81
71
This program is distributed in the hope that it will be useful,
82
72
but WITHOUT ANY WARRANTY; without even the implied warranty of
83
73
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84
74
GNU General Public License for more details.
85
-
86
75
You should have received a copy of the GNU General Public License
87
76
along with this program. If not, see <https://www.gnu.org/licenses/>.
88
77
78
+
Modifcations:
79
+
- Richard Zhang: Mach varying parachute drag coefficients
"""Returns the drag coefficient and area of the parachute, given the current altitude and Mach Number.
167
+
I.e., it checks if the main or drogue parachute is open, and returns the relevant values.
157
168
Args:
158
169
alt (float): Current altitude (m)
159
-
170
+
mach (float): Mach number
160
171
Returns:
161
172
float, float: Drag coefficient, parachute area (m^2)
162
173
"""
174
+
# if Mach < 0 or Mach > 7:
175
+
# print("Mach Number is {}, out of range!".format(Mach))
163
176
ifalt<self.main_alt:
164
-
c_d=self.main_c_d
165
177
s=self.main_s
178
+
ifself.variable_main_c_d==False:
179
+
c_d=self.main_c_d
180
+
elifself.variable_main_c_d==True:
181
+
c_d=self.main_c_d(mach)
166
182
else:
167
-
c_d=self.drogue_c_d
168
183
s=self.drogue_s
184
+
ifself.variable_main_c_d==False:
185
+
c_d=self.drogue_c_d
186
+
elifself.variable_main_c_d==True:
187
+
c_d=self.drogue_cd(mach)
169
188
returnc_d, s
170
189
171
190
172
191
classLaunchSite:
173
192
"""Object for holding launch site information.
174
-
175
193
Args:
176
194
rail_length (float): Length of the launch rail (m)
177
195
rail_yaw (float): Yaw angle of the launch rail (deg), using a right-hand rotation rule out the launch frame z-axis. "rail_yaw = 0" points South, "rail_yaw = 90" points East.
@@ -186,7 +204,6 @@ class LaunchSite:
186
204
forcast_time (str, optional): Forcast run time, must be "00", "06", "12" or "18". Defaults to "00".
187
205
forcast_plus_time (str, optional): Hours forcast forward from forcast time, must be three digits between 000 and 123 (?). Defaults to "000".
188
206
fast_wind (bool, optional): ???. Defaults to False.
189
-
190
207
Attributes:
191
208
rail_length (float): Length of the launch rail (m)
192
209
rail_yaw (float): Yaw angle of the launch rail (deg), using a right-hand rotation rule out the launch frame z-axis. "rail_yaw = 0" points South, "rail_yaw = 90" points East.
@@ -234,7 +251,6 @@ def __init__(
234
251
235
252
classRocket:
236
253
"""Rocket object to contain rocket data and run rocketry simulations.
237
-
238
254
Args:
239
255
mass_model (MassModel): MassModel object containing all the data on mass and moments of inertia.
240
256
motor (Motor): Motor object containing information on the rocket engine.
@@ -245,10 +261,9 @@ class Rocket:
245
261
rtol (float, optional): Relative error tolerance for integration. Defaults to 1e-7.
246
262
atol (float, optional): Absolute error tolerance for integration. Defaults to 1e-14.
alt_poll_interval (int, optional): ???. Defaults to 1.
264
+
alt_poll_interval (int, optional): How often to check for parachute opening. Defaults to 1.
249
265
thrust_vector (array, optional): Direction of thrust in body coordinates. Defaults to np.array([1,0,0]).
250
266
errors (dict, optional): Multiplication factors for the gravity, pressure, density and speed of sound. Used in the statistics model. Defaults to {"gravity":1.0,"pressure":1.0,"density":1.0,"speed_of_sound":1.0}.
251
-
252
267
Attributes:
253
268
mass_model (MassModel): MassModel object containing all the data on mass and moments of inertia.
254
269
motor (Motor): Motor object containing information on the rocket engine.
@@ -271,9 +286,9 @@ class Rocket:
271
286
alt (float): Rocket altitude (m).
272
287
on_rail (bool): True if the rocket is still on the rail, False if the rocket is off the rail.
273
288
burn_out (bool): False if engine is still firing, True if the engine has finished firing.
274
-
alt_record(???) : ???.
275
-
alt_poll_watch_interval (???) : ???
276
-
alt_poll_watch (???): ???
289
+
alt_record(float) : "Current" altitude of the rocket used to check for parahute opening.
290
+
alt_poll_watch_interval (float) : How often to check if the parachute needs to be openes (s).
291
+
alt_poll_watch (float): Last polled time.
277
292
"""
278
293
279
294
def__init__(
@@ -360,11 +375,9 @@ def __init__(
360
375
361
376
deffdot(self, time, fn):
362
377
"""Returns the rate of change of the rocket's state array, 'fn'.
"""Runs the rocket trajectory simulation. Uses the SciPy DOP853 O(h^8) integrator.
603
-
604
616
Args:
605
617
max_time (float, optional): Maximum time to run the simulation for (s). Defaults to 1000.
606
618
debug (bool, optional): If True, data will be printed to the console to aid with debugging. Defaults to False.
607
619
to_json (str, optional): Directory to export a .json file to, containing the results of the simulation. If False, no .json file will be produced. Defaults to False.
608
-
609
620
Returns:
610
621
pandas.DataFrame: pandas DataFrame containing the fundamental trajectory results. Most information can be derived from this in post processing.
611
622
"time" (array): List of times that all the data corresponds to (s).
"""Check what phase of flight the rocket is in, e.g. on the rail, off the rail, or with the parachute open.
739
-
740
750
Notes:
741
751
- Since this only checks after each time step, there may be a very short period where the rocket is orientated as if it is still on the rail, when it shouldn't be.
742
752
- For this reason, it may look like the rocket leaves the rail at an altitude greater than the rail length.
743
-
744
753
Args:
745
754
debug (bool, optional): If True, a message is printed when the rocket leaves the rail. Defaults to False.
746
-
747
755
Returns:
748
756
list: List of events that happened in this step, for the data log.
0 commit comments