def __init__( self, atmosphere: Atmosphere = Atmosphere(altitude=0), velocity: float = 1., alpha: float = 0., beta: float = 0., p: float = 0., q: float = 0., r: float = 0., ): """ An object that represents the instantaneous flight conditions of an aircraft. Args: atmosphere: velocity: The flight velocity, expressed in true airspeed. [m/s] alpha: The angle of attack. [degrees] beta: The sideslip angle. (Reminder: convention that a positive beta implies that the oncoming air comes from the pilot's right-hand side.) [degrees] p: The roll rate about the x_b axis. [rad/sec] q: The pitch rate about the y_b axis. [rad/sec] r: The yaw rate about the z_b axis. [rad/sec] """ self.atmosphere = atmosphere self.velocity = velocity # TODO rename "airspeed"? self.alpha = alpha self.beta = beta self.p = p self.q = q self.r = r
def op_point(self): return OperatingPoint( atmosphere=Atmosphere(altitude=self.altitude), velocity=self.speed, alpha=self.alpha, beta=self.beta, p=0, q=0, r=0, )
def test_diff_atmosphere(): altitudes = np.linspace(-50e2, 150e3, 1000) atmo_isa = Atmosphere(altitude=altitudes, method='isa') atmo_diff = Atmosphere(altitude=altitudes) temp_isa = atmo_isa.temperature() pressure_isa = atmo_isa.pressure() temp_diff = atmo_diff.temperature() pressure_diff = atmo_diff.pressure() assert max(abs( (temp_isa - temp_diff) / temp_isa)) < 0.025, "temperature failed for differentiable model" assert max(abs( (pressure_isa - pressure_diff) / pressure_isa)) < 0.01, "pressure failed for differentiable model"
def plot_isa_residuals(): atmo = Atmosphere(altitude=altitudes, method='isa') import matplotlib.pyplot as plt import seaborn as sns sns.set(palette=sns.color_palette("husl")) fig, ax = plt.subplots(1, 1, figsize=(6.4, 4.8), dpi=200) plt.plot(altitudes, atmo.pressure() - pressures) plt.xlabel(r"Altitude [m]") plt.ylabel(r"Pressure Difference [Pa]") plt.title(r"Pressure Difference between ASB ISA Model and ISA Table") plt.tight_layout() plt.legend() plt.show() fig, ax = plt.subplots(1, 1, figsize=(6.4, 4.8), dpi=200) plt.plot(altitudes, atmo.temperature() - temperatures) plt.xlabel(r"Altitude [m]") plt.ylabel(r"Temperature Difference [K]") plt.title(r"Temperature Difference between ASB ISA Model and ISA Table") plt.tight_layout() plt.legend() plt.show()
def __init__(self, atmosphere: Atmosphere = Atmosphere(altitude=0), velocity: float = 10., # m/s alpha: float = 5., # In degrees beta: float = 0., # In degrees p: float = 0., # About the body x-axis, in rad/sec q: float = 0., # About the body y-axis, in rad/sec r: float = 0., # About the body z-axis, in rad/sec ): self.atmosphere = atmosphere self.altitude = altitude self.velocity = velocity self.alpha = alpha self.beta = beta self.p = p self.q = q self.r = r
def test_isa_atmosphere(): for altitude, pressure, temperature, density, speed_of_sound in zip( altitudes, pressures, temperatures, densities, speeds_of_sound): atmo = Atmosphere(altitude=altitude, method='isa') if altitude >= atmo._valid_altitude_range[ 0] and altitude <= atmo._valid_altitude_range[1]: fail_message = f"FAILED @ {altitude} m" assert atmo.pressure() == pytest.approx(pressure, abs=100), fail_message assert atmo.temperature() == pytest.approx(temperature, abs=1), fail_message assert atmo.density() == pytest.approx(density, abs=0.01), fail_message assert atmo.speed_of_sound() == pytest.approx(speed_of_sound, abs=1), fail_message
def equivalent_airspeed(self): """ Returns the equivalent airspeed associated with the current flight condition, in meters per second. """ return self.velocity * np.sqrt(self.atmosphere.density() / Atmosphere( altitude=0, method="isa").density())