]> git.mxchange.org Git - flightgear.git/blob - src/FDM/LaRCsim/c172_gear.c
Updates from Tony.
[flightgear.git] / src / FDM / LaRCsim / c172_gear.c
1 /***************************************************************************
2
3         TITLE:  gear
4         
5 ----------------------------------------------------------------------------
6
7         FUNCTION:       Landing gear model for example simulation
8
9 ----------------------------------------------------------------------------
10
11         MODULE STATUS:  developmental
12
13 ----------------------------------------------------------------------------
14
15         GENEALOGY:      Created 931012 by E. B. Jackson
16
17 ----------------------------------------------------------------------------
18
19         DESIGNED BY:    E. B. Jackson
20         
21         CODED BY:       E. B. Jackson
22         
23         MAINTAINED BY:  E. B. Jackson
24
25 ----------------------------------------------------------------------------
26
27         MODIFICATION HISTORY:
28         
29         DATE    PURPOSE                                         BY
30
31         931218  Added navion.h header to allow connection with
32                 aileron displacement for nosewheel steering.    EBJ
33         940511  Connected nosewheel to rudder pedal; adjusted gain.
34         
35         CURRENT RCS HEADER:
36
37 $Header$
38 $Log$
39 Revision 1.13  1999/12/13 20:43:41  curt
40 Updates from Tony.
41
42
43 ----------------------------------------------------------------------------
44
45         REFERENCES:
46
47 ----------------------------------------------------------------------------
48
49         CALLED BY:
50
51 ----------------------------------------------------------------------------
52
53         CALLS TO:
54
55 ----------------------------------------------------------------------------
56
57         INPUTS:
58
59 ----------------------------------------------------------------------------
60
61         OUTPUTS:
62
63 --------------------------------------------------------------------------*/
64 #include <math.h>
65 #include "ls_types.h"
66 #include "ls_constants.h"
67 #include "ls_generic.h"
68 #include "ls_cockpit.h"
69
70 #define HEIGHT_AGL_WHEEL d_wheel_rwy_local_v[2]
71
72
73 sub3( DATA v1[],  DATA v2[], DATA result[] )
74 {
75     result[0] = v1[0] - v2[0];
76     result[1] = v1[1] - v2[1];
77     result[2] = v1[2] - v2[2];
78 }
79
80 add3( DATA v1[],  DATA v2[], DATA result[] )
81 {
82     result[0] = v1[0] + v2[0];
83     result[1] = v1[1] + v2[1];
84     result[2] = v1[2] + v2[2];
85 }
86
87 cross3( DATA v1[],  DATA v2[], DATA result[] )
88 {
89     result[0] = v1[1]*v2[2] - v1[2]*v2[1];
90     result[1] = v1[2]*v2[0] - v1[0]*v2[2];
91     result[2] = v1[0]*v2[1] - v1[1]*v2[0];
92 }
93
94 multtrans3x3by3( DATA m[][3], DATA v[], DATA result[] )
95 {
96     result[0] = m[0][0]*v[0] + m[1][0]*v[1] + m[2][0]*v[2];
97     result[1] = m[0][1]*v[0] + m[1][1]*v[1] + m[2][1]*v[2];
98     result[2] = m[0][2]*v[0] + m[1][2]*v[1] + m[2][2]*v[2];
99 }
100
101 mult3x3by3( DATA m[][3], DATA v[], DATA result[] )
102 {
103     result[0] = m[0][0]*v[0] + m[0][1]*v[1] + m[0][2]*v[2];
104     result[1] = m[1][0]*v[0] + m[1][1]*v[1] + m[1][2]*v[2];
105     result[2] = m[2][0]*v[0] + m[2][1]*v[1] + m[2][2]*v[2];
106 }
107
108 clear3( DATA v[] )
109 {
110     v[0] = 0.; v[1] = 0.; v[2] = 0.;
111 }
112
113 gear()
114 {
115 char rcsid[] = "$Id$";
116 #define NUM_WHEELS 4
117 char gear_strings[NUM_WHEELS][12]={"nose","right main", "left main", "tail skid"};
118   /*
119    * Aircraft specific initializations and data goes here
120    */
121    
122
123     static int num_wheels = NUM_WHEELS;             /* number of wheels  */
124     static DATA d_wheel_rp_body_v[NUM_WHEELS][3] =  /* X, Y, Z locations,full extension */
125     {
126         {  3.91,  0.,   6.67 },            /*nose*/ /* in feet */
127         { -1.47,  3.58, 6.71 },        /*right main*/
128         { -1.47, -3.58, 6.71 },        /*left main*/ 
129         { -15.67, 0, 2.42 }            /*tail skid */
130     };
131         static DATA gear_travel[NUM_WHEELS] = /*in Z-axis*/
132         { -0.5, 2.5, 2.5, 0};
133     static DATA spring_constant[NUM_WHEELS] =       /* springiness, lbs/ft */
134         { 1200., 900., 900., 10000. };
135     static DATA spring_damping[NUM_WHEELS] =        /* damping, lbs/ft/sec */
136         { 200.,  300., 300., 400. };    
137     static DATA percent_brake[NUM_WHEELS] =         /* percent applied braking */
138         { 0.,  0.,  0., 0. };                       /* 0 = none, 1 = full */
139     static DATA caster_angle_rad[NUM_WHEELS] =      /* steerable tires - in */
140         { 0., 0., 0., 0};                                   /* radians, +CW */  
141   /*
142    * End of aircraft specific code
143    */
144     
145   /*
146    * Constants & coefficients for tyres on tarmac - ref [1]
147    */
148    
149     /* skid function looks like:
150      * 
151      *           mu  ^
152      *               |
153      *       max_mu  |       +          
154      *               |      /|          
155      *   sliding_mu  |     / +------    
156      *               |    /             
157      *               |   /              
158      *               +--+------------------------> 
159      *               |  |    |      sideward V
160      *               0 bkout skid
161      *                 V     V
162      */
163   
164   
165     static int it_rolls[NUM_WHEELS] = { 1,1,1,0};       
166         static DATA sliding_mu[NUM_WHEELS] = { 0.5, 0.5, 0.5, 0.3};     
167     static DATA rolling_mu[NUM_WHEELS] = { 0.01, 0.01, 0.01, 0.0};      
168     static DATA max_brake_mu[NUM_WHEELS] ={ 0.0, 0.6, 0.6, 0.0};        
169     static DATA max_mu       = 0.8;     
170     static DATA bkout_v      = 0.1;
171     static DATA skid_v       = 1.0;
172   /*
173    * Local data variables
174    */
175    
176     DATA d_wheel_cg_body_v[3];          /* wheel offset from cg,  X-Y-Z */
177     DATA d_wheel_cg_local_v[3];         /* wheel offset from cg,  N-E-D */
178     DATA d_wheel_rwy_local_v[3];        /* wheel offset from rwy, N-E-U */
179         DATA v_wheel_cg_local_v[3];    /*wheel velocity rel to cg N-E-D*/
180     DATA v_wheel_body_v[3];             /* wheel velocity,        X-Y-Z */
181     DATA v_wheel_local_v[3];            /* wheel velocity,        N-E-D */
182     DATA f_wheel_local_v[3];            /* wheel reaction force,  N-E-D */
183         DATA altitude_local_v[3];       /*altitude vector in local (N-E-D) i.e. (0,0,h)*/
184         DATA altitude_body_v[3];        /*altitude vector in body (X,Y,Z)*/
185     DATA temp3a[3], temp3b[3], tempF[3], tempM[3];      
186     DATA reaction_normal_force;         /* wheel normal (to rwy) force  */
187     DATA cos_wheel_hdg_angle, sin_wheel_hdg_angle;      /* temp storage */
188     DATA v_wheel_forward, v_wheel_sideward,  abs_v_wheel_sideward;
189     DATA forward_mu, sideward_mu;       /* friction coefficients        */
190     DATA beta_mu;                       /* breakout friction slope      */
191     DATA forward_wheel_force, sideward_wheel_force;
192
193     int i;                              /* per wheel loop counter */
194   
195   /*
196    * Execution starts here
197    */
198    
199     beta_mu = max_mu/(skid_v-bkout_v);
200     clear3( F_gear_v );         /* Initialize sum of forces...  */
201     clear3( M_gear_v );         /* ...and moments               */
202     
203   /*
204    * Put aircraft specific executable code here
205    */
206    
207     percent_brake[1] = Brake_pct; /* replace with cockpit brake handle connection code */
208     percent_brake[2] = percent_brake[1];
209     
210     caster_angle_rad[0] = 0.52*Rudder_pedal;
211     
212     
213         for (i=0;i<num_wheels;i++)          /* Loop for each wheel */
214     {
215                 /* printf("%s:\n",gear_strings[i]); */
216
217
218
219                 /*========================================*/
220                 /* Calculate wheel position w.r.t. runway */
221                 /*========================================*/
222
223                 
224                 /* printf("\thgcg: %g, theta: %g,phi: %g\n",D_cg_above_rwy,Theta*RAD_TO_DEG,Phi*RAD_TO_DEG); */
225
226                 
227                         /* First calculate wheel location w.r.t. cg in body (X-Y-Z) axes... */
228
229                 sub3( d_wheel_rp_body_v[i], D_cg_rp_body_v, d_wheel_cg_body_v );
230
231                 /* then converting to local (North-East-Down) axes... */
232
233                 multtrans3x3by3( T_local_to_body_m,  d_wheel_cg_body_v, d_wheel_cg_local_v );
234                 
235
236                 /* Runway axes correction - third element is Altitude, not (-)Z... */
237
238                 d_wheel_cg_local_v[2] = -d_wheel_cg_local_v[2]; /* since altitude = -Z */
239
240                 /* Add wheel offset to cg location in local axes */
241
242                 add3( d_wheel_cg_local_v, D_cg_rwy_local_v, d_wheel_rwy_local_v );
243
244                 /* remove Runway axes correction so right hand rule applies */
245
246                 d_wheel_cg_local_v[2] = -d_wheel_cg_local_v[2]; /* now Z positive down */
247
248                 /*============================*/
249                 /* Calculate wheel velocities */
250                 /*============================*/
251
252                 /* contribution due to angular rates */
253
254                 cross3( Omega_body_v, d_wheel_cg_body_v, temp3a );
255
256                 /* transform into local axes */
257
258                 multtrans3x3by3( T_local_to_body_m, temp3a,v_wheel_cg_local_v );
259
260                 /* plus contribution due to cg velocities */
261
262                 add3( v_wheel_cg_local_v, V_local_rel_ground_v, v_wheel_local_v );
263
264                 clear3(f_wheel_local_v);
265                 reaction_normal_force=0;
266                 if( HEIGHT_AGL_WHEEL < 0. ) 
267                         /*the wheel is underground -- which implies ground contact 
268                           so calculate reaction forces */ 
269                         {
270                         /*===========================================*/
271                         /* Calculate forces & moments for this wheel */
272                         /*===========================================*/
273
274                         /* Add any anticipation, or frame lead/prediction, here... */
275
276                                 /* no lead used at present */
277
278                         /* Calculate sideward and forward velocities of the wheel 
279                                 in the runway plane                                     */
280
281                         cos_wheel_hdg_angle = cos(caster_angle_rad[i] + Psi);
282                         sin_wheel_hdg_angle = sin(caster_angle_rad[i] + Psi);
283
284                         v_wheel_forward  = v_wheel_local_v[0]*cos_wheel_hdg_angle
285                                          + v_wheel_local_v[1]*sin_wheel_hdg_angle;
286                         v_wheel_sideward = v_wheel_local_v[1]*cos_wheel_hdg_angle
287                                          - v_wheel_local_v[0]*sin_wheel_hdg_angle;
288                         
289                     
290                 /* Calculate normal load force (simple spring constant) */
291
292                 reaction_normal_force = 0.;
293         
294                 reaction_normal_force = spring_constant[i]*d_wheel_rwy_local_v[2]
295                                           - v_wheel_local_v[2]*spring_damping[i];
296                         /* printf("\treaction_normal_force: %g\n",reaction_normal_force); */
297
298                 if (reaction_normal_force > 0.) reaction_normal_force = 0.;
299                         /* to prevent damping component from swamping spring component */
300
301
302                 /* Calculate friction coefficients */
303
304                         if(it_rolls[i])
305                         {
306                            forward_mu = (max_brake_mu[i] - rolling_mu[i])*percent_brake[i] + rolling_mu[i];
307                            abs_v_wheel_sideward = sqrt(v_wheel_sideward*v_wheel_sideward);
308                            sideward_mu = sliding_mu[i];
309                            if (abs_v_wheel_sideward < skid_v) 
310                            sideward_mu = (abs_v_wheel_sideward - bkout_v)*beta_mu;
311                            if (abs_v_wheel_sideward < bkout_v) sideward_mu = 0.;
312                         }
313                         else
314                         {
315                                 forward_mu=sliding_mu[i];
316                                 sideward_mu=sliding_mu[i];
317                         }          
318
319                         /* Calculate foreward and sideward reaction forces */
320
321                         forward_wheel_force  =   forward_mu*reaction_normal_force;
322                         sideward_wheel_force =  sideward_mu*reaction_normal_force;
323                         if(v_wheel_forward < 0.) forward_wheel_force = -forward_wheel_force;
324                         if(v_wheel_sideward < 0.) sideward_wheel_force = -sideward_wheel_force;
325 /*                      printf("\tFfwdgear: %g Fsidegear: %g\n",forward_wheel_force,sideward_wheel_force);
326  */
327                         /* Rotate into local (N-E-D) axes */
328
329                         f_wheel_local_v[0] = forward_wheel_force*cos_wheel_hdg_angle
330                                           - sideward_wheel_force*sin_wheel_hdg_angle;
331                         f_wheel_local_v[1] = forward_wheel_force*sin_wheel_hdg_angle
332                                           + sideward_wheel_force*cos_wheel_hdg_angle;
333                         f_wheel_local_v[2] = reaction_normal_force;       
334
335                          /* Convert reaction force from local (N-E-D) axes to body (X-Y-Z) */
336                         mult3x3by3( T_local_to_body_m, f_wheel_local_v, tempF );
337
338                         /* Calculate moments from force and offsets in body axes */
339
340                         cross3( d_wheel_cg_body_v, tempF, tempM );
341
342                         /* Sum forces and moments across all wheels */
343
344                         add3( tempF, F_gear_v, F_gear_v );
345                         add3( tempM, M_gear_v, M_gear_v );   
346
347
348                 }
349
350
351
352                 /* printf("\tN: %g,dZrwy: %g dZdotrwy: %g\n",reaction_normal_force,HEIGHT_AGL_WHEEL,v_wheel_cg_local_v[2]); */
353
354                 /*printf("\tFxgear: %g Fygear: %g, Fzgear: %g\n",F_X_gear,F_Y_gear,F_Z_gear);
355                 printf("\tMgear: %g, Lgear: %g, Ngear: %g\n\n",M_m_gear,M_l_gear,M_n_gear); */
356
357
358     }
359 }