1 /***************************************************************************
5 ----------------------------------------------------------------------------
7 FUNCTION: Atmospheric and auxilary relationships for LaRCSim EOM
9 ----------------------------------------------------------------------------
11 MODULE STATUS: developmental
13 ----------------------------------------------------------------------------
15 GENEALOGY: Created 9208026 as part of C-castle simulation project.
17 ----------------------------------------------------------------------------
19 DESIGNED BY: B. Jackson
23 MAINTAINED BY: B. Jackson
25 ----------------------------------------------------------------------------
31 931006 Moved calculations of auxiliary accelerations from here
32 to ls_accel.c and corrected minus sign in front of A_Y_Pilot
33 contribution from Q_body*P_body*D_X_pilot term. EBJ
34 931014 Changed calculation of Alpha from atan to atan2 so sign is correct.
36 931220 Added calculations for static and total temperatures & pressures,
37 as well as dynamic and impact pressures and calibrated airspeed.
39 940111 Changed #included header files from old "ls_eom.h" to newer
40 "ls_types.h", "ls_constants.h" and "ls_generic.h". EBJ
42 950207 Changed use of "abs" to "fabs" in calculation of signU. EBJ
44 950228 Fixed bug in calculation of beta_dot. EBJ
46 CURRENT RCS HEADER INFO:
50 Revision 1.1 1997/05/29 00:09:54 curt
51 Initial Flight Gear revision.
53 * Revision 1.12 1995/02/28 17:57:16 bjax
54 * Corrected calculation of beta_dot. EBJ
56 * Revision 1.11 1995/02/07 21:09:47 bjax
57 * Corrected calculation of "signU"; was using divide by
58 * abs(), which returns an integer; now using fabs(), which
59 * returns a double. EBJ
61 * Revision 1.10 1994/05/10 20:09:42 bjax
62 * Fixed a major problem with dx_pilot_from_cg, etc. not being calculated locally.
64 * Revision 1.9 1994/01/11 18:44:33 bjax
65 * Changed header files to use ls_types, ls_constants, and ls_generic.
67 * Revision 1.8 1993/12/21 14:36:33 bjax
68 * Added calcs of pressures, temps and calibrated airspeeds.
70 * Revision 1.7 1993/10/14 11:25:38 bjax
71 * Changed calculation of Alpha to use 'atan2' instead of 'atan' so alphas
72 * larger than +/- 90 degrees are calculated correctly. EBJ
74 * Revision 1.6 1993/10/07 18:45:56 bjax
75 * A little cleanup; no significant changes. EBJ
77 * Revision 1.5 1993/10/07 18:42:22 bjax
78 * Moved calculations of auxiliary accelerations here from ls_aux, and
79 * corrected sign on Q_body*P_body*d_x_pilot term of A_Y_pilot calc. EBJ
81 * Revision 1.4 1993/07/16 18:28:58 bjax
82 * Changed call from atmos_62 to ls_atmos. EBJ
84 * Revision 1.3 1993/06/02 15:02:42 bjax
85 * Changed call to geodesy calcs from ls_geodesy to ls_geoc_to_geod.
87 * Revision 1.1 92/12/30 13:17:39 bjax
92 ----------------------------------------------------------------------------
94 REFERENCES: [ 1] Shapiro, Ascher H.: "The Dynamics and Thermodynamics
95 of Compressible Fluid Flow", Volume I, The Ronald
98 ----------------------------------------------------------------------------
102 ----------------------------------------------------------------------------
106 ----------------------------------------------------------------------------
110 ----------------------------------------------------------------------------
114 --------------------------------------------------------------------------*/
115 #include "ls_types.h"
116 #include "ls_constants.h"
117 #include "ls_generic.h"
123 SCALAR dx_pilot_from_cg, dy_pilot_from_cg, dz_pilot_from_cg;
125 SCALAR v_XZ_plane_2, signU, v_tangential;
126 SCALAR inv_radius_ratio;
127 SCALAR cos_rwy_hdg, sin_rwy_hdg;
128 SCALAR mach2, temp_ratio, pres_ratio;
130 /* update geodetic position */
132 ls_geoc_to_geod( Lat_geocentric, Radius_to_vehicle,
133 &Latitude, &Altitude, &Sea_level_radius );
134 Longitude = Lon_geocentric - Earth_position_angle;
136 /* Calculate body axis velocities */
138 /* Form relative velocity vector */
140 V_north_rel_ground = V_north;
141 V_east_rel_ground = V_east
142 - OMEGA_EARTH*Sea_level_radius*cos( Lat_geocentric );
143 V_down_rel_ground = V_down;
145 V_north_rel_airmass = V_north_rel_ground - V_north_airmass;
146 V_east_rel_airmass = V_east_rel_ground - V_east_airmass;
147 V_down_rel_airmass = V_down_rel_ground - V_down_airmass;
149 U_body = T_local_to_body_11*V_north_rel_airmass
150 + T_local_to_body_12*V_east_rel_airmass
151 + T_local_to_body_13*V_down_rel_airmass + U_gust;
152 V_body = T_local_to_body_21*V_north_rel_airmass
153 + T_local_to_body_22*V_east_rel_airmass
154 + T_local_to_body_23*V_down_rel_airmass + V_gust;
155 W_body = T_local_to_body_31*V_north_rel_airmass
156 + T_local_to_body_32*V_east_rel_airmass
157 + T_local_to_body_33*V_down_rel_airmass + W_gust;
159 V_rel_wind = sqrt(U_body*U_body + V_body*V_body + W_body*W_body);
162 /* Calculate alpha and beta rates */
164 v_XZ_plane_2 = (U_body*U_body + W_body*W_body);
169 signU = U_body/fabs(U_body);
171 if( (v_XZ_plane_2 == 0) || (V_rel_wind == 0) )
178 Alpha_dot = (U_body*W_dot_body - W_body*U_dot_body)/
180 Beta_dot = (signU*v_XZ_plane_2*V_dot_body
181 - V_body*(U_body*U_dot_body + W_body*W_dot_body))
182 /(V_rel_wind*V_rel_wind*sqrt(v_XZ_plane_2));
185 /* Calculate flight path and other flight condition values */
190 Alpha = atan2( W_body, U_body );
192 Cos_alpha = cos(Alpha);
193 Sin_alpha = sin(Alpha);
198 Beta = asin( V_body/ V_rel_wind );
200 Cos_beta = cos(Beta);
201 Sin_beta = sin(Beta);
203 V_true_kts = V_rel_wind * V_TO_KNOTS;
205 V_ground_speed = sqrt(V_north_rel_ground*V_north_rel_ground
206 + V_east_rel_ground*V_east_rel_ground );
208 V_rel_ground = sqrt(V_ground_speed*V_ground_speed
209 + V_down_rel_ground*V_down_rel_ground );
211 v_tangential = sqrt(V_north*V_north + V_east*V_east);
213 V_inertial = sqrt(v_tangential*v_tangential + V_down*V_down);
215 if( (V_ground_speed == 0) && (V_down == 0) )
218 Gamma_vert_rad = atan2( -V_down, V_ground_speed );
220 if( (V_north_rel_ground == 0) && (V_east_rel_ground == 0) )
223 Gamma_horiz_rad = atan2( V_east_rel_ground, V_north_rel_ground );
225 if (Gamma_horiz_rad < 0)
226 Gamma_horiz_rad = Gamma_horiz_rad + 2*PI;
228 /* Calculate local gravity */
230 ls_gravity( Radius_to_vehicle, Lat_geocentric, &Gravity );
232 /* call function for (smoothed) density ratio, sonic velocity, and
235 ls_atmos(Altitude, &Sigma, &V_sound,
236 &Static_temperature, &Static_pressure);
238 Density = Sigma*SEA_LEVEL_DENSITY;
240 Mach_number = V_rel_wind / V_sound;
242 V_equiv = V_rel_wind*sqrt(Sigma);
244 V_equiv_kts = V_equiv*V_TO_KNOTS;
246 /* calculate temperature and pressure ratios (from [1]) */
248 mach2 = Mach_number*Mach_number;
249 temp_ratio = 1.0 + 0.2*mach2;
250 pres_ratio = pow( temp_ratio, 3.5 );
252 Total_temperature = temp_ratio*Static_temperature;
253 Total_pressure = pres_ratio*Static_pressure;
255 /* calculate impact and dynamic pressures */
257 Impact_pressure = Total_pressure - Static_pressure;
259 Dynamic_pressure = 0.5*Density*V_rel_wind*V_rel_wind;
261 /* calculate calibrated airspeed indication */
263 V_calibrated = sqrt( 2.0*Dynamic_pressure / SEA_LEVEL_DENSITY );
264 V_calibrated_kts = V_calibrated*V_TO_KNOTS;
266 Centrifugal_relief = 1 - v_tangential/(Radius_to_vehicle*Gravity);
268 /* Determine location in runway coordinates */
270 Radius_to_rwy = Sea_level_radius + Runway_altitude;
271 cos_rwy_hdg = cos(Runway_heading*DEG_TO_RAD);
272 sin_rwy_hdg = sin(Runway_heading*DEG_TO_RAD);
274 D_cg_north_of_rwy = Radius_to_rwy*(Latitude - Runway_latitude);
275 D_cg_east_of_rwy = Radius_to_rwy*cos(Runway_latitude)
276 *(Longitude - Runway_longitude);
277 D_cg_above_rwy = Radius_to_vehicle - Radius_to_rwy;
279 X_cg_rwy = D_cg_north_of_rwy*cos_rwy_hdg
280 + D_cg_east_of_rwy*sin_rwy_hdg;
281 Y_cg_rwy =-D_cg_north_of_rwy*sin_rwy_hdg
282 + D_cg_east_of_rwy*cos_rwy_hdg;
283 H_cg_rwy = D_cg_above_rwy;
285 dx_pilot_from_cg = Dx_pilot - Dx_cg;
286 dy_pilot_from_cg = Dy_pilot - Dy_cg;
287 dz_pilot_from_cg = Dz_pilot - Dz_cg;
289 D_pilot_north_of_rwy = D_cg_north_of_rwy
290 + T_local_to_body_11*dx_pilot_from_cg
291 + T_local_to_body_21*dy_pilot_from_cg
292 + T_local_to_body_31*dz_pilot_from_cg;
293 D_pilot_east_of_rwy = D_cg_east_of_rwy
294 + T_local_to_body_12*dx_pilot_from_cg
295 + T_local_to_body_22*dy_pilot_from_cg
296 + T_local_to_body_32*dz_pilot_from_cg;
297 D_pilot_above_rwy = D_cg_above_rwy
298 - T_local_to_body_13*dx_pilot_from_cg
299 - T_local_to_body_23*dy_pilot_from_cg
300 - T_local_to_body_33*dz_pilot_from_cg;
302 X_pilot_rwy = D_pilot_north_of_rwy*cos_rwy_hdg
303 + D_pilot_east_of_rwy*sin_rwy_hdg;
304 Y_pilot_rwy = -D_pilot_north_of_rwy*sin_rwy_hdg
305 + D_pilot_east_of_rwy*cos_rwy_hdg;
306 H_pilot_rwy = D_pilot_above_rwy;
308 /* Calculate Euler rates */
312 Sin_theta = sin(Theta);
313 Cos_theta = cos(Theta);
320 Psi_dot = (Q_total*Sin_phi + R_total*Cos_phi)/Cos_theta;
322 Theta_dot = Q_total*Cos_phi - R_total*Sin_phi;
323 Phi_dot = P_total + Psi_dot*Sin_theta;
328 /*************************************************************************/