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