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