I am trying to model the trajectory of a rocket in RocketPy. I have successfully completed this, and now I am trying to look at the Monte Carlo simulations.
However, I am encountering an error:
AttributeError: 'Flight' object has no attribute 'apogee'
I have tried to make the code as simple as I can. I have the Rocket Part:
# Imports
from rocketpy import Environment, SolidMotor, Rocket, Flight, MonteCarlo
from rocketpy.stochastic import (
StochasticEnvironment,
StochasticSolidMotor,
StochasticRocket,
StochasticFlight,
)
import numpy as np
# Date:
import datetime
%matplotlib widget
# Environment
env = Environment(latitude=67.89325597913002,longitude=21.065756056273834, elevation=300)
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
env.set_date((tomorrow.year, tomorrow.month, tomorrow.day, 12))
env.set_atmospheric_model(type="Ensemble", file="GEFS")
# Motor
RedMotor = SolidMotor(
thrust_source=r"...\Python Modelling\Thrust curves\RedMotor.eng",
burn_time=13.1, # s
dry_mass=1.815, # kg
dry_inertia=(1.86, 1.86, 0.13),
center_of_dry_mass_position=0,
grains_center_of_mass_position=0,
grain_number=1,
grain_separation=0,
grain_density=1750, # kg/m^3
grain_outer_radius=0.2612, # m
grain_initial_inner_radius=0.0726, # m
grain_initial_height=2.6072, # m
nozzle_radius=0.235, # m
throat_radius=0.0726, # m
interpolation_method="linear",
nozzle_position=2.1, # from CG of motor
coordinate_system_orientation="combustion_chamber_to_nozzle", # combustion_chamber_to_nozzle"
)
# Rocket
RedRocket = Rocket(
radius=0.23,
mass=184.77,
inertia=(1315, 1315, 14.1155),
power_off_drag=r"...\\Python Modelling\\Drag curves\\Cesaroni_6026M1670_PpowerOffDragCurve.eng",
power_on_drag=r"...\\Python Modelling\\Drag curves\\Cesaroni_6026M1670_PpowerOnDragCurve.eng",
center_of_mass_without_motor=4.45,
coordinate_system_orientation="nose_to_tail",
)
rail_buttons = RedRocket.set_rail_buttons(
upper_button_position=3.8,
lower_button_position=1.5,
)
RedRocket.add_motor(RedMotor, position=6.6428125)
nose_cone = RedRocket.add_nose(length=0.9375, kind="ogive", position=0)
fin_set = RedRocket.add_trapezoidal_fins(
n=4,
root_chord=0.703125,
tip_chord=0.703125,
span=0.546875,
position=8.01,
)
transition = RedRocket.add_tail(
top_radius=0.23, bottom_radius=0.2795, length=0.705625, position=4.57,
)
Main = RedRocket.add_parachute(
"Main",
cd_s=2.2 * np.pi * (120 * 25.4 / 1000) * (120 * 25.4 / 1000) / 4,
trigger=167.64,
sampling_rate=105,
lag=1,
noise=(0, 8.3, 0.5),
)
Drogue = RedRocket.add_parachute(
"Drogue",
cd_s=1.5 * np.pi * (24 * 25.4 / 1000) * (24 * 25.4 / 1000) / 4,
trigger="apogee",
sampling_rate=105,
lag=1,
noise=(0, 8.3, 0.5),
)
# Flight
test_flight = Flight(
rocket=RedRocket,
environment=env,
rail_length=5.2,
inclination=60,
heading=0,
)
test_flight.all_info()
and the Stochastic section:
# Stochastic Environment
stochastic_env = StochasticEnvironment(
environment=env,
ensemble_member=list(range(env.num_ensemble_members)),
)
stochastic_env.visualize_attributes()
# Stochastic Motor
stochastic_motor = StochasticSolidMotor(
solid_motor=RedMotor,
burn_start_time=(0, 0.1, "binomial"),
grains_center_of_mass_position=0.001,
grain_density=50,
grain_separation=0.001,
grain_initial_height=0.001,
grain_initial_inner_radius= 0.00038,
grain_outer_radius= 0.00038,
total_impulse=(1.07*(RedMotor.total_impulse), (RedMotor.total_impulse/10)),
throat_radius= 0.0005,
nozzle_radius= 0.0005,
nozzle_position=0.001,
)
stochastic_motor.visualize_attributes()
# Stochastic Rocket
stochastic_rocket = StochasticRocket(
rocket=RedRocket,
radius=0.23,
mass= 184.77,
inertia_11= (1325.502, 0),
inertia_22= (1325.502,0.01000),
inertia_33= 0.01,
center_of_mass_without_motor=4.45,
)
stochastic_rocket.visualize_attributes()
# Stochastic flight
stochastic_flight = StochasticFlight(
flight=test_flight,
inclination=(60, 1),
heading=(0, 2),
)
stochastic_flight.visualize_attributes()
Which all works, but I can't make the Monte Carlo simulations work:
# Monte Carlo Simulations
test_dispersion = MonteCarlo(
filename="monte_carlo_analysis_outputs/monte_carlo_class_example",
environment=stochastic_env,
rocket=stochastic_rocket,
flight=stochastic_flight,
)
test_dispersion.simulate(
number_of_simulations=1000, append=False)
This is when I get the 'Flight' object has no attribute 'apogee' error. What am I doing wrong?
Below is the thrust curve:
; Red Rocket Motor Thrust Curve
RedRocket 559 3440 0 914 1176
0.05 180952.4
0.2381 180952.4
1.8929 202975.0
1.9524 202975.0
3 204762.5
3.5 205952.4
4.4762 207440.0
4.5357 208927.5
4.5952 207440.0
4.71 205952.4
4.7143 200000
4.8929 186905.0
5 180952.4
5.298 175000
7.0595 138392.5
7.2381 137202.5
10.5 130952.4
12.0476 125000
12.3571 126487.5
12.5357 114880
12.7143 92857.5
13 25000
13.1190 5952.4
;
When I call test_dispersion.prints.all()
right before test_dispersion.simulate
, this is the result:
Monte Carlo Simulation by RocketPy
Data Source: monte_carlo_analysis_outputs/monte_carlo_class_example
Number of simulations: 0
Results:
Parameter Mean Std. Dev.
------------------------------------------------------------
Thanks for that Onuralp. That's a good insight. I did get some good results for all the following:
stochastic_motor.visualize_attributes()
print(stochastic_motor.total_impulse)
stochastic_rocket.visualize_attributes()
stochastic_flight.visualize_attributes()
but something that stuck out to me as a potential problem was that when I tried print(stochastic_motor.total_impulse), I got back the following:
(np.float64(2221943.0652824277), np.float64(207658.2304002269), <bound method RandomState.normal of RandomState(MT19937) at 0x1D833D56840>)
Do you think this may have been the cause of the problem since it's not a single float? I had set it up like so in the script:
total_impulse=(1.07*(RedMotor.total_impulse), (RedMotor.total_impulse/10)),
type(stochastic_motor.total_impulse)
returns that it is a tuple. Could this be the cause of the problem?