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): # 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): """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 _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 test_calculate_alpha_beta_TAS(): u, v, w = 10, 0, 10 expected_TAS = sqrt(200) expected_alfa = atan(1) expected_beta = 0 alfa, beta, TAS = calculate_alpha_beta_TAS(u, v, w) assert_almost_equal((expected_alfa, expected_beta, expected_TAS), (alfa, beta, TAS)) u, v, w = 10, 10, 0 expected_alfa = 0 expected_beta = asin(10 / sqrt(200)) alfa, beta, TAS = calculate_alpha_beta_TAS(u, v, w) assert_almost_equal((expected_alfa, expected_beta, expected_TAS), (alfa, beta, TAS))
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)
forces_and_moments = cessna_310.get_forces_and_moments for ii, t in enumerate(time[1:]): forces, moments = forces_and_moments( TAS[ii], rho, alpha[ii], beta[ii], d_e[ii], 0, d_a[ii], d_r[ii], d_t[ii], attitude) results[ii+1, :] = equations.propagate(mass, inertia, forces, moments, dt) lin_vel = results[ii+1, 0:3] ang_vel = results[ii+1, 3:6] attitude = results[ii+1, 6:9] position = results[ii+1, 9:12] alpha[ii+1], beta[ii+1], TAS[ii+1] = calculate_alpha_beta_TAS(*lin_vel) _, _, rho, _ = atm(position[2]) velocities = results[:, 0:6] attitude_angles = results[:, 6:9] position = results[:, 9:12] # PLOTS plt.close('all') plt.style.use('ggplot') plt.figure('pos') plt.plot(time, position[:, 0], label='x') plt.plot(time, position[:, 1], label='y') plt.plot(time, position[:, 2], label='z')
def to_wind_frame(data): alpha, beta, TAS = calculate_alpha_beta_TAS(data[vel].values) for i, ind in enumerate(data.index): data.loc[ind, aerof] = body2wind(data.loc[ind, frc], alpha[i], beta[i]) * np.array([-1, 1, -1]) return data