]> git.mxchange.org Git - flightgear.git/blob - LaRCsim/ls_aux.c
MSVC++ portability tweaks contributed by Bernie Bright.
[flightgear.git] / LaRCsim / ls_aux.c
1 /***************************************************************************
2
3     TITLE:              ls_aux
4                 
5 ----------------------------------------------------------------------------
6
7     FUNCTION:   Atmospheric and auxilary relationships for LaRCSim EOM
8
9 ----------------------------------------------------------------------------
10
11     MODULE STATUS:      developmental
12
13 ----------------------------------------------------------------------------
14
15     GENEALOGY:  Created 9208026 as part of C-castle simulation project.
16
17 ----------------------------------------------------------------------------
18
19     DESIGNED BY:        B. Jackson
20     
21     CODED BY:           B. Jackson
22     
23     MAINTAINED BY:      B. Jackson
24
25 ----------------------------------------------------------------------------
26
27     MODIFICATION HISTORY:
28     
29     DATE    PURPOSE     
30     
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.
35                                                                     EBJ
36     931220  Added calculations for static and total temperatures & pressures,
37             as well as dynamic and impact pressures and calibrated airspeed.
38                                                                     EBJ
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
41
42     950207  Changed use of "abs" to "fabs" in calculation of signU. EBJ
43     
44     950228  Fixed bug in calculation of beta_dot.                   EBJ
45
46     CURRENT RCS HEADER INFO:
47
48 $Header$
49 $Log$
50 Revision 1.4  1998/08/24 20:09:26  curt
51 Code optimization tweaks from Norman Vine.
52
53 Revision 1.3  1998/08/06 12:46:38  curt
54 Header change.
55
56 Revision 1.2  1998/01/19 18:40:24  curt
57 Tons of little changes to clean up the code and to remove fatal errors
58 when building with the c++ compiler.
59
60 Revision 1.1  1997/05/29 00:09:54  curt
61 Initial Flight Gear revision.
62
63  * Revision 1.12  1995/02/28  17:57:16  bjax
64  * Corrected calculation of beta_dot. EBJ
65  *
66  * Revision 1.11  1995/02/07  21:09:47  bjax
67  * Corrected calculation of "signU"; was using divide by
68  * abs(), which returns an integer; now using fabs(), which
69  * returns a double.  EBJ
70  *
71  * Revision 1.10  1994/05/10  20:09:42  bjax
72  * Fixed a major problem with dx_pilot_from_cg, etc. not being calculated locally.
73  *
74  * Revision 1.9  1994/01/11  18:44:33  bjax
75  * Changed header files to use ls_types, ls_constants, and ls_generic.
76  *
77  * Revision 1.8  1993/12/21  14:36:33  bjax
78  * Added calcs of pressures, temps and calibrated airspeeds.
79  *
80  * Revision 1.7  1993/10/14  11:25:38  bjax
81  * Changed calculation of Alpha to use 'atan2' instead of 'atan' so alphas
82  * larger than +/- 90 degrees are calculated correctly.                 EBJ
83  *
84  * Revision 1.6  1993/10/07  18:45:56  bjax
85  * A little cleanup; no significant changes. EBJ
86  *
87  * Revision 1.5  1993/10/07  18:42:22  bjax
88  * Moved calculations of auxiliary accelerations here from ls_aux, and
89  * corrected sign on Q_body*P_body*d_x_pilot term of A_Y_pilot calc.  EBJ
90  *
91  * Revision 1.4  1993/07/16  18:28:58  bjax
92  * Changed call from atmos_62 to ls_atmos. EBJ
93  *
94  * Revision 1.3  1993/06/02  15:02:42  bjax
95  * Changed call to geodesy calcs from ls_geodesy to ls_geoc_to_geod.
96  *
97  * Revision 1.1  92/12/30  13:17:39  bjax
98  * Initial revision
99  * 
100
101
102 ----------------------------------------------------------------------------
103
104     REFERENCES: [ 1] Shapiro, Ascher H.: "The Dynamics and Thermodynamics
105                         of Compressible Fluid Flow", Volume I, The Ronald 
106                         Press, 1953.
107
108 ----------------------------------------------------------------------------
109
110                 CALLED BY:
111
112 ----------------------------------------------------------------------------
113
114                 CALLS TO:
115
116 ----------------------------------------------------------------------------
117
118                 INPUTS:
119
120 ----------------------------------------------------------------------------
121
122                 OUTPUTS:
123
124 --------------------------------------------------------------------------*/
125 #include "ls_types.h"
126 #include "ls_constants.h"
127 #include "ls_generic.h"
128
129 #include "ls_aux.h"
130
131 #include "atmos_62.h"
132 #include "ls_geodesy.h"
133 #include "ls_gravity.h"
134
135 #include <math.h>
136
137
138 void ls_aux( void ) {
139
140         SCALAR  dx_pilot_from_cg, dy_pilot_from_cg, dz_pilot_from_cg;
141         /* SCALAR inv_Mass; */
142         SCALAR  v_XZ_plane_2, signU, v_tangential;
143         /* SCALAR inv_radius_ratio; */
144         SCALAR  cos_rwy_hdg, sin_rwy_hdg;
145         SCALAR  mach2, temp_ratio, pres_ratio;
146         SCALAR  tmp;
147         
148     /* update geodetic position */
149
150         ls_geoc_to_geod( Lat_geocentric, Radius_to_vehicle, 
151                                 &Latitude, &Altitude, &Sea_level_radius );
152         Longitude = Lon_geocentric - Earth_position_angle;
153
154     /* Calculate body axis velocities */
155
156         /* Form relative velocity vector */
157
158         V_north_rel_ground = V_north;
159         V_east_rel_ground  = V_east 
160           - OMEGA_EARTH*Sea_level_radius*cos( Lat_geocentric );
161         V_down_rel_ground  = V_down;
162         
163         V_north_rel_airmass = V_north_rel_ground - V_north_airmass;
164         V_east_rel_airmass  = V_east_rel_ground  - V_east_airmass;
165         V_down_rel_airmass  = V_down_rel_ground  - V_down_airmass;
166         
167         U_body = T_local_to_body_11*V_north_rel_airmass 
168           + T_local_to_body_12*V_east_rel_airmass
169             + T_local_to_body_13*V_down_rel_airmass + U_gust;
170         V_body = T_local_to_body_21*V_north_rel_airmass 
171           + T_local_to_body_22*V_east_rel_airmass
172             + T_local_to_body_23*V_down_rel_airmass + V_gust;
173         W_body = T_local_to_body_31*V_north_rel_airmass 
174           + T_local_to_body_32*V_east_rel_airmass
175             + T_local_to_body_33*V_down_rel_airmass + W_gust;
176                                 
177         V_rel_wind = sqrt(U_body*U_body + V_body*V_body + W_body*W_body);
178
179
180     /* Calculate alpha and beta rates   */
181
182         v_XZ_plane_2 = (U_body*U_body + W_body*W_body);
183         
184         if (U_body == 0)
185                 signU = 1;
186         else
187                 signU = U_body/fabs(U_body);
188                 
189         if( (v_XZ_plane_2 == 0) || (V_rel_wind == 0) )
190         {
191                 Alpha_dot = 0;
192                 Beta_dot = 0;
193         }
194         else
195         {
196                 Alpha_dot = (U_body*W_dot_body - W_body*U_dot_body)/
197                   v_XZ_plane_2;
198                 Beta_dot = (signU*v_XZ_plane_2*V_dot_body 
199                   - V_body*(U_body*U_dot_body + W_body*W_dot_body))
200                     /(V_rel_wind*V_rel_wind*sqrt(v_XZ_plane_2));
201         }
202
203     /* Calculate flight path and other flight condition values */
204
205         if (U_body == 0) 
206                 Alpha = 0;
207         else
208                 Alpha = atan2( W_body, U_body );
209                 
210         Cos_alpha = cos(Alpha);
211         Sin_alpha = sin(Alpha);
212         
213         if (V_rel_wind == 0)
214                 Beta = 0;
215         else
216                 Beta = asin( V_body/ V_rel_wind );
217                 
218         Cos_beta = cos(Beta);
219         Sin_beta = sin(Beta);
220         
221         V_true_kts = V_rel_wind * V_TO_KNOTS;
222         
223         V_ground_speed = sqrt(V_north_rel_ground*V_north_rel_ground
224                               + V_east_rel_ground*V_east_rel_ground );
225
226         V_rel_ground = sqrt(V_ground_speed*V_ground_speed
227                             + V_down_rel_ground*V_down_rel_ground );
228         
229         v_tangential = sqrt(V_north*V_north + V_east*V_east);
230         
231         V_inertial = sqrt(v_tangential*v_tangential + V_down*V_down);
232         
233         if( (V_ground_speed == 0) && (V_down == 0) )
234           Gamma_vert_rad = 0;
235         else
236           Gamma_vert_rad = atan2( -V_down, V_ground_speed );
237                 
238         if( (V_north_rel_ground == 0) && (V_east_rel_ground == 0) )
239           Gamma_horiz_rad = 0;
240         else
241           Gamma_horiz_rad = atan2( V_east_rel_ground, V_north_rel_ground );
242         
243         if (Gamma_horiz_rad < 0) 
244           Gamma_horiz_rad = Gamma_horiz_rad + 2*PI;
245         
246     /* Calculate local gravity  */
247         
248         ls_gravity( Radius_to_vehicle, Lat_geocentric, &Gravity );
249         
250     /* call function for (smoothed) density ratio, sonic velocity, and
251            ambient pressure */
252
253         ls_atmos(Altitude, &Sigma, &V_sound, 
254                  &Static_temperature, &Static_pressure);
255         
256         Density = Sigma*SEA_LEVEL_DENSITY;
257         
258         Mach_number = V_rel_wind / V_sound;
259         
260         V_equiv = V_rel_wind*sqrt(Sigma);
261         
262         V_equiv_kts = V_equiv*V_TO_KNOTS;
263
264     /* calculate temperature and pressure ratios (from [1]) */
265
266         mach2 = Mach_number*Mach_number;
267         temp_ratio = 1.0 + 0.2*mach2; 
268         tmp = 3.5;
269         pres_ratio = pow( temp_ratio, tmp );
270
271         Total_temperature = temp_ratio*Static_temperature;
272         Total_pressure    = pres_ratio*Static_pressure;
273
274     /* calculate impact and dynamic pressures */
275         
276         Impact_pressure = Total_pressure - Static_pressure; 
277
278         Dynamic_pressure = 0.5*Density*V_rel_wind*V_rel_wind;
279
280     /* calculate calibrated airspeed indication */
281
282         V_calibrated = sqrt( 2.0*Dynamic_pressure / SEA_LEVEL_DENSITY );
283         V_calibrated_kts = V_calibrated*V_TO_KNOTS;
284         
285         Centrifugal_relief = 1 - v_tangential/(Radius_to_vehicle*Gravity);
286         
287 /* Determine location in runway coordinates */
288
289         Radius_to_rwy = Sea_level_radius + Runway_altitude;
290         cos_rwy_hdg = cos(Runway_heading*DEG_TO_RAD);
291         sin_rwy_hdg = sin(Runway_heading*DEG_TO_RAD);
292         
293         D_cg_north_of_rwy = Radius_to_rwy*(Latitude - Runway_latitude);
294         D_cg_east_of_rwy = Radius_to_rwy*cos(Runway_latitude)
295                 *(Longitude - Runway_longitude);
296         D_cg_above_rwy  = Radius_to_vehicle - Radius_to_rwy;
297         
298         X_cg_rwy = D_cg_north_of_rwy*cos_rwy_hdg 
299           + D_cg_east_of_rwy*sin_rwy_hdg;
300         Y_cg_rwy =-D_cg_north_of_rwy*sin_rwy_hdg 
301           + D_cg_east_of_rwy*cos_rwy_hdg;
302         H_cg_rwy = D_cg_above_rwy;
303         
304         dx_pilot_from_cg = Dx_pilot - Dx_cg;
305         dy_pilot_from_cg = Dy_pilot - Dy_cg;
306         dz_pilot_from_cg = Dz_pilot - Dz_cg;
307
308         D_pilot_north_of_rwy = D_cg_north_of_rwy 
309           + T_local_to_body_11*dx_pilot_from_cg 
310             + T_local_to_body_21*dy_pilot_from_cg
311               + T_local_to_body_31*dz_pilot_from_cg;
312         D_pilot_east_of_rwy  = D_cg_east_of_rwy 
313           + T_local_to_body_12*dx_pilot_from_cg 
314             + T_local_to_body_22*dy_pilot_from_cg
315               + T_local_to_body_32*dz_pilot_from_cg;
316         D_pilot_above_rwy    = D_cg_above_rwy 
317           - T_local_to_body_13*dx_pilot_from_cg 
318             - T_local_to_body_23*dy_pilot_from_cg
319               - T_local_to_body_33*dz_pilot_from_cg;
320                                                         
321         X_pilot_rwy =  D_pilot_north_of_rwy*cos_rwy_hdg
322           + D_pilot_east_of_rwy*sin_rwy_hdg;
323         Y_pilot_rwy = -D_pilot_north_of_rwy*sin_rwy_hdg
324           + D_pilot_east_of_rwy*cos_rwy_hdg;
325         H_pilot_rwy =  D_pilot_above_rwy;
326                                                                 
327 /* Calculate Euler rates */
328         
329         Sin_phi = sin(Phi);
330         Cos_phi = cos(Phi);
331         Sin_theta = sin(Theta);
332         Cos_theta = cos(Theta);
333         Sin_psi = sin(Psi);
334         Cos_psi = cos(Psi);
335         
336         if( Cos_theta == 0 )
337           Psi_dot = 0;
338         else
339           Psi_dot = (Q_total*Sin_phi + R_total*Cos_phi)/Cos_theta;
340         
341         Theta_dot = Q_total*Cos_phi - R_total*Sin_phi;
342         Phi_dot = P_total + Psi_dot*Sin_theta;
343         
344 /* end of ls_aux */
345
346 }
347 /*************************************************************************/