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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 //#include <algorithm>
46 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 static const char *IdSrc = "$Id$";
55 static const char *IdHdr = ID_LGEAR;
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : Exec(fdmex)
65 *AC_cfg >> tmp >> name >> vXYZ(1) >> vXYZ(2) >> vXYZ(3)
66 >> kSpring >> bDamp>> dynamicFCoeff >> staticFCoeff
67 >> rollingFCoeff >> sSteerType >> sBrakeGroup
68 >> maxSteerAngle >> sRetractable;
70 if (sBrakeGroup == "LEFT" ) eBrakeGrp = bgLeft;
71 else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
72 else if (sBrakeGroup == "CENTER") eBrakeGrp = bgCenter;
73 else if (sBrakeGroup == "NOSE" ) eBrakeGrp = bgNose;
74 else if (sBrakeGroup == "TAIL" ) eBrakeGrp = bgTail;
75 else if (sBrakeGroup == "NONE" ) eBrakeGrp = bgNone;
77 cerr << "Improper braking group specification in config file: "
78 << sBrakeGroup << " is undefined." << endl;
81 if (sSteerType == "STEERABLE") eSteerType = stSteer;
82 else if (sSteerType == "FIXED" ) eSteerType = stFixed;
83 else if (sSteerType == "CASTERED" ) eSteerType = stCaster;
85 cerr << "Improper steering type specification in config file: "
86 << sSteerType << " is undefined." << endl;
89 if ( sRetractable == "RETRACT" ) {
92 isRetractable = false;
99 // Add some AI here to determine if gear is located properly according to its
100 // brake group type ??
102 State = Exec->GetState();
103 Aircraft = Exec->GetAircraft();
104 Position = Exec->GetPosition();
105 Rotation = Exec->GetRotation();
106 FCS = Exec->GetFCS();
107 MassBalance = Exec->GetMassBalance();
109 WOW = lastWOW = true; // should the value be initialized to true?
111 FirstContact = false;
112 StartedGroundRun = false;
113 TakeoffReported = LandingReported = false;
114 LandingDistanceTraveled = TakeoffDistanceTraveled = TakeoffDistanceTraveled50ft = 0.0;
115 MaximumStrutForce = MaximumStrutTravel = 0.0;
116 SinkRate = GroundSpeed = 0.0;
118 vWhlBodyVec = MassBalance->StructuralToBody(vXYZ);
120 vLocalGear = State->GetTb2l() * vWhlBodyVec;
122 compressLength = 0.0;
127 WheelSlip = lastWheelSlip = 0.0;
129 compressLength = 0.0;
134 TirePressureNorm = 1.0;
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 FGLGear::FGLGear(const FGLGear& lgear)
144 Aircraft = lgear.Aircraft;
145 Position = lgear.Position;
146 Rotation = lgear.Rotation;
149 MassBalance = lgear.MassBalance;
152 vMoment = lgear.vMoment;
153 vWhlBodyVec = lgear.vWhlBodyVec;
154 vLocalGear = lgear.vLocalGear;
157 lastWOW = lgear.lastWOW;
158 ReportEnable = lgear.ReportEnable;
159 FirstContact = lgear.FirstContact;
160 StartedGroundRun = lgear.StartedGroundRun;
161 LandingDistanceTraveled = lgear.LandingDistanceTraveled;
162 TakeoffDistanceTraveled = lgear.TakeoffDistanceTraveled;
163 TakeoffDistanceTraveled50ft = lgear.TakeoffDistanceTraveled50ft;
164 MaximumStrutForce = lgear.MaximumStrutForce;
165 MaximumStrutTravel = lgear.MaximumStrutTravel;
167 kSpring = lgear.kSpring;
169 compressLength = lgear.compressLength;
170 compressSpeed = lgear.compressSpeed;
171 staticFCoeff = lgear.staticFCoeff;
172 dynamicFCoeff = lgear.dynamicFCoeff;
173 rollingFCoeff = lgear.rollingFCoeff;
174 brakePct = lgear.brakePct;
175 maxCompLen = lgear.maxCompLen;
176 SinkRate = lgear.SinkRate;
177 GroundSpeed = lgear.GroundSpeed;
178 LandingReported = lgear.LandingReported;
179 TakeoffReported = lgear.TakeoffReported;
181 sSteerType = lgear.sSteerType;
182 sRetractable = lgear.sRetractable;
183 eSteerType = lgear.eSteerType;
184 sBrakeGroup = lgear.sBrakeGroup;
185 eBrakeGrp = lgear.eBrakeGrp;
186 maxSteerAngle = lgear.maxSteerAngle;
187 isRetractable = lgear.isRetractable;
188 GearUp = lgear.GearUp;
189 GearDown = lgear.GearDown;
190 WheelSlip = lgear.WheelSlip;
191 lastWheelSlip = lgear.lastWheelSlip;
192 TirePressureNorm = lgear.TirePressureNorm;
193 Servicable = lgear.Servicable;
196 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 FGColumnVector3& FGLGear::Force(void)
207 double SteerGain = 0;
208 double SinWheel, CosWheel;
210 double deltaT = State->Getdt()*Aircraft->GetRate();
211 double maxdeltaSlip = 0.5*deltaT;
214 vMoment.InitMatrix();
217 if (FCS->GetGearPos() < 0.01) {
220 } else if (FCS->GetGearPos() > 0.99) {
234 vWhlBodyVec = MassBalance->StructuralToBody(vXYZ);
236 // vWhlBodyVec now stores the vector from the cg to this wheel
238 vLocalGear = State->GetTb2l() * vWhlBodyVec;
240 // vLocalGear now stores the vector from the cg to the wheel in local coords.
242 compressLength = vLocalGear(eZ) - Position->GetDistanceAGL();
244 // The compression length is currently measured in the Z-axis, only, at this time.
245 // It should be measured along the strut axis. If the local-frame gear position
246 // "hangs down" below the CG greater than the altitude, then the compressLength
247 // will be positive - i.e. the gear will have made contact.
249 if (compressLength > 0.00) {
251 WOW = true; // Weight-On-Wheels is true
253 // The next equation should really use the vector to the contact patch of the tire
254 // including the strut compression and not vWhlBodyVec. Will fix this later.
255 // As it stands, now, the following equation takes the aircraft body-frame
256 // rotational rate and calculates the cross-product with the vector from the CG
257 // to the wheel, thus producing the instantaneous velocity vector of the tire
258 // in Body coords. The frame is also converted to local coordinates. When the
259 // aircraft local-frame velocity is added to this quantity, the total velocity of
260 // the wheel in local frame is then known. Subsequently, the compression speed
261 // (used for calculating damping force) is found by taking the Z-component of the
264 vWhlVelVec = State->GetTb2l() * (Rotation->GetPQR() * vWhlBodyVec);
266 vWhlVelVec += Position->GetVel();
268 compressSpeed = vWhlVelVec(eZ);
270 // If this is the first time the wheel has made contact, remember some values
271 // for later printout.
275 SinkRate = compressSpeed;
276 GroundSpeed = Position->GetVel().Magnitude();
277 TakeoffReported = false;
280 // If the takeoff run is starting, initialize.
282 if ((Position->GetVel().Magnitude() > 0.1) &&
283 (FCS->GetBrake(bgLeft) == 0) &&
284 (FCS->GetBrake(bgRight) == 0) &&
285 (FCS->GetThrottlePos(0) == 1) && !StartedGroundRun)
287 TakeoffDistanceTraveled = 0;
288 TakeoffDistanceTraveled50ft = 0;
289 StartedGroundRun = true;
292 // The following needs work regarding friction coefficients and braking and
293 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
294 // It also assumes that we won't be turning and braking at the same time.
295 // Will fix this later.
296 // [JSB] The braking force coefficients include normal rolling coefficient +
297 // a percentage of the static friction coefficient based on braking applied.
301 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgLeft)) +
302 staticFCoeff*FCS->GetBrake(bgLeft) );
305 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgRight)) +
306 staticFCoeff*FCS->GetBrake(bgRight) );
309 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
310 staticFCoeff*FCS->GetBrake(bgCenter) );
313 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
314 staticFCoeff*FCS->GetBrake(bgCenter) );
317 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
318 staticFCoeff*FCS->GetBrake(bgCenter) );
321 BrakeFCoeff = rollingFCoeff;
324 cerr << "Improper brake group membership detected for this gear." << endl;
328 switch (eSteerType) {
330 SteerAngle = -maxSteerAngle * FCS->GetDrCmd() * 0.01745;
336 // Note to Jon: This is not correct for castering gear. I'll fix it later.
340 cerr << "Improper steering type membership detected for this gear." << endl;
344 // Transform the wheel velocities from the local axis system to the wheel axis system.
345 // For now, steering angle is assumed to happen in the Local Z axis,
346 // not the strut axis as it should be. Will fix this later.
348 SinWheel = sin(Rotation->Getpsi() + SteerAngle);
349 CosWheel = cos(Rotation->Getpsi() + SteerAngle);
350 RollingWhlVel = vWhlVelVec(eX)*CosWheel + vWhlVelVec(eY)*SinWheel;
351 SideWhlVel = vWhlVelVec(eY)*CosWheel - vWhlVelVec(eX)*SinWheel;
353 // Calculate tire slip angle.
355 if (RollingWhlVel == 0.0 && SideWhlVel == 0.0) {
357 } else if (fabs(RollingWhlVel) < 1.0) {
358 WheelSlip = 0.05*radtodeg*atan2(SideWhlVel, RollingWhlVel) + 0.95*WheelSlip;
360 WheelSlip = radtodeg*atan2(SideWhlVel, RollingWhlVel);
363 if (RollingWhlVel == 0.0 && SideWhlVel == 0.0) {
365 } else if (RollingWhlVel < 1.0) {
366 WheelSlip = radtodeg*atan2(SideWhlVel, RollingWhlVel);
367 deltaSlip = WheelSlip - lastWheelSlip;
368 if (fabs(deltaSlip) > maxdeltaSlip) {
369 if (WheelSlip > lastWheelSlip) {
370 WheelSlip = lastWheelSlip + maxdeltaSlip;
371 } else if (WheelSlip < lastWheelSlip) {
372 WheelSlip = lastWheelSlip - maxdeltaSlip;
376 WheelSlip = radtodeg*atan2(SideWhlVel, RollingWhlVel);
379 if ((WheelSlip < 0.0 && lastWheelSlip > 0.0) ||
380 (WheelSlip > 0.0 && lastWheelSlip < 0.0))
385 lastWheelSlip = WheelSlip;
387 // Compute the sideforce coefficients using similar assumptions to LaRCSim for now.
388 // Allow a maximum of 10 degrees tire slip angle before wheel slides. At that point,
389 // transition from static to dynamic friction. There are more complicated formulations
390 // of this that avoid the discrete jump. Will fix this later.
392 if (fabs(WheelSlip) <= 20.0) {
393 FCoeff = staticFCoeff*WheelSlip/20.0;
394 } else if (fabs(WheelSlip) <= 40.0) {
395 // FCoeff = dynamicFCoeff*fabs(WheelSlip)/WheelSlip;
396 FCoeff = (dynamicFCoeff*(fabs(WheelSlip) - 20.0)/20.0 +
397 staticFCoeff*(40.0 - fabs(WheelSlip))/20.0)*fabs(WheelSlip)/WheelSlip;
399 FCoeff = dynamicFCoeff*fabs(WheelSlip)/WheelSlip;
402 // Compute the vertical force on the wheel using square-law damping (per comment
403 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
404 // allowing for both square and linear damping force calculation. Also need to
405 // possibly give a "rebound damping factor" that differs from the compression
408 vLocalForce(eZ) = min(-compressLength * kSpring
409 - compressSpeed * bDamp, (double)0.0);
411 MaximumStrutForce = max(MaximumStrutForce, fabs(vLocalForce(eZ)));
412 MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
414 // Compute the forces in the wheel ground plane.
417 if (fabs(RollingWhlVel) > 1E-3) {
418 RollingForce = (1.0 - TirePressureNorm) * 30
419 + vLocalForce(eZ) * BrakeFCoeff
420 * fabs(RollingWhlVel)/RollingWhlVel;
422 SideForce = vLocalForce(eZ) * FCoeff;
424 // Transform these forces back to the local reference frame.
426 vLocalForce(eX) = RollingForce*CosWheel - SideForce*SinWheel;
427 vLocalForce(eY) = SideForce*CosWheel + RollingForce*SinWheel;
429 // Note to Jon: At this point the forces will be too big when the airplane is
430 // stopped or rolling to a stop. We need to make sure that the gear forces just
431 // balance out the non-gear forces when the airplane is stopped. That way the
432 // airplane won't start to accelerate until the non-gear/ forces are larger than
433 // the gear forces. I think that the proper fix should go into FGAircraft::FMGear.
434 // This routine would only compute the local strut forces and return them to
435 // FMGear. All of the gear forces would get adjusted in FMGear using the total
436 // non-gear forces. Then the gear moments would be calculated. If strange things
437 // start happening to the airplane during testing as it rolls to a stop, then we
438 // need to implement this change. I ran out of time to do it now but have the
441 // Transform the forces back to the body frame and compute the moment.
443 vForce = State->GetTl2b() * vLocalForce;
444 vMoment = vWhlBodyVec * vForce;
446 } else { // Gear is NOT compressed
450 if (Position->GetDistanceAGL() > 200.0) {
451 FirstContact = false;
452 StartedGroundRun = false;
453 LandingReported = false;
454 LandingDistanceTraveled = 0.0;
455 MaximumStrutForce = MaximumStrutTravel = 0.0;
458 compressLength = 0.0; // reset compressLength to zero for data output validity
461 if (FirstContact) LandingDistanceTraveled += Position->GetVground()*deltaT;
463 if (StartedGroundRun) {
464 TakeoffDistanceTraveled50ft += Position->GetVground()*deltaT;
465 if (WOW) TakeoffDistanceTraveled += Position->GetVground()*deltaT;
468 if (ReportEnable && Position->GetVground() <= 0.05 && !LandingReported) {
469 if (debug_lvl > 0) Report(erLand);
472 if (ReportEnable && !TakeoffReported &&
473 (vLocalGear(eZ) - Position->GetDistanceAGL()) < -50.0)
475 if (debug_lvl > 0) Report(erTakeoff);
478 if (lastWOW != WOW) {
479 PutMessage("GEAR_CONTACT: " + name, WOW);
484 // Crash detection logic (really out-of-bounds detection)
486 if (compressLength > 500.0 ||
487 vForce.Magnitude() > 100000000.0 ||
488 vMoment.Magnitude() > 5000000000.0 ||
489 SinkRate > 1.4666*30)
491 PutMessage("Crash Detected: Simulation FREEZE.");
498 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
500 void FGLGear::Report(ReportType repType)
504 cout << endl << "Touchdown report for " << name << endl;
505 cout << " Sink rate at contact: " << SinkRate << " fps, "
506 << SinkRate*0.3048 << " mps" << endl;
507 cout << " Contact ground speed: " << GroundSpeed*.5925 << " knots, "
508 << GroundSpeed*0.3048 << " mps" << endl;
509 cout << " Maximum contact force: " << MaximumStrutForce << " lbs, "
510 << MaximumStrutForce*4.448 << " Newtons" << endl;
511 cout << " Maximum strut travel: " << MaximumStrutTravel*12.0 << " inches, "
512 << MaximumStrutTravel*30.48 << " cm" << endl;
513 cout << " Distance traveled: " << LandingDistanceTraveled << " ft, "
514 << LandingDistanceTraveled*0.3048 << " meters" << endl;
515 LandingReported = true;
518 cout << endl << "Takeoff report for " << name << endl;
519 cout << " Distance traveled: " << TakeoffDistanceTraveled
520 << " ft, " << TakeoffDistanceTraveled*0.3048 << " meters" << endl;
521 cout << " Distance traveled (over 50'): " << TakeoffDistanceTraveled50ft
522 << " ft, " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl;
523 TakeoffReported = true;
528 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
529 // The bitmasked value choices are as follows:
530 // unset: In this case (the default) JSBSim would only print
531 // out the normally expected messages, essentially echoing
532 // the config files as they are read. If the environment
533 // variable is not set, debug_lvl is set to 1 internally
534 // 0: This requests JSBSim not to output any messages
536 // 1: This value explicity requests the normal JSBSim
538 // 2: This value asks for a message to be printed out when
539 // a class is instantiated
540 // 4: When this value is set, a message is displayed when a
541 // FGModel object executes its Run() method
542 // 8: When this value is set, various runtime state variables
543 // are printed out periodically
544 // 16: When set various parameters are sanity checked and
545 // a message is printed out when they go out of bounds
547 void FGLGear::Debug(int from)
549 if (debug_lvl <= 0) return;
551 if (debug_lvl & 1) { // Standard console startup message output
552 if (from == 0) { // Constructor
553 cout << " Name: " << name << endl;
554 cout << " Location: " << vXYZ << endl;
555 cout << " Spring Constant: " << kSpring << endl;
556 cout << " Damping Constant: " << bDamp << endl;
557 cout << " Dynamic Friction: " << dynamicFCoeff << endl;
558 cout << " Static Friction: " << staticFCoeff << endl;
559 cout << " Rolling Friction: " << rollingFCoeff << endl;
560 cout << " Steering Type: " << sSteerType << endl;
561 cout << " Grouping: " << sBrakeGroup << endl;
562 cout << " Max Steer Angle: " << maxSteerAngle << endl;
563 cout << " Retractable: " << sRetractable << endl;
566 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
567 if (from == 0) cout << "Instantiated: FGLGear" << endl;
568 if (from == 1) cout << "Destroyed: FGLGear" << endl;
570 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
572 if (debug_lvl & 8 ) { // Runtime state variables
574 if (debug_lvl & 16) { // Sanity checking
576 if (debug_lvl & 64) {
577 if (from == 0) { // Constructor
578 cout << IdSrc << endl;
579 cout << IdHdr << endl;
584 } // namespace JSBSim