def update(self, controls, system, environment): # If a control is not given, the previous value is assigned. for control_name, control_value in controls.items(): limits = self.control_limits[control_name] if limits[0] <= control_value <= limits[1]: self.controls[control_name] = control_value else: # TODO: maybe raise a warning and assign max deflection msg = "Control {} out of range ({} when max={} and min={" \ "}".format(control_name, limits[1], limits[0]) raise ValueError(msg) # Velocity relative to air: aerodynamic velocity. aero_vel = system.vel_body - environment.body_wind self.alpha, self.beta, self.TAS = calculate_alpha_beta_TAS( u=aero_vel[0], v=aero_vel[1], w=aero_vel[2]) self.p, self.q, self.r = system.vel_ang # Setting velocities & dynamic pressure self.CAS = tas2cas(self.TAS, environment.p, environment.rho) self.EAS = tas2eas(self.TAS, environment.rho) self.Mach = self.TAS / environment.a self.q_inf = 0.5 * environment.rho * self.TAS ** 2 # Gravity force self.gravity_force = environment.gravity_vector * self.mass
def update(self, controls, system, environment): # If a control is not given, the previous value is assigned. for control_name, control_value in controls.items(): limits = self.control_limits[control_name] if limits[0] <= control_value <= limits[1]: self.controls[control_name] = control_value else: # TODO: maybe raise a warning and assign max deflection msg = "Control {} out of range ({} when max={} and min={" \ "}".format(control_name, limits[1], limits[0]) raise ValueError(msg) # Velocity relative to air: aerodynamic velocity. aero_vel = system.vel_body - environment.body_wind self.alpha, self.beta, self.TAS = calculate_alpha_beta_TAS( u=aero_vel[0], v=aero_vel[1], w=aero_vel[2]) self.p, self.q, self.r = system.vel_ang # Setting velocities & dynamic pressure self.CAS = tas2cas(self.TAS, environment.p, environment.rho) self.EAS = tas2eas(self.TAS, environment.rho) self.Mach = self.TAS / environment.a self.q_inf = 0.5 * environment.rho * self.TAS**2 # Setting environment self.rho = environment.rho # Gravity force self.gravity_force = environment.gravity_vector * self.mass
def update(self, controls, system, environment): """Update the aircraft data using the values computed by the simulator Parameters ---------- controls : dictionary Dictionary with the control values. Outdated data, it is preserved just for backward compatibility. system : System Current simulator system environment : Enviroment Current Environment settings """ self.__environment = environment self.aero_vel = system.vel_body - environment.body_wind self.alpha, self.beta, self.TAS = calculate_alpha_beta_TAS( u=self.aero_vel[0], v=self.aero_vel[1], w=self.aero_vel[2]) self.p, self.q, self.r = system.vel_ang # Setting velocities & dynamic pressure self.CAS = tas2cas(self.TAS, environment.p, environment.rho) self.EAS = tas2eas(self.TAS, environment.rho) self.Mach = self.TAS / environment.a
def test_tas2cas(): # sea level tas = 275 cas_expected = 275 cas = tas2cas(tas, p_0, rho_0) assert_almost_equal(cas, cas_expected) # Test at 11000m _, p, rho, _ = atm(11000) tas = 275 cas_expected = 162.03569680495048 cas = tas2cas(tas, p, rho) assert_almost_equal(cas, cas_expected)
def _calculate_aerodynamics_2(self, TAS, alpha, beta, environment): self.alpha, self.beta, self.TAS = alpha, beta, TAS # Setting velocities & dynamic pressure self.CAS = tas2cas(self.TAS, environment.p, environment.rho) self.EAS = tas2eas(self.TAS, environment.rho) self.Mach = self.TAS / environment.a self.q_inf = 0.5 * environment.rho * self.TAS**2
def _calculate_aerodynamics_2(self, TAS, alpha, beta, environment): self.alpha, self.beta, self.TAS = alpha, beta, TAS # Setting velocities & dynamic pressure self.CAS = tas2cas(self.TAS, environment.p, environment.rho) self.EAS = tas2eas(self.TAS, environment.rho) self.Mach = self.TAS / environment.a self.q_inf = 0.5 * environment.rho * self.TAS ** 2
def _calculate_aerodynamics(self, state, environment): # Velocity relative to air: aerodynamic velocity. aero_vel = state.velocity.vel_body - environment.body_wind self.alpha, self.beta, self.TAS = calculate_alpha_beta_TAS( u=aero_vel[0], v=aero_vel[1], w=aero_vel[2]) # Setting velocities & dynamic pressure self.CAS = tas2cas(self.TAS, environment.p, environment.rho) self.EAS = tas2eas(self.TAS, environment.rho) self.Mach = self.TAS / environment.a self.q_inf = 0.5 * environment.rho * self.TAS**2
def _calculate_aerodynamics(self, state, environment): # Velocity relative to air: aerodynamic velocity. aero_vel = state.velocity.vel_body - environment.body_wind self.alpha, self.beta, self.TAS = calculate_alpha_beta_TAS( u=aero_vel[0], v=aero_vel[1], w=aero_vel[2] ) # Setting velocities & dynamic pressure self.CAS = tas2cas(self.TAS, environment.p, environment.rho) self.EAS = tas2eas(self.TAS, environment.rho) self.Mach = self.TAS / environment.a self.q_inf = 0.5 * environment.rho * self.TAS ** 2
def calculate_aero_conditions(self, state): # Getting conditions from environment body_wind = self.body_wind(state) T, P, rho, a = self.atmosphere.variables(state) # Velocity relative to air: aerodynamic velocity. aero_vel = (state.velocity - body_wind) alpha, beta, TAS = calculate_alpha_beta_TAS(aero_vel) # Setting velocities & dynamic pressure CAS = tas2cas(TAS, P, rho) EAS = tas2eas(TAS, rho) Mach = TAS / a q_inf = 0.5 * rho * np.square(TAS) # gravity vector gravity_vector = self.gravity_vector(state) return Conditions(TAS, CAS, Mach, q_inf, rho, T, P, a, alpha, beta, gravity_vector)