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 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 static const char *IdSrc = "$Id$";
56 static const char *IdHdr = ID_LGEAR;
58 // Body To Structural (body frame is rotated 180 deg about Y and lengths are given in
59 // ft instead of inches)
60 const FGMatrix33 FGLGear::Tb2s(-1./inchtoft, 0., 0., 0., 1./inchtoft, 0., 0., 0., -1./inchtoft);
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number) :
70 Element *force_table=0;
72 Element *dampCoeffRebound=0;
75 kSpring = bDamp = bDampRebound = dynamicFCoeff = staticFCoeff = rollingFCoeff = maxSteerAngle = 0;
76 sSteerType = sBrakeGroup = sSteerType = "";
79 eDampTypeRebound = dtLinear;
81 name = el->GetAttributeValue("name");
82 sContactType = el->GetAttributeValue("type");
83 if (sContactType == "BOGEY") {
84 eContactType = ctBOGEY;
85 } else if (sContactType == "STRUCTURE") {
86 eContactType = ctSTRUCTURE;
88 // Unknown contact point types will be treated as STRUCTURE.
89 eContactType = ctSTRUCTURE;
92 if (el->FindElement("spring_coeff"))
93 kSpring = el->FindElementValueAsNumberConvertTo("spring_coeff", "LBS/FT");
94 if (el->FindElement("damping_coeff")) {
95 dampCoeff = el->FindElement("damping_coeff");
96 if (dampCoeff->GetAttributeValue("type") == "SQUARE") {
98 bDamp = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT2/SEC2");
100 bDamp = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT/SEC");
104 if (el->FindElement("damping_coeff_rebound")) {
105 dampCoeffRebound = el->FindElement("damping_coeff_rebound");
106 if (dampCoeffRebound->GetAttributeValue("type") == "SQUARE") {
107 eDampTypeRebound = dtSquare;
108 bDampRebound = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT2/SEC2");
110 bDampRebound = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT/SEC");
113 bDampRebound = bDamp;
114 eDampTypeRebound = eDampType;
117 if (el->FindElement("dynamic_friction"))
118 dynamicFCoeff = el->FindElementValueAsNumber("dynamic_friction");
119 if (el->FindElement("static_friction"))
120 staticFCoeff = el->FindElementValueAsNumber("static_friction");
121 if (el->FindElement("rolling_friction"))
122 rollingFCoeff = el->FindElementValueAsNumber("rolling_friction");
123 if (el->FindElement("max_steer"))
124 maxSteerAngle = el->FindElementValueAsNumberConvertTo("max_steer", "DEG");
125 if (el->FindElement("retractable"))
126 isRetractable = ((unsigned int)el->FindElementValueAsNumber("retractable"))>0.0?true:false;
129 force_table = el->FindElement("table");
130 while (force_table) {
131 force_type = force_table->GetAttributeValue("type");
132 if (force_type == "CORNERING_COEFF") {
133 ForceY_Table = new FGTable(fdmex->GetPropertyManager(), force_table);
135 cerr << "Undefined force table for " << name << " contact point" << endl;
137 force_table = el->FindNextElement("table");
140 sBrakeGroup = el->FindElementValue("brake_group");
142 if (maxSteerAngle == 360) sSteerType = "CASTERED";
143 else if (maxSteerAngle == 0.0) sSteerType = "FIXED";
144 else sSteerType = "STEERABLE";
146 Element* element = el->FindElement("location");
147 if (element) vXYZn = element->FindElementTripletConvertTo("IN");
148 else {cerr << "No location given for contact " << name << endl; exit(-1);}
149 SetTransformType(FGForce::tCustom);
151 element = el->FindElement("orientation");
152 if (element && (eContactType == ctBOGEY)) {
153 vGearOrient = element->FindElementTripletConvertTo("RAD");
155 double cp,sp,cr,sr,cy,sy;
157 cp=cos(vGearOrient(ePitch)); sp=sin(vGearOrient(ePitch));
158 cr=cos(vGearOrient(eRoll)); sr=sin(vGearOrient(eRoll));
159 cy=cos(vGearOrient(eYaw)); sy=sin(vGearOrient(eYaw));
165 mTGear(1,2) = sr*sp*cy - cr*sy;
166 mTGear(2,2) = sr*sp*sy + cr*cy;
169 mTGear(1,3) = cr*sp*cy + sr*sy;
170 mTGear(2,3) = cr*sp*sy - sr*cy;
179 if (sBrakeGroup == "LEFT" ) eBrakeGrp = bgLeft;
180 else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
181 else if (sBrakeGroup == "CENTER") eBrakeGrp = bgCenter;
182 else if (sBrakeGroup == "NOSE" ) eBrakeGrp = bgNose;
183 else if (sBrakeGroup == "TAIL" ) eBrakeGrp = bgTail;
184 else if (sBrakeGroup == "NONE" ) eBrakeGrp = bgNone;
185 else if (sBrakeGroup.empty() ) {eBrakeGrp = bgNone;
186 sBrakeGroup = "NONE (defaulted)";}
188 cerr << "Improper braking group specification in config file: "
189 << sBrakeGroup << " is undefined." << endl;
192 if (sSteerType == "STEERABLE") eSteerType = stSteer;
193 else if (sSteerType == "FIXED" ) eSteerType = stFixed;
194 else if (sSteerType == "CASTERED" ) eSteerType = stCaster;
195 else if (sSteerType.empty() ) {eSteerType = stFixed;
196 sSteerType = "FIXED (defaulted)";}
198 cerr << "Improper steering type specification in config file: "
199 << sSteerType << " is undefined." << endl;
202 RFRV = 0.7; // Rolling force relaxation velocity, default value
203 SFRV = 0.7; // Side force relaxation velocity, default value
205 Element* relax_vel = el->FindElement("relaxation_velocity");
207 if (relax_vel->FindElement("rolling")) {
208 RFRV = relax_vel->FindElementValueAsNumberConvertTo("rolling", "FT/SEC");
210 if (relax_vel->FindElement("side")) {
211 SFRV = relax_vel->FindElementValueAsNumberConvertTo("side", "FT/SEC");
215 State = fdmex->GetState();
216 Aircraft = fdmex->GetAircraft();
217 Propagate = fdmex->GetPropagate();
218 Auxiliary = fdmex->GetAuxiliary();
219 FCS = fdmex->GetFCS();
220 MassBalance = fdmex->GetMassBalance();
222 LongForceLagFilterCoeff = 1/State->Getdt(); // default longitudinal force filter coefficient
223 LatForceLagFilterCoeff = 1/State->Getdt(); // default lateral force filter coefficient
225 Element* force_lag_filter_elem = el->FindElement("force_lag_filter");
226 if (force_lag_filter_elem) {
227 if (force_lag_filter_elem->FindElement("rolling")) {
228 LongForceLagFilterCoeff = force_lag_filter_elem->FindElementValueAsNumber("rolling");
230 if (force_lag_filter_elem->FindElement("side")) {
231 LatForceLagFilterCoeff = force_lag_filter_elem->FindElementValueAsNumber("side");
235 LongForceFilter = Filter(LongForceLagFilterCoeff, State->Getdt());
236 LatForceFilter = Filter(LatForceLagFilterCoeff, State->Getdt());
238 WheelSlipLagFilterCoeff = 1/State->Getdt();
240 Element *wheel_slip_angle_lag_elem = el->FindElement("wheel_slip_filter");
241 if (wheel_slip_angle_lag_elem) {
242 WheelSlipLagFilterCoeff = wheel_slip_angle_lag_elem->GetDataAsNumber();
245 WheelSlipFilter = Filter(WheelSlipLagFilterCoeff, State->Getdt());
250 useFCSGearPos = false;
253 // Add some AI here to determine if gear is located properly according to its
254 // brake group type ??
256 WOW = lastWOW = false;
258 FirstContact = false;
259 StartedGroundRun = false;
260 TakeoffReported = LandingReported = false;
261 LandingDistanceTraveled = TakeoffDistanceTraveled = TakeoffDistanceTraveled50ft = 0.0;
262 MaximumStrutForce = MaximumStrutTravel = 0.0;
263 SinkRate = GroundSpeed = 0.0;
265 vWhlBodyVec = MassBalance->StructuralToBody(vXYZn);
266 vLocalGear = Propagate->GetTb2l() * vWhlBodyVec;
267 vWhlVelVec.InitMatrix();
269 compressLength = 0.0;
275 TirePressureNorm = 1.0;
287 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 FGColumnVector3& FGLGear::GetBodyForces(void)
299 double t = fdmex->GetState()->Getsim_time();
300 dT = State->Getdt()*fdmex->GetGroundReactions()->GetRate();
304 if (isRetractable) ComputeRetractionState();
307 double verticalZProj = 0.;
309 vWhlBodyVec = MassBalance->StructuralToBody(vXYZn); // Get wheel in body frame
310 vLocalGear = Propagate->GetTb2l() * vWhlBodyVec; // Get local frame wheel location
312 gearLoc = Propagate->GetLocation().LocalToLocation(vLocalGear);
313 // Compute the height of the theoretical location of the wheel (if strut is not compressed) with
314 // respect to the ground level
315 double height = fdmex->GetGroundCallback()->GetAGLevel(t, gearLoc, contact, normal, cvel);
316 vGroundNormal = -1. * Propagate->GetTec2b() * normal;
318 // The height returned above is the AGL and is expressed in the Z direction of the local
319 // coordinate frame. We now need to transform this height in actual compression of the strut (BOGEY)
320 // of in the normal direction to the ground (STRUCTURE)
321 switch (eContactType) {
323 verticalZProj = (Propagate->GetTb2l()*mTGear*FGColumnVector3(0.,0.,1.))(eZ);
324 compressLength = verticalZProj > 0.0 ? -height / verticalZProj : 0.0;
327 verticalZProj = (Propagate->GetTec2l()*normal)(eZ);
328 compressLength = fabs(verticalZProj) > 0.0 ? -height / verticalZProj : 0.0;
332 if (compressLength > 0.00) {
336 // [The next equation should really use the vector to the contact patch of
337 // the tire including the strut compression and not the original vWhlBodyVec.]
339 FGColumnVector3 vWhlDisplVec = mTGear * FGColumnVector3(0., 0., compressLength);
340 FGColumnVector3 vWhlContactVec = vWhlBodyVec - vWhlDisplVec;
341 vActingXYZn = vXYZn - Tb2s * vWhlDisplVec;
342 FGColumnVector3 vBodyWhlVel = Propagate->GetPQR() * vWhlContactVec;
343 vBodyWhlVel += Propagate->GetUVW() - Propagate->GetTec2b() * cvel;
345 vWhlVelVec = mTGear.Transposed() * vBodyWhlVel;
347 InitializeReporting();
348 ComputeSteeringAngle();
349 ComputeGroundCoordSys();
351 vLocalWhlVel = Transform().Transposed() * vBodyWhlVel;
353 switch (eContactType) {
355 // Compression speed along the strut
356 compressSpeed = -vWhlVelVec(eZ);
358 // Compression speed along the ground normal
359 compressSpeed = -vLocalWhlVel(eX);
362 ComputeVerticalStrutForce();
364 // Compute the forces in the wheel ground plane.
365 if (eContactType == ctBOGEY) {
367 ComputeBrakeForceCoefficient();
368 ComputeSideForceCoefficient();
369 double sign = vLocalWhlVel(eY)>0?1.0:(vLocalWhlVel(eY)<0?-1.0:0.0);
370 vFn(eY) = - ((1.0 - TirePressureNorm) * 30 + vFn(eX) * BrakeFCoeff) * sign;
371 vFn(eZ) = vFn(eX) * FCoeff;
373 else if (eContactType == ctSTRUCTURE) {
374 FGColumnVector3 vSlipVec = vLocalWhlVel;
376 vSlipVec.Normalize();
377 vFn -= staticFCoeff * vFn(eX) * vSlipVec;
380 // Lag and attenuate the XY-plane forces dependent on velocity. This code
381 // uses a lag filter, C/(s + C) where "C" is the filter coefficient. When
382 // "C" is chosen at the frame rate (in Hz), the jittering is significantly
383 // reduced. This is because the jitter is present *at* the execution rate.
384 // If a coefficient is set to something equal to or less than zero, the
385 // filter is bypassed.
387 if (LongForceLagFilterCoeff > 0) vFn(eY) = LongForceFilter.execute(vFn(eY));
388 if (LatForceLagFilterCoeff > 0) vFn(eZ) = LatForceFilter.execute(vFn(eZ));
390 if ((fabs(vLocalWhlVel(eY)) <= RFRV) && RFRV > 0) vFn(eY) *= fabs(vLocalWhlVel(eY))/RFRV;
391 if ((fabs(vLocalWhlVel(eZ)) <= SFRV) && SFRV > 0) vFn(eZ) *= fabs(vLocalWhlVel(eZ))/SFRV;
393 // End section for attenuating gear jitter
395 } else { // Gear is NOT compressed
398 compressLength = 0.0;
401 // Let wheel spin down slowly
402 vWhlVelVec(eX) -= 13.0*dT;
403 if (vWhlVelVec(eX) < 0.0) vWhlVelVec(eX) = 0.0;
405 // Return to neutral position between 1.0 and 0.8 gear pos.
406 SteerAngle *= max(GetGearUnitPos()-0.8, 0.0)/0.2;
412 ReportTakeoffOrLanding();
414 // Require both WOW and LastWOW to be true before checking crash conditions
415 // to allow the WOW flag to be used in terminating a scripted run.
416 if (WOW && lastWOW) CrashDetect();
420 return FGForce::GetBodyForces();
423 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
424 // Build a local "ground" coordinate system defined by
425 // eX : normal to the ground
426 // eY : projection of the rolling direction on the ground
427 // eZ : projection of the sliping direction on the ground
429 void FGLGear::ComputeGroundCoordSys(void)
431 // Euler angles are built up to create a local frame to describe the forces
432 // applied to the gear by the ground. Here pitch, yaw and roll do not have
433 // any physical meaning. It is just a convenient notation.
434 // First, "pitch" and "yaw" are determined in order to align eX with the
436 if (vGroundNormal(eZ) < -1.0)
437 vOrient(ePitch) = 0.5*M_PI;
438 else if (1.0 < vGroundNormal(eZ))
439 vOrient(ePitch) = -0.5*M_PI;
441 vOrient(ePitch) = asin(-vGroundNormal(eZ));
443 if (fabs(vOrient(ePitch)) == 0.5*M_PI)
446 vOrient(eYaw) = atan2(vGroundNormal(eY), vGroundNormal(eX));
449 UpdateCustomTransformMatrix();
451 if (eContactType == ctBOGEY) {
452 // In the case of a bogey, the third angle "roll" is used to align the axis eY and eZ
453 // to the rolling and sliping direction respectively.
454 FGColumnVector3 updatedRollingAxis = Transform().Transposed() * mTGear
455 * FGColumnVector3(-sin(SteerAngle), cos(SteerAngle), 0.);
457 vOrient(eRoll) = atan2(updatedRollingAxis(eY), -updatedRollingAxis(eZ));
458 UpdateCustomTransformMatrix();
462 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
464 void FGLGear::ComputeRetractionState(void)
466 double gearPos = GetGearUnitPos();
467 if (gearPos < 0.01) {
471 vWhlVelVec.InitMatrix();
472 } else if (gearPos > 0.99) {
481 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483 void FGLGear::ComputeSlipAngle(void)
485 // Calculate tire slip angle.
486 WheelSlip = -atan2(vLocalWhlVel(eZ), fabs(vLocalWhlVel(eY)))*radtodeg;
488 // Filter the wheel slip angle
489 if (WheelSlipLagFilterCoeff > 0) WheelSlip = WheelSlipFilter.execute(WheelSlip);
492 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
493 // Compute the steering angle in any case.
494 // This will also make sure that animations will look right.
496 void FGLGear::ComputeSteeringAngle(void)
498 switch (eSteerType) {
500 SteerAngle = degtorad * FCS->GetSteerPosDeg(GearNumber);
506 SteerAngle = atan2(vWhlVelVec(eY), fabs(vWhlVelVec(eX)));
509 cerr << "Improper steering type membership detected for this gear." << endl;
514 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
515 // Reset reporting functionality after takeoff
517 void FGLGear::ResetReporting(void)
519 if (Propagate->GetDistanceAGL() > 200.0) {
520 FirstContact = false;
521 StartedGroundRun = false;
522 LandingReported = false;
523 TakeoffReported = true;
524 LandingDistanceTraveled = 0.0;
525 MaximumStrutForce = MaximumStrutTravel = 0.0;
529 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
531 void FGLGear::InitializeReporting(void)
533 // If this is the first time the wheel has made contact, remember some values
534 // for later printout.
538 SinkRate = compressSpeed;
539 GroundSpeed = Propagate->GetVel().Magnitude();
540 TakeoffReported = false;
543 // If the takeoff run is starting, initialize.
545 if ((Propagate->GetVel().Magnitude() > 0.1) &&
546 (FCS->GetBrake(bgLeft) == 0) &&
547 (FCS->GetBrake(bgRight) == 0) &&
548 (FCS->GetThrottlePos(0) > 0.90) && !StartedGroundRun)
550 TakeoffDistanceTraveled = 0;
551 TakeoffDistanceTraveled50ft = 0;
552 StartedGroundRun = true;
556 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
557 // Takeoff and landing reporting functionality
559 void FGLGear::ReportTakeoffOrLanding(void)
561 double deltaT = State->Getdt()*fdmex->GetGroundReactions()->GetRate();
564 LandingDistanceTraveled += Auxiliary->GetVground()*deltaT;
566 if (StartedGroundRun) {
567 TakeoffDistanceTraveled50ft += Auxiliary->GetVground()*deltaT;
568 if (WOW) TakeoffDistanceTraveled += Auxiliary->GetVground()*deltaT;
572 && Auxiliary->GetVground() <= 0.05
574 && fdmex->GetGroundReactions()->GetWOW())
576 if (debug_lvl > 0) Report(erLand);
581 && (Propagate->GetDistanceAGL() - vLocalGear(eZ)) > 50.0
582 && !fdmex->GetGroundReactions()->GetWOW())
584 if (debug_lvl > 0) Report(erTakeoff);
587 if (lastWOW != WOW) PutMessage("GEAR_CONTACT: " + name, WOW);
590 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
591 // Crash detection logic (really out-of-bounds detection)
593 void FGLGear::CrashDetect(void)
595 if ( (compressLength > 500.0 ||
596 vFn.Magnitude() > 100000000.0 ||
597 GetMoments().Magnitude() > 5000000000.0 ||
598 SinkRate > 1.4666*30 ) && !State->IntegrationSuspended())
600 PutMessage("Crash Detected: Simulation FREEZE.");
601 State->SuspendIntegration();
605 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
606 // The following needs work regarding friction coefficients and braking and
607 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
608 // It also assumes that we won't be turning and braking at the same time.
609 // Will fix this later.
610 // [JSB] The braking force coefficients include normal rolling coefficient +
611 // a percentage of the static friction coefficient based on braking applied.
613 void FGLGear::ComputeBrakeForceCoefficient(void)
617 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgLeft)) +
618 staticFCoeff*FCS->GetBrake(bgLeft) );
621 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgRight)) +
622 staticFCoeff*FCS->GetBrake(bgRight) );
625 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
626 staticFCoeff*FCS->GetBrake(bgCenter) );
629 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
630 staticFCoeff*FCS->GetBrake(bgCenter) );
633 BrakeFCoeff = ( rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
634 staticFCoeff*FCS->GetBrake(bgCenter) );
637 BrakeFCoeff = rollingFCoeff;
640 cerr << "Improper brake group membership detected for this gear." << endl;
645 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646 // Compute the sideforce coefficients using Pacejka's Magic Formula.
648 // y(x) = D sin {C arctan [Bx - E(Bx - arctan Bx)]}
650 // Where: B = Stiffness Factor (0.06, here)
651 // C = Shape Factor (2.8, here)
652 // D = Peak Factor (0.8, here)
653 // E = Curvature Factor (1.03, here)
655 void FGLGear::ComputeSideForceCoefficient(void)
658 FCoeff = ForceY_Table->GetValue(WheelSlip);
660 double StiffSlip = Stiffness*WheelSlip;
661 FCoeff = Peak * sin(Shape*atan(StiffSlip - Curvature*(StiffSlip - atan(StiffSlip))));
665 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
666 // Compute the vertical force on the wheel using square-law damping (per comment
667 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
668 // allowing for both square and linear damping force calculation. Also need to
669 // possibly give a "rebound damping factor" that differs from the compression
672 void FGLGear::ComputeVerticalStrutForce(void)
674 double springForce = 0;
675 double dampForce = 0;
677 springForce = -compressLength * kSpring;
679 if (compressSpeed >= 0.0) {
681 if (eDampType == dtLinear) dampForce = -compressSpeed * bDamp;
682 else dampForce = -compressSpeed * compressSpeed * bDamp;
686 if (eDampTypeRebound == dtLinear)
687 dampForce = -compressSpeed * bDampRebound;
689 dampForce = compressSpeed * compressSpeed * bDampRebound;
693 StrutForce = min(springForce + dampForce, (double)0.0);
695 // The reaction force of the wheel is always normal to the ground
696 switch (eContactType) {
698 // Project back the strut force in the local coordinate frame of the ground
699 vFn(eX) = StrutForce / (mTGear.Transposed()*vGroundNormal)(eZ);
702 vFn(eX) = -StrutForce;
706 // Remember these values for reporting
707 MaximumStrutForce = max(MaximumStrutForce, fabs(StrutForce));
708 MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
711 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
713 double FGLGear::GetGearUnitPos(void)
715 // hack to provide backward compatibility to gear/gear-pos-norm property
716 if( useFCSGearPos || FCS->GetGearPos() != 1.0 ) {
717 useFCSGearPos = true;
718 return FCS->GetGearPos();
723 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
725 void FGLGear::bind(void)
727 string property_name;
728 string base_property_name;
729 base_property_name = CreateIndexedPropertyName("gear/unit", GearNumber);
730 if (eContactType == ctBOGEY) {
731 property_name = base_property_name + "/slip-angle-deg";
732 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &WheelSlip );
733 property_name = base_property_name + "/WOW";
734 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &WOW );
735 property_name = base_property_name + "/wheel-speed-fps";
736 fdmex->GetPropertyManager()->Tie( property_name.c_str(), (FGLGear*)this,
737 &FGLGear::GetWheelRollVel);
738 property_name = base_property_name + "/z-position";
739 fdmex->GetPropertyManager()->Tie( property_name.c_str(), (FGForce*)this,
740 &FGForce::GetLocationZ, &FGForce::SetLocationZ);
741 property_name = base_property_name + "/compression-ft";
742 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &compressLength );
743 property_name = base_property_name + "/side_friction_coeff";
744 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &FCoeff );
746 property_name = base_property_name + "/static_friction_coeff";
747 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &staticFCoeff );
749 if (eSteerType == stCaster) {
750 property_name = base_property_name + "/steering-angle-rad";
751 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &SteerAngle );
755 if( isRetractable ) {
756 property_name = base_property_name + "/pos-norm";
757 fdmex->GetPropertyManager()->Tie( property_name.c_str(), &GearPos );
761 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
763 void FGLGear::Report(ReportType repType)
765 if (fabs(TakeoffDistanceTraveled) < 0.001) return; // Don't print superfluous reports
769 cout << endl << "Touchdown report for " << name << " (WOW at time: "
770 << fdmex->GetState()->Getsim_time() << " seconds)" << endl;
771 cout << " Sink rate at contact: " << SinkRate << " fps, "
772 << SinkRate*0.3048 << " mps" << endl;
773 cout << " Contact ground speed: " << GroundSpeed*.5925 << " knots, "
774 << GroundSpeed*0.3048 << " mps" << endl;
775 cout << " Maximum contact force: " << MaximumStrutForce << " lbs, "
776 << MaximumStrutForce*4.448 << " Newtons" << endl;
777 cout << " Maximum strut travel: " << MaximumStrutTravel*12.0 << " inches, "
778 << MaximumStrutTravel*30.48 << " cm" << endl;
779 cout << " Distance traveled: " << LandingDistanceTraveled << " ft, "
780 << LandingDistanceTraveled*0.3048 << " meters" << endl;
781 LandingReported = true;
784 cout << endl << "Takeoff report for " << name << " (Liftoff at time: "
785 << fdmex->GetState()->Getsim_time() << " seconds)" << endl;
786 cout << " Distance traveled: " << TakeoffDistanceTraveled
787 << " ft, " << TakeoffDistanceTraveled*0.3048 << " meters" << endl;
788 cout << " Distance traveled (over 50'): " << TakeoffDistanceTraveled50ft
789 << " ft, " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl;
790 cout << " [Altitude (ASL): " << fdmex->GetPropagate()->GetAltitudeASL() << " ft. / "
791 << fdmex->GetPropagate()->GetAltitudeASLmeters() << " m | Temperature: "
792 << fdmex->GetAtmosphere()->GetTemperature() - 459.67 << " F / "
793 << RankineToCelsius(fdmex->GetAtmosphere()->GetTemperature()) << " C]" << endl;
794 cout << " [Velocity (KCAS): " << fdmex->GetAuxiliary()->GetVcalibratedKTS() << "]" << endl;
795 TakeoffReported = true;
802 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
803 // The bitmasked value choices are as follows:
804 // unset: In this case (the default) JSBSim would only print
805 // out the normally expected messages, essentially echoing
806 // the config files as they are read. If the environment
807 // variable is not set, debug_lvl is set to 1 internally
808 // 0: This requests JSBSim not to output any messages
810 // 1: This value explicity requests the normal JSBSim
812 // 2: This value asks for a message to be printed out when
813 // a class is instantiated
814 // 4: When this value is set, a message is displayed when a
815 // FGModel object executes its Run() method
816 // 8: When this value is set, various runtime state variables
817 // are printed out periodically
818 // 16: When set various parameters are sanity checked and
819 // a message is printed out when they go out of bounds
821 void FGLGear::Debug(int from)
823 if (debug_lvl <= 0) return;
825 if (debug_lvl & 1) { // Standard console startup message output
826 if (from == 0) { // Constructor - loading and initialization
827 cout << " " << sContactType << " " << name << endl;
828 cout << " Location: " << vXYZn << endl;
829 cout << " Spring Constant: " << kSpring << endl;
831 if (eDampType == dtLinear)
832 cout << " Damping Constant: " << bDamp << " (linear)" << endl;
834 cout << " Damping Constant: " << bDamp << " (square law)" << endl;
836 if (eDampTypeRebound == dtLinear)
837 cout << " Rebound Damping Constant: " << bDampRebound << " (linear)" << endl;
839 cout << " Rebound Damping Constant: " << bDampRebound << " (square law)" << endl;
841 cout << " Dynamic Friction: " << dynamicFCoeff << endl;
842 cout << " Static Friction: " << staticFCoeff << endl;
843 if (eContactType == ctBOGEY) {
844 cout << " Rolling Friction: " << rollingFCoeff << endl;
845 cout << " Steering Type: " << sSteerType << endl;
846 cout << " Grouping: " << sBrakeGroup << endl;
847 cout << " Max Steer Angle: " << maxSteerAngle << endl;
848 cout << " Retractable: " << isRetractable << endl;
849 cout << " Relaxation Velocities:" << endl;
850 cout << " Rolling: " << RFRV << endl;
851 cout << " Side: " << SFRV << endl;
855 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
856 if (from == 0) cout << "Instantiated: FGLGear" << endl;
857 if (from == 1) cout << "Destroyed: FGLGear" << endl;
859 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
861 if (debug_lvl & 8 ) { // Runtime state variables
863 if (debug_lvl & 16) { // Sanity checking
865 if (debug_lvl & 64) {
866 if (from == 0) { // Constructor
867 cout << IdSrc << endl;
868 cout << IdHdr << endl;
873 } // namespace JSBSim