]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGLGear.cpp
Sync w. JSBSim as of 20/01/2007
[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 = (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   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     SideForce    = vLocalForce(eZ) * FCoeff;
338
339     // Transform these forces back to the local reference frame.
340
341     vLocalForce(eX) = RollingForce*CosWheel - SideForce*SinWheel;
342     vLocalForce(eY) = SideForce*CosWheel    + RollingForce*SinWheel;
343
344     // Transform the forces back to the body frame and compute the moment.
345
346     vForce  = Propagate->GetTl2b() * vLocalForce;
347
348 // Start experimental section for gear jitter reduction
349 //
350 // Lag and attenuate the XY-plane forces dependent on velocity
351
352     double ca, cb, denom;
353     FGColumnVector3 Output;
354
355 // This code implements a lag filter, C/(s + C) where
356 // "C" is the filter coefficient. When "C" is chosen at the 
357 // frame rate (in Hz), the jittering is significantly reduced. This is because
358 // the jitter is present *at* the execution rate.
359 // If a coefficient is set to something equal to or less than zero, the filter
360 // is bypassed.
361
362     if (LongForceLagFilterCoeff > 0) { 
363       denom = 2.00 + dT*LongForceLagFilterCoeff;
364       ca = dT*LongForceLagFilterCoeff / denom;
365       cb = (2.00 - dT*LongForceLagFilterCoeff) / denom;
366       Output(eX) = vForce(eX) * ca + prevIn(eX) * ca + prevOut(eX) * cb;
367       vForce(eX) = Output(eX);
368     }
369     if (LatForceLagFilterCoeff > 0) { 
370       denom = 2.00 + dT*LatForceLagFilterCoeff;
371       ca = dT*LatForceLagFilterCoeff / denom;
372       cb = (2.00 - dT*LatForceLagFilterCoeff) / denom;
373       Output(eY) = vForce(eY) * ca + prevIn(eY) * ca + prevOut(eY) * cb;
374       vForce(eY) = Output(eY);
375     }
376
377     prevIn = vForce;
378     prevOut = Output;
379
380     if ((fabs(RollingWhlVel) <= RFRV) && RFRV > 0) vForce(eX) *= fabs(RollingWhlVel)/RFRV;
381     if ((fabs(SideWhlVel) <= SFRV) && SFRV > 0) vForce(eY) *= fabs(SideWhlVel)/SFRV;
382
383 // End experimental section for attentuating gear jitter
384
385     vMoment = vWhlBodyVec * vForce;
386
387   } else { // Gear is NOT compressed
388
389     WOW = false;
390     compressLength = 0.0;
391
392     // Return to neutral position between 1.0 and 0.8 gear pos.
393     SteerAngle *= max(FCS->GetGearPos()-0.8, 0.0)/0.2;
394
395     ResetReporting();
396   }
397
398   ReportTakeoffOrLanding();
399   CrashDetect();
400
401   return vForce;
402 }
403
404 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
405
406 void FGLGear::ComputeRetractionState(void)
407 {
408   if (FCS->GetGearPos() < 0.01) {
409     GearUp   = true;
410     GearDown = false;
411   } else if (FCS->GetGearPos() > 0.99) {
412     GearDown = true;
413     GearUp   = false;
414   } else {
415     GearUp   = false;
416     GearDown = false;
417   }
418 }
419
420 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421
422 void FGLGear::ComputeSlipAngle(void)
423 {
424   // Transform the wheel velocities from the local axis system to the wheel axis system.
425   RollingWhlVel = vWhlVelVec(eX)*CosWheel + vWhlVelVec(eY)*SinWheel;
426   SideWhlVel    = vWhlVelVec(eY)*CosWheel - vWhlVelVec(eX)*SinWheel;
427
428   // Calculate tire slip angle.
429   if (fabs(RollingWhlVel) < 0.02 && fabs(SideWhlVel) < 0.02) {
430     WheelSlip = -SteerAngle*radtodeg;
431   } else {
432     WheelSlip = atan2(SideWhlVel, fabs(RollingWhlVel))*radtodeg;
433   }
434
435 // Filter the wheel slip angle
436
437   double SlipOutput, ca, cb, denom;
438
439   if (WheelSlipLagFilterCoeff > 0) {
440     denom = 2.00 + dT*WheelSlipLagFilterCoeff;
441     ca = dT*WheelSlipLagFilterCoeff / denom;
442     cb = (2.00 - dT*WheelSlipLagFilterCoeff) / denom;
443
444     SlipOutput = ca * (WheelSlip + prevSlipIn) + cb * prevSlipOut;
445
446     prevSlipIn = WheelSlip;
447     WheelSlip = prevSlipOut = SlipOutput;
448   }
449 }
450
451 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
452 // Compute the steering angle in any case.
453 // This will also make sure that animations will look right.
454
455 void FGLGear::ComputeSteeringAngle(void)
456 {
457   switch (eSteerType) {
458   case stSteer:
459     SteerAngle = degtorad * FCS->GetSteerPosDeg(GearNumber);
460     break;
461   case stFixed:
462     SteerAngle = 0.0;
463     break;
464   case stCaster:
465     // This is not correct for castering gear. Should make steer angle parallel
466     // to the actual velocity vector of the wheel, given aircraft velocity vector
467     // and omega.
468     SteerAngle = 0.0;
469     break;
470   default:
471     cerr << "Improper steering type membership detected for this gear." << endl;
472     break;
473   }
474
475   SinWheel      = sin(Propagate->GetEuler(ePsi) + SteerAngle);
476   CosWheel      = cos(Propagate->GetEuler(ePsi) + SteerAngle);
477 }
478
479 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480 // Reset reporting functionality after takeoff
481
482 void FGLGear::ResetReporting(void)
483 {
484   if (Propagate->GetDistanceAGL() > 200.0) {
485     FirstContact = false;
486     StartedGroundRun = false;
487     LandingReported = false;
488     LandingDistanceTraveled = 0.0;
489     MaximumStrutForce = MaximumStrutTravel = 0.0;
490   }
491 }
492
493 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
494
495 void FGLGear::InitializeReporting(void)
496 {
497   // If this is the first time the wheel has made contact, remember some values
498   // for later printout.
499
500   if (!FirstContact) {
501     FirstContact  = true;
502     SinkRate      =  compressSpeed;
503     GroundSpeed   =  Propagate->GetVel().Magnitude();
504     TakeoffReported = false;
505   }
506
507   // If the takeoff run is starting, initialize.
508
509   if ((Propagate->GetVel().Magnitude() > 0.1) &&
510       (FCS->GetBrake(bgLeft) == 0) &&
511       (FCS->GetBrake(bgRight) == 0) &&
512       (FCS->GetThrottlePos(0) == 1) && !StartedGroundRun)
513   {
514     TakeoffDistanceTraveled = 0;
515     TakeoffDistanceTraveled50ft = 0;
516     StartedGroundRun = true;
517   }
518 }
519
520 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
521 // Takeoff and landing reporting functionality
522
523 void FGLGear::ReportTakeoffOrLanding(void)
524 {
525   double deltaT = State->Getdt()*Exec->GetGroundReactions()->GetRate();
526
527   if (FirstContact) LandingDistanceTraveled += Auxiliary->GetVground()*deltaT;
528
529   if (StartedGroundRun) {
530      TakeoffDistanceTraveled50ft += Auxiliary->GetVground()*deltaT;
531     if (WOW) TakeoffDistanceTraveled += Auxiliary->GetVground()*deltaT;
532   }
533
534   if (ReportEnable && Auxiliary->GetVground() <= 0.05 && !LandingReported) {
535     if (debug_lvl > 0) Report(erLand);
536   }
537
538   if (ReportEnable && !TakeoffReported &&
539      (vLocalGear(eZ) - Propagate->GetDistanceAGL()) < -50.0)
540   {
541     if (debug_lvl > 0) Report(erTakeoff);
542   }
543
544   if (lastWOW != WOW) PutMessage("GEAR_CONTACT: " + name, WOW);
545   lastWOW = WOW;
546 }
547
548 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
549 // Crash detection logic (really out-of-bounds detection)
550
551 void FGLGear::CrashDetect(void)
552 {
553   if ( (compressLength > 500.0 ||
554       vForce.Magnitude() > 100000000.0 ||
555       vMoment.Magnitude() > 5000000000.0 ||
556       SinkRate > 1.4666*30 ) && !State->IntegrationSuspended())
557   {
558     PutMessage("Crash Detected: Simulation FREEZE.");
559     State->SuspendIntegration();
560   }
561 }
562
563 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
564 // The following needs work regarding friction coefficients and braking and
565 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
566 // It also assumes that we won't be turning and braking at the same time.
567 // Will fix this later.
568 // [JSB] The braking force coefficients include normal rolling coefficient +
569 // a percentage of the static friction coefficient based on braking applied.
570
571 void FGLGear::ComputeBrakeForceCoefficient(void)
572 {
573   switch (eBrakeGrp) {
574   case bgLeft:
575     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgLeft)) +
576                      staticFCoeff*FCS->GetBrake(bgLeft) );
577     break;
578   case bgRight:
579     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgRight)) +
580                      staticFCoeff*FCS->GetBrake(bgRight) );
581     break;
582   case bgCenter:
583     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
584                      staticFCoeff*FCS->GetBrake(bgCenter) );
585     break;
586   case bgNose:
587     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
588                      staticFCoeff*FCS->GetBrake(bgCenter) );
589     break;
590   case bgTail:
591     BrakeFCoeff =  ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
592                      staticFCoeff*FCS->GetBrake(bgCenter) );
593     break;
594   case bgNone:
595     BrakeFCoeff =  rollingFCoeff;
596     break;
597   default:
598     cerr << "Improper brake group membership detected for this gear." << endl;
599     break;
600   }
601 }
602
603 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
604 // Compute the sideforce coefficients using similar assumptions to LaRCSim for now.
605 // Allow a maximum of 10 degrees tire slip angle before wheel slides.  At that point,
606 // transition from static to dynamic friction.  There are more complicated formulations
607 // of this that avoid the discrete jump (similar to Pacejka).  Will fix this later.
608
609 void FGLGear::ComputeSideForceCoefficient(void)
610 {
611   if (ForceY_Table) {
612
613     FCoeff = ForceY_Table->GetValue(WheelSlip);
614
615   } else {
616
617     if (fabs(WheelSlip) <= 10.0) {
618       FCoeff = staticFCoeff*WheelSlip/10.0;
619     } else if (fabs(WheelSlip) <= 40.0) {
620       FCoeff = (dynamicFCoeff*(fabs(WheelSlip) - 10.0)/10.0
621                 + staticFCoeff*(40.0 - fabs(WheelSlip))/10.0)*(WheelSlip>=0?1.0:-1.0);
622     } else {
623       FCoeff = dynamicFCoeff*(WheelSlip>=0?1.0:-1.0);
624     }
625   }
626 }
627
628 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629 // Compute the vertical force on the wheel using square-law damping (per comment
630 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
631 // allowing for both square and linear damping force calculation. Also need to
632 // possibly give a "rebound damping factor" that differs from the compression
633 // case.
634
635 void FGLGear::ComputeVerticalStrutForce(void)
636 {
637   double springForce = 0;
638   double dampForce = 0;
639
640   springForce = -compressLength * kSpring;
641
642   if (compressSpeed >= 0.0) {
643     dampForce   = -compressSpeed * bDamp;
644   } else {
645     dampForce   = -compressSpeed * bDampRebound;
646   }
647   vLocalForce(eZ) =  min(springForce + dampForce, (double)0.0);
648
649   // Remember these values for reporting
650   MaximumStrutForce = max(MaximumStrutForce, fabs(vLocalForce(eZ)));
651   MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
652 }
653
654 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
655
656 void FGLGear::bind(void)
657 {
658   char property_name[80];
659   snprintf(property_name, 80, "gear/unit[%d]/slip-angle-deg", GearNumber);
660   Exec->GetPropertyManager()->Tie( property_name, &WheelSlip );
661 }
662
663 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664
665 void FGLGear::unbind(void)
666 {
667   char property_name[80];
668   snprintf(property_name, 80, "gear/unit[%d]/slip-angle-deg", GearNumber);
669   Exec->GetPropertyManager()->Untie( property_name );
670 }
671
672 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
673
674 void FGLGear::Report(ReportType repType)
675 {
676   switch(repType) {
677   case erLand:
678     cout << endl << "Touchdown report for " << name << endl;
679     cout << "  Sink rate at contact:  " << SinkRate                << " fps,    "
680                                 << SinkRate*0.3048          << " mps"     << endl;
681     cout << "  Contact ground speed:  " << GroundSpeed*.5925       << " knots,  "
682                                 << GroundSpeed*0.3048       << " mps"     << endl;
683     cout << "  Maximum contact force: " << MaximumStrutForce       << " lbs,    "
684                                 << MaximumStrutForce*4.448  << " Newtons" << endl;
685     cout << "  Maximum strut travel:  " << MaximumStrutTravel*12.0 << " inches, "
686                                 << MaximumStrutTravel*30.48 << " cm"      << endl;
687     cout << "  Distance traveled:     " << LandingDistanceTraveled        << " ft,     "
688                                 << LandingDistanceTraveled*0.3048  << " meters"  << endl;
689     LandingReported = true;
690     break;
691   case erTakeoff:
692     cout << endl << "Takeoff report for " << name << endl;
693     cout << "  Distance traveled:                " << TakeoffDistanceTraveled
694          << " ft,     " << TakeoffDistanceTraveled*0.3048  << " meters"  << endl;
695     cout << "  Distance traveled (over 50'):     " << TakeoffDistanceTraveled50ft
696          << " ft,     " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl;
697     TakeoffReported = true;
698     break;
699   }
700 }
701
702 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
703 //    The bitmasked value choices are as follows:
704 //    unset: In this case (the default) JSBSim would only print
705 //       out the normally expected messages, essentially echoing
706 //       the config files as they are read. If the environment
707 //       variable is not set, debug_lvl is set to 1 internally
708 //    0: This requests JSBSim not to output any messages
709 //       whatsoever.
710 //    1: This value explicity requests the normal JSBSim
711 //       startup messages
712 //    2: This value asks for a message to be printed out when
713 //       a class is instantiated
714 //    4: When this value is set, a message is displayed when a
715 //       FGModel object executes its Run() method
716 //    8: When this value is set, various runtime state variables
717 //       are printed out periodically
718 //    16: When set various parameters are sanity checked and
719 //       a message is printed out when they go out of bounds
720
721 void FGLGear::Debug(int from)
722 {
723   if (debug_lvl <= 0) return;
724
725   if (debug_lvl & 1) { // Standard console startup message output
726     if (from == 0) { // Constructor - loading and initialization
727       cout << "    " << sContactType << " " << name          << endl;
728       cout << "      Location: "         << vXYZ          << endl;
729       cout << "      Spring Constant:  " << kSpring       << endl;
730       cout << "      Damping Constant: " << bDamp         << endl;
731       cout << "      Dynamic Friction: " << dynamicFCoeff << endl;
732       cout << "      Static Friction:  " << staticFCoeff  << endl;
733       if (sContactType == "BOGEY") {
734         cout << "      Rolling Friction: " << rollingFCoeff << endl;
735         cout << "      Steering Type:    " << sSteerType    << endl;
736         cout << "      Grouping:         " << sBrakeGroup   << endl;
737         cout << "      Max Steer Angle:  " << maxSteerAngle << endl;
738         cout << "      Retractable:      " << isRetractable  << endl;
739         cout << "      Relaxation Velocities:" << endl;
740         cout << "        Rolling:          " << RFRV << endl;
741         cout << "        Side:             " << SFRV << endl;
742       }
743     }
744   }
745   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
746     if (from == 0) cout << "Instantiated: FGLGear" << endl;
747     if (from == 1) cout << "Destroyed:    FGLGear" << endl;
748   }
749   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
750   }
751   if (debug_lvl & 8 ) { // Runtime state variables
752   }
753   if (debug_lvl & 16) { // Sanity checking
754   }
755   if (debug_lvl & 64) {
756     if (from == 0) { // Constructor
757       cout << IdSrc << endl;
758       cout << IdHdr << endl;
759     }
760   }
761 }
762
763 } // namespace JSBSim
764