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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 static const char *IdSrc = "$Id$";
54 static const char *IdHdr = ID_LGEAR;
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : vXYZ(3),
71 *AC_cfg >> tmp >> name >> vXYZ(1) >> vXYZ(2) >> vXYZ(3)
72 >> kSpring >> bDamp>> dynamicFCoeff >> staticFCoeff
73 >> rollingFCoeff >> sSteerType >> sBrakeGroup
74 >> maxSteerAngle >> Retractable;
77 cout << " Name: " << name << endl;
78 cout << " Location: " << vXYZ << endl;
79 cout << " Spring Constant: " << kSpring << endl;
80 cout << " Damping Constant: " << bDamp << endl;
81 cout << " Dynamic Friction: " << dynamicFCoeff << endl;
82 cout << " Static Friction: " << staticFCoeff << endl;
83 cout << " Rolling Friction: " << rollingFCoeff << endl;
84 cout << " Steering Type: " << sSteerType << endl;
85 cout << " Grouping: " << sBrakeGroup << endl;
86 cout << " Max Steer Angle: " << maxSteerAngle << endl;
87 cout << " Retractable: " << Retractable << endl;
90 if (sBrakeGroup == "LEFT" ) eBrakeGrp = bgLeft;
91 else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
92 else if (sBrakeGroup == "CENTER") eBrakeGrp = bgCenter;
93 else if (sBrakeGroup == "NOSE" ) eBrakeGrp = bgNose;
94 else if (sBrakeGroup == "TAIL" ) eBrakeGrp = bgTail;
95 else if (sBrakeGroup == "NONE" ) eBrakeGrp = bgNone;
97 cerr << "Improper braking group specification in config file: "
98 << sBrakeGroup << " is undefined." << endl;
101 if (sSteerType == "STEERABLE") eSteerType = stSteer;
102 else if (sSteerType == "FIXED" ) eSteerType = stFixed;
103 else if (sSteerType == "CASTERED" ) eSteerType = stCaster;
105 cerr << "Improper steering type specification in config file: "
106 << sSteerType << " is undefined." << endl;
109 if( Retractable == "RETRACT" ) {
115 GearUp=false; GearDown=true;
117 // Add some AI here to determine if gear is located properly according to its
118 // brake group type ??
120 State = Exec->GetState();
121 Aircraft = Exec->GetAircraft();
122 Position = Exec->GetPosition();
123 Rotation = Exec->GetRotation();
124 FCS = Exec->GetFCS();
125 MassBalance = Exec->GetMassBalance();
127 WOW = lastWOW = false;
129 FirstContact = false;
131 DistanceTraveled = 0.0;
132 MaximumStrutForce = MaximumStrutTravel = 0.0;
133 SinkRate = GroundSpeed = 0.0;
135 vWhlBodyVec = (vXYZ - MassBalance->GetXYZcg()) / 12.0;
136 vWhlBodyVec(eX) = -vWhlBodyVec(eX);
137 vWhlBodyVec(eZ) = -vWhlBodyVec(eZ);
139 vLocalGear = State->GetTb2l() * vWhlBodyVec;
141 if (debug_lvl & 2) cout << "Instantiated: FGLGear" << endl;
144 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 FGLGear::FGLGear(const FGLGear& lgear)
149 Aircraft = lgear.Aircraft;
150 Position = lgear.Position;
151 Rotation = lgear.Rotation;
154 MassBalance = lgear.MassBalance;
157 vMoment = lgear.vMoment;
158 vWhlBodyVec = lgear.vWhlBodyVec;
159 vLocalGear = lgear.vLocalGear;
162 lastWOW = lgear.lastWOW;
163 ReportEnable = lgear.ReportEnable;
164 FirstContact = lgear.FirstContact;
165 DistanceTraveled = lgear.DistanceTraveled;
166 MaximumStrutForce = lgear.MaximumStrutForce;
167 MaximumStrutTravel = lgear.MaximumStrutTravel;
169 kSpring = lgear.kSpring;
171 compressLength = lgear.compressLength;
172 compressSpeed = lgear.compressSpeed;
173 staticFCoeff = lgear.staticFCoeff;
174 dynamicFCoeff = lgear.dynamicFCoeff;
175 rollingFCoeff = lgear.rollingFCoeff;
176 brakePct = lgear.brakePct;
177 maxCompLen = lgear.maxCompLen;
178 SinkRate = lgear.SinkRate;
179 GroundSpeed = lgear.GroundSpeed;
180 Reported = lgear.Reported;
182 sSteerType = lgear.sSteerType;
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;
192 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196 if (debug_lvl & 2) cout << "Destroyed: FGLGear" << endl;
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 FGColumnVector3& FGLGear::Force(void)
204 vMoment.InitMatrix();
206 if( FCS->GetGearPos() < 0.01 ) {
207 GearUp=true;GearDown=false;
208 } else if(FCS->GetGearPos() > 0.99) {
209 GearDown=true;GearUp=false;
211 GearUp=false; GearDown=false;
214 GearUp=false; GearDown=true;
218 double SteerGain = 0;
219 double SinWheel, CosWheel, SideWhlVel, RollingWhlVel;
220 double RollingForce, SideForce, FCoeff;
223 vWhlBodyVec = (vXYZ - MassBalance->GetXYZcg()) / 12.0;
224 vWhlBodyVec(eX) = -vWhlBodyVec(eX);
225 vWhlBodyVec(eZ) = -vWhlBodyVec(eZ);
227 // vWhlBodyVec now stores the vector from the cg to this wheel
229 vLocalGear = State->GetTb2l() * vWhlBodyVec;
231 // vLocalGear now stores the vector from the cg to the wheel in local coords.
233 compressLength = vLocalGear(eZ) - Position->GetDistanceAGL();
235 // The compression length is currently measured in the Z-axis, only, at this time.
236 // It should be measured along the strut axis. If the local-frame gear position
237 // "hangs down" below the CG greater than the altitude, then the compressLength
238 // will be positive - i.e. the gear will have made contact.
240 if (compressLength > 0.00) {
242 WOW = true;// Weight-On-Wheels is true
244 // The next equation should really use the vector to the contact patch of the tire
245 // including the strut compression and not vWhlBodyVec. Will fix this later.
246 // As it stands, now, the following equation takes the aircraft body-frame
247 // rotational rate and calculates the cross-product with the vector from the CG
248 // to the wheel, thus producing the instantaneous velocity vector of the tire
249 // in Body coords. The frame is also converted to local coordinates. When the
250 // aircraft local-frame velocity is added to this quantity, the total velocity of
251 // the wheel in local frame is then known. Subsequently, the compression speed
252 // (used for calculating damping force) is found by taking the Z-component of the
255 vWhlVelVec = State->GetTb2l() * (Rotation->GetPQR() * vWhlBodyVec);
257 vWhlVelVec += Position->GetVel();
259 compressSpeed = vWhlVelVec(eZ);
261 // If this is the first time the wheel has made contact, remember some values
262 // for later printout.
266 SinkRate = compressSpeed;
267 GroundSpeed = Position->GetVel().Magnitude();
270 // The following needs work regarding friction coefficients and braking and
271 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
272 // It also assumes that we won't be turning and braking at the same time.
273 // Will fix this later.
274 // [JSB] The braking force coefficients include normal rolling coefficient +
275 // a percentage of the static friction coefficient based on braking applied.
280 BrakeFCoeff = rollingFCoeff*(1.0 - FCS->GetBrake(bgLeft)) +
281 staticFCoeff*FCS->GetBrake(bgLeft);
285 BrakeFCoeff = rollingFCoeff*(1.0 - FCS->GetBrake(bgRight)) +
286 staticFCoeff*FCS->GetBrake(bgRight);
290 BrakeFCoeff = rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
291 staticFCoeff*FCS->GetBrake(bgCenter);
295 BrakeFCoeff = rollingFCoeff;
299 BrakeFCoeff = rollingFCoeff;
303 BrakeFCoeff = rollingFCoeff;
306 cerr << "Improper brake group membership detected for this gear." << endl;
310 switch (eSteerType) {
312 SteerAngle = SteerGain*FCS->GetDrPos();
318 // Note to Jon: This is not correct for castering gear. I'll fix it later.
322 cerr << "Improper steering type membership detected for this gear." << endl;
326 // Transform the wheel velocities from the local axis system to the wheel axis system.
327 // For now, steering angle is assumed to happen in the Local Z axis,
328 // not the strut axis as it should be. Will fix this later.
330 SinWheel = sin(Rotation->Getpsi() + SteerAngle);
331 CosWheel = cos(Rotation->Getpsi() + SteerAngle);
332 RollingWhlVel = vWhlVelVec(eX)*CosWheel + vWhlVelVec(eY)*SinWheel;
333 SideWhlVel = vWhlVelVec(eY)*CosWheel - vWhlVelVec(eX)*SinWheel;
335 // Calculate tire slip angle.
337 if (RollingWhlVel == 0.0 && SideWhlVel == 0.0) {
340 WheelSlip = radtodeg*atan2(SideWhlVel, RollingWhlVel);
343 // The following code normalizes the wheel velocity vector, reverses it, and zeroes out
344 // the z component of the velocity. The question is, should the Z axis velocity be zeroed
345 // out first before the normalization takes place or not? Subsequent to that, the Wheel
346 // Velocity vector now points as a unit vector backwards and parallel to the wheel
347 // velocity vector. It acts AT the wheel.
349 // Note to Jon: I commented out this line because I wasn't sure we want to do this.
350 // vWhlVelVec = -1.0 * vWhlVelVec.Normalize();
351 // vWhlVelVec(eZ) = 0.00;
353 // Compute the sideforce coefficients using similar assumptions to LaRCSim for now.
354 // Allow a maximum of 10 degrees tire slip angle before wheel slides. At that point,
355 // transition from static to dynamic friction. There are more complicated formulations
356 // of this that avoid the discrete jump. Will fix this later.
358 if (fabs(WheelSlip) <= 10.0) {
359 FCoeff = staticFCoeff*WheelSlip/10.0;
361 FCoeff = dynamicFCoeff*fabs(WheelSlip)/WheelSlip;
364 // Compute the vertical force on the wheel using square-law damping (per comment
365 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
366 // allowing for both square and linear damping force calculation. Also need to
367 // possibly give a "rebound damping factor" that differs from the compression
368 // case. NOTE: SQUARE LAW DAMPING NO GOOD!
370 vLocalForce(eZ) = min(-compressLength * kSpring
371 - compressSpeed * bDamp, (double)0.0);
373 MaximumStrutForce = max(MaximumStrutForce, fabs(vLocalForce(eZ)));
374 MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
376 // Compute the forces in the wheel ground plane.
379 if (fabs(RollingWhlVel) > 1E-3) {
380 RollingForce = vLocalForce(eZ) * BrakeFCoeff * fabs(RollingWhlVel)/RollingWhlVel;
382 SideForce = vLocalForce(eZ) * FCoeff;
384 // Transform these forces back to the local reference frame.
386 vLocalForce(eX) = RollingForce*CosWheel - SideForce*SinWheel;
387 vLocalForce(eY) = SideForce*CosWheel + RollingForce*SinWheel;
389 // Note to Jon: At this point the forces will be too big when the airplane is
390 // stopped or rolling to a stop. We need to make sure that the gear forces just
391 // balance out the non-gear forces when the airplane is stopped. That way the
392 // airplane won't start to accelerate until the non-gear/ forces are larger than
393 // the gear forces. I think that the proper fix should go into FGAircraft::FMGear.
394 // This routine would only compute the local strut forces and return them to
395 // FMGear. All of the gear forces would get adjusted in FMGear using the total
396 // non-gear forces. Then the gear moments would be calculated. If strange things
397 // start happening to the airplane during testing as it rolls to a stop, then we
398 // need to implement this change. I ran out of time to do it now but have the
401 // Transform the forces back to the body frame and compute the moment.
403 vForce = State->GetTl2b() * vLocalForce;
404 vMoment = vWhlBodyVec * vForce;
410 if (Position->GetDistanceAGL() > 200.0) {
411 FirstContact = false;
413 DistanceTraveled = 0.0;
414 MaximumStrutForce = MaximumStrutTravel = 0.0;
417 compressLength = 0.0;// reset compressLength to zero for data output validity
423 DistanceTraveled += Position->GetVel().Magnitude()*State->Getdt()*Aircraft->GetRate();
426 if (ReportEnable && Position->GetVel().Magnitude() <= 0.05 && !Reported) {
427 if (debug_lvl > 0) Report();
430 if (lastWOW != WOW) {
431 PutMessage("GEAR_CONTACT", WOW);
436 // Crash detection logic (really out-of-bounds detection)
438 if (compressLength > 500.0 ||
439 vForce.Magnitude() > 100000000.0 ||
440 vMoment.Magnitude() > 5000000000.0 ||
441 SinkRate > 1.4666*30)
443 PutMessage("Crash Detected");
452 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454 void FGLGear::Report(void)
456 cout << endl << "Touchdown report for " << name << endl;
457 cout << " Sink rate at contact: " << SinkRate << " fps, "
458 << SinkRate*0.3408 << " mps" << endl;
459 cout << " Contact ground speed: " << GroundSpeed*.5925 << " knots, "
460 << GroundSpeed*0.3408 << " mps" << endl;
461 cout << " Maximum contact force: " << MaximumStrutForce << " lbs, "
462 << MaximumStrutForce*4.448 << " Newtons" << endl;
463 cout << " Maximum strut travel: " << MaximumStrutTravel*12.0 << " inches, "
464 << MaximumStrutTravel*30.48 << " cm" << endl;
465 cout << " Distance traveled: " << DistanceTraveled << " ft, "
466 << DistanceTraveled*0.3408 << " meters" << endl;
470 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
472 void FGLGear::Debug(void)
474 // TODO: Add user code here