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: rocketflightsim/rocket_classes.py
+55-51Lines changed: 55 additions & 51 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Define Motor, Rocket, LaunchConditions, and Airbrakes classes
1
+
# Define classes used by the package
2
2
3
3
importnumpyasnp
4
4
@@ -10,13 +10,13 @@ class Motor:
10
10
The Motor class is used to store the properties of a rocket motor. The properties are:
11
11
12
12
- dry_mass: mass of the motor without fuel (kg)
13
-
- thrust_curve: dictionary of thrust (N) at time (s after ignition)
13
+
- thrust_curve: dictionary of thrust (N) produced by the motor at time after ignition (s)
14
14
- total_impulse: total impulse of the motor (Ns)
15
15
- burn_time: time it takes for the motor to burn all of its fuel (s)
16
-
- fuel_mass_curve: dictionary of mass (kg) at time (s after ignition)
16
+
- fuel_mass_curve: dictionary of mass (kg) at time after ignition (s)
17
17
- fuel_mass: total mass of fuel in the motor before ignition (kg)
18
18
19
-
If fuel_mass_curve is not provided but feul_mass is, fuel_mass_curve is calculated from the thrust_curve and fuel_mass (assuming fuel burn is proportional to thrust). If fuel_mass_curve is provided, fuel_mass is set to the initial mass in fuel_mass_curve. If neither are provided, fuel_mass and fuel_mass_curve are set to 0.
19
+
If fuel_mass_curve is not provided but fuel_mass is, fuel_mass_curve is calculated from the thrust_curve and fuel_mass (assuming fuel burn is proportional to thrust). If fuel_mass_curve is provided, fuel_mass is set to the initial mass in fuel_mass_curve. If neither are provided, fuel_mass and fuel_mass_curve are set to 0.
# TODO: make it actually operate as a constant if it's not a function
112
112
self.Cd_A_rocket=Cd_A_rocket_fn
113
113
114
-
""" TODO Adding wind to the simulation
114
+
""" TODO Improve wind in the simulation
115
115
116
-
For first implementation:
117
-
- wind will only act in directions parallel to the ground
118
-
- wind will have a constant speed and direction for the entire flight
119
-
- wind will only affect the rocket's relative airspeed
120
-
- lateral forces will not be considered
121
-
- wind will not affect flight from ignition to launch rail clearance
122
-
- at launch rail clearance, the rocket will instantly have the wind's velocity added to its velocity vector (instantly weathercock the rocket, keeping the 0 angle of attack assumption used in the simulator)
116
+
First (current) implementation:
117
+
- wind only acts in directions parallel to the ground
118
+
- wind has constant speed and direction for the entire flight
119
+
- wind only affects a rocket's airspeed, affecting drag and angle of attack
120
+
- lateral forces not considered
121
+
- wind has no effect on flight from ignition to launch rail clearance
122
+
- at rail clearance, a rocket instantly has 20% of the wind's velocity added to its velocity vector to get the new airspeed, then the full vector added at burnout. Placeholder for a better mode of transition from the angle of attack leaving the launch rail to a 0 deg AoA
123
123
124
+
Next up:
125
+
- Use this to get data for Spaceport America for the example configuration: https://www.dropbox.com/sh/swi7jrl14evqmap/AADW6GMVIv87KkOBY1-flsoIa?e=1
126
+
- Note that time is in UTC
127
+
- Also use it to add to the Prometheus launch conditions in the airbrakes repo
128
+
- Remember that launches can't happen if wind > 20mph, so don't consider data with wind speeds above that when trying to find an average
129
+
- after comp, incorporate looking at/recording/visualizing flightpath moving in 3D/relative to the launchpad
124
130
125
-
In the simulation, need to add the wind speed to the rocket's velocity vector and have that relative airspeed vector used to determine the drag force and the rocket's angle of attack (but not the rocket's displacement, which should still be calculated using the rocket's velocity vector).
126
-
127
-
Use this to get data for Spaceport America for the example configuration: https://www.dropbox.com/sh/swi7jrl14evqmap/AADW6GMVIv87KkOBY1-flsoIa?e=1
128
-
Note that time is in UTC
129
-
Also use it to add to the Prometheus launch conditions in the airbrakes repo
130
-
Remember that launches can't happen if wind > 20mph, so don't consider data with wind speeds above that when trying to find an average
131
-
132
-
Is it worth describing the wind as None when not specified and having the simulator run faster by not having to add the wind speed to the velocity vector if it's None?
133
-
134
-
Could be added later:
135
-
Varying wind speed and direction with altitude or time, gusts, etc
136
-
- varying_wind_speed: list of tuples
137
-
- Each tuple contains the time (s after ignition) and the wind speed (m/s) at that time. Wind speed is relative to the ground.
138
-
- varying_wind_direction: list of tuples
139
-
- Each tuple contains the time (s after ignition) and the direction of the wind (deg). 0 is a headwind, 90 is a crosswind from the right, 180 is a tailwind, 270 is a crosswind from the left.
140
-
- wind_gusts: list of tuples
141
-
- Each tuple contains the time (s after ignition) and the wind speed (m/s) at that time. Wind speed is relative to the ground.
131
+
Could be added later:
132
+
- possibly set windspeed as None when not specified and have the simulator run faster by not having to deal with wind. Likely after the break up of the simulation function into different functions for different phases of flight. Maybe a series of sim functions will be chosen from?
133
+
- Varying wind speed and direction with altitude or time, gusts, etc
134
+
- varying_wind_speed: list of tuples
135
+
- Each tuple contains the time (s after ignition) and the wind speed (m/s) at that time. Wind speed is relative to the ground.
136
+
- varying_wind_heading: list of tuples
137
+
- Each tuple contains the time (s after ignition) and the direction of the wind (deg). 0 is a headwind, 90 is a crosswind from the right, 180 is a tailwind, 270 is a crosswind from the left.
138
+
- wind_gusts: list of tuples
139
+
- Each tuple contains the time (s after ignition) and the wind speed (m/s) at that time. Wind speed is relative to the ground.
140
+
- vertical wind/updrafts/downdrafts
142
141
"""
143
142
144
143
classLaunchConditions:
@@ -152,31 +151,33 @@ class LaunchConditions:
152
151
Temperature at the launchpad (°C).
153
152
L_launch_rail : float
154
153
Length of the launch rail (m).
155
-
launch_angle : float
156
-
Launch angle from horizontal (deg).
154
+
launch_rail_elevation : float
155
+
Angle of the launch rail from horizontal (deg).
156
+
launch_driection : float
157
+
Direction of the launch rail (deg). 0 is north, 90 is east, 180 is south, 270 is west.
157
158
local_gravity : float
158
159
Acceleration due to gravity at the launch site (m/s^2).
159
160
local_T_lapse_rate : float
160
161
Temperature lapse rate at the launch site (°C/m, K/m).
161
162
mean_wind_speed : float
162
163
Mean wind speed relative to the ground (m/s).
163
-
wind_direction : float
164
-
Direction of the (mean) wind relative to the launch direction (deg). 0 is a headwind, 90 is a crosswind from the right, 180 is a tailwind, 270 is a crosswind from the left.
164
+
wind_heading : float
165
+
Direction the (mean) wind is headed towards (deg). 0 is north, 90 is east, 180 is south, 270 is west.
165
166
"""
166
-
167
+
# TODO: maybe have it calculate the atmospheric conditions on the ground in init?
167
168
def__init__(
168
169
self,
169
170
launchpad_pressure: float,
170
171
launchpad_temp: float,
171
172
L_launch_rail: float,
172
-
launch_angle: float=90,
173
+
launch_rail_elevation: float=90,
174
+
launch_rail_direction: float=0,
173
175
local_gravity: float=None,
174
176
local_T_lapse_rate: float=con.T_lapse_rate,
175
177
latitude: float=None,
176
178
altitude: float=0,
177
-
# better way to do wind, take a launch direction and a wind direction and calculate the angle between them, then could use the sim for looking at flightpath moving in 3D/relative to the launchpad, but still use the same computational power as just a relative wind direction
178
-
mean_wind_speed=None,
179
-
wind_direction=0,
179
+
mean_wind_speed=0,
180
+
wind_heading=0,
180
181
):
181
182
"""Initializes the LaunchConditions object.
182
183
@@ -188,8 +189,10 @@ def __init__(
188
189
Temperature at the launchpad (°C).
189
190
L_launch_rail : float
190
191
Length of the launch rail (m).
191
-
launch_angle : float, optional
192
-
Launch angle from horizontal (deg). Defaults to 90 (vertical launch).
192
+
launch_rail_elevation : float
193
+
Angle of the launch rail from horizontal (deg). Defaults to 90 (vertical launch rail).
194
+
launch_driection : float
195
+
Direction of the launch rail (deg). 0 is north, 90 is east, 180 is south, 270 is west. Defaults to 0 (north).
193
196
local_gravity : float, optional
194
197
Acceleration due to gravity at the launch site (m/s^2). Defaults to 9.80665.
195
198
local_T_lapse_rate : float, optional
@@ -199,14 +202,15 @@ def __init__(
199
202
altitude : float, optional
200
203
Altitude of the launch site (m ASL). Used along with latitude to calculate local gravity if local_gravity is not provided. Defaults to 0.
201
204
mean_wind_speed : float, optional
202
-
Mean wind speed relative to the ground (m/s). Defaults to None.
203
-
wind_direction : float, optional
204
-
Direction of the (mean) wind relative to the launch direction (deg). 0 is a headwind, 90 is a crosswind from the right, 180 is a tailwind, 270 is a crosswind from the left. Defaults to 0 (headwind).
205
+
Mean wind speed relative to the ground (m/s). Defaults to 0.
206
+
wind_heading : float, optional
207
+
Direction the (mean) wind is headed towards (deg). 0 is north, 90 is east, 180 is south, 270 is west. Defaults to 0.
205
208
"""
206
209
self.launchpad_pressure=launchpad_pressure
207
210
self.launchpad_temp=launchpad_temp+273.15
208
211
self.L_launch_rail=L_launch_rail
209
-
self.launch_angle=launch_angle
212
+
self.launch_rail_elevation=launch_rail_elevation
213
+
self.launch_rail_direction=launch_rail_direction
210
214
211
215
self.local_T_lapse_rate=local_T_lapse_rate
212
216
@@ -218,7 +222,7 @@ def __init__(
218
222
self.local_gravity=con.F_gravity
219
223
220
224
self.mean_wind_speed=mean_wind_speed
221
-
self.wind_direction=wind_direction
225
+
self.wind_heading=wind_heading
222
226
223
227
classAirbrakes:
224
228
"""
@@ -233,7 +237,7 @@ class Airbrakes:
233
237
Cd_brakes : float
234
238
Coefficient of drag of the airbrakes.
235
239
max_deployment_angle : float
236
-
Maximum angle that the flaps can deploy to (deg).
240
+
Maximum angle that the flaps can deploy to (deg).
237
241
max_deployment_rate : float
238
242
Maximum rate at which the airbrakes can be deployed (deg/s).
239
243
max_retraction_rate : float
@@ -280,19 +284,19 @@ class StateVector:
280
284
"""
281
285
The StateVector class is used to store the state of the rocket at a given time. The state is stored as a dictionary with the following keys:
282
286
287
+
- launch_conditions: The LaunchConditions object associated with the flight.
283
288
- t: time (s)
284
-
# do this after adding wind, before breaking stages of flight simulator into separate functions
289
+
# do this for breaking stages of flight simulator into separate functions
285
290
"""
286
-
287
-
291
+
288
292
289
293
classPastFlight ():
290
294
"""
291
295
Stores the rocket, launch conditions, and apogee of a past flight
292
-
likely add more things like max speed, max acceleration later
296
+
likely add more things like max speed, max acceleration later. Also the option to feed a full flightpath, good for comparisons of sim projection to actual flightpaths
0 commit comments