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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 #include "FGGroundReactions.h"
46 #include "FGAuxiliary.h"
47 #include "FGAtmosphere.h"
48 #include "FGMassBalance.h"
49 #include "math/FGTable.h"
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64 static const char *IdSrc = "$Id: FGLGear.cpp,v 1.74 2010/05/18 10:54:14 jberndt Exp $";
65 static const char *IdHdr = ID_LGEAR;
67 // Body To Structural (body frame is rotated 180 deg about Y and lengths are given in
68 // ft instead of inches)
69 const FGMatrix33 FGLGear::Tb2s(-1./inchtoft, 0., 0., 0., 1./inchtoft, 0., 0., 0., -1./inchtoft);
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75 FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) :
81 Element *force_table=0;
83 Element *dampCoeffRebound=0;
86 kSpring = bDamp = bDampRebound = dynamicFCoeff = staticFCoeff = rollingFCoeff = maxSteerAngle = 0;
87 sSteerType = sBrakeGroup = sSteerType = "";
90 eDampTypeRebound = dtLinear;
92 name = el->GetAttributeValue("name");
93 sContactType = el->GetAttributeValue("type");
94 if (sContactType == "BOGEY") {
95 eContactType = ctBOGEY;
96 } else if (sContactType == "STRUCTURE") {
97 eContactType = ctSTRUCTURE;
99 // Unknown contact point types will be treated as STRUCTURE.
100 eContactType = ctSTRUCTURE;
103 if (el->FindElement("spring_coeff"))
104 kSpring = el->FindElementValueAsNumberConvertTo("spring_coeff", "LBS/FT");
105 if (el->FindElement("damping_coeff")) {
106 dampCoeff = el->FindElement("damping_coeff");
107 if (dampCoeff->GetAttributeValue("type") == "SQUARE") {
108 eDampType = dtSquare;
109 bDamp = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT2/SEC2");
111 bDamp = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT/SEC");
115 if (el->FindElement("damping_coeff_rebound")) {
116 dampCoeffRebound = el->FindElement("damping_coeff_rebound");
117 if (dampCoeffRebound->GetAttributeValue("type") == "SQUARE") {
118 eDampTypeRebound = dtSquare;
119 bDampRebound = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT2/SEC2");
121 bDampRebound = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT/SEC");
124 bDampRebound = bDamp;
125 eDampTypeRebound = eDampType;
128 if (el->FindElement("dynamic_friction"))
129 dynamicFCoeff = el->FindElementValueAsNumber("dynamic_friction");
130 if (el->FindElement("static_friction"))
131 staticFCoeff = el->FindElementValueAsNumber("static_friction");
132 if (el->FindElement("rolling_friction"))
133 rollingFCoeff = el->FindElementValueAsNumber("rolling_friction");
134 if (el->FindElement("max_steer"))
135 maxSteerAngle = el->FindElementValueAsNumberConvertTo("max_steer", "DEG");
136 if (el->FindElement("retractable"))
137 isRetractable = ((unsigned int)el->FindElementValueAsNumber("retractable"))>0.0?true:false;
140 force_table = el->FindElement("table");
141 while (force_table) {
142 force_type = force_table->GetAttributeValue("type");
143 if (force_type == "CORNERING_COEFF") {
144 ForceY_Table = new FGTable(fdmex->GetPropertyManager(), force_table);
146 cerr << "Undefined force table for " << name << " contact point" << endl;
148 force_table = el->FindNextElement("table");
151 sBrakeGroup = el->FindElementValue("brake_group");
153 if (maxSteerAngle == 360) sSteerType = "CASTERED";
154 else if (maxSteerAngle == 0.0) sSteerType = "FIXED";
155 else sSteerType = "STEERABLE";
157 Element* element = el->FindElement("location");
158 if (element) vXYZn = element->FindElementTripletConvertTo("IN");
159 else {cerr << "No location given for contact " << name << endl; exit(-1);}
160 SetTransformType(FGForce::tCustom);
162 element = el->FindElement("orientation");
163 if (element && (eContactType == ctBOGEY)) {
164 vGearOrient = element->FindElementTripletConvertTo("RAD");
166 double cp,sp,cr,sr,cy,sy;
168 cp=cos(vGearOrient(ePitch)); sp=sin(vGearOrient(ePitch));
169 cr=cos(vGearOrient(eRoll)); sr=sin(vGearOrient(eRoll));
170 cy=cos(vGearOrient(eYaw)); sy=sin(vGearOrient(eYaw));
176 mTGear(1,2) = sr*sp*cy - cr*sy;
177 mTGear(2,2) = sr*sp*sy + cr*cy;
180 mTGear(1,3) = cr*sp*cy + sr*sy;
181 mTGear(2,3) = cr*sp*sy - sr*cy;
190 if (sBrakeGroup == "LEFT" ) eBrakeGrp = bgLeft;
191 else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
192 else if (sBrakeGroup == "CENTER") eBrakeGrp = bgCenter;
193 else if (sBrakeGroup == "NOSE" ) eBrakeGrp = bgNose;
194 else if (sBrakeGroup == "TAIL" ) eBrakeGrp = bgTail;
195 else if (sBrakeGroup == "NONE" ) eBrakeGrp = bgNone;
196 else if (sBrakeGroup.empty() ) {eBrakeGrp = bgNone;
197 sBrakeGroup = "NONE (defaulted)";}
199 cerr << "Improper braking group specification in config file: "
200 << sBrakeGroup << " is undefined." << endl;
203 if (sSteerType == "STEERABLE") eSteerType = stSteer;
204 else if (sSteerType == "FIXED" ) eSteerType = stFixed;
205 else if (sSteerType == "CASTERED" ) {eSteerType = stCaster; Castered = true;}
206 else if (sSteerType.empty() ) {eSteerType = stFixed;
207 sSteerType = "FIXED (defaulted)";}
209 cerr << "Improper steering type specification in config file: "
210 << sSteerType << " is undefined." << endl;
213 RFRV = 0.7; // Rolling force relaxation velocity, default value
214 SFRV = 0.7; // Side force relaxation velocity, default value
216 Element* relax_vel = el->FindElement("relaxation_velocity");
218 if (relax_vel->FindElement("rolling")) {
219 RFRV = relax_vel->FindElementValueAsNumberConvertTo("rolling", "FT/SEC");
221 if (relax_vel->FindElement("side")) {
222 SFRV = relax_vel->FindElementValueAsNumberConvertTo("side", "FT/SEC");
226 Aircraft = fdmex->GetAircraft();
227 Propagate = fdmex->GetPropagate();
228 Auxiliary = fdmex->GetAuxiliary();
229 FCS = fdmex->GetFCS();
230 MassBalance = fdmex->GetMassBalance();
232 LongForceLagFilterCoeff = 1/fdmex->GetDeltaT(); // default longitudinal force filter coefficient
233 LatForceLagFilterCoeff = 1/fdmex->GetDeltaT(); // default lateral force filter coefficient
235 Element* force_lag_filter_elem = el->FindElement("force_lag_filter");
236 if (force_lag_filter_elem) {
237 if (force_lag_filter_elem->FindElement("rolling")) {
238 LongForceLagFilterCoeff = force_lag_filter_elem->FindElementValueAsNumber("rolling");
240 if (force_lag_filter_elem->FindElement("side")) {
241 LatForceLagFilterCoeff = force_lag_filter_elem->FindElementValueAsNumber("side");
245 LongForceFilter = Filter(LongForceLagFilterCoeff, fdmex->GetDeltaT());
246 LatForceFilter = Filter(LatForceLagFilterCoeff, fdmex->GetDeltaT());
248 WheelSlipLagFilterCoeff = 1/fdmex->GetDeltaT();
250 Element *wheel_slip_angle_lag_elem = el->FindElement("wheel_slip_filter");
251 if (wheel_slip_angle_lag_elem) {
252 WheelSlipLagFilterCoeff = wheel_slip_angle_lag_elem->GetDataAsNumber();
255 WheelSlipFilter = Filter(WheelSlipLagFilterCoeff, fdmex->GetDeltaT());
260 useFCSGearPos = false;
263 // Add some AI here to determine if gear is located properly according to its
264 // brake group type ??
266 WOW = lastWOW = false;
268 FirstContact = false;
269 StartedGroundRun = false;
270 TakeoffReported = LandingReported = false;
271 LandingDistanceTraveled = TakeoffDistanceTraveled = TakeoffDistanceTraveled50ft = 0.0;
272 MaximumStrutForce = MaximumStrutTravel = 0.0;
273 SinkRate = GroundSpeed = 0.0;
275 vWhlBodyVec = MassBalance->StructuralToBody(vXYZn);
276 vLocalGear = Propagate->GetTb2l() * vWhlBodyVec;
277 vWhlVelVec.InitMatrix();
279 compressLength = 0.0;
285 TirePressureNorm = 1.0;
297 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 FGColumnVector3& FGLGear::GetBodyForces(void)
309 double t = fdmex->GetSimTime();
310 dT = fdmex->GetDeltaT()*fdmex->GetGroundReactions()->GetRate();
314 if (isRetractable) ComputeRetractionState();
317 double verticalZProj = 0.;
319 vWhlBodyVec = MassBalance->StructuralToBody(vXYZn); // Get wheel in body frame
320 vLocalGear = Propagate->GetTb2l() * vWhlBodyVec; // Get local frame wheel location
322 gearLoc = Propagate->GetLocation().LocalToLocation(vLocalGear);
323 // Compute the height of the theoretical location of the wheel (if strut is not compressed) with
324 // respect to the ground level
325 double height = fdmex->GetGroundCallback()->GetAGLevel(t, gearLoc, contact, normal, cvel);
326 vGroundNormal = Propagate->GetTec2b() * normal;
328 // The height returned above is the AGL and is expressed in the Z direction of the local
329 // coordinate frame. We now need to transform this height in actual compression of the strut (BOGEY)
330 // of in the normal direction to the ground (STRUCTURE)
331 switch (eContactType) {
333 verticalZProj = (Propagate->GetTb2l()*mTGear*FGColumnVector3(0.,0.,1.))(eZ);
334 compressLength = verticalZProj > 0.0 ? -height / verticalZProj : 0.0;
337 verticalZProj = -(Propagate->GetTec2l()*normal)(eZ);
338 compressLength = fabs(verticalZProj) > 0.0 ? -height / verticalZProj : 0.0;
342 if (compressLength > 0.00) {
346 // [The next equation should really use the vector to the contact patch of
347 // the tire including the strut compression and not the original vWhlBodyVec.]
349 FGColumnVector3 vWhlDisplVec = mTGear * FGColumnVector3(0., 0., compressLength);
350 FGColumnVector3 vWhlContactVec = vWhlBodyVec - vWhlDisplVec;
351 vActingXYZn = vXYZn - Tb2s * vWhlDisplVec;
352 FGColumnVector3 vBodyWhlVel = Propagate->GetPQR() * vWhlContactVec;
353 vBodyWhlVel += Propagate->GetUVW() - Propagate->GetTec2b() * cvel;
355 vWhlVelVec = mTGear.Transposed() * vBodyWhlVel;
357 InitializeReporting();
358 ComputeSteeringAngle();
359 ComputeGroundCoordSys();
361 vLocalWhlVel = Transform().Transposed() * vBodyWhlVel;
363 switch (eContactType) {
365 // Compression speed along the strut
366 compressSpeed = -vWhlVelVec(eZ);
368 // Compression speed along the ground normal
369 compressSpeed = -vLocalWhlVel(eX);
372 ComputeVerticalStrutForce();
374 // Compute the forces in the wheel ground plane.
375 if (eContactType == ctBOGEY) {
377 ComputeBrakeForceCoefficient();
378 ComputeSideForceCoefficient();
379 double sign = vLocalWhlVel(eY)>0?1.0:(vLocalWhlVel(eY)<0?-1.0:0.0);
380 vFn(eY) = - ((1.0 - TirePressureNorm) * 30 + vFn(eX) * BrakeFCoeff) * sign;
381 vFn(eZ) = vFn(eX) * FCoeff;
383 else if (eContactType == ctSTRUCTURE) {
384 FGColumnVector3 vSlipVec = vLocalWhlVel;
386 vSlipVec.Normalize();
387 vFn -= staticFCoeff * vFn(eX) * vSlipVec;
390 // Lag and attenuate the XY-plane forces dependent on velocity. This code
391 // uses a lag filter, C/(s + C) where "C" is the filter coefficient. When
392 // "C" is chosen at the frame rate (in Hz), the jittering is significantly
393 // reduced. This is because the jitter is present *at* the execution rate.
394 // If a coefficient is set to something equal to or less than zero, the
395 // filter is bypassed.
397 if (LongForceLagFilterCoeff > 0) vFn(eY) = LongForceFilter.execute(vFn(eY));
398 if (LatForceLagFilterCoeff > 0) vFn(eZ) = LatForceFilter.execute(vFn(eZ));
400 if ((fabs(vLocalWhlVel(eY)) <= RFRV) && RFRV > 0) vFn(eY) *= fabs(vLocalWhlVel(eY))/RFRV;
401 if ((fabs(vLocalWhlVel(eZ)) <= SFRV) && SFRV > 0) vFn(eZ) *= fabs(vLocalWhlVel(eZ))/SFRV;
403 // End section for attenuating gear jitter
405 } else { // Gear is NOT compressed
408 compressLength = 0.0;
413 // Let wheel spin down slowly
414 vWhlVelVec(eX) -= 13.0*dT;
415 if (vWhlVelVec(eX) < 0.0) vWhlVelVec(eX) = 0.0;
417 // Return to neutral position between 1.0 and 0.8 gear pos.
418 SteerAngle *= max(GetGearUnitPos()-0.8, 0.0)/0.2;
424 ReportTakeoffOrLanding();
426 // Require both WOW and LastWOW to be true before checking crash conditions
427 // to allow the WOW flag to be used in terminating a scripted run.
428 if (WOW && lastWOW) CrashDetect();
432 return FGForce::GetBodyForces();
435 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436 // Build a local "ground" coordinate system defined by
437 // eX : normal to the ground
438 // eY : projection of the rolling direction on the ground
439 // eZ : projection of the sliping direction on the ground
441 void FGLGear::ComputeGroundCoordSys(void)
443 // Euler angles are built up to create a local frame to describe the forces
444 // applied to the gear by the ground. Here pitch, yaw and roll do not have
445 // any physical meaning. It is just a convenient notation.
446 // First, "pitch" and "yaw" are determined in order to align eX with the
448 if (vGroundNormal(eZ) < -1.0)
449 vOrient(ePitch) = 0.5*M_PI;
450 else if (1.0 < vGroundNormal(eZ))
451 vOrient(ePitch) = -0.5*M_PI;
453 vOrient(ePitch) = asin(-vGroundNormal(eZ));
455 if (fabs(vOrient(ePitch)) == 0.5*M_PI)
458 vOrient(eYaw) = atan2(vGroundNormal(eY), vGroundNormal(eX));
461 UpdateCustomTransformMatrix();
463 if (eContactType == ctBOGEY) {
464 // In the case of a bogey, the third angle "roll" is used to align the axis eY and eZ
465 // to the rolling and sliping direction respectively.
466 FGColumnVector3 updatedRollingAxis = Transform().Transposed() * mTGear
467 * FGColumnVector3(-sin(SteerAngle), cos(SteerAngle), 0.);
469 vOrient(eRoll) = atan2(updatedRollingAxis(eY), -updatedRollingAxis(eZ));
470 UpdateCustomTransformMatrix();
474 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476 void FGLGear::ComputeRetractionState(void)
478 double gearPos = GetGearUnitPos();
479 if (gearPos < 0.01) {
483 vWhlVelVec.InitMatrix();
484 } else if (gearPos > 0.99) {
493 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
495 void FGLGear::ComputeSlipAngle(void)
497 // Calculate tire slip angle.
498 WheelSlip = -atan2(vLocalWhlVel(eZ), fabs(vLocalWhlVel(eY)))*radtodeg;
500 // Filter the wheel slip angle
501 if (WheelSlipLagFilterCoeff > 0) WheelSlip = WheelSlipFilter.execute(WheelSlip);
504 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
505 // Compute the steering angle in any case.
506 // This will also make sure that animations will look right.
508 void FGLGear::ComputeSteeringAngle(void)
510 switch (eSteerType) {
512 SteerAngle = degtorad * FCS->GetSteerPosDeg(GearNumber);
519 SteerAngle = degtorad * FCS->GetSteerPosDeg(GearNumber);
521 // Check that the speed is non-null otherwise use the current angle
522 if (vWhlVelVec.Magnitude(eX,eY) > 1E-3)
523 SteerAngle = atan2(vWhlVelVec(eY), fabs(vWhlVelVec(eX)));
527 cerr << "Improper steering type membership detected for this gear." << endl;
532 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533 // Reset reporting functionality after takeoff
535 void FGLGear::ResetReporting(void)
537 if (Propagate->GetDistanceAGL() > 200.0) {
538 FirstContact = false;
539 StartedGroundRun = false;
540 LandingReported = false;
541 TakeoffReported = true;
542 LandingDistanceTraveled = 0.0;
543 MaximumStrutForce = MaximumStrutTravel = 0.0;
547 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
549 void FGLGear::InitializeReporting(void)
551 // If this is the first time the wheel has made contact, remember some values
552 // for later printout.
556 SinkRate = compressSpeed;
557 GroundSpeed = Propagate->GetVel().Magnitude();
558 TakeoffReported = false;
561 // If the takeoff run is starting, initialize.
563 if ((Propagate->GetVel().Magnitude() > 0.1) &&
564 (FCS->GetBrake(bgLeft) == 0) &&
565 (FCS->GetBrake(bgRight) == 0) &&
566 (FCS->GetThrottlePos(0) > 0.90) && !StartedGroundRun)
568 TakeoffDistanceTraveled = 0;
569 TakeoffDistanceTraveled50ft = 0;
570 StartedGroundRun = true;
574 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
575 // Takeoff and landing reporting functionality
577 void FGLGear::ReportTakeoffOrLanding(void)
579 double deltaT = fdmex->GetDeltaT()*fdmex->GetGroundReactions()->GetRate();
582 LandingDistanceTraveled += Auxiliary->GetVground()*deltaT;
584 if (StartedGroundRun) {
585 TakeoffDistanceTraveled50ft += Auxiliary->GetVground()*deltaT;
586 if (WOW) TakeoffDistanceTraveled += Auxiliary->GetVground()*deltaT;
590 && Auxiliary->GetVground() <= 0.05
592 && fdmex->GetGroundReactions()->GetWOW())
594 if (debug_lvl > 0) Report(erLand);
599 && (Propagate->GetDistanceAGL() - vLocalGear(eZ)) > 50.0
600 && !fdmex->GetGroundReactions()->GetWOW())
602 if (debug_lvl > 0) Report(erTakeoff);
605 if (lastWOW != WOW) PutMessage("GEAR_CONTACT: " + name, WOW);
608 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609 // Crash detection logic (really out-of-bounds detection)
611 void FGLGear::CrashDetect(void)
613 if ( (compressLength > 500.0 ||
614 vFn.Magnitude() > 100000000.0 ||
615 GetMoments().Magnitude() > 5000000000.0 ||
616 SinkRate > 1.4666*30 ) && !fdmex->IntegrationSuspended())
618 PutMessage("Crash Detected: Simulation FREEZE.");
619 fdmex->SuspendIntegration();
623 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
624 // The following needs work regarding friction coefficients and braking and
625 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
626 // It also assumes that we won't be turning and braking at the same time.
627 // Will fix this later.
628 // [JSB] The braking force coefficients include normal rolling coefficient +
629 // a percentage of the static friction coefficient based on braking applied.
631 void FGLGear::ComputeBrakeForceCoefficient(void)
635 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgLeft)) +
636 staticFCoeff*FCS->GetBrake(bgLeft) );
639 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgRight)) +
640 staticFCoeff*FCS->GetBrake(bgRight) );
643 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
644 staticFCoeff*FCS->GetBrake(bgCenter) );
647 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
648 staticFCoeff*FCS->GetBrake(bgCenter) );
651 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
652 staticFCoeff*FCS->GetBrake(bgCenter) );
655 BrakeFCoeff = rollingFCoeff;
658 cerr << "Improper brake group membership detected for this gear." << endl;
663 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664 // Compute the sideforce coefficients using Pacejka's Magic Formula.
666 // y(x) = D sin {C arctan [Bx - E(Bx - arctan Bx)]}
668 // Where: B = Stiffness Factor (0.06, here)
669 // C = Shape Factor (2.8, here)
670 // D = Peak Factor (0.8, here)
671 // E = Curvature Factor (1.03, here)
673 void FGLGear::ComputeSideForceCoefficient(void)
676 FCoeff = ForceY_Table->GetValue(WheelSlip);
678 double StiffSlip = Stiffness*WheelSlip;
679 FCoeff = Peak * sin(Shape*atan(StiffSlip - Curvature*(StiffSlip - atan(StiffSlip))));
683 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
684 // Compute the vertical force on the wheel using square-law damping (per comment
685 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
686 // allowing for both square and linear damping force calculation. Also need to
687 // possibly give a "rebound damping factor" that differs from the compression
690 void FGLGear::ComputeVerticalStrutForce(void)
692 double springForce = 0;
693 double dampForce = 0;
695 springForce = -compressLength * kSpring;
697 if (compressSpeed >= 0.0) {
699 if (eDampType == dtLinear) dampForce = -compressSpeed * bDamp;
700 else dampForce = -compressSpeed * compressSpeed * bDamp;
704 if (eDampTypeRebound == dtLinear)
705 dampForce = -compressSpeed * bDampRebound;
707 dampForce = compressSpeed * compressSpeed * bDampRebound;
711 StrutForce = min(springForce + dampForce, (double)0.0);
713 // The reaction force of the wheel is always normal to the ground
714 switch (eContactType) {
716 // Project back the strut force in the local coordinate frame of the ground
717 vFn(eX) = StrutForce / (mTGear.Transposed()*vGroundNormal)(eZ);
720 vFn(eX) = -StrutForce;
724 // Remember these values for reporting
725 MaximumStrutForce = max(MaximumStrutForce, fabs(StrutForce));
726 MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
729 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
731 double FGLGear::GetGearUnitPos(void)
733 // hack to provide backward compatibility to gear/gear-pos-norm property
734 if( useFCSGearPos || FCS->GetGearPos() != 1.0 ) {
735 useFCSGearPos = true;
736 return FCS->GetGearPos();
741 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
743 void FGLGear::bind(void)
745 string property_name;
746 string base_property_name;
747 base_property_name = CreateIndexedPropertyName("gear/unit", GearNumber);
748 if (eContactType == ctBOGEY) {
749 property_name = base_property_name + "/slip-angle-deg";
750 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &WheelSlip );
751 property_name = base_property_name + "/WOW";
752 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &WOW );
753 property_name = base_property_name + "/wheel-speed-fps";
754 fdmex->GetPropertyManager()->Tie( property_name.c_str(), (FGLGear*)this,
755 &FGLGear::GetWheelRollVel);
756 property_name = base_property_name + "/z-position";
757 fdmex->GetPropertyManager()->Tie( property_name.c_str(), (FGForce*)this,
758 &FGForce::GetLocationZ, &FGForce::SetLocationZ);
759 property_name = base_property_name + "/compression-ft";
760 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &compressLength );
761 property_name = base_property_name + "/side_friction_coeff";
762 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &FCoeff );
764 property_name = base_property_name + "/static_friction_coeff";
765 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &staticFCoeff );
767 if (eSteerType == stCaster) {
768 property_name = base_property_name + "/steering-angle-deg";
769 fdmex->GetPropertyManager()->Tie( property_name.c_str(), this, &FGLGear::GetSteerAngleDeg );
770 property_name = base_property_name + "/castered";
771 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &Castered);
775 if( isRetractable ) {
776 property_name = base_property_name + "/pos-norm";
777 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &GearPos );
781 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
783 void FGLGear::Report(ReportType repType)
785 if (fabs(TakeoffDistanceTraveled) < 0.001) return; // Don't print superfluous reports
789 cout << endl << "Touchdown report for " << name << " (WOW at time: "
790 << fdmex->GetSimTime() << " seconds)" << endl;
791 cout << " Sink rate at contact: " << SinkRate << " fps, "
792 << SinkRate*0.3048 << " mps" << endl;
793 cout << " Contact ground speed: " << GroundSpeed*.5925 << " knots, "
794 << GroundSpeed*0.3048 << " mps" << endl;
795 cout << " Maximum contact force: " << MaximumStrutForce << " lbs, "
796 << MaximumStrutForce*4.448 << " Newtons" << endl;
797 cout << " Maximum strut travel: " << MaximumStrutTravel*12.0 << " inches, "
798 << MaximumStrutTravel*30.48 << " cm" << endl;
799 cout << " Distance traveled: " << LandingDistanceTraveled << " ft, "
800 << LandingDistanceTraveled*0.3048 << " meters" << endl;
801 LandingReported = true;
804 cout << endl << "Takeoff report for " << name << " (Liftoff at time: "
805 << fdmex->GetSimTime() << " seconds)" << endl;
806 cout << " Distance traveled: " << TakeoffDistanceTraveled
807 << " ft, " << TakeoffDistanceTraveled*0.3048 << " meters" << endl;
808 cout << " Distance traveled (over 50'): " << TakeoffDistanceTraveled50ft
809 << " ft, " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl;
810 cout << " [Altitude (ASL): " << fdmex->GetPropagate()->GetAltitudeASL() << " ft. / "
811 << fdmex->GetPropagate()->GetAltitudeASLmeters() << " m | Temperature: "
812 << fdmex->GetAtmosphere()->GetTemperature() - 459.67 << " F / "
813 << RankineToCelsius(fdmex->GetAtmosphere()->GetTemperature()) << " C]" << endl;
814 cout << " [Velocity (KCAS): " << fdmex->GetAuxiliary()->GetVcalibratedKTS() << "]" << endl;
815 TakeoffReported = true;
822 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
823 // The bitmasked value choices are as follows:
824 // unset: In this case (the default) JSBSim would only print
825 // out the normally expected messages, essentially echoing
826 // the config files as they are read. If the environment
827 // variable is not set, debug_lvl is set to 1 internally
828 // 0: This requests JSBSim not to output any messages
830 // 1: This value explicity requests the normal JSBSim
832 // 2: This value asks for a message to be printed out when
833 // a class is instantiated
834 // 4: When this value is set, a message is displayed when a
835 // FGModel object executes its Run() method
836 // 8: When this value is set, various runtime state variables
837 // are printed out periodically
838 // 16: When set various parameters are sanity checked and
839 // a message is printed out when they go out of bounds
841 void FGLGear::Debug(int from)
843 if (debug_lvl <= 0) return;
845 if (debug_lvl & 1) { // Standard console startup message output
846 if (from == 0) { // Constructor - loading and initialization
847 cout << " " << sContactType << " " << name << endl;
848 cout << " Location: " << vXYZn << endl;
849 cout << " Spring Constant: " << kSpring << endl;
851 if (eDampType == dtLinear)
852 cout << " Damping Constant: " << bDamp << " (linear)" << endl;
854 cout << " Damping Constant: " << bDamp << " (square law)" << endl;
856 if (eDampTypeRebound == dtLinear)
857 cout << " Rebound Damping Constant: " << bDampRebound << " (linear)" << endl;
859 cout << " Rebound Damping Constant: " << bDampRebound << " (square law)" << endl;
861 cout << " Dynamic Friction: " << dynamicFCoeff << endl;
862 cout << " Static Friction: " << staticFCoeff << endl;
863 if (eContactType == ctBOGEY) {
864 cout << " Rolling Friction: " << rollingFCoeff << endl;
865 cout << " Steering Type: " << sSteerType << endl;
866 cout << " Grouping: " << sBrakeGroup << endl;
867 cout << " Max Steer Angle: " << maxSteerAngle << endl;
868 cout << " Retractable: " << isRetractable << endl;
869 cout << " Relaxation Velocities:" << endl;
870 cout << " Rolling: " << RFRV << endl;
871 cout << " Side: " << SFRV << endl;
875 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
876 if (from == 0) cout << "Instantiated: FGLGear" << endl;
877 if (from == 1) cout << "Destroyed: FGLGear" << endl;
879 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
881 if (debug_lvl & 8 ) { // Runtime state variables
883 if (debug_lvl & 16) { // Sanity checking
885 if (debug_lvl & 64) {
886 if (from == 0) { // Constructor
887 cout << IdSrc << endl;
888 cout << IdHdr << endl;
893 } // namespace JSBSim