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