]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGLGear.cpp
c7a7534c7d1e84dd7f4bd735bd8576725847086e
[flightgear.git] / src / FDM / JSBSim / models / FGLGear.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGLGear.cpp
4  Author:       Jon S. Berndt
5                Norman H. Princen
6                Bertrand Coconnier
7  Date started: 11/18/99
8  Purpose:      Encapsulates the landing gear elements
9  Called by:    FGAircraft
10
11  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
12
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU Lesser General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
21  details.
22
23  You should have received a copy of the GNU Lesser General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
25  Place - Suite 330, Boston, MA  02111-1307, USA.
26
27  Further information about the GNU Lesser General Public License can also be found on
28  the world wide web at http://www.gnu.org.
29
30 FUNCTIONAL DESCRIPTION
31 --------------------------------------------------------------------------------
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 11/18/99   JSB   Created
36 01/30/01   NHP   Extended gear model to properly simulate steering and braking
37 07/08/09   BC    Modified gear model to support large angles between aircraft and ground
38
39 /%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 INCLUDES
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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) :
63   GearNumber(number),
64   Exec(fdmex)
65 {
66   Element *force_table=0;
67   Element *dampCoeff=0;
68   Element *dampCoeffRebound=0;
69   string force_type="";
70
71   kSpring = bDamp = bDampRebound = dynamicFCoeff = staticFCoeff = rollingFCoeff = maxSteerAngle = 0;
72   sSteerType = sBrakeGroup = sSteerType = "";
73   isRetractable = 0;
74   eDampType = dtLinear;
75   eDampTypeRebound = dtLinear;
76
77   name = el->GetAttributeValue("name");
78   sContactType = el->GetAttributeValue("type");
79   if (sContactType == "BOGEY") {
80     eContactType = ctBOGEY;
81   } else if (sContactType == "STRUCTURE") {
82     eContactType = ctSTRUCTURE;
83   } else {
84     eContactType = ctUNKNOWN;
85   }
86
87   if (el->FindElement("spring_coeff"))
88     kSpring = el->FindElementValueAsNumberConvertTo("spring_coeff", "LBS/FT");
89   if (el->FindElement("damping_coeff")) {
90     dampCoeff = el->FindElement("damping_coeff");
91     if (dampCoeff->GetAttributeValue("type") == "SQUARE") {
92       eDampType = dtSquare;
93       bDamp   = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT2/SEC2");
94     } else {
95       bDamp   = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT/SEC");
96     }
97   }
98
99   if (el->FindElement("damping_coeff_rebound")) {
100     dampCoeffRebound = el->FindElement("damping_coeff_rebound");
101     if (dampCoeffRebound->GetAttributeValue("type") == "SQUARE") {
102       eDampTypeRebound = dtSquare;
103       bDampRebound   = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT2/SEC2");
104     } else {
105       bDampRebound   = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT/SEC");
106     }
107   } else {
108     bDampRebound   = bDamp;
109     eDampTypeRebound = eDampType;
110   }
111
112   if (el->FindElement("dynamic_friction"))
113     dynamicFCoeff = el->FindElementValueAsNumber("dynamic_friction");
114   if (el->FindElement("static_friction"))
115     staticFCoeff = el->FindElementValueAsNumber("static_friction");
116   if (el->FindElement("rolling_friction"))
117     rollingFCoeff = el->FindElementValueAsNumber("rolling_friction");
118   if (el->FindElement("max_steer"))
119     maxSteerAngle = el->FindElementValueAsNumberConvertTo("max_steer", "DEG");
120   if (el->FindElement("retractable"))
121     isRetractable = ((unsigned int)el->FindElementValueAsNumber("retractable"))>0.0?true:false;
122
123   ForceY_Table = 0;
124   force_table = el->FindElement("table");
125   while (force_table) {
126     force_type = force_table->GetAttributeValue("type");
127     if (force_type == "CORNERING_COEFF") {
128       ForceY_Table = new FGTable(Exec->GetPropertyManager(), force_table);
129     } else {
130       cerr << "Undefined force table for " << name << " contact point" << endl;
131     }
132     force_table = el->FindNextElement("table");
133   }
134
135   sBrakeGroup = el->FindElementValue("brake_group");
136
137   if (maxSteerAngle == 360) sSteerType = "CASTERED";
138   else if (maxSteerAngle == 0.0) sSteerType = "FIXED";
139   else sSteerType = "STEERABLE";
140
141   Element* element = el->FindElement("location");
142   if (element) vXYZ = element->FindElementTripletConvertTo("IN");
143   else {cerr << "No location given for contact " << name << endl; exit(-1);}
144
145   if      (sBrakeGroup == "LEFT"  ) eBrakeGrp = bgLeft;
146   else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
147   else if (sBrakeGroup == "CENTER") eBrakeGrp = bgCenter;
148   else if (sBrakeGroup == "NOSE"  ) eBrakeGrp = bgNose;
149   else if (sBrakeGroup == "TAIL"  ) eBrakeGrp = bgTail;
150   else if (sBrakeGroup == "NONE"  ) eBrakeGrp = bgNone;
151   else if (sBrakeGroup.empty()    ) {eBrakeGrp = bgNone;
152                                      sBrakeGroup = "NONE (defaulted)";}
153   else {
154     cerr << "Improper braking group specification in config file: "
155          << sBrakeGroup << " is undefined." << endl;
156   }
157
158   if      (sSteerType == "STEERABLE") eSteerType = stSteer;
159   else if (sSteerType == "FIXED"    ) eSteerType = stFixed;
160   else if (sSteerType == "CASTERED" ) eSteerType = stCaster;
161   else if (sSteerType.empty()       ) {eSteerType = stFixed;
162                                        sSteerType = "FIXED (defaulted)";}
163   else {
164     cerr << "Improper steering type specification in config file: "
165          << sSteerType << " is undefined." << endl;
166   }
167
168   RFRV = 0.7;  // Rolling force relaxation velocity, default value
169   SFRV = 0.7;  // Side force relaxation velocity, default value
170
171   Element* relax_vel = el->FindElement("relaxation_velocity");
172   if (relax_vel) {
173     if (relax_vel->FindElement("rolling")) {
174       RFRV = relax_vel->FindElementValueAsNumberConvertTo("rolling", "FT/SEC");
175     }
176     if (relax_vel->FindElement("side")) {
177       SFRV = relax_vel->FindElementValueAsNumberConvertTo("side", "FT/SEC");
178     }
179   }
180
181   State = Exec->GetState();
182   LongForceLagFilterCoeff = 1/State->Getdt(); // default longitudinal force filter coefficient
183   LatForceLagFilterCoeff  = 1/State->Getdt(); // default lateral force filter coefficient
184
185   Element* force_lag_filter_elem = el->FindElement("force_lag_filter");
186   if (force_lag_filter_elem) {
187     if (force_lag_filter_elem->FindElement("rolling")) {
188       LongForceLagFilterCoeff = force_lag_filter_elem->FindElementValueAsNumber("rolling");
189     }
190     if (force_lag_filter_elem->FindElement("side")) {
191       LatForceLagFilterCoeff = force_lag_filter_elem->FindElementValueAsNumber("side");
192     }
193   }
194
195   LongForceFilter = Filter(LongForceLagFilterCoeff, State->Getdt());
196   LatForceFilter = Filter(LatForceLagFilterCoeff, State->Getdt());
197
198   WheelSlipLagFilterCoeff = 1/State->Getdt();
199
200   Element *wheel_slip_angle_lag_elem = el->FindElement("wheel_slip_filter");
201   if (wheel_slip_angle_lag_elem) {
202     WheelSlipLagFilterCoeff = wheel_slip_angle_lag_elem->GetDataAsNumber();
203   }
204   
205   WheelSlipFilter = Filter(WheelSlipLagFilterCoeff, State->Getdt());
206
207   GearUp = false;
208   GearDown = true;
209   GearPos  = 1.0;
210   useFCSGearPos = false;
211   Servicable = true;
212
213 // Add some AI here to determine if gear is located properly according to its
214 // brake group type ??
215
216   State       = Exec->GetState();
217   Aircraft    = Exec->GetAircraft();
218   Propagate   = Exec->GetPropagate();
219   Auxiliary   = Exec->GetAuxiliary();
220   FCS         = Exec->GetFCS();
221   MassBalance = Exec->GetMassBalance();
222
223   WOW = lastWOW = false;
224   ReportEnable = true;
225   FirstContact = false;
226   StartedGroundRun = false;
227   TakeoffReported = LandingReported = false;
228   LandingDistanceTraveled = TakeoffDistanceTraveled = TakeoffDistanceTraveled50ft = 0.0;
229   MaximumStrutForce = MaximumStrutTravel = 0.0;
230   SinkRate = GroundSpeed = 0.0;
231
232   vWhlBodyVec = MassBalance->StructuralToBody(vXYZ);
233
234   vLocalGear = Propagate->GetTb2l() * vWhlBodyVec;
235
236   vLocalWhlVel.InitMatrix();
237
238   compressLength  = 0.0;
239   compressSpeed   = 0.0;
240   brakePct        = 0.0;
241   maxCompLen      = 0.0;
242
243   WheelSlip = 0.0;
244   TirePressureNorm = 1.0;
245
246   // Set Pacejka terms
247
248   Stiffness = 0.06;
249   Shape = 2.8;
250   Peak = staticFCoeff;
251   Curvature = 1.03;
252
253   Debug(0);
254 }
255
256 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257
258 FGLGear::~FGLGear()
259 {
260   delete ForceY_Table;
261   Debug(1);
262 }
263
264 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265
266 FGColumnVector3& FGLGear::Force(void)
267 {
268   double t = Exec->GetState()->Getsim_time();
269   dT = State->Getdt()*Exec->GetGroundReactions()->GetRate();
270
271   vForce.InitMatrix();
272   vLocalForce.InitMatrix();
273   vMoment.InitMatrix();
274
275   if (isRetractable) ComputeRetractionState();
276
277   if (GearDown) {
278
279     vWhlBodyVec = MassBalance->StructuralToBody(vXYZ); // Get wheel in body frame
280     vLocalGear = Propagate->GetTb2l() * vWhlBodyVec; // Get local frame wheel location
281
282     gearLoc = Propagate->GetLocation().LocalToLocation(vLocalGear);
283     // Compute the height of the theoretical location of the wheel (if strut is not compressed) with
284     // respect to the ground level
285     double height = Exec->GetGroundCallback()->GetAGLevel(t, gearLoc, contact, normal, cvel);
286     vGroundNormal = -1. * Propagate->GetTec2b() * normal;
287
288     switch (eContactType) {
289     case ctBOGEY:
290       // Project the height in the local coordinate frame of the strut to compute the actual compression
291       // length. The strut is assumed to be parallel to Z in the body frame.
292       compressLength = vGroundNormal(eZ) < 0.0 ? height / vGroundNormal(eZ) : 0.0;
293       break;
294     case ctSTRUCTURE:
295       compressLength = -height;
296       break;
297     }
298
299     if (compressLength > 0.00) {
300
301       WOW = true;
302
303       // [The next equation should really use the vector to the contact patch of
304       // the tire including the strut compression and not the original vWhlBodyVec.]
305
306       FGColumnVector3 vWhlContactVec = vWhlBodyVec - FGColumnVector3(0., 0., compressLength);
307       vWhlVelVec      =  Propagate->GetPQR() * vWhlContactVec;
308       vWhlVelVec     +=  Propagate->GetUVW() - Propagate->GetTec2b() * cvel;
309
310       InitializeReporting();
311       ComputeSteeringAngle();
312       ComputeGroundCoordSys();
313
314       vLocalWhlVel = Tb2g * vWhlVelVec;
315
316       compressSpeed = -vLocalWhlVel(eZ);
317       if (eContactType == ctBOGEY)
318         // Project the compression speed in the local coordinate frame of the strut
319         compressSpeed /= -vGroundNormal(eZ);
320
321       ComputeVerticalStrutForce();
322
323       // Compute the forces in the wheel ground plane.
324       if (eContactType == ctBOGEY) {
325         ComputeSlipAngle();
326         ComputeBrakeForceCoefficient();
327         ComputeSideForceCoefficient();
328         double sign = vLocalWhlVel(eX)>0?1.0:(vLocalWhlVel(eX)<0?-1.0:0.0);
329         vLocalForce(eX) = - ((1.0 - TirePressureNorm) * 30 + vLocalForce(eZ) * BrakeFCoeff) * sign;
330         vLocalForce(eY) = vLocalForce(eZ) * FCoeff;
331       }
332       else if (eContactType == ctSTRUCTURE) {
333         FGColumnVector3 vSlipVec = vLocalWhlVel;
334         vSlipVec(eZ) = 0.;
335         vSlipVec.Normalize();
336         vLocalForce -= staticFCoeff * vLocalForce(eZ) * vSlipVec;
337       }
338
339       // Lag and attenuate the XY-plane forces dependent on velocity. This code
340       // uses a lag filter, C/(s + C) where "C" is the filter coefficient. When
341       // "C" is chosen at the frame rate (in Hz), the jittering is significantly
342       // reduced. This is because the jitter is present *at* the execution rate.
343       // If a coefficient is set to something equal to or less than zero, the
344       // filter is bypassed.
345
346       if (LongForceLagFilterCoeff > 0) vLocalForce(eX) = LongForceFilter.execute(vLocalForce(eX));
347       if (LatForceLagFilterCoeff > 0)  vLocalForce(eY) = LatForceFilter.execute(vLocalForce(eY));
348
349       if ((fabs(vLocalWhlVel(eX)) <= RFRV) && RFRV > 0) vLocalForce(eX) *= fabs(vLocalWhlVel(eX))/RFRV;
350       if ((fabs(vLocalWhlVel(eY)) <= SFRV) && SFRV > 0) vLocalForce(eY) *= fabs(vLocalWhlVel(eY))/SFRV;
351
352       // End section for attenuating gear jitter
353
354       // Transform the forces back to the body frame and compute the moment.
355
356       vForce  = Tg2b * vLocalForce;
357       vMoment = vWhlContactVec * vForce;
358
359     } else { // Gear is NOT compressed
360
361       WOW = false;
362       compressLength = 0.0;
363       compressSpeed = 0.0;
364
365       // Let wheel spin down slowly
366       vLocalWhlVel(eX) -= 13.0*dT;
367       if (vLocalWhlVel(eX) < 0.0) vLocalWhlVel(eX) = 0.0;
368
369       // Return to neutral position between 1.0 and 0.8 gear pos.
370       SteerAngle *= max(GetGearUnitPos()-0.8, 0.0)/0.2;
371
372       ResetReporting();
373     }
374   }
375
376   ReportTakeoffOrLanding();
377
378   // Require both WOW and LastWOW to be true before checking crash conditions
379   // to allow the WOW flag to be used in terminating a scripted run.
380   if (WOW && lastWOW) CrashDetect();
381
382   lastWOW = WOW;
383
384   return vForce;
385 }
386
387 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388 // Build a local "ground" coordinate system defined by
389 //  eX : projection of the rolling direction on the ground
390 //  eY : projection of the sliping direction on the ground
391 //  eZ : normal to the ground
392
393 void FGLGear::ComputeGroundCoordSys(void)
394 {
395   // Compute the rolling direction projected on the ground
396   // It consists in finding a vector 'r' such that 'r' lies in the plane (w,z) and r.n = 0 (scalar
397   // product) where:
398   // 'n' is the normal to the ground,
399   // (x,y,z) are the directions defined in the body coord system
400   // and 'w' is 'x' rotated by the steering angle (SteerAngle) in the plane (x,y). 
401   // r = u * w + v * z and r.n = 0 => v/u = -w.n/z.n = a
402   // We also want u**2+v**2=1 and u > 0 (i.e. r orientated in the same 'direction' than w)
403   // after some arithmetic, one finds that :
404   double a = -(vGroundNormal(eX)*cos(SteerAngle)+vGroundNormal(eY)*sin(SteerAngle)) / vGroundNormal(eZ);
405   double u = 1. / sqrt(1. + a*a);
406   double v = a * u;
407   FGColumnVector3 vRollingGroundVec = FGColumnVector3(u * cos(SteerAngle), u * sin(SteerAngle), v);
408
409   // The sliping direction is the cross product multiplication of the ground normal and rolling
410   // directions
411   FGColumnVector3 vSlipGroundVec = vGroundNormal * vRollingGroundVec;
412
413   Tg2b(1,1) = vRollingGroundVec(eX);
414   Tg2b(2,1) = vRollingGroundVec(eY);
415   Tg2b(3,1) = vRollingGroundVec(eZ);
416   Tg2b(1,2) = vSlipGroundVec(eX);
417   Tg2b(2,2) = vSlipGroundVec(eY);
418   Tg2b(3,2) = vSlipGroundVec(eZ);
419   Tg2b(1,3) = vGroundNormal(eX);
420   Tg2b(2,3) = vGroundNormal(eY);
421   Tg2b(3,3) = vGroundNormal(eZ);
422
423   Tb2g = Tg2b.Transposed();
424 }
425
426 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427
428 void FGLGear::ComputeRetractionState(void)
429 {
430   double gearPos = GetGearUnitPos();
431   if (gearPos < 0.01) {
432     GearUp   = true;
433     WOW      = false;
434     GearDown = false;
435     vLocalWhlVel.InitMatrix();
436   } else if (gearPos > 0.99) {
437     GearDown = true;
438     GearUp   = false;
439   } else {
440     GearUp   = false;
441     GearDown = false;
442   }
443 }
444
445 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
446
447 void FGLGear::ComputeSlipAngle(void)
448 {
449   // Calculate tire slip angle.
450   WheelSlip = -atan2(vLocalWhlVel(eY), fabs(vLocalWhlVel(eX)))*radtodeg;
451
452   // Filter the wheel slip angle
453   if (WheelSlipLagFilterCoeff > 0) WheelSlip = WheelSlipFilter.execute(WheelSlip);
454 }
455
456 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
457 // Compute the steering angle in any case.
458 // This will also make sure that animations will look right.
459
460 void FGLGear::ComputeSteeringAngle(void)
461 {
462   switch (eSteerType) {
463   case stSteer:
464     SteerAngle = degtorad * FCS->GetSteerPosDeg(GearNumber);
465     break;
466   case stFixed:
467     SteerAngle = 0.0;
468     break;
469   case stCaster:
470     SteerAngle = atan2(fabs(vWhlVelVec(eX)), vWhlVelVec(eY));
471     break;
472   default:
473     cerr << "Improper steering type membership detected for this gear." << endl;
474     break;
475   }
476 }
477
478 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479 // Reset reporting functionality after takeoff
480
481 void FGLGear::ResetReporting(void)
482 {
483   if (Propagate->GetDistanceAGL() > 200.0) {
484     FirstContact = false;
485     StartedGroundRun = false;
486     LandingReported = false;
487     TakeoffReported = true;
488     LandingDistanceTraveled = 0.0;
489     MaximumStrutForce = MaximumStrutTravel = 0.0;
490   }
491 }
492
493 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
494
495 void FGLGear::InitializeReporting(void)
496 {
497   // If this is the first time the wheel has made contact, remember some values
498   // for later printout.
499
500   if (!FirstContact) {
501     FirstContact  = true;
502     SinkRate      =  compressSpeed;
503     GroundSpeed   =  Propagate->GetVel().Magnitude();
504     TakeoffReported = false;
505   }
506
507   // If the takeoff run is starting, initialize.
508
509   if ((Propagate->GetVel().Magnitude() > 0.1) &&
510       (FCS->GetBrake(bgLeft) == 0) &&
511       (FCS->GetBrake(bgRight) == 0) &&
512       (FCS->GetThrottlePos(0) > 0.90) && !StartedGroundRun)
513   {
514     TakeoffDistanceTraveled = 0;
515     TakeoffDistanceTraveled50ft = 0;
516     StartedGroundRun = true;
517   }
518 }
519
520 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
521 // Takeoff and landing reporting functionality
522
523 void FGLGear::ReportTakeoffOrLanding(void)
524 {
525   double deltaT = State->Getdt()*Exec->GetGroundReactions()->GetRate();
526
527   if (FirstContact)
528     LandingDistanceTraveled += Auxiliary->GetVground()*deltaT;
529
530   if (StartedGroundRun) {
531     TakeoffDistanceTraveled50ft += Auxiliary->GetVground()*deltaT;
532     if (WOW) TakeoffDistanceTraveled += Auxiliary->GetVground()*deltaT;
533   }
534
535   if ( ReportEnable
536        && Auxiliary->GetVground() <= 0.05
537        && !LandingReported
538        && Exec->GetGroundReactions()->GetWOW())
539   {
540     if (debug_lvl > 0) Report(erLand);
541   }
542
543   if ( ReportEnable
544        && !TakeoffReported
545        && (Propagate->GetDistanceAGL() - vLocalGear(eZ)) > 50.0
546        && !Exec->GetGroundReactions()->GetWOW())
547   {
548     if (debug_lvl > 0) Report(erTakeoff);
549   }
550
551   if (lastWOW != WOW) PutMessage("GEAR_CONTACT: " + name, 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 Pacejka's Magic Formula.
611 //
612 //   y(x) = D sin {C arctan [Bx - E(Bx - arctan Bx)]}
613 //
614 // Where: B = Stiffness Factor (0.06, here)
615 //        C = Shape Factor (2.8, here)
616 //        D = Peak Factor (0.8, here)
617 //        E = Curvature Factor (1.03, here)
618
619 void FGLGear::ComputeSideForceCoefficient(void)
620 {
621   if (ForceY_Table) {
622     FCoeff = ForceY_Table->GetValue(WheelSlip);
623   } else {
624     double StiffSlip = Stiffness*WheelSlip;
625     FCoeff = Peak * sin(Shape*atan(StiffSlip - Curvature*(StiffSlip - atan(StiffSlip))));
626   }
627 }
628
629 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
630 // Compute the vertical force on the wheel using square-law damping (per comment
631 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
632 // allowing for both square and linear damping force calculation. Also need to
633 // possibly give a "rebound damping factor" that differs from the compression
634 // case.
635
636 void FGLGear::ComputeVerticalStrutForce(void)
637 {
638   double springForce = 0;
639   double dampForce = 0;
640
641   springForce = -compressLength * kSpring;
642
643   if (compressSpeed >= 0.0) {
644
645     if (eDampType == dtLinear)   dampForce = -compressSpeed * bDamp;
646     else         dampForce = -compressSpeed * compressSpeed * bDamp;
647
648   } else {
649
650     if (eDampTypeRebound == dtLinear)
651       dampForce   = -compressSpeed * bDampRebound;
652     else
653       dampForce   =  compressSpeed * compressSpeed * bDampRebound;
654
655   }
656
657   StrutForce = min(springForce + dampForce, (double)0.0);
658
659   // The reaction force of the wheel is always normal to the ground
660   switch (eContactType) {
661   case ctBOGEY:
662     // Project back the strut force in the local coordinate frame of the ground
663     vLocalForce(eZ) =  StrutForce / vGroundNormal(eZ);
664     break;
665   case ctSTRUCTURE:
666     vLocalForce(eZ) = -StrutForce;
667     break;
668   }
669
670   // Remember these values for reporting
671   MaximumStrutForce = max(MaximumStrutForce, fabs(StrutForce));
672   MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
673 }
674
675 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
676
677 double FGLGear::GetGearUnitPos(void)
678 {
679   // hack to provide backward compatibility to gear/gear-pos-norm property
680   if( useFCSGearPos || FCS->GetGearPos() != 1.0 ) {
681     useFCSGearPos = true;
682     return FCS->GetGearPos();
683   }
684   return GearPos;
685 }
686
687 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
688
689 void FGLGear::bind(void)
690 {
691   string property_name;
692   string base_property_name;
693   base_property_name = CreateIndexedPropertyName("gear/unit", GearNumber);
694   if (eContactType == ctBOGEY) {
695     property_name = base_property_name + "/slip-angle-deg";
696     Exec->GetPropertyManager()->Tie( property_name.c_str(), &WheelSlip );
697     property_name = base_property_name + "/WOW";
698     Exec->GetPropertyManager()->Tie( property_name.c_str(), &WOW );
699     property_name = base_property_name + "/wheel-speed-fps";
700     Exec->GetPropertyManager()->Tie( property_name.c_str(), (FGLGear*)this,
701                           &FGLGear::GetWheelRollVel);
702     property_name = base_property_name + "/z-position";
703     Exec->GetPropertyManager()->Tie( property_name.c_str(), (FGLGear*)this,
704                           &FGLGear::GetZPosition, &FGLGear::SetZPosition);
705     property_name = base_property_name + "/compression-ft";
706     Exec->GetPropertyManager()->Tie( property_name.c_str(), &compressLength );
707     property_name = base_property_name + "/side_friction_coeff";
708     Exec->GetPropertyManager()->Tie( property_name.c_str(), &FCoeff );
709
710     property_name = base_property_name + "/static_friction_coeff";
711     Exec->GetPropertyManager()->Tie( property_name.c_str(), &staticFCoeff );
712
713   }
714
715   if( isRetractable ) {
716     property_name = base_property_name + "/pos-norm";
717     Exec->GetPropertyManager()->Tie( property_name.c_str(), &GearPos );
718   }
719
720 }
721
722 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
723
724 void FGLGear::Report(ReportType repType)
725 {
726   if (fabs(TakeoffDistanceTraveled) < 0.001) return; // Don't print superfluous reports
727
728   switch(repType) {
729   case erLand:
730     cout << endl << "Touchdown report for " << name << " (WOW at time: "
731          << Exec->GetState()->Getsim_time() << " seconds)" << endl;
732     cout << "  Sink rate at contact:  " << SinkRate                << " fps,    "
733                                 << SinkRate*0.3048          << " mps"     << endl;
734     cout << "  Contact ground speed:  " << GroundSpeed*.5925       << " knots,  "
735                                 << GroundSpeed*0.3048       << " mps"     << endl;
736     cout << "  Maximum contact force: " << MaximumStrutForce       << " lbs,    "
737                                 << MaximumStrutForce*4.448  << " Newtons" << endl;
738     cout << "  Maximum strut travel:  " << MaximumStrutTravel*12.0 << " inches, "
739                                 << MaximumStrutTravel*30.48 << " cm"      << endl;
740     cout << "  Distance traveled:     " << LandingDistanceTraveled        << " ft,     "
741                                 << LandingDistanceTraveled*0.3048  << " meters"  << endl;
742     LandingReported = true;
743     break;
744   case erTakeoff:
745     cout << endl << "Takeoff report for " << name << " (Liftoff at time: "
746          << Exec->GetState()->Getsim_time() << " seconds)" << endl;
747     cout << "  Distance traveled:                " << TakeoffDistanceTraveled
748          << " ft,     " << TakeoffDistanceTraveled*0.3048  << " meters"  << endl;
749     cout << "  Distance traveled (over 50'):     " << TakeoffDistanceTraveled50ft
750          << " ft,     " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl;
751     cout << "  [Altitude (ASL): " << Exec->GetPropagate()->GetAltitudeASL() << " ft. / "
752          << Exec->GetPropagate()->GetAltitudeASLmeters() << " m  | Temperature: "
753          << Exec->GetAtmosphere()->GetTemperature() - 459.67 << " F / "
754          << RankineToCelsius(Exec->GetAtmosphere()->GetTemperature()) << " C]" << endl;
755     cout << "  [Velocity (KCAS): " << Exec->GetAuxiliary()->GetVcalibratedKTS() << "]" << endl;
756     TakeoffReported = true;
757     break;
758   }
759 }
760
761 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
762 //    The bitmasked value choices are as follows:
763 //    unset: In this case (the default) JSBSim would only print
764 //       out the normally expected messages, essentially echoing
765 //       the config files as they are read. If the environment
766 //       variable is not set, debug_lvl is set to 1 internally
767 //    0: This requests JSBSim not to output any messages
768 //       whatsoever.
769 //    1: This value explicity requests the normal JSBSim
770 //       startup messages
771 //    2: This value asks for a message to be printed out when
772 //       a class is instantiated
773 //    4: When this value is set, a message is displayed when a
774 //       FGModel object executes its Run() method
775 //    8: When this value is set, various runtime state variables
776 //       are printed out periodically
777 //    16: When set various parameters are sanity checked and
778 //       a message is printed out when they go out of bounds
779
780 void FGLGear::Debug(int from)
781 {
782   if (debug_lvl <= 0) return;
783
784   if (debug_lvl & 1) { // Standard console startup message output
785     if (from == 0) { // Constructor - loading and initialization
786       cout << "    " << sContactType << " " << name          << endl;
787       cout << "      Location: "         << vXYZ          << endl;
788       cout << "      Spring Constant:  " << kSpring       << endl;
789
790       if (eDampType == dtLinear)
791         cout << "      Damping Constant: " << bDamp << " (linear)" << endl;
792       else
793         cout << "      Damping Constant: " << bDamp << " (square law)" << endl;
794
795       if (eDampTypeRebound == dtLinear)
796         cout << "      Rebound Damping Constant: " << bDampRebound << " (linear)" << endl;
797       else 
798         cout << "      Rebound Damping Constant: " << bDampRebound << " (square law)" << endl;
799
800       cout << "      Dynamic Friction: " << dynamicFCoeff << endl;
801       cout << "      Static Friction:  " << staticFCoeff  << endl;
802       if (eContactType == ctBOGEY) {
803         cout << "      Rolling Friction: " << rollingFCoeff << endl;
804         cout << "      Steering Type:    " << sSteerType    << endl;
805         cout << "      Grouping:         " << sBrakeGroup   << endl;
806         cout << "      Max Steer Angle:  " << maxSteerAngle << endl;
807         cout << "      Retractable:      " << isRetractable  << endl;
808         cout << "      Relaxation Velocities:" << endl;
809         cout << "        Rolling:          " << RFRV << endl;
810         cout << "        Side:             " << SFRV << endl;
811       }
812     }
813   }
814   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
815     if (from == 0) cout << "Instantiated: FGLGear" << endl;
816     if (from == 1) cout << "Destroyed:    FGLGear" << endl;
817   }
818   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
819   }
820   if (debug_lvl & 8 ) { // Runtime state variables
821   }
822   if (debug_lvl & 16) { // Sanity checking
823   }
824   if (debug_lvl & 64) {
825     if (from == 0) { // Constructor
826       cout << IdSrc << endl;
827       cout << IdHdr << endl;
828     }
829   }
830 }
831
832 } // namespace JSBSim
833