]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGLGear.cpp
6f3d6f2fadd5086c580d50bf1aac72d826450b58
[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 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 General Public License for more
20  details.
21
22  You should have received a copy of the GNU 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 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 = (int)el->FindElementValueAsNumber("retractable");
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   GearUp = false;
139   GearDown = true;
140   Servicable = true;
141
142 // Add some AI here to determine if gear is located properly according to its
143 // brake group type ??
144
145   State       = Exec->GetState();
146   Aircraft    = Exec->GetAircraft();
147   Propagate   = Exec->GetPropagate();
148   Auxiliary   = Exec->GetAuxiliary();
149   FCS         = Exec->GetFCS();
150   MassBalance = Exec->GetMassBalance();
151
152   WOW = lastWOW = true; // should the value be initialized to true?
153   ReportEnable = true;
154   FirstContact = false;
155   StartedGroundRun = false;
156   TakeoffReported = LandingReported = false;
157   LandingDistanceTraveled = TakeoffDistanceTraveled = TakeoffDistanceTraveled50ft = 0.0;
158   MaximumStrutForce = MaximumStrutTravel = 0.0;
159   SideForce = RollingForce = 0.0;
160   SinkRate = GroundSpeed = 0.0;
161
162   vWhlBodyVec = MassBalance->StructuralToBody(vXYZ);
163
164   vLocalGear = Propagate->GetTb2l() * vWhlBodyVec;
165
166   compressLength  = 0.0;
167   compressSpeed   = 0.0;
168   brakePct        = 0.0;
169   maxCompLen      = 0.0;
170
171   WheelSlip = last_WheelSlip = 0.0;
172   slipIn = last_SlipIn = 0;
173   TirePressureNorm = 1.0;
174
175   Debug(0);
176 }
177
178 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179
180 FGLGear::FGLGear(const FGLGear& lgear)
181 {
182   GearNumber = lgear.GearNumber;
183   State    = lgear.State;
184   Aircraft = lgear.Aircraft;
185   Propagate = lgear.Propagate;
186   Auxiliary = lgear.Auxiliary;
187   Exec     = lgear.Exec;
188   FCS      = lgear.FCS;
189   MassBalance = lgear.MassBalance;
190
191   vXYZ = lgear.vXYZ;
192   vMoment = lgear.vMoment;
193   vWhlBodyVec = lgear.vWhlBodyVec;
194   vLocalGear = lgear.vLocalGear;
195
196   WOW                = lgear.WOW;
197   lastWOW            = lgear.lastWOW;
198   ReportEnable       = lgear.ReportEnable;
199   FirstContact       = lgear.FirstContact;
200   StartedGroundRun   = lgear.StartedGroundRun;
201   LandingDistanceTraveled   = lgear.LandingDistanceTraveled;
202   TakeoffDistanceTraveled   = lgear.TakeoffDistanceTraveled;
203   TakeoffDistanceTraveled50ft   = lgear.TakeoffDistanceTraveled50ft;
204   MaximumStrutForce  = lgear.MaximumStrutForce;
205   MaximumStrutTravel = lgear.MaximumStrutTravel;
206   SideForce          = lgear.SideForce;
207   RollingForce       = lgear.RollingForce;
208
209   kSpring         = lgear.kSpring;
210   bDamp           = lgear.bDamp;
211   bDampRebound    = lgear.bDampRebound;
212   compressLength  = lgear.compressLength;
213   compressSpeed   = lgear.compressSpeed;
214   staticFCoeff    = lgear.staticFCoeff;
215   dynamicFCoeff   = lgear.dynamicFCoeff;
216   rollingFCoeff   = lgear.rollingFCoeff;
217   brakePct        = lgear.brakePct;
218   maxCompLen      = lgear.maxCompLen;
219   SinkRate        = lgear.SinkRate;
220   GroundSpeed     = lgear.GroundSpeed;
221   LandingReported = lgear.LandingReported;
222   TakeoffReported = lgear.TakeoffReported;
223   name            = lgear.name;
224   sSteerType      = lgear.sSteerType;
225   sRetractable    = lgear.sRetractable;
226   sContactType    = lgear.sContactType;
227   sBrakeGroup     = lgear.sBrakeGroup;
228   eSteerType      = lgear.eSteerType;
229   eBrakeGrp       = lgear.eBrakeGrp;
230   maxSteerAngle   = lgear.maxSteerAngle;
231   isRetractable   = lgear.isRetractable;
232   GearUp          = lgear.GearUp;
233   GearDown        = lgear.GearDown;
234   WheelSlip       = lgear.WheelSlip;
235   TirePressureNorm = lgear.TirePressureNorm;
236   Servicable      = lgear.Servicable;
237   ForceY_Table    = lgear.ForceY_Table;
238   CosWheel        = lgear.CosWheel;
239   SinWheel        = lgear.SinWheel;
240   In              = lgear.In;
241   prevIn          = lgear.prevIn;
242   prevOut         = lgear.prevOut;
243   slipIn          = lgear.slipIn;
244   last_SlipIn     = lgear.last_SlipIn;
245   last_WheelSlip  = lgear.last_WheelSlip;
246 }
247
248 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249
250 FGLGear::~FGLGear()
251 {
252   Debug(1);
253 }
254
255 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256
257 FGColumnVector3& FGLGear::Force(void)
258 {
259   FGColumnVector3 normal, cvel;
260   FGLocation contact, gearLoc;
261   double t = Exec->GetState()->Getsim_time();
262
263   vForce.InitMatrix();
264   vMoment.InitMatrix();
265
266   if (isRetractable) ComputeRetractionState();
267
268   if (GearUp) return vForce;
269
270   vWhlBodyVec = MassBalance->StructuralToBody(vXYZ); // Get wheel in body frame
271   vLocalGear = Propagate->GetTb2l() * vWhlBodyVec; // Get local frame wheel location
272
273   gearLoc = Propagate->GetLocation().LocalToLocation(vLocalGear);
274   compressLength = -Exec->GetGroundCallback()->GetAGLevel(t, gearLoc, contact, normal, cvel);
275
276   // The compression length is measured in the Z-axis, only, at this time.
277
278   if (compressLength > 0.00) {
279
280     WOW = true;
281
282     // [The next equation should really use the vector to the contact patch of
283     // the tire including the strut compression and not the original vWhlBodyVec.]
284
285     vWhlVelVec      =  Propagate->GetTb2l() * (Propagate->GetPQR() * vWhlBodyVec);
286     vWhlVelVec     +=  Propagate->GetVel() - cvel;
287     compressSpeed   =  vWhlVelVec(eZ);
288
289     InitializeReporting();
290     ComputeBrakeForceCoefficient();
291     ComputeSteeringAngle();
292     ComputeSlipAngle();
293     ComputeSideForceCoefficient();
294     ComputeVerticalStrutForce();
295
296     // Compute the forces in the wheel ground plane.
297
298     RollingForce = (1.0 - TirePressureNorm) * 30
299                    + vLocalForce(eZ) * BrakeFCoeff * (RollingWhlVel>=0?1.0:-1.0);
300     SideForce    = vLocalForce(eZ) * FCoeff;
301
302     // Transform these forces back to the local reference frame.
303
304     vLocalForce(eX) = RollingForce*CosWheel - SideForce*SinWheel;
305     vLocalForce(eY) = SideForce*CosWheel    + RollingForce*SinWheel;
306
307     // Transform the forces back to the body frame and compute the moment.
308
309     vForce  = Propagate->GetTl2b() * vLocalForce;
310
311     // Lag and attenuate the XY-plane forces dependent on velocity
312
313     double RFRV = 0.015; // Rolling force relaxation velocity
314     double SFRV = 0.25;  // Side force relaxation velocity
315     double dT = State->Getdt()*Exec->GetGroundReactions()->GetRate();
316
317     In = vForce;
318     vForce(eX) = (0.25)*(In(eX) + prevIn(eX)) + (0.50)*prevOut(eX);
319     vForce(eY) = (0.15)*(In(eY) + prevIn(eY)) + (0.70)*prevOut(eY);
320     prevOut = vForce;
321     prevIn = In;
322
323     if (fabs(RollingWhlVel) <= RFRV) vForce(eX) *= fabs(RollingWhlVel)/RFRV;
324     if (fabs(SideWhlVel) <= SFRV) vForce(eY) *= fabs(SideWhlVel)/SFRV;
325
326     vMoment = vWhlBodyVec * vForce;
327
328   } else { // Gear is NOT compressed
329
330     WOW = false;
331     compressLength = 0.0;
332
333     // Return to neutral position between 1.0 and 0.8 gear pos.
334     SteerAngle *= max(FCS->GetGearPos()-0.8, 0.0)/0.2;
335
336     ResetReporting();
337   }
338
339   ReportTakeoffOrLanding();
340   CrashDetect();
341
342   return vForce;
343 }
344
345 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346
347 void FGLGear::ComputeRetractionState(void)
348 {
349   if (FCS->GetGearPos() < 0.01) {
350     GearUp   = true;
351     GearDown = false;
352   } else if (FCS->GetGearPos() > 0.99) {
353     GearDown = true;
354     GearUp   = false;
355   } else {
356     GearUp   = false;
357     GearDown = false;
358   }
359 }
360
361 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
362
363 void FGLGear::ComputeSlipAngle(void)
364 {
365   double dT = State->Getdt()*Exec->GetGroundReactions()->GetRate();
366
367   // Transform the wheel velocities from the local axis system to the wheel axis system.
368
369   RollingWhlVel = vWhlVelVec(eX)*CosWheel + vWhlVelVec(eY)*SinWheel;
370   SideWhlVel    = vWhlVelVec(eY)*CosWheel - vWhlVelVec(eX)*SinWheel;
371
372   // Calculate tire slip angle.
373
374   if (fabs(RollingWhlVel) < 0.1 && fabs(SideWhlVel) < 0.01) {
375     WheelSlip = -SteerAngle*radtodeg;
376   } else {
377     WheelSlip = atan2(SideWhlVel, fabs(RollingWhlVel))*radtodeg;
378   }
379   slipIn = WheelSlip;
380   WheelSlip = (0.46)*(slipIn + last_SlipIn) + (0.08)*last_WheelSlip;
381   last_WheelSlip = WheelSlip;
382   last_SlipIn = slipIn;
383 }
384
385 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386 // Compute the steering angle in any case.
387 // This will also make sure that animations will look right.
388
389 void FGLGear::ComputeSteeringAngle(void)
390 {
391   switch (eSteerType) {
392   case stSteer:
393     SteerAngle = degtorad * FCS->GetSteerPosDeg(GearNumber);
394     break;
395   case stFixed:
396     SteerAngle = 0.0;
397     break;
398   case stCaster:
399     // This is not correct for castering gear. Should make steer angle parallel
400     // to the actual velocity vector of the wheel, given aircraft velocity vector
401     // and omega.
402     SteerAngle = 0.0;
403     break;
404   default:
405     cerr << "Improper steering type membership detected for this gear." << endl;
406     break;
407   }
408
409   SinWheel      = sin(Propagate->GetEuler(ePsi) + SteerAngle);
410   CosWheel      = cos(Propagate->GetEuler(ePsi) + SteerAngle);
411 }
412
413 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414 // Reset reporting functionality after takeoff
415
416 void FGLGear::ResetReporting(void)
417 {
418   if (Propagate->GetDistanceAGL() > 200.0) {
419     FirstContact = false;
420     StartedGroundRun = false;
421     LandingReported = false;
422     LandingDistanceTraveled = 0.0;
423     MaximumStrutForce = MaximumStrutTravel = 0.0;
424   }
425 }
426
427 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428
429 void FGLGear::InitializeReporting(void)
430 {
431   // If this is the first time the wheel has made contact, remember some values
432   // for later printout.
433
434   if (!FirstContact) {
435     FirstContact  = true;
436     SinkRate      =  compressSpeed;
437     GroundSpeed   =  Propagate->GetVel().Magnitude();
438     TakeoffReported = false;
439   }
440
441   // If the takeoff run is starting, initialize.
442
443   if ((Propagate->GetVel().Magnitude() > 0.1) &&
444       (FCS->GetBrake(bgLeft) == 0) &&
445       (FCS->GetBrake(bgRight) == 0) &&
446       (FCS->GetThrottlePos(0) == 1) && !StartedGroundRun)
447   {
448     TakeoffDistanceTraveled = 0;
449     TakeoffDistanceTraveled50ft = 0;
450     StartedGroundRun = true;
451   }
452 }
453
454 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
455 // Takeoff and landing reporting functionality
456
457 void FGLGear::ReportTakeoffOrLanding(void)
458 {
459   double deltaT = State->Getdt()*Exec->GetGroundReactions()->GetRate();
460
461   if (FirstContact) LandingDistanceTraveled += Auxiliary->GetVground()*deltaT;
462
463   if (StartedGroundRun) {
464      TakeoffDistanceTraveled50ft += Auxiliary->GetVground()*deltaT;
465     if (WOW) TakeoffDistanceTraveled += Auxiliary->GetVground()*deltaT;
466   }
467
468   if (ReportEnable && Auxiliary->GetVground() <= 0.05 && !LandingReported) {
469     if (debug_lvl > 0) Report(erLand);
470   }
471
472   if (ReportEnable && !TakeoffReported &&
473      (vLocalGear(eZ) - Propagate->GetDistanceAGL()) < -50.0)
474   {
475     if (debug_lvl > 0) Report(erTakeoff);
476   }
477
478   if (lastWOW != WOW) PutMessage("GEAR_CONTACT: " + name, WOW);
479   lastWOW = WOW;
480 }
481
482 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483 // Crash detection logic (really out-of-bounds detection)
484
485 void FGLGear::CrashDetect(void)
486 {
487   if (compressLength > 500.0 ||
488       vForce.Magnitude() > 100000000.0 ||
489       vMoment.Magnitude() > 5000000000.0 ||
490       SinkRate > 1.4666*30)
491   {
492     PutMessage("Crash Detected: Simulation FREEZE.");
493     State->SuspendIntegration();
494   }
495 }
496
497 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498 // The following needs work regarding friction coefficients and braking and
499 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
500 // It also assumes that we won't be turning and braking at the same time.
501 // Will fix this later.
502 // [JSB] The braking force coefficients include normal rolling coefficient +
503 // a percentage of the static friction coefficient based on braking applied.
504
505 void FGLGear::ComputeBrakeForceCoefficient(void)
506 {
507   switch (eBrakeGrp) {
508   case bgLeft:
509     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgLeft)) +
510                      staticFCoeff*FCS->GetBrake(bgLeft) );
511     break;
512   case bgRight:
513     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgRight)) +
514                      staticFCoeff*FCS->GetBrake(bgRight) );
515     break;
516   case bgCenter:
517     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
518                      staticFCoeff*FCS->GetBrake(bgCenter) );
519     break;
520   case bgNose:
521     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
522                      staticFCoeff*FCS->GetBrake(bgCenter) );
523     break;
524   case bgTail:
525     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
526                      staticFCoeff*FCS->GetBrake(bgCenter) );
527     break;
528   case bgNone:
529     BrakeFCoeff =  rollingFCoeff;
530     break;
531   default:
532     cerr << "Improper brake group membership detected for this gear." << endl;
533     break;
534   }
535 }
536
537 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
538 // Compute the sideforce coefficients using similar assumptions to LaRCSim for now.
539 // Allow a maximum of 10 degrees tire slip angle before wheel slides.  At that point,
540 // transition from static to dynamic friction.  There are more complicated formulations
541 // of this that avoid the discrete jump (similar to Pacejka).  Will fix this later.
542
543 void FGLGear::ComputeSideForceCoefficient(void)
544 {
545   if (ForceY_Table) {
546
547     FCoeff = ForceY_Table->GetValue(WheelSlip);
548
549   } else {
550
551     if (fabs(WheelSlip) <= 10.0) {
552       FCoeff = staticFCoeff*WheelSlip/10.0;
553     } else if (fabs(WheelSlip) <= 40.0) {
554       FCoeff = (dynamicFCoeff*(fabs(WheelSlip) - 10.0)/10.0
555                 + staticFCoeff*(40.0 - fabs(WheelSlip))/10.0)*(WheelSlip>=0?1.0:-1.0);
556     } else {
557       FCoeff = dynamicFCoeff*(WheelSlip>=0?1.0:-1.0);
558     }
559   }
560 }
561
562 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
563 // Compute the vertical force on the wheel using square-law damping (per comment
564 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
565 // allowing for both square and linear damping force calculation. Also need to
566 // possibly give a "rebound damping factor" that differs from the compression
567 // case.
568
569 void FGLGear::ComputeVerticalStrutForce(void)
570 {
571   double springForce = 0;
572   double dampForce = 0;
573
574   springForce = -compressLength * kSpring;
575
576   if (compressSpeed >= 0.0) {
577     dampForce   = -compressSpeed * bDamp;
578   } else {
579     dampForce   = -compressSpeed * bDampRebound;
580   }
581   vLocalForce(eZ) =  min(springForce + dampForce, (double)0.0);
582
583   // Remember these values for reporting
584   MaximumStrutForce = max(MaximumStrutForce, fabs(vLocalForce(eZ)));
585   MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
586 }
587
588 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
589
590 void FGLGear::bind(void)
591 {
592   char property_name[80];
593   snprintf(property_name, 80, "gear/unit[%d]/slip-angle-deg", GearNumber);
594   Exec->GetPropertyManager()->Tie( property_name, &WheelSlip );
595 }
596
597 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
598
599 void FGLGear::unbind(void)
600 {
601   char property_name[80];
602   snprintf(property_name, 80, "gear/unit[%d]/slip-angle-deg", GearNumber);
603   Exec->GetPropertyManager()->Untie( property_name );
604 }
605
606 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
607
608 void FGLGear::Report(ReportType repType)
609 {
610   switch(repType) {
611   case erLand:
612     cout << endl << "Touchdown report for " << name << endl;
613     cout << "  Sink rate at contact:  " << SinkRate                << " fps,    "
614                                 << SinkRate*0.3048          << " mps"     << endl;
615     cout << "  Contact ground speed:  " << GroundSpeed*.5925       << " knots,  "
616                                 << GroundSpeed*0.3048       << " mps"     << endl;
617     cout << "  Maximum contact force: " << MaximumStrutForce       << " lbs,    "
618                                 << MaximumStrutForce*4.448  << " Newtons" << endl;
619     cout << "  Maximum strut travel:  " << MaximumStrutTravel*12.0 << " inches, "
620                                 << MaximumStrutTravel*30.48 << " cm"      << endl;
621     cout << "  Distance traveled:     " << LandingDistanceTraveled        << " ft,     "
622                                 << LandingDistanceTraveled*0.3048  << " meters"  << endl;
623     LandingReported = true;
624     break;
625   case erTakeoff:
626     cout << endl << "Takeoff report for " << name << endl;
627     cout << "  Distance traveled:                " << TakeoffDistanceTraveled
628          << " ft,     " << TakeoffDistanceTraveled*0.3048  << " meters"  << endl;
629     cout << "  Distance traveled (over 50'):     " << TakeoffDistanceTraveled50ft
630          << " ft,     " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl;
631     TakeoffReported = true;
632     break;
633   }
634 }
635
636 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
637 //    The bitmasked value choices are as follows:
638 //    unset: In this case (the default) JSBSim would only print
639 //       out the normally expected messages, essentially echoing
640 //       the config files as they are read. If the environment
641 //       variable is not set, debug_lvl is set to 1 internally
642 //    0: This requests JSBSim not to output any messages
643 //       whatsoever.
644 //    1: This value explicity requests the normal JSBSim
645 //       startup messages
646 //    2: This value asks for a message to be printed out when
647 //       a class is instantiated
648 //    4: When this value is set, a message is displayed when a
649 //       FGModel object executes its Run() method
650 //    8: When this value is set, various runtime state variables
651 //       are printed out periodically
652 //    16: When set various parameters are sanity checked and
653 //       a message is printed out when they go out of bounds
654
655 void FGLGear::Debug(int from)
656 {
657   if (debug_lvl <= 0) return;
658
659   if (debug_lvl & 1) { // Standard console startup message output
660     if (from == 0) { // Constructor - loading and initialization
661       cout << "    " << sContactType << " " << name          << endl;
662       cout << "      Location: "         << vXYZ          << endl;
663       cout << "      Spring Constant:  " << kSpring       << endl;
664       cout << "      Damping Constant: " << bDamp         << endl;
665       cout << "      Dynamic Friction: " << dynamicFCoeff << endl;
666       cout << "      Static Friction:  " << staticFCoeff  << endl;
667       if (sContactType == "BOGEY") {
668         cout << "      Rolling Friction: " << rollingFCoeff << endl;
669         cout << "      Steering Type:    " << sSteerType    << endl;
670         cout << "      Grouping:         " << sBrakeGroup   << endl;
671         cout << "      Max Steer Angle:  " << maxSteerAngle << endl;
672         cout << "      Retractable:      " << isRetractable  << endl;
673       }
674     }
675   }
676   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
677     if (from == 0) cout << "Instantiated: FGLGear" << endl;
678     if (from == 1) cout << "Destroyed:    FGLGear" << endl;
679   }
680   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
681   }
682   if (debug_lvl & 8 ) { // Runtime state variables
683   }
684   if (debug_lvl & 16) { // Sanity checking
685   }
686   if (debug_lvl & 64) {
687     if (from == 0) { // Constructor
688       cout << IdSrc << endl;
689       cout << IdHdr << endl;
690     }
691   }
692 }
693
694 } // namespace JSBSim
695