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