]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGLGear.cpp
b11041c9a4a542b9118705026a0863406c2699eb
[flightgear.git] / src / FDM / JSBSim / models / FGLGear.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGLGear.cpp
4  Author:       Jon S. Berndt
5                Norman H. Princen
6  Date started: 11/18/99
7  Purpose:      Encapsulates the landing gear elements
8  Called by:    FGAircraft
9
10  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
11
12  This program is free software; you can redistribute it and/or modify it under
13  the terms of the GNU Lesser General Public License as published by the Free Software
14  Foundation; either version 2 of the License, or (at your option) any later
15  version.
16
17  This program is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
20  details.
21
22  You should have received a copy of the GNU Lesser General Public License along with
23  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24  Place - Suite 330, Boston, MA  02111-1307, USA.
25
26  Further information about the GNU Lesser General Public License can also be found on
27  the world wide web at http://www.gnu.org.
28
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
31
32 HISTORY
33 --------------------------------------------------------------------------------
34 11/18/99   JSB   Created
35 01/30/01   NHP   Extended gear model to properly simulate steering and braking
36
37 /%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "FGLGear.h"
42
43 namespace JSBSim {
44
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 DEFINITIONS
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 GLOBAL DATA
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 static const char *IdSrc = "$Id$";
54 static const char *IdHdr = ID_LGEAR;
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 CLASS IMPLEMENTATION
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) : Exec(fdmex),
61                  GearNumber(number)
62 {
63   Element *force_table=0;
64   string force_type="";
65
66   kSpring = bDamp = bDampRebound = dynamicFCoeff = staticFCoeff = rollingFCoeff = maxSteerAngle = 0;
67   sSteerType = sBrakeGroup = sSteerType = "";
68   isRetractable = 0;
69
70   name = el->GetAttributeValue("name");
71   sContactType = el->GetAttributeValue("type");
72   if (el->FindElement("spring_coeff"))
73     kSpring = el->FindElementValueAsNumberConvertTo("spring_coeff", "LBS/FT");
74   if (el->FindElement("damping_coeff"))
75     bDamp   = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT/SEC");
76
77   if (el->FindElement("damping_coeff_rebound"))
78     bDampRebound   = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT/SEC");
79   else
80     bDampRebound   = bDamp;
81
82   if (el->FindElement("dynamic_friction"))
83     dynamicFCoeff = el->FindElementValueAsNumber("dynamic_friction");
84   if (el->FindElement("static_friction"))
85     staticFCoeff = el->FindElementValueAsNumber("static_friction");
86   if (el->FindElement("rolling_friction"))
87     rollingFCoeff = el->FindElementValueAsNumber("rolling_friction");
88   if (el->FindElement("max_steer"))
89     maxSteerAngle = el->FindElementValueAsNumberConvertTo("max_steer", "DEG");
90   if (el->FindElement("retractable"))
91     isRetractable = ((unsigned int)el->FindElementValueAsNumber("retractable"))>0.0?true:false;
92
93   ForceY_Table = 0;
94   force_table = el->FindElement("table");
95   while (force_table) {
96     force_type = force_table->GetAttributeValue("type");
97     if (force_type == "CORNERING_COEFF") {
98       ForceY_Table = new FGTable(Exec->GetPropertyManager(), force_table);
99     } else {
100       cerr << "Undefined force table for " << name << " contact point" << endl;
101     }
102     force_table = el->FindNextElement("table");
103   }
104
105   sBrakeGroup = el->FindElementValue("brake_group");
106
107   if (maxSteerAngle == 360) sSteerType = "CASTERED";
108   else if (maxSteerAngle == 0.0) sSteerType = "FIXED";
109   else sSteerType = "STEERABLE";
110
111   Element* element = el->FindElement("location");
112   if (element) vXYZ = element->FindElementTripletConvertTo("IN");
113   else {cerr << "No location given for contact " << name << endl; exit(-1);}
114
115   if      (sBrakeGroup == "LEFT"  ) eBrakeGrp = bgLeft;
116   else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
117   else if (sBrakeGroup == "CENTER") eBrakeGrp = bgCenter;
118   else if (sBrakeGroup == "NOSE"  ) eBrakeGrp = bgNose;
119   else if (sBrakeGroup == "TAIL"  ) eBrakeGrp = bgTail;
120   else if (sBrakeGroup == "NONE"  ) eBrakeGrp = bgNone;
121   else if (sBrakeGroup.empty()    ) {eBrakeGrp = bgNone;
122                                      sBrakeGroup = "NONE (defaulted)";}
123   else {
124     cerr << "Improper braking group specification in config file: "
125          << sBrakeGroup << " is undefined." << endl;
126   }
127
128   if      (sSteerType == "STEERABLE") eSteerType = stSteer;
129   else if (sSteerType == "FIXED"    ) eSteerType = stFixed;
130   else if (sSteerType == "CASTERED" ) eSteerType = stCaster;
131   else if (sSteerType.empty()       ) {eSteerType = stFixed;
132                                        sSteerType = "FIXED (defaulted)";}
133   else {
134     cerr << "Improper steering type specification in config file: "
135          << sSteerType << " is undefined." << endl;
136   }
137
138   RFRV = 0.7;  // Rolling force relaxation velocity, default value
139   SFRV = 0.7;  // Side force relaxation velocity, default value
140
141   Element* relax_vel = el->FindElement("relaxation_velocity");
142   if (relax_vel) {
143     if (relax_vel->FindElement("rolling")) {
144       RFRV = relax_vel->FindElementValueAsNumberConvertTo("rolling", "FT/SEC");
145     }
146     if (relax_vel->FindElement("side")) {
147       SFRV = relax_vel->FindElementValueAsNumberConvertTo("side", "FT/SEC");
148     }
149   }
150
151   State = Exec->GetState();
152   LongForceLagFilterCoeff = 1/State->Getdt(); // default longitudinal force filter coefficient
153   LatForceLagFilterCoeff  = 1/State->Getdt(); // default lateral force filter coefficient
154
155   Element* force_lag_filter_elem = el->FindElement("force_lag_filter");
156   if (force_lag_filter_elem) {
157     if (force_lag_filter_elem->FindElement("rolling")) {
158       LongForceLagFilterCoeff = force_lag_filter_elem->FindElementValueAsNumber("rolling");
159     }
160     if (force_lag_filter_elem->FindElement("side")) {
161       LatForceLagFilterCoeff = force_lag_filter_elem->FindElementValueAsNumber("side");
162     }
163   }
164
165   WheelSlipLagFilterCoeff = 1/State->Getdt();
166
167   Element *wheel_slip_angle_lag_elem = el->FindElement("wheel_slip_filter");
168   if (wheel_slip_angle_lag_elem) {
169     WheelSlipLagFilterCoeff = wheel_slip_angle_lag_elem->GetDataAsNumber();
170   }
171   
172   GearUp = false;
173   GearDown = true;
174   Servicable = true;
175
176 // Add some AI here to determine if gear is located properly according to its
177 // brake group type ??
178
179   State       = Exec->GetState();
180   Aircraft    = Exec->GetAircraft();
181   Propagate   = Exec->GetPropagate();
182   Auxiliary   = Exec->GetAuxiliary();
183   FCS         = Exec->GetFCS();
184   MassBalance = Exec->GetMassBalance();
185
186   WOW = lastWOW = false;
187   ReportEnable = true;
188   FirstContact = false;
189   StartedGroundRun = false;
190   TakeoffReported = LandingReported = false;
191   LandingDistanceTraveled = TakeoffDistanceTraveled = TakeoffDistanceTraveled50ft = 0.0;
192   MaximumStrutForce = MaximumStrutTravel = 0.0;
193   SideForce = RollingForce = 0.0;
194   SinkRate = GroundSpeed = 0.0;
195
196   vWhlBodyVec = MassBalance->StructuralToBody(vXYZ);
197
198   vLocalGear = Propagate->GetTb2l() * vWhlBodyVec;
199
200   compressLength  = 0.0;
201   compressSpeed   = 0.0;
202   brakePct        = 0.0;
203   maxCompLen      = 0.0;
204
205   WheelSlip = 0.0;
206   TirePressureNorm = 1.0;
207
208   Debug(0);
209 }
210
211 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212
213 FGLGear::FGLGear(const FGLGear& lgear)
214 {
215   GearNumber = lgear.GearNumber;
216   State    = lgear.State;
217   Aircraft = lgear.Aircraft;
218   Propagate = lgear.Propagate;
219   Auxiliary = lgear.Auxiliary;
220   Exec     = lgear.Exec;
221   FCS      = lgear.FCS;
222   MassBalance = lgear.MassBalance;
223
224   vXYZ = lgear.vXYZ;
225   vMoment = lgear.vMoment;
226   vWhlBodyVec = lgear.vWhlBodyVec;
227   vLocalGear = lgear.vLocalGear;
228
229   WOW                = lgear.WOW;
230   lastWOW            = lgear.lastWOW;
231   ReportEnable       = lgear.ReportEnable;
232   FirstContact       = lgear.FirstContact;
233   StartedGroundRun   = lgear.StartedGroundRun;
234   LandingDistanceTraveled   = lgear.LandingDistanceTraveled;
235   TakeoffDistanceTraveled   = lgear.TakeoffDistanceTraveled;
236   TakeoffDistanceTraveled50ft   = lgear.TakeoffDistanceTraveled50ft;
237   MaximumStrutForce  = lgear.MaximumStrutForce;
238   MaximumStrutTravel = lgear.MaximumStrutTravel;
239   SideForce          = lgear.SideForce;
240   RollingForce       = lgear.RollingForce;
241
242   kSpring         = lgear.kSpring;
243   bDamp           = lgear.bDamp;
244   bDampRebound    = lgear.bDampRebound;
245   compressLength  = lgear.compressLength;
246   compressSpeed   = lgear.compressSpeed;
247   staticFCoeff    = lgear.staticFCoeff;
248   dynamicFCoeff   = lgear.dynamicFCoeff;
249   rollingFCoeff   = lgear.rollingFCoeff;
250   brakePct        = lgear.brakePct;
251   maxCompLen      = lgear.maxCompLen;
252   SinkRate        = lgear.SinkRate;
253   GroundSpeed     = lgear.GroundSpeed;
254   LandingReported = lgear.LandingReported;
255   TakeoffReported = lgear.TakeoffReported;
256   name            = lgear.name;
257   sSteerType      = lgear.sSteerType;
258   sRetractable    = lgear.sRetractable;
259   sContactType    = lgear.sContactType;
260   sBrakeGroup     = lgear.sBrakeGroup;
261   eSteerType      = lgear.eSteerType;
262   eBrakeGrp       = lgear.eBrakeGrp;
263   maxSteerAngle   = lgear.maxSteerAngle;
264   isRetractable   = lgear.isRetractable;
265   GearUp          = lgear.GearUp;
266   GearDown        = lgear.GearDown;
267   WheelSlip       = lgear.WheelSlip;
268   TirePressureNorm = lgear.TirePressureNorm;
269   Servicable      = lgear.Servicable;
270   ForceY_Table    = lgear.ForceY_Table;
271   CosWheel        = lgear.CosWheel;
272   SinWheel        = lgear.SinWheel;
273   prevOut         = lgear.prevOut;
274   prevIn          = lgear.prevIn;
275   prevSlipIn      = lgear.prevSlipIn;
276   prevSlipOut     = lgear.prevSlipOut;
277   RFRV            = lgear.RFRV;
278   SFRV            = lgear.SFRV;
279   LongForceLagFilterCoeff = lgear.LongForceLagFilterCoeff;
280   LatForceLagFilterCoeff = lgear.LatForceLagFilterCoeff;
281   WheelSlipLagFilterCoeff = lgear.WheelSlipLagFilterCoeff;
282 }
283
284 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285
286 FGLGear::~FGLGear()
287 {
288   Debug(1);
289 }
290
291 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292
293 FGColumnVector3& FGLGear::Force(void)
294 {
295   FGColumnVector3 normal, cvel;
296   FGLocation contact, gearLoc;
297   double t = Exec->GetState()->Getsim_time();
298   dT = State->Getdt()*Exec->GetGroundReactions()->GetRate();
299
300   vForce.InitMatrix();
301   vMoment.InitMatrix();
302
303   if (isRetractable) ComputeRetractionState();
304
305   if (GearUp) return vForce;
306
307   vWhlBodyVec = MassBalance->StructuralToBody(vXYZ); // Get wheel in body frame
308   vLocalGear = Propagate->GetTb2l() * vWhlBodyVec; // Get local frame wheel location
309
310   gearLoc = Propagate->GetLocation().LocalToLocation(vLocalGear);
311   compressLength = -Exec->GetGroundCallback()->GetAGLevel(t, gearLoc, contact, normal, cvel);
312
313   // The compression length is measured in the Z-axis, only, at this time.
314
315   if (compressLength > 0.00) {
316
317     WOW = true;
318
319     // [The next equation should really use the vector to the contact patch of
320     // the tire including the strut compression and not the original vWhlBodyVec.]
321
322     vWhlVelVec      =  Propagate->GetTb2l() * (Propagate->GetPQR() * vWhlBodyVec);
323     vWhlVelVec     +=  Propagate->GetVel() - cvel;
324     compressSpeed   =  vWhlVelVec(eZ);
325
326     InitializeReporting();
327     ComputeBrakeForceCoefficient();
328     ComputeSteeringAngle();
329     ComputeSlipAngle();
330     ComputeSideForceCoefficient();
331     ComputeVerticalStrutForce();
332
333     // Compute the forces in the wheel ground plane.
334
335     RollingForce = ((1.0 - TirePressureNorm) * 30
336                    + vLocalForce(eZ) * BrakeFCoeff) * (RollingWhlVel>=0?1.0:-1.0);
337
338     SideForce    = vLocalForce(eZ) * FCoeff;
339
340     // Transform these forces back to the local reference frame.
341
342     vLocalForce(eX) = RollingForce*CosWheel - SideForce*SinWheel;
343     vLocalForce(eY) = SideForce*CosWheel    + RollingForce*SinWheel;
344
345     // Transform the forces back to the body frame and compute the moment.
346
347     vForce  = Propagate->GetTl2b() * vLocalForce;
348
349 // Start experimental section for gear jitter reduction
350 //
351 // Lag and attenuate the XY-plane forces dependent on velocity
352
353     double ca, cb, denom;
354     FGColumnVector3 Output;
355
356 // This code implements a lag filter, C/(s + C) where
357 // "C" is the filter coefficient. When "C" is chosen at the 
358 // frame rate (in Hz), the jittering is significantly reduced. This is because
359 // the jitter is present *at* the execution rate.
360 // If a coefficient is set to something equal to or less than zero, the filter
361 // is bypassed.
362
363     if (LongForceLagFilterCoeff > 0) { 
364       denom = 2.00 + dT*LongForceLagFilterCoeff;
365       ca = dT*LongForceLagFilterCoeff / denom;
366       cb = (2.00 - dT*LongForceLagFilterCoeff) / denom;
367       Output(eX) = vForce(eX) * ca + prevIn(eX) * ca + prevOut(eX) * cb;
368       vForce(eX) = Output(eX);
369     }
370     if (LatForceLagFilterCoeff > 0) { 
371       denom = 2.00 + dT*LatForceLagFilterCoeff;
372       ca = dT*LatForceLagFilterCoeff / denom;
373       cb = (2.00 - dT*LatForceLagFilterCoeff) / denom;
374       Output(eY) = vForce(eY) * ca + prevIn(eY) * ca + prevOut(eY) * cb;
375       vForce(eY) = Output(eY);
376     }
377
378     prevIn = vForce;
379     prevOut = Output;
380
381     if ((fabs(RollingWhlVel) <= RFRV) && RFRV > 0) vForce(eX) *= fabs(RollingWhlVel)/RFRV;
382     if ((fabs(SideWhlVel) <= SFRV) && SFRV > 0) vForce(eY) *= fabs(SideWhlVel)/SFRV;
383
384 // End section for attentuating gear jitter
385
386     vMoment = vWhlBodyVec * vForce;
387
388   } else { // Gear is NOT compressed
389
390     WOW = false;
391     compressLength = 0.0;
392
393     // Return to neutral position between 1.0 and 0.8 gear pos.
394     SteerAngle *= max(FCS->GetGearPos()-0.8, 0.0)/0.2;
395
396     ResetReporting();
397   }
398
399   ReportTakeoffOrLanding();
400   CrashDetect();
401
402   return vForce;
403 }
404
405 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406
407 void FGLGear::ComputeRetractionState(void)
408 {
409   if (FCS->GetGearPos() < 0.01) {
410     GearUp   = true;
411     GearDown = false;
412   } else if (FCS->GetGearPos() > 0.99) {
413     GearDown = true;
414     GearUp   = false;
415   } else {
416     GearUp   = false;
417     GearDown = false;
418   }
419 }
420
421 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422
423 void FGLGear::ComputeSlipAngle(void)
424 {
425   // Transform the wheel velocities from the local axis system to the wheel axis system.
426   RollingWhlVel = vWhlVelVec(eX)*CosWheel + vWhlVelVec(eY)*SinWheel;
427   SideWhlVel    = vWhlVelVec(eY)*CosWheel - vWhlVelVec(eX)*SinWheel;
428
429   // Calculate tire slip angle.
430     WheelSlip = atan2(SideWhlVel, fabs(RollingWhlVel))*radtodeg;
431
432   // Filter the wheel slip angle
433
434   double SlipOutput, ca, cb, denom;
435
436   if (WheelSlipLagFilterCoeff > 0) {
437     denom = 2.00 + dT*WheelSlipLagFilterCoeff;
438     ca = dT*WheelSlipLagFilterCoeff / denom;
439     cb = (2.00 - dT*WheelSlipLagFilterCoeff) / denom;
440
441     SlipOutput = ca * (WheelSlip + prevSlipIn) + cb * prevSlipOut;
442
443     prevSlipIn = WheelSlip;
444     WheelSlip = prevSlipOut = SlipOutput;
445   }
446 }
447
448 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
449 // Compute the steering angle in any case.
450 // This will also make sure that animations will look right.
451
452 void FGLGear::ComputeSteeringAngle(void)
453 {
454   switch (eSteerType) {
455   case stSteer:
456     SteerAngle = degtorad * FCS->GetSteerPosDeg(GearNumber);
457     break;
458   case stFixed:
459     SteerAngle = 0.0;
460     break;
461   case stCaster:
462     // This is not correct for castering gear. Should make steer angle parallel
463     // to the actual velocity vector of the wheel, given aircraft velocity vector
464     // and omega.
465     SteerAngle = 0.0;
466     break;
467   default:
468     cerr << "Improper steering type membership detected for this gear." << endl;
469     break;
470   }
471
472   SinWheel      = sin(Propagate->GetEuler(ePsi) + SteerAngle);
473   CosWheel      = cos(Propagate->GetEuler(ePsi) + SteerAngle);
474 }
475
476 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
477 // Reset reporting functionality after takeoff
478
479 void FGLGear::ResetReporting(void)
480 {
481   if (Propagate->GetDistanceAGL() > 200.0) {
482     FirstContact = false;
483     StartedGroundRun = false;
484     LandingReported = false;
485     LandingDistanceTraveled = 0.0;
486     MaximumStrutForce = MaximumStrutTravel = 0.0;
487   }
488 }
489
490 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
491
492 void FGLGear::InitializeReporting(void)
493 {
494   // If this is the first time the wheel has made contact, remember some values
495   // for later printout.
496
497   if (!FirstContact) {
498     FirstContact  = true;
499     SinkRate      =  compressSpeed;
500     GroundSpeed   =  Propagate->GetVel().Magnitude();
501     TakeoffReported = false;
502   }
503
504   // If the takeoff run is starting, initialize.
505
506   if ((Propagate->GetVel().Magnitude() > 0.1) &&
507       (FCS->GetBrake(bgLeft) == 0) &&
508       (FCS->GetBrake(bgRight) == 0) &&
509       (FCS->GetThrottlePos(0) == 1) && !StartedGroundRun)
510   {
511     TakeoffDistanceTraveled = 0;
512     TakeoffDistanceTraveled50ft = 0;
513     StartedGroundRun = true;
514   }
515 }
516
517 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
518 // Takeoff and landing reporting functionality
519
520 void FGLGear::ReportTakeoffOrLanding(void)
521 {
522   double deltaT = State->Getdt()*Exec->GetGroundReactions()->GetRate();
523
524   if (FirstContact) LandingDistanceTraveled += Auxiliary->GetVground()*deltaT;
525
526   if (StartedGroundRun) {
527      TakeoffDistanceTraveled50ft += Auxiliary->GetVground()*deltaT;
528     if (WOW) TakeoffDistanceTraveled += Auxiliary->GetVground()*deltaT;
529   }
530
531   if (ReportEnable && Auxiliary->GetVground() <= 0.05 && !LandingReported) {
532     if (debug_lvl > 0) Report(erLand);
533   }
534
535   if (ReportEnable && !TakeoffReported &&
536      (vLocalGear(eZ) - Propagate->GetDistanceAGL()) < -50.0)
537   {
538     if (debug_lvl > 0) Report(erTakeoff);
539   }
540
541   if (lastWOW != WOW) PutMessage("GEAR_CONTACT: " + name, WOW);
542   lastWOW = WOW;
543 }
544
545 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
546 // Crash detection logic (really out-of-bounds detection)
547
548 void FGLGear::CrashDetect(void)
549 {
550   if ( (compressLength > 500.0 ||
551       vForce.Magnitude() > 100000000.0 ||
552       vMoment.Magnitude() > 5000000000.0 ||
553       SinkRate > 1.4666*30 ) && !State->IntegrationSuspended())
554   {
555     PutMessage("Crash Detected: Simulation FREEZE.");
556     State->SuspendIntegration();
557   }
558 }
559
560 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
561 // The following needs work regarding friction coefficients and braking and
562 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
563 // It also assumes that we won't be turning and braking at the same time.
564 // Will fix this later.
565 // [JSB] The braking force coefficients include normal rolling coefficient +
566 // a percentage of the static friction coefficient based on braking applied.
567
568 void FGLGear::ComputeBrakeForceCoefficient(void)
569 {
570   switch (eBrakeGrp) {
571   case bgLeft:
572     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgLeft)) +
573                      staticFCoeff*FCS->GetBrake(bgLeft) );
574     break;
575   case bgRight:
576     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgRight)) +
577                      staticFCoeff*FCS->GetBrake(bgRight) );
578     break;
579   case bgCenter:
580     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
581                      staticFCoeff*FCS->GetBrake(bgCenter) );
582     break;
583   case bgNose:
584     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
585                      staticFCoeff*FCS->GetBrake(bgCenter) );
586     break;
587   case bgTail:
588     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
589                      staticFCoeff*FCS->GetBrake(bgCenter) );
590     break;
591   case bgNone:
592     BrakeFCoeff =  rollingFCoeff;
593     break;
594   default:
595     cerr << "Improper brake group membership detected for this gear." << endl;
596     break;
597   }
598 }
599
600 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 // Compute the sideforce coefficients using similar assumptions to LaRCSim for now.
602 // Allow a maximum of 10 degrees tire slip angle before wheel slides.  At that point,
603 // transition from static to dynamic friction.  There are more complicated formulations
604 // of this that avoid the discrete jump (similar to Pacejka).  Will fix this later.
605
606 void FGLGear::ComputeSideForceCoefficient(void)
607 {
608   if (ForceY_Table) {
609
610     FCoeff = ForceY_Table->GetValue(WheelSlip);
611
612   } else {
613
614     if (fabs(WheelSlip) <= 10.0) {
615       FCoeff = staticFCoeff*WheelSlip/10.0;
616     } else if (fabs(WheelSlip) <= 40.0) {
617       FCoeff = (dynamicFCoeff*(fabs(WheelSlip) - 10.0)/10.0
618                 + staticFCoeff*(40.0 - fabs(WheelSlip))/10.0)*(WheelSlip>=0?1.0:-1.0);
619     } else {
620       FCoeff = dynamicFCoeff*(WheelSlip>=0?1.0:-1.0);
621     }
622   }
623 }
624
625 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
626 // Compute the vertical force on the wheel using square-law damping (per comment
627 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
628 // allowing for both square and linear damping force calculation. Also need to
629 // possibly give a "rebound damping factor" that differs from the compression
630 // case.
631
632 void FGLGear::ComputeVerticalStrutForce(void)
633 {
634   double springForce = 0;
635   double dampForce = 0;
636
637   springForce = -compressLength * kSpring;
638
639   if (compressSpeed >= 0.0) {
640     dampForce   = -compressSpeed * bDamp;
641   } else {
642     dampForce   = -compressSpeed * bDampRebound;
643   }
644   vLocalForce(eZ) =  min(springForce + dampForce, (double)0.0);
645
646   // Remember these values for reporting
647   MaximumStrutForce = max(MaximumStrutForce, fabs(vLocalForce(eZ)));
648   MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
649 }
650
651 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652
653 void FGLGear::bind(void)
654 {
655   char property_name[80];
656   snprintf(property_name, 80, "gear/unit[%d]/slip-angle-deg", GearNumber);
657   Exec->GetPropertyManager()->Tie( property_name, &WheelSlip );
658 }
659
660 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
661
662 void FGLGear::unbind(void)
663 {
664   char property_name[80];
665   snprintf(property_name, 80, "gear/unit[%d]/slip-angle-deg", GearNumber);
666   Exec->GetPropertyManager()->Untie( property_name );
667 }
668
669 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670
671 void FGLGear::Report(ReportType repType)
672 {
673   switch(repType) {
674   case erLand:
675     cout << endl << "Touchdown report for " << name << endl;
676     cout << "  Sink rate at contact:  " << SinkRate                << " fps,    "
677                                 << SinkRate*0.3048          << " mps"     << endl;
678     cout << "  Contact ground speed:  " << GroundSpeed*.5925       << " knots,  "
679                                 << GroundSpeed*0.3048       << " mps"     << endl;
680     cout << "  Maximum contact force: " << MaximumStrutForce       << " lbs,    "
681                                 << MaximumStrutForce*4.448  << " Newtons" << endl;
682     cout << "  Maximum strut travel:  " << MaximumStrutTravel*12.0 << " inches, "
683                                 << MaximumStrutTravel*30.48 << " cm"      << endl;
684     cout << "  Distance traveled:     " << LandingDistanceTraveled        << " ft,     "
685                                 << LandingDistanceTraveled*0.3048  << " meters"  << endl;
686     LandingReported = true;
687     break;
688   case erTakeoff:
689     cout << endl << "Takeoff report for " << name << endl;
690     cout << "  Distance traveled:                " << TakeoffDistanceTraveled
691          << " ft,     " << TakeoffDistanceTraveled*0.3048  << " meters"  << endl;
692     cout << "  Distance traveled (over 50'):     " << TakeoffDistanceTraveled50ft
693          << " ft,     " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl;
694     TakeoffReported = true;
695     break;
696   }
697 }
698
699 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
700 //    The bitmasked value choices are as follows:
701 //    unset: In this case (the default) JSBSim would only print
702 //       out the normally expected messages, essentially echoing
703 //       the config files as they are read. If the environment
704 //       variable is not set, debug_lvl is set to 1 internally
705 //    0: This requests JSBSim not to output any messages
706 //       whatsoever.
707 //    1: This value explicity requests the normal JSBSim
708 //       startup messages
709 //    2: This value asks for a message to be printed out when
710 //       a class is instantiated
711 //    4: When this value is set, a message is displayed when a
712 //       FGModel object executes its Run() method
713 //    8: When this value is set, various runtime state variables
714 //       are printed out periodically
715 //    16: When set various parameters are sanity checked and
716 //       a message is printed out when they go out of bounds
717
718 void FGLGear::Debug(int from)
719 {
720   if (debug_lvl <= 0) return;
721
722   if (debug_lvl & 1) { // Standard console startup message output
723     if (from == 0) { // Constructor - loading and initialization
724       cout << "    " << sContactType << " " << name          << endl;
725       cout << "      Location: "         << vXYZ          << endl;
726       cout << "      Spring Constant:  " << kSpring       << endl;
727       cout << "      Damping Constant: " << bDamp         << endl;
728       cout << "      Dynamic Friction: " << dynamicFCoeff << endl;
729       cout << "      Static Friction:  " << staticFCoeff  << endl;
730       if (sContactType == "BOGEY") {
731         cout << "      Rolling Friction: " << rollingFCoeff << endl;
732         cout << "      Steering Type:    " << sSteerType    << endl;
733         cout << "      Grouping:         " << sBrakeGroup   << endl;
734         cout << "      Max Steer Angle:  " << maxSteerAngle << endl;
735         cout << "      Retractable:      " << isRetractable  << endl;
736         cout << "      Relaxation Velocities:" << endl;
737         cout << "        Rolling:          " << RFRV << endl;
738         cout << "        Side:             " << SFRV << endl;
739       }
740     }
741   }
742   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
743     if (from == 0) cout << "Instantiated: FGLGear" << endl;
744     if (from == 1) cout << "Destroyed:    FGLGear" << endl;
745   }
746   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
747   }
748   if (debug_lvl & 8 ) { // Runtime state variables
749   }
750   if (debug_lvl & 16) { // Sanity checking
751   }
752   if (debug_lvl & 64) {
753     if (from == 0) { // Constructor
754       cout << IdSrc << endl;
755       cout << IdHdr << endl;
756     }
757   }
758 }
759
760 } // namespace JSBSim
761