]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGLGear.cpp
Synced with latest JSBSim cvs.
[flightgear.git] / src / FDM / JSBSim / FGLGear.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGLGear.cpp
4  Author:       Jon S. Berndt
5                Norman H. Princen
6  Date started: 11/18/99
7  Purpose:      Encapsulates the landing gear elements
8  Called by:    FGAircraft
9
10  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
11
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
15  version.
16
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
20  details.
21
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.
25
26  Further information about the GNU General Public License can also be found on
27  the world wide web at http://www.gnu.org.
28
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
31
32 HISTORY
33 --------------------------------------------------------------------------------
34 11/18/99   JSB   Created
35 01/30/01   NHP   Extended gear model to properly simulate steering and braking
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "FGLGear.h"
42 #include <algorithm>
43
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 DEFINITIONS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 GLOBAL DATA
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52
53 static const char *IdSrc = "$Id$";
54 static const char *IdHdr = ID_LGEAR;
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 CLASS IMPLEMENTATION
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : vXYZ(3),
61                                                            vMoment(3),
62                                                            vWhlBodyVec(3),
63                                                            vForce(3),
64                                                            vLocalForce(3),
65                                                            vWhlVelVec(3),
66                                                            Exec(fdmex)
67 {
68   string tmp;
69   *AC_cfg >> tmp >> name >> vXYZ(1) >> vXYZ(2) >> vXYZ(3)
70             >> kSpring >> bDamp>> dynamicFCoeff >> staticFCoeff
71                   >> rollingFCoeff >> sSteerType >> sBrakeGroup >> maxSteerAngle;
72
73   if (debug_lvl > 0) {
74     cout << "    Name: " << name << endl;
75     cout << "      Location: " << vXYZ << endl;
76     cout << "      Spring Constant:  " << kSpring << endl;
77     cout << "      Damping Constant: " << bDamp << endl;
78     cout << "      Dynamic Friction: " << dynamicFCoeff << endl;
79     cout << "      Static Friction:  " << staticFCoeff << endl;
80     cout << "      Rolling Friction: " << rollingFCoeff << endl;
81     cout << "      Steering Type:    " << sSteerType << endl;
82     cout << "      Grouping:         " << sBrakeGroup << endl;
83     cout << "      Max Steer Angle:  " << maxSteerAngle << endl;
84   }
85
86   if      (sBrakeGroup == "LEFT"  ) eBrakeGrp = bgLeft;
87   else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
88   else if (sBrakeGroup == "CENTER") eBrakeGrp = bgCenter;
89   else if (sBrakeGroup == "NOSE"  ) eBrakeGrp = bgNose;
90   else if (sBrakeGroup == "TAIL"  ) eBrakeGrp = bgTail;
91   else if (sBrakeGroup == "NONE"  ) eBrakeGrp = bgNone;
92   else {
93     cerr << "Improper braking group specification in config file: "
94          << sBrakeGroup << " is undefined." << endl;
95   }
96
97   if      (sSteerType == "STEERABLE") eSteerType = stSteer;
98   else if (sSteerType == "FIXED"    ) eSteerType = stFixed;
99   else if (sSteerType == "CASTERED" ) eSteerType = stCaster;
100   else {
101     cerr << "Improper steering type specification in config file: "
102          << sSteerType << " is undefined." << endl;
103   }
104
105 // Add some AI here to determine if gear is located properly according to its
106 // brake group type ??
107
108   State       = Exec->GetState();
109   Aircraft    = Exec->GetAircraft();
110   Position    = Exec->GetPosition();
111   Rotation    = Exec->GetRotation();
112   FCS         = Exec->GetFCS();
113   MassBalance = Exec->GetMassBalance();
114
115   WOW = lastWOW = false;
116   ReportEnable = true;
117   FirstContact = false;
118   Reported = false;
119   DistanceTraveled = 0.0;
120   MaximumStrutForce = MaximumStrutTravel = 0.0;
121   SinkRate = GroundSpeed = 0.0;
122
123   vWhlBodyVec     = (vXYZ - MassBalance->GetXYZcg()) / 12.0;
124   vWhlBodyVec(eX) = -vWhlBodyVec(eX);
125   vWhlBodyVec(eZ) = -vWhlBodyVec(eZ);
126
127   vLocalGear = State->GetTb2l() * vWhlBodyVec;
128
129   if (debug_lvl & 2) cout << "Instantiated: FGLGear" << endl;
130 }
131
132 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133
134 FGLGear::FGLGear(const FGLGear& lgear)
135 {
136   State    = lgear.State;
137   Aircraft = lgear.Aircraft;
138   Position = lgear.Position;
139   Rotation = lgear.Rotation;
140   Exec     = lgear.Exec;
141   FCS      = lgear.FCS;
142   MassBalance = lgear.MassBalance;
143
144   vXYZ = lgear.vXYZ;
145   vMoment = lgear.vMoment;
146   vWhlBodyVec = lgear.vWhlBodyVec;
147   vLocalGear = lgear.vLocalGear;
148
149   WOW                = lgear.WOW;
150   lastWOW            = lgear.lastWOW;
151   ReportEnable       = lgear.ReportEnable;
152   FirstContact       = lgear.FirstContact;
153   DistanceTraveled   = lgear.DistanceTraveled;
154   MaximumStrutForce  = lgear.MaximumStrutForce;
155   MaximumStrutTravel = lgear.MaximumStrutTravel;
156
157   kSpring         = lgear.kSpring;
158   bDamp           = lgear.bDamp;
159   compressLength  = lgear.compressLength;
160   compressSpeed   = lgear.compressSpeed;
161   staticFCoeff    = lgear.staticFCoeff;
162   dynamicFCoeff   = lgear.dynamicFCoeff;
163   rollingFCoeff   = lgear.rollingFCoeff;
164   brakePct        = lgear.brakePct;
165   maxCompLen      = lgear.maxCompLen;
166   SinkRate        = lgear.SinkRate;
167   GroundSpeed     = lgear.GroundSpeed;
168   Reported        = lgear.Reported;
169   name            = lgear.name;
170   sSteerType      = lgear.sSteerType;
171   eSteerType      = lgear.eSteerType;
172   sBrakeGroup     = lgear.sBrakeGroup;
173   eBrakeGrp       = lgear.eBrakeGrp;
174   maxSteerAngle   = lgear.maxSteerAngle;
175 }
176
177 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178
179 FGLGear::~FGLGear()
180 {
181   if (debug_lvl & 2) cout << "Destroyed:    FGLGear" << endl;
182 }
183
184 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185
186 FGColumnVector3& FGLGear::Force(void)
187 {
188   double SteerGain;
189   double SinWheel, CosWheel, SideWhlVel, RollingWhlVel;
190   double RudderPedal, RollingForce, SideForce, FCoeff;
191   double WheelSlip;
192
193   vWhlBodyVec     = (vXYZ - MassBalance->GetXYZcg()) / 12.0;
194   vWhlBodyVec(eX) = -vWhlBodyVec(eX);
195   vWhlBodyVec(eZ) = -vWhlBodyVec(eZ);
196
197 // vWhlBodyVec now stores the vector from the cg to this wheel
198
199   vLocalGear = State->GetTb2l() * vWhlBodyVec;
200
201 // vLocalGear now stores the vector from the cg to the wheel in local coords.
202
203   compressLength = vLocalGear(eZ) - Position->GetDistanceAGL();
204
205 // The compression length is currently measured in the Z-axis, only, at this time.
206 // It should be measured along the strut axis. If the local-frame gear position
207 // "hangs down" below the CG greater than the altitude, then the compressLength
208 // will be positive - i.e. the gear will have made contact.
209
210   if (compressLength > 0.00) {
211
212     WOW = true; // Weight-On-Wheels is true
213
214 // The next equation should really use the vector to the contact patch of the tire
215 // including the strut compression and not vWhlBodyVec.  Will fix this later.
216 // As it stands, now, the following equation takes the aircraft body-frame
217 // rotational rate and calculates the cross-product with the vector from the CG
218 // to the wheel, thus producing the instantaneous velocity vector of the tire
219 // in Body coords. The frame is also converted to local coordinates. When the
220 // aircraft local-frame velocity is added to this quantity, the total velocity of
221 // the wheel in local frame is then known. Subsequently, the compression speed
222 // (used for calculating damping force) is found by taking the Z-component of the
223 // wheel velocity.
224
225     vWhlVelVec      =  State->GetTb2l() * (Rotation->GetPQR() * vWhlBodyVec);
226
227     vWhlVelVec     +=  Position->GetVel();
228
229     compressSpeed   =  vWhlVelVec(eZ);
230
231 // If this is the first time the wheel has made contact, remember some values
232 // for later printout.
233
234     if (!FirstContact) {
235       FirstContact  = true;
236       SinkRate      =  compressSpeed;
237       GroundSpeed   =  Position->GetVel().Magnitude();
238     }
239
240 // The following needs work regarding friction coefficients and braking and
241 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
242 // It also assumes that we won't be turning and braking at the same time.
243 // Will fix this later.
244 // [JSB] The braking force coefficients include normal rolling coefficient +
245 // a percentage of the static friction coefficient based on braking applied.
246
247     switch (eBrakeGrp) {
248     case bgLeft:
249       SteerGain = -0.10;
250       BrakeFCoeff = rollingFCoeff*(1.0 - FCS->GetBrake(bgLeft)) +
251                                             staticFCoeff*FCS->GetBrake(bgLeft);
252       break;
253     case bgRight:
254       SteerGain = -0.10;
255       BrakeFCoeff = rollingFCoeff*(1.0 - FCS->GetBrake(bgRight)) +
256                                            staticFCoeff*FCS->GetBrake(bgRight);
257       break;
258     case bgCenter:
259       SteerGain = -0.10;
260       BrakeFCoeff = rollingFCoeff*(1.0 - FCS->GetBrake(bgCenter)) +
261                                            staticFCoeff*FCS->GetBrake(bgCenter);
262       break;
263     case bgNose:
264       SteerGain = 0.10;
265       BrakeFCoeff = rollingFCoeff;
266       break;
267     case bgTail:
268       SteerGain = -0.10;
269       BrakeFCoeff = rollingFCoeff;
270       break;
271     case bgNone:
272       SteerGain = -0.10;
273       BrakeFCoeff = rollingFCoeff;
274       break;
275     default:
276       cerr << "Improper brake group membership detected for this gear." << endl;
277       break;
278     }
279
280     switch (eSteerType) {
281     case stSteer:
282       SteerAngle = SteerGain*FCS->GetDrPos();
283       break;
284     case stFixed:
285       SteerAngle = 0.0;
286       break;
287     case stCaster:
288     // Note to Jon: This is not correct for castering gear.  I'll fix it later.
289       SteerAngle = 0.0;
290       break;
291     default:
292       cerr << "Improper steering type membership detected for this gear." << endl;
293       break;
294     }
295
296 // Transform the wheel velocities from the local axis system to the wheel axis system.
297 // For now, steering angle is assumed to happen in the Local Z axis,
298 // not the strut axis as it should be.  Will fix this later.
299
300     SinWheel      = sin(Rotation->Getpsi() + SteerAngle);
301     CosWheel      = cos(Rotation->Getpsi() + SteerAngle);
302     RollingWhlVel = vWhlVelVec(eX)*CosWheel + vWhlVelVec(eY)*SinWheel;
303     SideWhlVel    = vWhlVelVec(eY)*CosWheel - vWhlVelVec(eX)*SinWheel;
304
305 // Calculate tire slip angle.
306
307     if (RollingWhlVel == 0.0 && SideWhlVel == 0.0) {
308       WheelSlip = 0.0;
309     } else {
310       WheelSlip = radtodeg*atan2(SideWhlVel, RollingWhlVel);
311     }
312
313 // The following code normalizes the wheel velocity vector, reverses it, and zeroes out
314 // the z component of the velocity. The question is, should the Z axis velocity be zeroed
315 // out first before the normalization takes place or not? Subsequent to that, the Wheel
316 // Velocity vector now points as a unit vector backwards and parallel to the wheel
317 // velocity vector. It acts AT the wheel.
318
319 // Note to Jon: I commented out this line because I wasn't sure we want to do this.
320 //    vWhlVelVec      = -1.0 * vWhlVelVec.Normalize();
321 //    vWhlVelVec(eZ)  =  0.00;
322
323 // Compute the sideforce coefficients using similar assumptions to LaRCSim for now.
324 // Allow a maximum of 10 degrees tire slip angle before wheel slides.  At that point,
325 // transition from static to dynamic friction.  There are more complicated formulations
326 // of this that avoid the discrete jump.  Will fix this later.
327
328     if (fabs(WheelSlip) <= 10.0) {
329       FCoeff = staticFCoeff*WheelSlip/10.0;
330     } else {
331       FCoeff = dynamicFCoeff*fabs(WheelSlip)/WheelSlip;
332     }
333
334 // Compute the vertical force on the wheel using square-law damping (per comment
335 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
336 // allowing for both square and linear damping force calculation. Also need to
337 // possibly give a "rebound damping factor" that differs from the compression
338 // case. NOTE: SQUARE LAW DAMPING NO GOOD!
339
340     vLocalForce(eZ) =  min(-compressLength * kSpring
341                            - compressSpeed * bDamp, (double)0.0);
342
343     MaximumStrutForce = max(MaximumStrutForce, fabs(vLocalForce(eZ)));
344     MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
345
346 // Compute the forces in the wheel ground plane.
347
348     RollingForce = 0;
349     if (fabs(RollingWhlVel) > 1E-3) {
350       RollingForce = vLocalForce(eZ) * BrakeFCoeff * fabs(RollingWhlVel)/RollingWhlVel;
351     }
352     SideForce    = vLocalForce(eZ) * FCoeff;
353
354 // Transform these forces back to the local reference frame.
355
356     vLocalForce(eX) = RollingForce*CosWheel - SideForce*SinWheel;
357     vLocalForce(eY) = SideForce*CosWheel    + RollingForce*SinWheel;
358
359 // Note to Jon: At this point the forces will be too big when the airplane is
360 // stopped or rolling to a stop.  We need to make sure that the gear forces just
361 // balance out the non-gear forces when the airplane is stopped.  That way the
362 // airplane won't start to accelerate until the non-gear/ forces are larger than
363 // the gear forces.  I think that the proper fix should go into FGAircraft::FMGear.
364 // This routine would only compute the local strut forces and return them to
365 // FMGear. All of the gear forces would get adjusted in FMGear using the total
366 // non-gear forces. Then the gear moments would be calculated. If strange things
367 // start happening to the airplane during testing as it rolls to a stop, then we
368 // need to implement this change.  I ran out of time to do it now but have the
369 // equations.
370
371 // Transform the forces back to the body frame and compute the moment.
372
373     vForce  = State->GetTl2b() * vLocalForce;
374     vMoment = vWhlBodyVec * vForce;
375
376   } else {
377
378     WOW = false;
379
380     if (Position->GetDistanceAGL() > 200.0) {
381       FirstContact = false;
382       Reported = false;
383       DistanceTraveled = 0.0;
384       MaximumStrutForce = MaximumStrutTravel = 0.0;
385     }
386
387     compressLength = 0.0; // reset compressLength to zero for data output validity
388
389     vForce.InitMatrix();
390     vMoment.InitMatrix();
391   }
392
393   if (FirstContact) {
394     DistanceTraveled += Position->GetVel().Magnitude()*State->Getdt()*Aircraft->GetRate();
395   }
396
397   if (ReportEnable && Position->GetVel().Magnitude() <= 0.05 && !Reported) {
398     if (debug_lvl > 0) Report();
399   }
400
401   if (lastWOW != WOW) {
402     PutMessage("GEAR_CONTACT", WOW);
403   }
404
405   lastWOW = WOW;
406
407   // Crash detection logic (really out-of-bounds detection)
408   
409   if (compressLength > 500.0 ||
410       vForce.Magnitude() > 100000000.0 ||
411       vMoment.Magnitude() > 5000000000.0 ||
412       SinkRate > 1.4666*30)
413   {
414     PutMessage("Crash Detected");
415     Exec->Freeze();
416   }
417
418   return vForce;
419 }
420
421 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422
423 void FGLGear::Report(void)
424 {
425   cout << endl << "Touchdown report for " << name << endl;
426   cout << "  Sink rate at contact:  " << SinkRate                << " fps,    "
427                               << SinkRate*0.3408          << " mps"     << endl;
428   cout << "  Contact ground speed:  " << GroundSpeed*.5925       << " knots,  "
429                               << GroundSpeed*0.3408       << " mps"     << endl;
430   cout << "  Maximum contact force: " << MaximumStrutForce       << " lbs,    "
431                               << MaximumStrutForce*4.448  << " Newtons" << endl;
432   cout << "  Maximum strut travel:  " << MaximumStrutTravel*12.0 << " inches, "
433                               << MaximumStrutTravel*30.48 << " cm"      << endl;
434   cout << "  Distance traveled:     " << DistanceTraveled        << " ft,     "
435                               << DistanceTraveled*0.3408  << " meters"  << endl;
436   Reported = true;
437 }
438
439 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
440
441 void FGLGear::Debug(void)
442 {
443   // TODO: Add user code here
444 }
445