Compare Flights#

This example demonstrates how to use the rocketpy CompareFlights class. This class has many applications, including the comparison of different flight setups for a single rocket, the simulation of deployable systems, and the multi-stage rocket analysis.

Importing classes#

We will start by importing the necessary classes and modules:

from rocketpy.plots.compare import CompareFlights
from rocketpy import Environment, Flight, Rocket, SolidMotor
from datetime import datetime, timedelta

Create Environment, Motor and Rocket#

First, let’s create the environment, motor and rocket objects. This is done following the same steps as in the First Simulation with RocketPy example.

after_tomorrow = datetime.now() + timedelta(days=2)
env = Environment(latitude=-23, longitude=-49, date=after_tomorrow)
env.set_atmospheric_model(type="Forecast", file="GFS")

cesaroni_motor = SolidMotor(
    thrust_source="../data/motors/Cesaroni_M1670.eng",
    dry_mass=1.815,
    dry_inertia=(0.125, 0.125, 0.002),
    nozzle_radius=33 / 1000,
    grain_number=5,
    grain_density=1815,
    grain_outer_radius=33 / 1000,
    grain_initial_inner_radius=15 / 1000,
    grain_initial_height=120 / 1000,
    grain_separation=5 / 1000,
    grains_center_of_mass_position=0.397,
    center_of_dry_mass_position=0.317,
    nozzle_position=0,
    burn_time=3.9,
    throat_radius=11 / 1000,
    coordinate_system_orientation="nozzle_to_combustion_chamber",
)

calisto = Rocket(
    radius=127 / 2000,
    mass=14.426,
    inertia=(6.321, 6.321, 0.034),
    power_off_drag="../data/calisto/powerOffDragCurve.csv",
    power_on_drag="../data/calisto/powerOnDragCurve.csv",
    center_of_mass_without_motor=0,
    coordinate_system_orientation="tail_to_nose",
)

calisto.set_rail_buttons(
    upper_button_position=0.0818,
    lower_button_position=-0.618,
    angular_position=45,
)

calisto.add_motor(cesaroni_motor, position=-1.255)

nosecone = calisto.add_nose(length=0.55829, kind="vonKarman", position=1.278)

fin_set = calisto.add_trapezoidal_fins(
    n=4,
    root_chord=0.120,
    tip_chord=0.060,
    span=0.110,
    position=-1.04956,
    cant_angle=0.5,
    airfoil=("../data/calisto/NACA0012-radians.csv", "radians"),
)

tail = calisto.add_tail(
    top_radius=0.0635, bottom_radius=0.0435, length=0.060, position=-1.194656
)

main_chute = calisto.add_parachute(
    "Main",
    cd_s=10.0,
    trigger=800,
    sampling_rate=105,
    lag=1.5,
    noise=(0, 8.3, 0.5),
)

drogue_chute = calisto.add_parachute(
    "Drogue",
    cd_s=1.0,
    trigger="apogee",
    sampling_rate=105,
    lag=1.5,
    noise=(0, 8.3, 0.5),
)

Creating the Flight objects#

Now we can create different flights varying the launch angle and the rail inclination:

inclinations = [85, 75]
headings = [90, 135]
flights = []

for heading in headings:
    for inclination in inclinations:
        flight = Flight(
            environment=env,
            rocket=calisto,
            rail_length=5.2,
            inclination=inclination,
            heading=heading,
            name=f"Incl {inclination} Head {heading}",
        )
        flights.append(flight)

We can easily visualize the number of flights created:

print("Number of flights: ", len(flights))
Number of flights:  4

Start the comparison#

It is easy to initialize the CompareFlights object:

comparison = CompareFlights(flights)

After the initialization, we can use different methods to plot the results in a comparative way. To see a full description of the available methods, you can check the CompareFlights documentation.

Plotting results one by one#

The flights results are divided into different methods, so we can plot them one by one. This is practical when we want to focus on a specific aspect of the flights.

comparison.trajectories_3d(legend=True)
../_images/compare_flights_5_0.png
comparison.positions()
../_images/compare_flights_6_0.png
comparison.trajectories_2d(plane="xy", legend=True)
../_images/compare_flights_7_0.png
comparison.velocities()
../_images/compare_flights_8_0.png
comparison.stream_velocities()
../_images/compare_flights_9_0.png
comparison.accelerations()
../_images/compare_flights_10_0.png
comparison.angular_velocities()
../_images/compare_flights_11_0.png
comparison.angular_accelerations()
../_images/compare_flights_12_0.png
comparison.attitude_angles()
../_images/compare_flights_13_0.png
comparison.euler_angles()
../_images/compare_flights_14_0.png
comparison.quaternions()
../_images/compare_flights_15_0.png
comparison.angles_of_attack()
../_images/compare_flights_16_0.png
comparison.aerodynamic_forces()
../_images/compare_flights_17_0.png
comparison.aerodynamic_moments()
../_images/compare_flights_18_0.png
comparison.fluid_mechanics()
../_images/compare_flights_19_0.png
comparison.energies()
../_images/compare_flights_20_0.png
comparison.powers()
../_images/compare_flights_21_0.png

Plotting using the all method#

Alternatively, we can plot the results altogether by calling one simple method:

comparison.all()
../_images/compare_flights_22_0.png ../_images/compare_flights_22_1.png ../_images/compare_flights_22_2.png ../_images/compare_flights_22_3.png ../_images/compare_flights_22_4.png ../_images/compare_flights_22_5.png ../_images/compare_flights_22_6.png ../_images/compare_flights_22_7.png ../_images/compare_flights_22_8.png ../_images/compare_flights_22_9.png ../_images/compare_flights_22_10.png ../_images/compare_flights_22_11.png
This method is not implemented yet
../_images/compare_flights_22_13.png ../_images/compare_flights_22_14.png ../_images/compare_flights_22_15.png ../_images/compare_flights_22_16.png ../_images/compare_flights_22_17.png ../_images/compare_flights_22_18.png
This method is not implemented yet