1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 Purpose: Encapsulates the landing gear elements
10 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free Software
14 Foundation; either version 2 of the License, or (at your option) any later
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 General Public License for more
22 You should have received a copy of the GNU 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.
26 Further information about the GNU General Public License can also be found on
27 the world wide web at http://www.gnu.org.
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
33 --------------------------------------------------------------------------------
35 01/30/01 NHP Extended gear model to properly simulate steering and braking
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 static const char *IdSrc = "$Id$";
54 static const char *IdHdr = ID_LGEAR;
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex, int number) : Exec(fdmex)
66 *AC_cfg >> tmp >> name >> vXYZ(1) >> vXYZ(2) >> vXYZ(3)
67 >> kSpring >> bDamp>> dynamicFCoeff >> staticFCoeff
68 >> rollingFCoeff >> sSteerType >> sBrakeGroup
69 >> maxSteerAngle >> sRetractable;
71 if (sBrakeGroup == "LEFT" ) eBrakeGrp = bgLeft;
72 else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
73 else if (sBrakeGroup == "CENTER") eBrakeGrp = bgCenter;
74 else if (sBrakeGroup == "NOSE" ) eBrakeGrp = bgNose;
75 else if (sBrakeGroup == "TAIL" ) eBrakeGrp = bgTail;
76 else if (sBrakeGroup == "NONE" ) eBrakeGrp = bgNone;
78 cerr << "Improper braking group specification in config file: "
79 << sBrakeGroup << " is undefined." << endl;
82 if (sSteerType == "STEERABLE") eSteerType = stSteer;
83 else if (sSteerType == "FIXED" ) eSteerType = stFixed;
84 else if (sSteerType == "CASTERED" ) eSteerType = stCaster;
86 cerr << "Improper steering type specification in config file: "
87 << sSteerType << " is undefined." << endl;
90 if ( sRetractable == "RETRACT" ) {
93 isRetractable = false;
100 // Add some AI here to determine if gear is located properly according to its
101 // brake group type ??
103 State = Exec->GetState();
104 Aircraft = Exec->GetAircraft();
105 Propagate = Exec->GetPropagate();
106 Auxiliary = Exec->GetAuxiliary();
107 FCS = Exec->GetFCS();
108 MassBalance = Exec->GetMassBalance();
110 WOW = lastWOW = true; // should the value be initialized to true?
112 FirstContact = false;
113 StartedGroundRun = false;
114 TakeoffReported = LandingReported = false;
115 LandingDistanceTraveled = TakeoffDistanceTraveled = TakeoffDistanceTraveled50ft = 0.0;
116 MaximumStrutForce = MaximumStrutTravel = 0.0;
117 SideForce = RollingForce = 0.0;
118 SinkRate = GroundSpeed = 0.0;
120 vWhlBodyVec = MassBalance->StructuralToBody(vXYZ);
122 vLocalGear = Propagate->GetTb2l() * vWhlBodyVec;
124 compressLength = 0.0;
129 WheelSlip = lastWheelSlip = 0.0;
131 compressLength = 0.0;
136 TirePressureNorm = 1.0;
141 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 FGLGear::FGLGear(const FGLGear& lgear)
145 GearNumber = lgear.GearNumber;
148 Aircraft = lgear.Aircraft;
149 Propagate = lgear.Propagate;
150 Auxiliary = lgear.Auxiliary;
153 MassBalance = lgear.MassBalance;
156 vMoment = lgear.vMoment;
157 vWhlBodyVec = lgear.vWhlBodyVec;
158 vLocalGear = lgear.vLocalGear;
161 lastWOW = lgear.lastWOW;
162 ReportEnable = lgear.ReportEnable;
163 FirstContact = lgear.FirstContact;
164 StartedGroundRun = lgear.StartedGroundRun;
165 LandingDistanceTraveled = lgear.LandingDistanceTraveled;
166 TakeoffDistanceTraveled = lgear.TakeoffDistanceTraveled;
167 TakeoffDistanceTraveled50ft = lgear.TakeoffDistanceTraveled50ft;
168 MaximumStrutForce = lgear.MaximumStrutForce;
169 MaximumStrutTravel = lgear.MaximumStrutTravel;
170 SideForce = lgear.SideForce;
171 RollingForce = lgear.RollingForce;
173 kSpring = lgear.kSpring;
175 compressLength = lgear.compressLength;
176 compressSpeed = lgear.compressSpeed;
177 staticFCoeff = lgear.staticFCoeff;
178 dynamicFCoeff = lgear.dynamicFCoeff;
179 rollingFCoeff = lgear.rollingFCoeff;
180 brakePct = lgear.brakePct;
181 maxCompLen = lgear.maxCompLen;
182 SinkRate = lgear.SinkRate;
183 GroundSpeed = lgear.GroundSpeed;
184 LandingReported = lgear.LandingReported;
185 TakeoffReported = lgear.TakeoffReported;
187 sSteerType = lgear.sSteerType;
188 sRetractable = lgear.sRetractable;
189 eSteerType = lgear.eSteerType;
190 sBrakeGroup = lgear.sBrakeGroup;
191 eBrakeGrp = lgear.eBrakeGrp;
192 maxSteerAngle = lgear.maxSteerAngle;
193 isRetractable = lgear.isRetractable;
194 GearUp = lgear.GearUp;
195 GearDown = lgear.GearDown;
196 WheelSlip = lgear.WheelSlip;
197 lastWheelSlip = lgear.lastWheelSlip;
198 TirePressureNorm = lgear.TirePressureNorm;
199 Servicable = lgear.Servicable;
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 FGColumnVector3& FGLGear::Force(void)
213 double SinWheel, CosWheel;
214 double deltaT = State->Getdt()*Aircraft->GetRate();
217 vMoment.InitMatrix();
220 if (FCS->GetGearPos() < 0.01) {
223 } else if (FCS->GetGearPos() > 0.99) {
235 // Compute the steering angle in any case.
236 // Will make shure that animations will look right.
237 switch (eSteerType) {
239 SteerAngle = degtorad * FCS->GetSteerPosDeg(GearNumber);
245 // Note to Jon: This is not correct for castering gear. I'll fix it later.
249 cerr << "Improper steering type membership detected for this gear." << endl;
255 vWhlBodyVec = MassBalance->StructuralToBody(vXYZ);
257 // vWhlBodyVec now stores the vector from the cg to this wheel
259 vLocalGear = Propagate->GetTb2l() * vWhlBodyVec;
261 // vLocalGear now stores the vector from the cg to the wheel in local coords.
263 compressLength = vLocalGear(eZ) - Propagate->GetDistanceAGL();
265 // The compression length is currently measured in the Z-axis, only, at this time.
266 // It should be measured along the strut axis. If the local-frame gear position
267 // "hangs down" below the CG greater than the altitude, then the compressLength
268 // will be positive - i.e. the gear will have made contact.
270 if (compressLength > 0.00) {
272 WOW = true; // Weight-On-Wheels is true
274 // The next equation should really use the vector to the contact patch of the tire
275 // including the strut compression and not vWhlBodyVec. Will fix this later.
276 // As it stands, now, the following equation takes the aircraft body-frame
277 // rotational rate and calculates the cross-product with the vector from the CG
278 // to the wheel, thus producing the instantaneous velocity vector of the tire
279 // in Body coords. The frame is also converted to local coordinates. When the
280 // aircraft local-frame velocity is added to this quantity, the total velocity of
281 // the wheel in local frame is then known. Subsequently, the compression speed
282 // (used for calculating damping force) is found by taking the Z-component of the
285 vWhlVelVec = Propagate->GetTb2l() * (Propagate->GetPQR() * vWhlBodyVec);
286 vWhlVelVec += Propagate->GetVel();
287 compressSpeed = vWhlVelVec(eZ);
289 // If this is the first time the wheel has made contact, remember some values
290 // for later printout.
294 SinkRate = compressSpeed;
295 GroundSpeed = Propagate->GetVel().Magnitude();
296 TakeoffReported = false;
299 // If the takeoff run is starting, initialize.
301 if ((Propagate->GetVel().Magnitude() > 0.1) &&
302 (FCS->GetBrake(bgLeft) == 0) &&
303 (FCS->GetBrake(bgRight) == 0) &&
304 (FCS->GetThrottlePos(0) == 1) && !StartedGroundRun)
306 TakeoffDistanceTraveled = 0;
307 TakeoffDistanceTraveled50ft = 0;
308 StartedGroundRun = true;
311 // The following needs work regarding friction coefficients and braking and
312 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
313 // It also assumes that we won't be turning and braking at the same time.
314 // Will fix this later.
315 // [JSB] The braking force coefficients include normal rolling coefficient +
316 // a percentage of the static friction coefficient based on braking applied.
320 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgLeft)) +
321 staticFCoeff*FCS->GetBrake(bgLeft) );
324 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgRight)) +
325 staticFCoeff*FCS->GetBrake(bgRight) );
328 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
329 staticFCoeff*FCS->GetBrake(bgCenter) );
332 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
333 staticFCoeff*FCS->GetBrake(bgCenter) );
336 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
337 staticFCoeff*FCS->GetBrake(bgCenter) );
340 BrakeFCoeff = rollingFCoeff;
343 cerr << "Improper brake group membership detected for this gear." << endl;
347 // Transform the wheel velocities from the local axis system to the wheel axis system.
348 // For now, steering angle is assumed to happen in the Local Z axis,
349 // not the strut axis as it should be. Will fix this later.
351 SinWheel = sin(Propagate->GetEuler(ePsi) + SteerAngle);
352 CosWheel = cos(Propagate->GetEuler(ePsi) + SteerAngle);
353 RollingWhlVel = vWhlVelVec(eX)*CosWheel + vWhlVelVec(eY)*SinWheel;
354 SideWhlVel = vWhlVelVec(eY)*CosWheel - vWhlVelVec(eX)*SinWheel;
356 // Calculate tire slip angle.
358 if (RollingWhlVel == 0.0 && SideWhlVel == 0.0) {
360 } else if (fabs(RollingWhlVel) < 1.0) {
361 WheelSlip = 0.05*radtodeg*atan2(SideWhlVel, fabs(RollingWhlVel)) + 0.95*WheelSlip;
363 WheelSlip = radtodeg*atan2(SideWhlVel, fabs(RollingWhlVel));
366 double maxdeltaSlip = 0.5*deltaT;
368 if (RollingWhlVel == 0.0 && SideWhlVel == 0.0) {
370 } else if (RollingWhlVel < 1.0) {
371 WheelSlip = radtodeg*atan2(SideWhlVel, RollingWhlVel);
372 deltaSlip = WheelSlip - lastWheelSlip;
373 if (fabs(deltaSlip) > maxdeltaSlip) {
374 if (WheelSlip > lastWheelSlip) {
375 WheelSlip = lastWheelSlip + maxdeltaSlip;
376 } else if (WheelSlip < lastWheelSlip) {
377 WheelSlip = lastWheelSlip - maxdeltaSlip;
381 WheelSlip = radtodeg*atan2(SideWhlVel, RollingWhlVel);
384 if ((WheelSlip < 0.0 && lastWheelSlip > 0.0) ||
385 (WheelSlip > 0.0 && lastWheelSlip < 0.0))
390 lastWheelSlip = WheelSlip;
392 // Compute the sideforce coefficients using similar assumptions to LaRCSim for now.
393 // Allow a maximum of 10 degrees tire slip angle before wheel slides. At that point,
394 // transition from static to dynamic friction. There are more complicated formulations
395 // of this that avoid the discrete jump (similar to Pacejka). Will fix this later.
397 if (fabs(WheelSlip) <= 20.0) {
398 FCoeff = staticFCoeff*WheelSlip/20.0;
399 } else if (fabs(WheelSlip) <= 40.0) {
400 // FCoeff = dynamicFCoeff*fabs(WheelSlip)/WheelSlip;
401 FCoeff = (dynamicFCoeff*(fabs(WheelSlip) - 20.0)/20.0 +
402 staticFCoeff*(40.0 - fabs(WheelSlip))/20.0)*fabs(WheelSlip)/WheelSlip;
404 FCoeff = dynamicFCoeff*fabs(WheelSlip)/WheelSlip;
407 // Compute the vertical force on the wheel using square-law damping (per comment
408 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
409 // allowing for both square and linear damping force calculation. Also need to
410 // possibly give a "rebound damping factor" that differs from the compression
413 vLocalForce(eZ) = min(-compressLength * kSpring
414 - compressSpeed * bDamp, (double)0.0);
416 MaximumStrutForce = max(MaximumStrutForce, fabs(vLocalForce(eZ)));
417 MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
419 // Compute the forces in the wheel ground plane.
422 if (fabs(RollingWhlVel) > 1E-3) {
423 RollingForce = (1.0 - TirePressureNorm) * 30
424 + vLocalForce(eZ) * BrakeFCoeff
425 * fabs(RollingWhlVel)/RollingWhlVel;
427 SideForce = vLocalForce(eZ) * FCoeff;
429 // Transform these forces back to the local reference frame.
431 vLocalForce(eX) = RollingForce*CosWheel - SideForce*SinWheel;
432 vLocalForce(eY) = SideForce*CosWheel + RollingForce*SinWheel;
434 // Note to Jon: At this point the forces will be too big when the airplane is
435 // stopped or rolling to a stop. We need to make sure that the gear forces just
436 // balance out the non-gear forces when the airplane is stopped. That way the
437 // airplane won't start to accelerate until the non-gear/ forces are larger than
438 // the gear forces. I think that the proper fix should go into FGAircraft::FMGear.
439 // This routine would only compute the local strut forces and return them to
440 // FMGear. All of the gear forces would get adjusted in FMGear using the total
441 // non-gear forces. Then the gear moments would be calculated. If strange things
442 // start happening to the airplane during testing as it rolls to a stop, then we
443 // need to implement this change. I ran out of time to do it now but have the
446 // Transform the forces back to the body frame and compute the moment.
448 vForce = Propagate->GetTl2b() * vLocalForce;
449 vMoment = vWhlBodyVec * vForce;
451 } else { // Gear is NOT compressed
455 // Return to neutral position between 1.0 and 0.8 gear pos.
456 SteerAngle *= max(FCS->GetGearPos()-0.8, 0.0)/0.2;
458 if (Propagate->GetDistanceAGL() > 200.0) {
459 FirstContact = false;
460 StartedGroundRun = false;
461 LandingReported = false;
462 LandingDistanceTraveled = 0.0;
463 MaximumStrutForce = MaximumStrutTravel = 0.0;
466 compressLength = 0.0; // reset compressLength to zero for data output validity
469 if (FirstContact) LandingDistanceTraveled += Auxiliary->GetVground()*deltaT;
471 if (StartedGroundRun) {
472 TakeoffDistanceTraveled50ft += Auxiliary->GetVground()*deltaT;
473 if (WOW) TakeoffDistanceTraveled += Auxiliary->GetVground()*deltaT;
476 if (ReportEnable && Auxiliary->GetVground() <= 0.05 && !LandingReported) {
477 if (debug_lvl > 0) Report(erLand);
480 if (ReportEnable && !TakeoffReported &&
481 (vLocalGear(eZ) - Propagate->GetDistanceAGL()) < -50.0)
483 if (debug_lvl > 0) Report(erTakeoff);
486 if (lastWOW != WOW) {
487 PutMessage("GEAR_CONTACT: " + name, WOW);
492 // Crash detection logic (really out-of-bounds detection)
494 if (compressLength > 500.0 ||
495 vForce.Magnitude() > 100000000.0 ||
496 vMoment.Magnitude() > 5000000000.0 ||
497 SinkRate > 1.4666*30)
499 PutMessage("Crash Detected: Simulation FREEZE.");
506 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
508 void FGLGear::Report(ReportType repType)
512 cout << endl << "Touchdown report for " << name << endl;
513 cout << " Sink rate at contact: " << SinkRate << " fps, "
514 << SinkRate*0.3048 << " mps" << endl;
515 cout << " Contact ground speed: " << GroundSpeed*.5925 << " knots, "
516 << GroundSpeed*0.3048 << " mps" << endl;
517 cout << " Maximum contact force: " << MaximumStrutForce << " lbs, "
518 << MaximumStrutForce*4.448 << " Newtons" << endl;
519 cout << " Maximum strut travel: " << MaximumStrutTravel*12.0 << " inches, "
520 << MaximumStrutTravel*30.48 << " cm" << endl;
521 cout << " Distance traveled: " << LandingDistanceTraveled << " ft, "
522 << LandingDistanceTraveled*0.3048 << " meters" << endl;
523 LandingReported = true;
526 cout << endl << "Takeoff report for " << name << endl;
527 cout << " Distance traveled: " << TakeoffDistanceTraveled
528 << " ft, " << TakeoffDistanceTraveled*0.3048 << " meters" << endl;
529 cout << " Distance traveled (over 50'): " << TakeoffDistanceTraveled50ft
530 << " ft, " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl;
531 TakeoffReported = true;
536 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
537 // The bitmasked value choices are as follows:
538 // unset: In this case (the default) JSBSim would only print
539 // out the normally expected messages, essentially echoing
540 // the config files as they are read. If the environment
541 // variable is not set, debug_lvl is set to 1 internally
542 // 0: This requests JSBSim not to output any messages
544 // 1: This value explicity requests the normal JSBSim
546 // 2: This value asks for a message to be printed out when
547 // a class is instantiated
548 // 4: When this value is set, a message is displayed when a
549 // FGModel object executes its Run() method
550 // 8: When this value is set, various runtime state variables
551 // are printed out periodically
552 // 16: When set various parameters are sanity checked and
553 // a message is printed out when they go out of bounds
555 void FGLGear::Debug(int from)
557 if (debug_lvl <= 0) return;
559 if (debug_lvl & 1) { // Standard console startup message output
560 if (from == 0) { // Constructor
561 cout << " Name: " << name << endl;
562 cout << " Location: " << vXYZ << endl;
563 cout << " Spring Constant: " << kSpring << endl;
564 cout << " Damping Constant: " << bDamp << endl;
565 cout << " Dynamic Friction: " << dynamicFCoeff << endl;
566 cout << " Static Friction: " << staticFCoeff << endl;
567 cout << " Rolling Friction: " << rollingFCoeff << endl;
568 cout << " Steering Type: " << sSteerType << endl;
569 cout << " Grouping: " << sBrakeGroup << endl;
570 cout << " Max Steer Angle: " << maxSteerAngle << endl;
571 cout << " Retractable: " << sRetractable << endl;
574 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
575 if (from == 0) cout << "Instantiated: FGLGear" << endl;
576 if (from == 1) cout << "Destroyed: FGLGear" << endl;
578 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
580 if (debug_lvl & 8 ) { // Runtime state variables
582 if (debug_lvl & 16) { // Sanity checking
584 if (debug_lvl & 64) {
585 if (from == 0) { // Constructor
586 cout << IdSrc << endl;
587 cout << IdHdr << endl;
592 } // namespace JSBSim