]> git.mxchange.org Git - flightgear.git/blob - LaRCsim/ls_accel.c
Tons of little changes to clean up the code and to remove fatal errors
[flightgear.git] / LaRCsim / ls_accel.c
1 /***************************************************************************
2   
3   TITLE:        ls_Accel
4   
5   ----------------------------------------------------------------------------
6   
7   FUNCTION:     Sums forces and moments and calculates accelerations
8   
9   ----------------------------------------------------------------------------
10   
11   MODULE STATUS:        developmental
12   
13   ----------------------------------------------------------------------------
14   
15   GENEALOGY:    Written 920731 by Bruce Jackson.  Based upon equations
16   given in reference [1] and a Matrix-X/System Build block
17   diagram model of equations of motion coded by David Raney
18   at NASA-Langley in June of 1992.
19   
20   ----------------------------------------------------------------------------
21   
22   DESIGNED BY:  Bruce Jackson
23   
24   CODED BY:             Bruce Jackson
25   
26   MAINTAINED BY:        
27   
28   ----------------------------------------------------------------------------
29   
30   MODIFICATION HISTORY:
31   
32   DATE          PURPOSE         
33   
34   931007    Moved calculations of auxiliary accelerations here from ls_aux.c                                                                    BY
35             and corrected minus sign in front of A_Y_Pilot 
36             contribution from Q_body*P_body*D_X_pilot term.
37   940111    Changed DATA to SCALAR; updated header files
38             
39 $Header$
40 $Log$
41 Revision 1.2  1998/01/19 18:40:24  curt
42 Tons of little changes to clean up the code and to remove fatal errors
43 when building with the c++ compiler.
44
45 Revision 1.1  1997/05/29 00:09:53  curt
46 Initial Flight Gear revision.
47
48  * Revision 1.5  1994/01/11  18:42:16  bjax
49  * Oops! Changed data types from DATA to SCALAR for precision control.
50  *
51  * Revision 1.4  1994/01/11  18:36:58  bjax
52  * Removed ls_eom.h include directive; replaced with ls_types, ls_constants,
53  * and ls_generic.h includes.
54  *
55  * Revision 1.3  1993/10/07  18:45:24  bjax
56  * Added local defn of d[xyz]_pilot_from_cg to support previous mod. EBJ
57  *
58  * Revision 1.2  1993/10/07  18:41:31  bjax
59  * Moved calculations of auxiliary accelerations here from ls_aux, and
60  * corrected sign on Q_body*P_body*d_x_pilot term of A_Y_pilot calc.  EBJ
61  *
62  * Revision 1.1  1992/12/30  13:17:02  bjax
63  * Initial revision
64  *
65   
66   ----------------------------------------------------------------------------
67   
68   REFERENCES:
69   
70   [  1] McFarland, Richard E.: "A Standard Kinematic Model
71   for Flight Simulation at NASA-Ames", NASA CR-2497,
72   January 1975 
73   
74   ----------------------------------------------------------------------------
75   
76   CALLED BY:
77   
78   ----------------------------------------------------------------------------
79   
80   CALLS TO:
81   
82   ----------------------------------------------------------------------------
83   
84   INPUTS:  Aero, engine, gear forces & moments
85   
86   ----------------------------------------------------------------------------
87   
88   OUTPUTS:      State derivatives
89   
90   -------------------------------------------------------------------------*/
91 #include "ls_types.h"
92 #include "ls_generic.h"
93 #include "ls_constants.h"
94 #include "ls_accel.h"
95 #include <math.h>
96
97 void ls_accel( void ) {
98   
99   SCALAR        inv_Mass, inv_Radius;
100   SCALAR        ixz2, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10;
101   SCALAR        dx_pilot_from_cg, dy_pilot_from_cg, dz_pilot_from_cg;
102   
103   
104   /* Sum forces and moments at reference point */
105   
106   
107   F_X = F_X_aero + F_X_engine + F_X_gear;
108   F_Y = F_Y_aero + F_Y_engine + F_Y_gear;
109   F_Z = F_Z_aero + F_Z_engine + F_Z_gear;
110   
111   M_l_rp = M_l_aero + M_l_engine + M_l_gear;
112   M_m_rp = M_m_aero + M_m_engine + M_m_gear;
113   M_n_rp = M_n_aero + M_n_engine + M_n_gear;
114   
115   /* Transfer moments to center of gravity */
116   
117   M_l_cg = M_l_rp + F_Y*Dz_cg - F_Z*Dy_cg;
118   M_m_cg = M_m_rp + F_Z*Dx_cg - F_X*Dz_cg;
119   M_n_cg = M_n_rp + F_X*Dy_cg - F_Y*Dx_cg;
120   
121   /* Transform from body to local frame */
122   
123   F_north = T_local_to_body_11*F_X + T_local_to_body_21*F_Y 
124     + T_local_to_body_31*F_Z;
125   F_east  = T_local_to_body_12*F_X + T_local_to_body_22*F_Y 
126     + T_local_to_body_32*F_Z;
127   F_down  = T_local_to_body_13*F_X + T_local_to_body_23*F_Y 
128     + T_local_to_body_33*F_Z;
129   
130   /* Calculate linear accelerations */
131   
132   inv_Mass = 1/Mass;
133   inv_Radius = 1/Radius_to_vehicle;
134   V_dot_north = inv_Mass*F_north + 
135     inv_Radius*(V_north*V_down - V_east*V_east*tan(Lat_geocentric));
136   V_dot_east  = inv_Mass*F_east  + 
137     inv_Radius*(V_east*V_down + V_north*V_east*tan(Lat_geocentric));
138   V_dot_down  = inv_Mass*(F_down) + Gravity -
139     inv_Radius*(V_north*V_north + V_east*V_east);
140   
141   /* Invert the symmetric inertia matrix */
142   
143   ixz2 = I_xz*I_xz;
144   c0  = 1/(I_xx*I_zz - ixz2);
145   c1  = c0*((I_yy-I_zz)*I_zz - ixz2);
146   c2  = c0*I_xz*(I_xx - I_yy + I_zz);
147   c3  = c0*I_zz;
148   c4  = c0*I_xz;
149   c7  = 1/I_yy;
150   c5  = c7*(I_zz - I_xx);
151   c6  = c7*I_xz;
152   c8  = c0*((I_xx - I_yy)*I_xx + ixz2);
153   c9  = c0*I_xz*(I_yy - I_zz - I_xx);
154   c10 = c0*I_xx;
155   
156   /* Calculate the rotational body axis accelerations */
157   
158   P_dot_body = (c1*R_body + c2*P_body)*Q_body + c3*M_l_cg +  c4*M_n_cg;
159   Q_dot_body = c5*R_body*P_body + c6*(R_body*R_body - P_body*P_body) + c7*M_m_cg;
160   R_dot_body = (c8*P_body + c9*R_body)*Q_body + c4*M_l_cg + c10*M_n_cg;
161   
162   /* Calculate body axis accelerations (move to ls_accel?)      */
163
164     inv_Mass = 1/Mass;
165     
166     A_X_cg = F_X * inv_Mass;
167     A_Y_cg = F_Y * inv_Mass;
168     A_Z_cg = F_Z * inv_Mass;
169     
170     dx_pilot_from_cg = Dx_pilot - Dx_cg;
171     dy_pilot_from_cg = Dy_pilot - Dy_cg;
172     dz_pilot_from_cg = Dz_pilot - Dz_cg;
173     
174     A_X_pilot = A_X_cg  + (-R_body*R_body - Q_body*Q_body)*dx_pilot_from_cg
175                                             + ( P_body*Q_body - R_dot_body   )*dy_pilot_from_cg
176                                             + ( P_body*R_body + Q_dot_body   )*dz_pilot_from_cg;
177     A_Y_pilot = A_Y_cg  + ( P_body*Q_body + R_dot_body   )*dx_pilot_from_cg
178                                             + (-P_body*P_body - R_body*R_body)*dy_pilot_from_cg
179                                             + ( Q_body*R_body - P_dot_body   )*dz_pilot_from_cg;
180     A_Z_pilot = A_Z_cg  + ( P_body*R_body - Q_dot_body   )*dx_pilot_from_cg
181                                             + ( Q_body*R_body + P_dot_body   )*dy_pilot_from_cg
182                                             + (-Q_body*Q_body - P_body*P_body)*dz_pilot_from_cg;
183                                             
184     N_X_cg = INVG*A_X_cg;
185     N_Y_cg = INVG*A_Y_cg;
186     N_Z_cg = INVG*A_Z_cg;
187     
188     N_X_pilot = INVG*A_X_pilot;
189     N_Y_pilot = INVG*A_Y_pilot;
190     N_Z_pilot = INVG*A_Z_pilot;
191     
192     
193     U_dot_body = T_local_to_body_11*V_dot_north + T_local_to_body_12*V_dot_east
194                                     + T_local_to_body_13*V_dot_down - Q_total*W_body + R_total*V_body;
195     V_dot_body = T_local_to_body_21*V_dot_north + T_local_to_body_22*V_dot_east
196                                     + T_local_to_body_23*V_dot_down - R_total*U_body + P_total*W_body;
197     W_dot_body = T_local_to_body_31*V_dot_north + T_local_to_body_32*V_dot_east
198                                     + T_local_to_body_33*V_dot_down - P_total*V_body + Q_total*U_body;
199     /* End of ls_accel */
200   
201 }
202 /**************************************************************************/
203
204
205
206