1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 Purpose: Encapsulates the landing gear elements
11 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
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
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
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.
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.
30 FUNCTIONAL DESCRIPTION
31 --------------------------------------------------------------------------------
34 --------------------------------------------------------------------------------
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
39 /%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #include "input_output/FGPropertyManager.h"
48 #include "models/FGGroundReactions.h"
49 #include "math/FGTable.h"
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 static const char *IdSrc = "$Id: FGLGear.cpp,v 1.92 2011/11/10 12:06:14 jberndt Exp $";
64 static const char *IdHdr = ID_LGEAR;
66 // Body To Structural (body frame is rotated 180 deg about Y and lengths are given in
67 // ft instead of inches)
68 const FGMatrix33 FGLGear::Tb2s(-1./inchtoft, 0., 0., 0., 1./inchtoft, 0., 0., 0., -1./inchtoft);
70 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74 FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number, const struct Inputs& inputs) :
82 Element *force_table=0;
84 Element *dampCoeffRebound=0;
87 kSpring = bDamp = bDampRebound = dynamicFCoeff = staticFCoeff = rollingFCoeff = maxSteerAngle = 0;
88 sSteerType = sBrakeGroup = sSteerType = "";
91 eDampTypeRebound = dtLinear;
93 name = el->GetAttributeValue("name");
94 sContactType = el->GetAttributeValue("type");
95 if (sContactType == "BOGEY") {
96 eContactType = ctBOGEY;
97 } else if (sContactType == "STRUCTURE") {
98 eContactType = ctSTRUCTURE;
100 // Unknown contact point types will be treated as STRUCTURE.
101 eContactType = ctSTRUCTURE;
104 // Default values for structural contact points
105 if (eContactType == ctSTRUCTURE) {
106 kSpring = in.EmptyWeight;
108 bDampRebound = kSpring * 10;
113 if (el->FindElement("spring_coeff"))
114 kSpring = el->FindElementValueAsNumberConvertTo("spring_coeff", "LBS/FT");
115 if (el->FindElement("damping_coeff")) {
116 dampCoeff = el->FindElement("damping_coeff");
117 if (dampCoeff->GetAttributeValue("type") == "SQUARE") {
118 eDampType = dtSquare;
119 bDamp = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT2/SEC2");
121 bDamp = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT/SEC");
125 if (el->FindElement("damping_coeff_rebound")) {
126 dampCoeffRebound = el->FindElement("damping_coeff_rebound");
127 if (dampCoeffRebound->GetAttributeValue("type") == "SQUARE") {
128 eDampTypeRebound = dtSquare;
129 bDampRebound = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT2/SEC2");
131 bDampRebound = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT/SEC");
134 bDampRebound = bDamp;
135 eDampTypeRebound = eDampType;
138 if (el->FindElement("dynamic_friction"))
139 dynamicFCoeff = el->FindElementValueAsNumber("dynamic_friction");
140 if (el->FindElement("static_friction"))
141 staticFCoeff = el->FindElementValueAsNumber("static_friction");
142 if (el->FindElement("rolling_friction"))
143 rollingFCoeff = el->FindElementValueAsNumber("rolling_friction");
144 if (el->FindElement("max_steer"))
145 maxSteerAngle = el->FindElementValueAsNumberConvertTo("max_steer", "DEG");
146 if (el->FindElement("retractable"))
147 isRetractable = ((unsigned int)el->FindElementValueAsNumber("retractable"))>0.0?true:false;
149 GroundReactions = fdmex->GetGroundReactions();
150 PropertyManager = fdmex->GetPropertyManager();
153 force_table = el->FindElement("table");
154 while (force_table) {
155 force_type = force_table->GetAttributeValue("type");
156 if (force_type == "CORNERING_COEFF") {
157 ForceY_Table = new FGTable(PropertyManager, force_table);
159 cerr << "Undefined force table for " << name << " contact point" << endl;
161 force_table = el->FindNextElement("table");
164 sBrakeGroup = el->FindElementValue("brake_group");
166 if (maxSteerAngle == 360) sSteerType = "CASTERED";
167 else if (maxSteerAngle == 0.0) sSteerType = "FIXED";
168 else sSteerType = "STEERABLE";
170 Element* element = el->FindElement("location");
171 if (element) vXYZn = element->FindElementTripletConvertTo("IN");
172 else {cerr << "No location given for contact " << name << endl; exit(-1);}
173 SetTransformType(FGForce::tCustom);
175 element = el->FindElement("orientation");
176 if (element && (eContactType == ctBOGEY)) {
177 vGearOrient = element->FindElementTripletConvertTo("RAD");
179 double cp,sp,cr,sr,cy,sy;
181 cp=cos(vGearOrient(ePitch)); sp=sin(vGearOrient(ePitch));
182 cr=cos(vGearOrient(eRoll)); sr=sin(vGearOrient(eRoll));
183 cy=cos(vGearOrient(eYaw)); sy=sin(vGearOrient(eYaw));
189 mTGear(1,2) = sr*sp*cy - cr*sy;
190 mTGear(2,2) = sr*sp*sy + cr*cy;
193 mTGear(1,3) = cr*sp*cy + sr*sy;
194 mTGear(2,3) = cr*sp*sy - sr*cy;
203 if (sBrakeGroup == "LEFT" ) eBrakeGrp = bgLeft;
204 else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
205 else if (sBrakeGroup == "CENTER") eBrakeGrp = bgCenter;
206 else if (sBrakeGroup == "NOSE" ) eBrakeGrp = bgNose;
207 else if (sBrakeGroup == "TAIL" ) eBrakeGrp = bgTail;
208 else if (sBrakeGroup == "NONE" ) eBrakeGrp = bgNone;
209 else if (sBrakeGroup.empty() ) {eBrakeGrp = bgNone;
210 sBrakeGroup = "NONE (defaulted)";}
212 cerr << "Improper braking group specification in config file: "
213 << sBrakeGroup << " is undefined." << endl;
216 if (sSteerType == "STEERABLE") eSteerType = stSteer;
217 else if (sSteerType == "FIXED" ) eSteerType = stFixed;
218 else if (sSteerType == "CASTERED" ) {eSteerType = stCaster; Castered = true;}
219 else if (sSteerType.empty() ) {eSteerType = stFixed;
220 sSteerType = "FIXED (defaulted)";}
222 cerr << "Improper steering type specification in config file: "
223 << sSteerType << " is undefined." << endl;
229 useFCSGearPos = false;
232 // Add some AI here to determine if gear is located properly according to its
233 // brake group type ??
235 WOW = lastWOW = false;
237 FirstContact = false;
238 StartedGroundRun = false;
239 TakeoffReported = LandingReported = false;
240 LandingDistanceTraveled = TakeoffDistanceTraveled = TakeoffDistanceTraveled50ft = 0.0;
241 MaximumStrutForce = MaximumStrutTravel = 0.0;
242 SinkRate = GroundSpeed = 0.0;
244 vWhlVelVec.InitMatrix();
246 compressLength = 0.0;
252 TirePressureNorm = 1.0;
261 // Initialize Lagrange multipliers
262 memset(LMultiplier, 0, sizeof(LMultiplier));
267 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 const FGColumnVector3& FGLGear::GetBodyForces(void)
279 double t = fdmex->GetSimTime();
283 if (isRetractable) ComputeRetractionState();
286 FGColumnVector3 terrainVel, dummy;
288 vLocalGear = in.Tb2l * in.vWhlBodyVec[GearNumber]; // Get local frame wheel location
290 gearLoc = in.Location.LocalToLocation(vLocalGear);
291 // Compute the height of the theoretical location of the wheel (if strut is
292 // not compressed) with respect to the ground level
293 double height = gearLoc.GetContactPoint(t, contact, normal, terrainVel, dummy);
294 vGroundNormal = in.Tec2b * normal;
296 // The height returned above is the AGL and is expressed in the Z direction
297 // of the ECEF coordinate frame. We now need to transform this height in
298 // actual compression of the strut (BOGEY) of in the normal direction to the
299 // ground (STRUCTURE)
300 double normalZ = (in.Tec2l*normal)(eZ);
301 double LGearProj = -(mTGear.Transposed() * vGroundNormal)(eZ);
303 switch (eContactType) {
305 compressLength = LGearProj > 0.0 ? height * normalZ / LGearProj : 0.0;
308 compressLength = height * normalZ / DotProduct(normal, normal);
312 if (compressLength > 0.00) {
315 // The following equations use the vector to the tire contact patch
316 // including the strut compression.
317 FGColumnVector3 vWhlDisplVec;
319 switch(eContactType) {
321 vWhlDisplVec = mTGear * FGColumnVector3(0., 0., -compressLength);
324 vWhlDisplVec = compressLength * vGroundNormal;
328 FGColumnVector3 vWhlContactVec = in.vWhlBodyVec[GearNumber] + vWhlDisplVec;
329 vActingXYZn = vXYZn + Tb2s * vWhlDisplVec;
330 FGColumnVector3 vBodyWhlVel = in.PQR * vWhlContactVec;
331 vBodyWhlVel += in.UVW - in.Tec2b * terrainVel;
333 vWhlVelVec = mTGear.Transposed() * vBodyWhlVel;
335 InitializeReporting();
336 ComputeSteeringAngle();
337 ComputeGroundCoordSys();
339 vLocalWhlVel = Transform().Transposed() * vBodyWhlVel;
341 if (fdmex->GetTrimStatus())
342 compressSpeed = 0.0; // Steady state is sought during trimming
344 compressSpeed = -vLocalWhlVel(eX);
345 if (eContactType == ctBOGEY) compressSpeed /= LGearProj;
348 ComputeVerticalStrutForce();
350 // Compute the friction coefficients in the wheel ground plane.
351 if (eContactType == ctBOGEY) {
353 ComputeBrakeForceCoefficient();
354 ComputeSideForceCoefficient();
357 // Prepare the Jacobians and the Lagrange multipliers for later friction
358 // forces calculations.
359 ComputeJacobian(vWhlContactVec);
361 } else { // Gear is NOT compressed
364 compressLength = 0.0;
369 // Let wheel spin down slowly
370 vWhlVelVec(eX) -= 13.0 * in.TotalDeltaT;
371 if (vWhlVelVec(eX) < 0.0) vWhlVelVec(eX) = 0.0;
373 // Return to neutral position between 1.0 and 0.8 gear pos.
374 SteerAngle *= max(GetGearUnitPos()-0.8, 0.0)/0.2;
380 if (!fdmex->GetTrimStatus()) {
381 ReportTakeoffOrLanding();
383 // Require both WOW and LastWOW to be true before checking crash conditions
384 // to allow the WOW flag to be used in terminating a scripted run.
385 if (WOW && lastWOW) CrashDetect();
390 return FGForce::GetBodyForces();
393 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
394 // Build a local "ground" coordinate system defined by
395 // eX : normal to the ground
396 // eY : projection of the rolling direction on the ground
397 // eZ : projection of the sliping direction on the ground
399 void FGLGear::ComputeGroundCoordSys(void)
401 // Euler angles are built up to create a local frame to describe the forces
402 // applied to the gear by the ground. Here pitch, yaw and roll do not have
403 // any physical meaning. It is just a convenient notation.
404 // First, "pitch" and "yaw" are determined in order to align eX with the
406 if (vGroundNormal(eZ) < -1.0)
407 vOrient(ePitch) = 0.5*M_PI;
408 else if (1.0 < vGroundNormal(eZ))
409 vOrient(ePitch) = -0.5*M_PI;
411 vOrient(ePitch) = asin(-vGroundNormal(eZ));
413 if (fabs(vOrient(ePitch)) == 0.5*M_PI)
416 vOrient(eYaw) = atan2(vGroundNormal(eY), vGroundNormal(eX));
419 UpdateCustomTransformMatrix();
421 if (eContactType == ctBOGEY) {
422 // In the case of a bogey, the third angle "roll" is used to align the axis eY and eZ
423 // to the rolling and sliping direction respectively.
424 FGColumnVector3 updatedRollingAxis = Transform().Transposed() * mTGear
425 * FGColumnVector3(-sin(SteerAngle), cos(SteerAngle), 0.);
427 vOrient(eRoll) = atan2(updatedRollingAxis(eY), -updatedRollingAxis(eZ));
428 UpdateCustomTransformMatrix();
432 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434 void FGLGear::ComputeRetractionState(void)
436 double gearPos = GetGearUnitPos();
437 if (gearPos < 0.01) {
441 vWhlVelVec.InitMatrix();
442 } else if (gearPos > 0.99) {
451 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
452 // Calculate tire slip angle.
454 void FGLGear::ComputeSlipAngle(void)
456 // Check that the speed is non-null otherwise use the current angle
457 if (vLocalWhlVel.Magnitude(eY,eZ) > 1E-3)
458 WheelSlip = -atan2(vLocalWhlVel(eZ), fabs(vLocalWhlVel(eY)))*radtodeg;
461 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
462 // Compute the steering angle in any case.
463 // This will also make sure that animations will look right.
465 void FGLGear::ComputeSteeringAngle(void)
467 switch (eSteerType) {
469 SteerAngle = degtorad * in.SteerPosDeg[GearNumber];
476 SteerAngle = degtorad * in.SteerPosDeg[GearNumber];
478 // Check that the speed is non-null otherwise use the current angle
479 if (vWhlVelVec.Magnitude(eX,eY) > 0.1)
480 SteerAngle = atan2(vWhlVelVec(eY), fabs(vWhlVelVec(eX)));
484 cerr << "Improper steering type membership detected for this gear." << endl;
489 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
490 // Reset reporting functionality after takeoff
492 void FGLGear::ResetReporting(void)
494 if (in.DistanceAGL > 200.0) {
495 FirstContact = false;
496 StartedGroundRun = false;
497 LandingReported = false;
498 TakeoffReported = true;
499 LandingDistanceTraveled = 0.0;
500 MaximumStrutForce = MaximumStrutTravel = 0.0;
504 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506 void FGLGear::InitializeReporting(void)
508 // If this is the first time the wheel has made contact, remember some values
509 // for later printout.
513 SinkRate = compressSpeed;
514 GroundSpeed = in.Vground;
515 TakeoffReported = false;
518 // If the takeoff run is starting, initialize.
520 if ((in.Vground > 0.1) &&
521 (in.BrakePos[bgLeft] == 0) &&
522 (in.BrakePos[bgRight] == 0) &&
523 (in.TakeoffThrottle && !StartedGroundRun))
525 TakeoffDistanceTraveled = 0;
526 TakeoffDistanceTraveled50ft = 0;
527 StartedGroundRun = true;
531 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
532 // Takeoff and landing reporting functionality
534 void FGLGear::ReportTakeoffOrLanding(void)
537 LandingDistanceTraveled += in.Vground * in.TotalDeltaT;
539 if (StartedGroundRun) {
540 TakeoffDistanceTraveled50ft += in.Vground * in.TotalDeltaT;
541 if (WOW) TakeoffDistanceTraveled += in.Vground * in.TotalDeltaT;
545 && in.Vground <= 0.05
549 if (debug_lvl > 0) Report(erLand);
554 && (in.DistanceAGL - vLocalGear(eZ)) > 50.0
557 if (debug_lvl > 0) Report(erTakeoff);
560 if (lastWOW != WOW) PutMessage("GEAR_CONTACT: " + name, WOW);
563 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
564 // Crash detection logic (really out-of-bounds detection)
566 void FGLGear::CrashDetect(void)
568 if ( (compressLength > 500.0 ||
569 vFn.Magnitude() > 100000000.0 ||
570 GetMoments().Magnitude() > 5000000000.0 ||
571 SinkRate > 1.4666*30 ) && !fdmex->IntegrationSuspended())
573 PutMessage("Crash Detected: Simulation FREEZE.");
574 fdmex->SuspendIntegration();
578 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
579 // The following needs work regarding friction coefficients and braking and
580 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
581 // It also assumes that we won't be turning and braking at the same time.
582 // Will fix this later.
583 // [JSB] The braking force coefficients include normal rolling coefficient +
584 // a percentage of the static friction coefficient based on braking applied.
586 void FGLGear::ComputeBrakeForceCoefficient(void)
590 BrakeFCoeff = ( rollingFCoeff * (1.0 - in.BrakePos[bgLeft]) +
591 staticFCoeff * in.BrakePos[bgLeft] );
594 BrakeFCoeff = ( rollingFCoeff * (1.0 - in.BrakePos[bgRight]) +
595 staticFCoeff * in.BrakePos[bgRight] );
598 BrakeFCoeff = ( rollingFCoeff * (1.0 - in.BrakePos[bgCenter]) +
599 staticFCoeff * in.BrakePos[bgCenter] );
602 BrakeFCoeff = ( rollingFCoeff * (1.0 - in.BrakePos[bgCenter]) +
603 staticFCoeff * in.BrakePos[bgCenter] );
606 BrakeFCoeff = ( rollingFCoeff * (1.0 - in.BrakePos[bgCenter]) +
607 staticFCoeff * in.BrakePos[bgCenter] );
610 BrakeFCoeff = rollingFCoeff;
613 cerr << "Improper brake group membership detected for this gear." << endl;
618 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619 // Compute the sideforce coefficients using Pacejka's Magic Formula.
621 // y(x) = D sin {C arctan [Bx - E(Bx - arctan Bx)]}
623 // Where: B = Stiffness Factor (0.06, here)
624 // C = Shape Factor (2.8, here)
625 // D = Peak Factor (0.8, here)
626 // E = Curvature Factor (1.03, here)
628 void FGLGear::ComputeSideForceCoefficient(void)
631 FCoeff = ForceY_Table->GetValue(WheelSlip);
633 double StiffSlip = Stiffness*WheelSlip;
634 FCoeff = Peak * sin(Shape*atan(StiffSlip - Curvature*(StiffSlip - atan(StiffSlip))));
638 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
639 // Compute the vertical force on the wheel using square-law damping (per comment
640 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
641 // allowing for both square and linear damping force calculation. Also need to
642 // possibly give a "rebound damping factor" that differs from the compression
645 void FGLGear::ComputeVerticalStrutForce(void)
647 double springForce = 0;
648 double dampForce = 0;
650 springForce = -compressLength * kSpring;
652 if (compressSpeed >= 0.0) {
654 if (eDampType == dtLinear) dampForce = -compressSpeed * bDamp;
655 else dampForce = -compressSpeed * compressSpeed * bDamp;
659 if (eDampTypeRebound == dtLinear)
660 dampForce = -compressSpeed * bDampRebound;
662 dampForce = compressSpeed * compressSpeed * bDampRebound;
666 StrutForce = min(springForce + dampForce, (double)0.0);
668 // The reaction force of the wheel is always normal to the ground
669 switch (eContactType) {
671 // Project back the strut force in the local coordinate frame of the ground
672 vFn(eX) = StrutForce / (mTGear.Transposed()*vGroundNormal)(eZ);
675 vFn(eX) = -StrutForce;
679 // Remember these values for reporting
680 MaximumStrutForce = max(MaximumStrutForce, fabs(StrutForce));
681 MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
684 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
686 double FGLGear::GetGearUnitPos(void)
688 // hack to provide backward compatibility to gear/gear-pos-norm property
689 if( useFCSGearPos || in.FCSGearPos != 1.0 ) {
690 useFCSGearPos = true;
691 return in.FCSGearPos;
696 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
697 // Compute the jacobian entries for the friction forces resolution later
700 void FGLGear::ComputeJacobian(const FGColumnVector3& vWhlContactVec)
702 // When the point of contact is moving, dynamic friction is used
703 // This type of friction is limited to ctSTRUCTURE elements because their
704 // friction coefficient is the same in every directions
705 if ((eContactType == ctSTRUCTURE) && (vLocalWhlVel.Magnitude(eY,eZ) > 1E-3)) {
706 FGColumnVector3 velocityDirection = vLocalWhlVel;
708 StaticFriction = false;
710 velocityDirection(eX) = 0.;
711 velocityDirection.Normalize();
713 LMultiplier[ftDynamic].ForceJacobian = Transform()*velocityDirection;
714 LMultiplier[ftDynamic].MomentJacobian = vWhlContactVec * LMultiplier[ftDynamic].ForceJacobian;
715 LMultiplier[ftDynamic].Max = 0.;
716 LMultiplier[ftDynamic].Min = -fabs(dynamicFCoeff * vFn(eX));
718 // The Lagrange multiplier value obtained from the previous iteration is kept
719 // This is supposed to accelerate the convergence of the projected Gauss-Seidel
720 // algorithm. The code just below is to make sure that the initial value
721 // is consistent with the current friction coefficient and normal reaction.
722 LMultiplier[ftDynamic].value = Constrain(LMultiplier[ftDynamic].Min, LMultiplier[ftDynamic].value, LMultiplier[ftDynamic].Max);
724 GroundReactions->RegisterLagrangeMultiplier(&LMultiplier[ftDynamic]);
727 // Static friction is used for ctSTRUCTURE when the contact point is not moving.
728 // It is always used for ctBOGEY elements because the friction coefficients
729 // of a tyre depend on the direction of the movement (roll & side directions).
730 // This cannot be handled properly by the so-called "dynamic friction".
731 StaticFriction = true;
733 LMultiplier[ftRoll].ForceJacobian = Transform()*FGColumnVector3(0.,1.,0.);
734 LMultiplier[ftSide].ForceJacobian = Transform()*FGColumnVector3(0.,0.,1.);
735 LMultiplier[ftRoll].MomentJacobian = vWhlContactVec * LMultiplier[ftRoll].ForceJacobian;
736 LMultiplier[ftSide].MomentJacobian = vWhlContactVec * LMultiplier[ftSide].ForceJacobian;
738 switch(eContactType) {
740 LMultiplier[ftRoll].Max = fabs(BrakeFCoeff * vFn(eX));
741 LMultiplier[ftSide].Max = fabs(FCoeff * vFn(eX));
744 LMultiplier[ftRoll].Max = fabs(staticFCoeff * vFn(eX));
745 LMultiplier[ftSide].Max = fabs(staticFCoeff * vFn(eX));
749 LMultiplier[ftRoll].Min = -LMultiplier[ftRoll].Max;
750 LMultiplier[ftSide].Min = -LMultiplier[ftSide].Max;
752 // The Lagrange multiplier value obtained from the previous iteration is kept
753 // This is supposed to accelerate the convergence of the projected Gauss-Seidel
754 // algorithm. The code just below is to make sure that the initial value
755 // is consistent with the current friction coefficient and normal reaction.
756 LMultiplier[ftRoll].value = Constrain(LMultiplier[ftRoll].Min, LMultiplier[ftRoll].value, LMultiplier[ftRoll].Max);
757 LMultiplier[ftSide].value = Constrain(LMultiplier[ftSide].Min, LMultiplier[ftSide].value, LMultiplier[ftSide].Max);
759 GroundReactions->RegisterLagrangeMultiplier(&LMultiplier[ftRoll]);
760 GroundReactions->RegisterLagrangeMultiplier(&LMultiplier[ftSide]);
764 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765 // This routine is called after the Lagrange multiplier has been computed in
766 // the FGAccelerations class. The friction forces of the landing gear are then
767 // updated accordingly.
768 void FGLGear::UpdateForces(void)
770 if (StaticFriction) {
771 vFn(eY) = LMultiplier[ftRoll].value;
772 vFn(eZ) = LMultiplier[ftSide].value;
775 vFn += LMultiplier[ftDynamic].value * (Transform ().Transposed() * LMultiplier[ftDynamic].ForceJacobian);
778 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
780 void FGLGear::bind(void)
782 string property_name;
783 string base_property_name;
785 switch(eContactType) {
787 base_property_name = CreateIndexedPropertyName("gear/unit", GearNumber);
790 base_property_name = CreateIndexedPropertyName("contact/unit", GearNumber);
796 property_name = base_property_name + "/WOW";
797 PropertyManager->Tie( property_name.c_str(), &WOW );
798 property_name = base_property_name + "/z-position";
799 PropertyManager->Tie( property_name.c_str(), (FGForce*)this,
800 &FGForce::GetLocationZ, &FGForce::SetLocationZ);
801 property_name = base_property_name + "/compression-ft";
802 PropertyManager->Tie( property_name.c_str(), &compressLength );
803 property_name = base_property_name + "/static_friction_coeff";
804 PropertyManager->Tie( property_name.c_str(), &staticFCoeff );
805 property_name = base_property_name + "/dynamic_friction_coeff";
806 PropertyManager->Tie( property_name.c_str(), &dynamicFCoeff );
808 if (eContactType == ctBOGEY) {
809 property_name = base_property_name + "/slip-angle-deg";
810 PropertyManager->Tie( property_name.c_str(), &WheelSlip );
811 property_name = base_property_name + "/wheel-speed-fps";
812 PropertyManager->Tie( property_name.c_str(), (FGLGear*)this,
813 &FGLGear::GetWheelRollVel);
814 property_name = base_property_name + "/side_friction_coeff";
815 PropertyManager->Tie( property_name.c_str(), &FCoeff );
816 property_name = base_property_name + "/rolling_friction_coeff";
817 PropertyManager->Tie( property_name.c_str(), &rollingFCoeff );
819 if (eSteerType == stCaster) {
820 property_name = base_property_name + "/steering-angle-deg";
821 PropertyManager->Tie( property_name.c_str(), this, &FGLGear::GetSteerAngleDeg );
822 property_name = base_property_name + "/castered";
823 PropertyManager->Tie( property_name.c_str(), &Castered);
827 if( isRetractable ) {
828 property_name = base_property_name + "/pos-norm";
829 PropertyManager->Tie( property_name.c_str(), &GearPos );
833 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
835 void FGLGear::Report(ReportType repType)
837 if (fabs(TakeoffDistanceTraveled) < 0.001) return; // Don't print superfluous reports
841 cout << endl << "Touchdown report for " << name << " (WOW at time: "
842 << fdmex->GetSimTime() << " seconds)" << endl;
843 cout << " Sink rate at contact: " << SinkRate << " fps, "
844 << SinkRate*0.3048 << " mps" << endl;
845 cout << " Contact ground speed: " << GroundSpeed*.5925 << " knots, "
846 << GroundSpeed*0.3048 << " mps" << endl;
847 cout << " Maximum contact force: " << MaximumStrutForce << " lbs, "
848 << MaximumStrutForce*4.448 << " Newtons" << endl;
849 cout << " Maximum strut travel: " << MaximumStrutTravel*12.0 << " inches, "
850 << MaximumStrutTravel*30.48 << " cm" << endl;
851 cout << " Distance traveled: " << LandingDistanceTraveled << " ft, "
852 << LandingDistanceTraveled*0.3048 << " meters" << endl;
853 LandingReported = true;
856 cout << endl << "Takeoff report for " << name << " (Liftoff at time: "
857 << fdmex->GetSimTime() << " seconds)" << endl;
858 cout << " Distance traveled: " << TakeoffDistanceTraveled
859 << " ft, " << TakeoffDistanceTraveled*0.3048 << " meters" << endl;
860 cout << " Distance traveled (over 50'): " << TakeoffDistanceTraveled50ft
861 << " ft, " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl;
862 cout << " [Altitude (ASL): " << in.DistanceASL << " ft. / "
863 << in.DistanceASL*FGJSBBase::fttom << " m | Temperature: "
864 << in.Temperature - 459.67 << " F / "
865 << RankineToCelsius(in.Temperature) << " C]" << endl;
866 cout << " [Velocity (KCAS): " << in.VcalibratedKts << "]" << endl;
867 TakeoffReported = true;
874 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
875 // The bitmasked value choices are as follows:
876 // unset: In this case (the default) JSBSim would only print
877 // out the normally expected messages, essentially echoing
878 // the config files as they are read. If the environment
879 // variable is not set, debug_lvl is set to 1 internally
880 // 0: This requests JSBSim not to output any messages
882 // 1: This value explicity requests the normal JSBSim
884 // 2: This value asks for a message to be printed out when
885 // a class is instantiated
886 // 4: When this value is set, a message is displayed when a
887 // FGModel object executes its Run() method
888 // 8: When this value is set, various runtime state variables
889 // are printed out periodically
890 // 16: When set various parameters are sanity checked and
891 // a message is printed out when they go out of bounds
893 void FGLGear::Debug(int from)
895 if (debug_lvl <= 0) return;
897 if (debug_lvl & 1) { // Standard console startup message output
898 if (from == 0) { // Constructor - loading and initialization
899 cout << " " << sContactType << " " << name << endl;
900 cout << " Location: " << vXYZn << endl;
901 cout << " Spring Constant: " << kSpring << endl;
903 if (eDampType == dtLinear)
904 cout << " Damping Constant: " << bDamp << " (linear)" << endl;
906 cout << " Damping Constant: " << bDamp << " (square law)" << endl;
908 if (eDampTypeRebound == dtLinear)
909 cout << " Rebound Damping Constant: " << bDampRebound << " (linear)" << endl;
911 cout << " Rebound Damping Constant: " << bDampRebound << " (square law)" << endl;
913 cout << " Dynamic Friction: " << dynamicFCoeff << endl;
914 cout << " Static Friction: " << staticFCoeff << endl;
915 if (eContactType == ctBOGEY) {
916 cout << " Rolling Friction: " << rollingFCoeff << endl;
917 cout << " Steering Type: " << sSteerType << endl;
918 cout << " Grouping: " << sBrakeGroup << endl;
919 cout << " Max Steer Angle: " << maxSteerAngle << endl;
920 cout << " Retractable: " << isRetractable << endl;
924 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
925 if (from == 0) cout << "Instantiated: FGLGear" << endl;
926 if (from == 1) cout << "Destroyed: FGLGear" << endl;
928 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
930 if (debug_lvl & 8 ) { // Runtime state variables
932 if (debug_lvl & 16) { // Sanity checking
934 if (debug_lvl & 64) {
935 if (from == 0) { // Constructor
936 cout << IdSrc << endl;
937 cout << IdHdr << endl;
942 } // namespace JSBSim