Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

project = "RocketPy"
copyright = "2020, Projeto Jupiter"

author = "Giovani Hidalgo Ceotto"

# The full version, including alpha/beta/rc tags
Expand Down
4,194 changes: 2,097 additions & 2,097 deletions docs/notebooks/getting_started.ipynb

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions rocketpy/Parachute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
__author__ = "Giovani Hidalgo Ceotto, Franz Masatoshi Yuri"
__copyright__ = "Copyright 20XX, Projeto Jupiter"
__license__ = "MIT"

import re
import math
import bisect
import warnings
import time
from datetime import datetime, timedelta
from inspect import signature, getsourcelines
from collections import namedtuple

import numpy as np
from scipy import integrate
from scipy import linalg
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from numpy import genfromtxt

from .Function import Function


class Parachute:
"""Keeps parachute information.

Attributes
----------
Parachute attributes:
name : string
Parachute name, such as drogue and main. Has no impact in
simulation, as it is only used to display data in a more
organized matter.
CdS : float
Drag coefficient times reference area for parachute. It is
used to compute the drag force exerted on the parachute by
the equation F = ((1/2)*rho*V^2)*CdS, that is, the drag
force is the dynamic pressure computed on the parachute
times its CdS coefficient. Has units of area and must be
given in squared meters.
trigger : function
Function which defines if the parachute ejection system is
to be triggered. It must take as input the freestream
pressure in pascal and the state vector of the simulation,
which is defined by [x, y, z, vx, vy, vz, e0, e1, e2, e3, wx, wy, wz].
It will be called according to the sampling rate given next.
It should return True if the parachute ejection system is
to be triggered and False otherwise.
samplingRate : float
Sampling rate in which the trigger function works. It is used to
simulate the refresh rate of onboard sensors such as barometers.
Default value is 100. Value must be given in hertz.
lag : float
Time between the parachute ejection system is triggered and the
parachute is fully opened. During this time, the simulation will
consider the rocket as flying without a parachute. Default value
is 0. Must be given in seconds.
noiseBias : float
Mean value of the noise added to the pressure signal, which is
passed to the trigger function. Unit is in pascal.
noiseDeviation : float
Standard deviation of the noise added to the pressure signal,
which is passed to the trigger function. Unit is in pascal.
noiseCorr : tuple, list
Tupple with the correlation between noise and time.
noiseSignal : list
List of (t, noise signal) corresponding to signal passed to
trigger function. Completed after running a simulation.
noisyPressureSignal : list
List of (t, noisy pressure signal) that is passed to the
trigger function. Completed after running a simulation.
cleanPressureSignal : list
List of (t, clean pressure signal) corresponding to signal passed to
trigger function. Completed after running a simulation.
noiseSignalFunction : Function
Function of noiseSignal.
noisyPressureSignalFunction : Function
Function of noisyPressureSignal.
cleanPressureSignalFunction : Function
Function of cleanPressureSignal.
"""

def __init__(
self,
name,
CdS,
Trigger,
samplingRate,
lag,
noise=(0, 0, 0),
):
"""Initializes Parachute class.
Parameters
----------
name : string
Name of the parachute.
CdS : float
CdS of the parachute.
Trigger : function
Trigger function.
samplngRate : float
Sampling rate, in hertz, for the Trigger function.
lag : float
Time, in seconds, between the parachute ejection system is triggered and the
parachute is fully opened.
noise : tuple, list, optional
Comment thread
FranzYuri marked this conversation as resolved.
List in the format (mean, standard deviation, time-correlation).
The values are used to add noise to the pressure signal which is
passed to the trigger function. Default value is (0, 0, 0). Units
are in pascal.
Returns
-------
None
"""
self.name = name
self.CdS = CdS
self.trigger = Trigger
self.samplingRate = samplingRate
self.lag = lag
self.noiseSignal = [[-1e-6, np.random.normal(noise[0], noise[1])]]
self.noisyPressureSignal = []
self.cleanPressureSignal = []
self.noiseBias = noise[0]
self.noiseDeviation = noise[1]
self.noiseCorr = (noise[2], (1 - noise[2] ** 2) ** 0.5)
alpha, beta = self.noiseCorr
self.noiseFunction = lambda: alpha * self.noiseSignal[-1][
1
] + beta * np.random.normal(noise[0], noise[1])
return None
81 changes: 6 additions & 75 deletions rocketpy/Rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from numpy import genfromtxt

from .Function import Function
from .Parachute import Parachute


class Rocket:
Expand Down Expand Up @@ -84,59 +85,6 @@ class Rocket:
Thrust vector position relative to center of mass in the x
axis, perpendicular to axis of cylindrical symmetry, in meters.

Parachute attributes:
Rocket.parachutes : list
List of parachutes of the rocket.
Each parachute has the following attributes:
name : string
Parachute name, such as drogue and main. Has no impact in
simulation, as it is only used to display data in a more
organized matter.
CdS : float
Drag coefficient times reference area for parachute. It is
used to compute the drag force exerted on the parachute by
the equation F = ((1/2)*rho*V^2)*CdS, that is, the drag
force is the dynamic pressure computed on the parachute
times its CdS coefficient. Has units of area and must be
given in squared meters.
trigger : function
Function which defines if the parachute ejection system is
to be triggered. It must take as input the freestream
pressure in pascal and the state vector of the simulation,
which is defined by [x, y, z, vx, vy, vz, e0, e1, e2, e3, wx, wy, wz].
It will be called according to the sampling rate given next.
It should return True if the parachute ejection system is
to be triggered and False otherwise.
samplingRate : float, optional
Sampling rate in which the trigger function works. It is used to
simulate the refresh rate of onboard sensors such as barometers.
Default value is 100. Value must be given in hertz.
lag : float, optional
Time between the parachute ejection system is triggered and the
parachute is fully opened. During this time, the simulation will
consider the rocket as flying without a parachute. Default value
is 0. Must be given in seconds.
noise : tuple, list, optional
List in the format (mean, standard deviation, time-correlation).
The values are used to add noise to the pressure signal which is
passed to the trigger function. Default value is (0, 0, 0). Units
are in pascal.
noiseSignal : list
List of (t, noise signal) corresponding to signal passed to
trigger function. Completed after running a simulation.
noisyPressureSignal : list
List of (t, noisy pressure signal) that is passed to the
trigger function. Completed after running a simulation.
cleanPressureSignal : list
List of (t, clean pressure signal) corresponding to signal passed to
trigger function. Completed after running a simulation.
noiseSignalFunction : Function
Function of noiseSignal.
noisyPressureSignalFunction : Function
Function of noisyPressureSignal.
cleanPressureSignalFunction : Function
Function of cleanPressureSignal.

Aerodynamic attributes
Rocket.aerodynamicSurfaces : list
List of aerodynamic surfaces of the rocket.
Expand Down Expand Up @@ -834,31 +782,14 @@ def addParachute(

Returns
-------
parachute : Parachute Object
Parachute object containing trigger, samplingRate, lag, CdS, noise
and name as attributes. Furthermore, it stores cleanPressureSignal,
parachute : Parachute
Parachute containing trigger, samplingRate, lag, CdS, noise
and name. Furthermore, it stores cleanPressureSignal,
noiseSignal and noisyPressureSignal which are filled in during
Flight simulation.
"""
# Create an object to serve as the parachute
parachute = type("", (), {})()

# Store Cds coefficient, lag, name and trigger function
parachute.trigger = trigger
parachute.samplingRate = samplingRate
parachute.lag = lag
parachute.CdS = CdS
parachute.name = name
parachute.noiseBias = noise[0]
parachute.noiseDeviation = noise[1]
parachute.noiseCorr = (noise[2], (1 - noise[2] ** 2) ** 0.5)
alpha, beta = parachute.noiseCorr
parachute.noiseSignal = [[-1e-6, np.random.normal(noise[0], noise[1])]]
parachute.noiseFunction = lambda: alpha * parachute.noiseSignal[-1][
1
] + beta * np.random.normal(noise[0], noise[1])
parachute.cleanPressureSignal = []
parachute.noisyPressureSignal = []
# Create a parachute
parachute = Parachute(name, CdS, trigger, samplingRate, lag, noise)

# Add parachute to list of parachutes
self.parachutes.append(parachute)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from rocketpy import Environment, SolidMotor, Rocket, Flight
from rocketpy import Environment, SolidMotor, Rocket, Flight, Parachute


@patch("matplotlib.pyplot.show")
Expand Down