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