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