Debian Codegraph @

src/FDM/JSBSim/models/FGLGear.cpp

raw symbols SCIP
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGLGear.cpp
4 Author: Jon S. Berndt
5 Norman H. Princen
6 Bertrand Coconnier
7 Date started: 11/18/99
8 Purpose: Encapsulates the landing gear elements
9 Called by: FGAircraft
10
11 ------------- Copyright (C) 1999 Jon S. Berndt ([email protected]) -------------
12
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
15 Software Foundation; either version 2 of the License, or (at your option) any
16 later version.
17
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
21 details.
22
23 You should have received a copy of the GNU Lesser General Public License along
24 with this program; if not, write to the Free Software Foundation, Inc., 59
25 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 Further information about the GNU Lesser General Public License can also be
28 found on the world wide web at http://www.gnu.org.
29
30 FUNCTIONAL DESCRIPTION
31 --------------------------------------------------------------------------------
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 11/18/99 JSB Created
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
38 and ground
39
40 /%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 INCLUDES
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43
44 #include "FGLGear.h"
45 #include "models/FGGroundReactions.h"
46 #include "math/FGTable.h"
47 #include "input_output/FGXMLElement.h"
48 #include "models/FGInertial.h"
49
50 using namespace std;
51
52 namespace JSBSim {
53
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 DEFINITIONS
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57
58 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 GLOBAL DATA
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61
62 // Body To Structural (body frame is rotated 180 deg about Y and lengths are
63 // given in ft instead of inches)
64 const FGMatrix33 FGLGear::Tb2s(-1./inchtoft, 0., 0., 0., 1./inchtoft, 0., 0., 0., -1./inchtoft);
65 const FGMatrix33 FGLGear::Ts2b(-inchtoft, 0., 0., 0., inchtoft, 0., 0., 0., -inchtoft);
66
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 CLASS IMPLEMENTATION
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70
71 FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number, const struct Inputs& inputs) :
72 FGForce(fdmex),
73 in(inputs),
74 GearNumber(number),
75 SteerAngle(0.0),
76 Castered(false),
77 StaticFriction(false),
78 eSteerType(stSteer)
79 {
80 kSpring = bDamp = bDampRebound = dynamicFCoeff = staticFCoeff = rollingFCoeff = maxSteerAngle = 0;
81 isRetractable = false;
82 eDampType = dtLinear;
83 eDampTypeRebound = dtLinear;
84
85 name = el->GetAttributeValue("name");
86 string sContactType = el->GetAttributeValue("type");
87 if (sContactType == "BOGEY") {
88 eContactType = ctBOGEY;
89 } else if (sContactType == "STRUCTURE") {
90 eContactType = ctSTRUCTURE;
91 } else {
92 // Unknown contact point types will be treated as STRUCTURE.
93 eContactType = ctSTRUCTURE;
94 }
95
96 // Default values for structural contact points
97 if (eContactType == ctSTRUCTURE) {
98 kSpring = in.EmptyWeight;
99 bDamp = kSpring;
100 bDampRebound = kSpring * 10;
101 staticFCoeff = 1.0;
102 dynamicFCoeff = 1.0;
103 }
104
105 PropertyManager = fdmex->GetPropertyManager();
106
107 fStrutForce = 0;
108 Element* strutForce = el->FindElement("strut_force");
109 if (strutForce) {
110 Element* springFunc = strutForce->FindElement("function");
111 fStrutForce = new FGFunction(fdmex, springFunc);
112 }
113 else {
114 if (el->FindElement("spring_coeff"))
115 kSpring = el->FindElementValueAsNumberConvertTo("spring_coeff", "LBS/FT");
116 if (el->FindElement("damping_coeff")) {
117 Element* dampCoeff = el->FindElement("damping_coeff");
118 if (dampCoeff->GetAttributeValue("type") == "SQUARE") {
119 eDampType = dtSquare;
120 bDamp = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT2/SEC2");
121 } else {
122 bDamp = el->FindElementValueAsNumberConvertTo("damping_coeff", "LBS/FT/SEC");
123 }
124 }
125
126 if (el->FindElement("damping_coeff_rebound")) {
127 Element* dampCoeffRebound = el->FindElement("damping_coeff_rebound");
128 if (dampCoeffRebound->GetAttributeValue("type") == "SQUARE") {
129 eDampTypeRebound = dtSquare;
130 bDampRebound = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT2/SEC2");
131 } else {
132 bDampRebound = el->FindElementValueAsNumberConvertTo("damping_coeff_rebound", "LBS/FT/SEC");
133 }
134 } else {
135 bDampRebound = bDamp;
136 eDampTypeRebound = eDampType;
137 }
138 }
139
140 if (el->FindElement("dynamic_friction"))
141 dynamicFCoeff = el->FindElementValueAsNumber("dynamic_friction");
142 if (el->FindElement("static_friction"))
143 staticFCoeff = el->FindElementValueAsNumber("static_friction");
144 if (el->FindElement("rolling_friction"))
145 rollingFCoeff = el->FindElementValueAsNumber("rolling_friction");
146 if (el->FindElement("retractable"))
147 isRetractable = ((unsigned int)el->FindElementValueAsNumber("retractable"))>0.0?true:false;
148
149 if (el->FindElement("max_steer"))
150 maxSteerAngle = el->FindElementValueAsNumberConvertTo("max_steer", "DEG");
151
152 Element* castered_el = el->FindElement("castered");
153
154 if ((maxSteerAngle == 360 && !castered_el)
155 || (castered_el && castered_el->GetDataAsNumber() != 0.0)) {
156 eSteerType = stCaster;
157 Castered = true;
158 }
159 else if (maxSteerAngle == 0.0) {
160 eSteerType = stFixed;
161 }
162 else
163 eSteerType = stSteer;
164
165 GroundReactions = fdmex->GetGroundReactions();
166
167 ForceY_Table = 0;
168 Element* force_table = el->FindElement("table");
169 while (force_table) {
170 string force_type = force_table->GetAttributeValue("name");
171 if (force_type == "CORNERING_COEFF") {
172 ForceY_Table = new FGTable(PropertyManager, force_table);
173 break;
174 } else {
175 cerr << "Undefined force table for " << name << " contact point" << endl;
176 }
177 force_table = el->FindNextElement("table");
178 }
179
180 Element* element = el->FindElement("location");
181 if (element) vXYZn = element->FindElementTripletConvertTo("IN");
182 else {
183 stringstream s;
184 s << "No location given for contact " << name;
185 cerr << endl << s.str() << endl;
186 throw BaseException(s.str());
187 }
188 SetTransformType(FGForce::tCustom);
189
190 element = el->FindElement("orientation");
191 if (element && (eContactType == ctBOGEY)) {
192 FGQuaternion quatFromEuler(element->FindElementTripletConvertTo("RAD"));
193
194 mTGear = quatFromEuler.GetT();
195 }
196 else {
197 mTGear(1,1) = 1.;
198 mTGear(2,2) = 1.;
199 mTGear(3,3) = 1.;
200 }
201
202 string sBrakeGroup = el->FindElementValue("brake_group");
203
204 if (sBrakeGroup == "LEFT" ) eBrakeGrp = bgLeft;
205 else if (sBrakeGroup == "RIGHT" ) eBrakeGrp = bgRight;
206 else if (sBrakeGroup == "CENTER") eBrakeGrp = bgCenter;
207 else if (sBrakeGroup == "NOSE" ) eBrakeGrp = bgCenter; // Nose brake is not supported by FGFCS
208 else if (sBrakeGroup == "TAIL" ) eBrakeGrp = bgCenter; // Tail brake is not supported by FGFCS
209 else if (sBrakeGroup == "NONE" ) eBrakeGrp = bgNone;
210 else if (sBrakeGroup.empty() ) eBrakeGrp = bgNone;
211 else {
212 cerr << "Improper braking group specification in config file: "
213 << sBrakeGroup << " is undefined." << endl;
214 }
215
216 // Add some AI here to determine if gear is located properly according to its
217 // brake group type ??
218
219 useFCSGearPos = false;
220 ReportEnable = true;
221 TakeoffReported = LandingReported = false;
222
223 // Set Pacejka terms
224
225 Stiffness = 0.06;
226 Shape = 2.8;
227 Peak = staticFCoeff;
228 Curvature = 1.03;
229
230 ResetToIC();
231
232 Debug(0);
233 }
234
235 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236
237 FGLGear::~FGLGear()
238 {
239 delete ForceY_Table;
240 delete fStrutForce;
241 Debug(1);
242 }
243
244 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245
246 void FGLGear::ResetToIC(void)
247 {
248 GearPos = 1.0;
249
250 WOW = lastWOW = false;
251 FirstContact = false;
252 StartedGroundRun = false;
253 LandingDistanceTraveled = TakeoffDistanceTraveled = TakeoffDistanceTraveled50ft = 0.0;
254 MaximumStrutForce = MaximumStrutTravel = 0.0;
255 SinkRate = GroundSpeed = 0.0;
256 SteerAngle = 0.0;
257
258 vWhlVelVec.InitMatrix();
259
260 compressLength = 0.0;
261 compressSpeed = 0.0;
262 maxCompLen = 0.0;
263
264 WheelSlip = 0.0;
265
266 // Initialize Lagrange multipliers
267 for (int i=0; i < 3; i++) {
268 LMultiplier[i].ForceJacobian.InitMatrix();
269 LMultiplier[i].LeverArm.InitMatrix();
270 LMultiplier[i].Min = 0.0;
271 LMultiplier[i].Max = 0.0;
272 LMultiplier[i].value = 0.0;
273 }
274 }
275
276 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277
278 const FGColumnVector3& FGLGear::GetBodyForces(void)
279 {
280 double gearPos = 1.0;
281
282 vFn.InitMatrix();
283
284 if (isRetractable) gearPos = GetGearUnitPos();
285
286 if (gearPos > 0.99) { // Gear DOWN
287 FGColumnVector3 normal, terrainVel, dummy;
288 FGLocation gearLoc, contact;
289 FGColumnVector3 vWhlBodyVec = Ts2b * (vXYZn - in.vXYZcg);
290
291 vLocalGear = in.Tb2l * vWhlBodyVec; // Get local frame wheel location
292 gearLoc = in.Location.LocalToLocation(vLocalGear);
293
294 // Compute the height of the theoretical location of the wheel (if strut is
295 // not compressed) with respect to the ground level
296 double height = fdmex->GetInertial()->GetContactPoint(gearLoc, contact,
297 normal, terrainVel,
298 dummy);
299
300 if (!fdmex->GetTrimStatus())
301 height -= GroundReactions->GetBumpHeight();
302 staticFFactor = GroundReactions->GetStaticFFactor();
303 rollingFFactor = GroundReactions->GetRollingFFactor();
304 maximumForce = GroundReactions->GetMaximumForce();
305 bumpiness = GroundReactions->GetBumpiness();
306 isSolid = GroundReactions->GetSolid();
307
308 FGColumnVector3 vWhlDisplVec;
309 double LGearProj = 1.0;
310
311 if (height < 0.0) {
312 WOW = true;
313 vGroundNormal = in.Tec2b * normal;
314
315 // The height returned by GetGroundCallback() is the AGL and is expressed
316 // in the Z direction of the local coordinate frame. We now need to
317 // transform this height in actual compression of the strut (BOGEY) or in
318 // the normal direction to the ground (STRUCTURE)
319 double normalZ = (in.Tec2l*normal)(eZ);
320 LGearProj = -(mTGear.Transposed() * vGroundNormal)(eZ);
321
322 // The following equations use the vector to the tire contact patch
323 // including the strut compression.
324 switch(eContactType) {
325 case ctBOGEY:
326 if (isSolid) {
327 compressLength = LGearProj > 0.0 ? height * normalZ / LGearProj : 0.0;
328 vWhlDisplVec = mTGear * FGColumnVector3(0., 0., -compressLength);
329 } else {
330 // Gears don't (or hardly) compress in liquids
331 WOW = false;
332 }
333 break;
334 case ctSTRUCTURE:
335 compressLength = height * normalZ / DotProduct(normal, normal);
336 vWhlDisplVec = compressLength * vGroundNormal;
337 break;
338 }
339 }
340 else
341 WOW = false;
342
343 if (WOW) {
344 FGColumnVector3 vWhlContactVec = vWhlBodyVec + vWhlDisplVec;
345 vActingXYZn = vXYZn + Tb2s * vWhlDisplVec;
346 FGColumnVector3 vBodyWhlVel = in.PQR * vWhlContactVec;
347 vBodyWhlVel += in.UVW - in.Tec2b * terrainVel;
348 vWhlVelVec = mTGear.Transposed() * vBodyWhlVel;
349
350 InitializeReporting();
351 ComputeSteeringAngle();
352 ComputeGroundFrame();
353
354 vGroundWhlVel = mT.Transposed() * vBodyWhlVel;
355
356 if (fdmex->GetTrimStatus() || in.TotalDeltaT == 0.0)
357 compressSpeed = 0.0; // Steady state is sought during trimming
358 else {
359 compressSpeed = -vGroundWhlVel(eZ);
360 if (eContactType == ctBOGEY)
361 compressSpeed /= LGearProj;
362
363 // If the gear is entering in contact with the ground during the current
364 // time step, the compression speed might actually be lower than the
365 // aircraft velocity projected along the gear leg (compressSpeed).
366 double maxCompressSpeed = compressLength/in.TotalDeltaT;
367 if (fabs(compressSpeed) > maxCompressSpeed)
368 compressSpeed = sign(compressSpeed)*maxCompressSpeed;
369 }
370
371 ComputeVerticalStrutForce();
372
373 // Compute the friction coefficients in the wheel ground plane.
374 if (eContactType == ctBOGEY) {
375 ComputeSlipAngle();
376 ComputeBrakeForceCoefficient();
377 ComputeSideForceCoefficient();
378 }
379
380 // Prepare the Jacobians and the Lagrange multipliers for later friction
381 // forces calculations.
382 ComputeJacobian(vWhlContactVec);
383 } else { // Gear is NOT compressed
384 compressLength = 0.0;
385 compressSpeed = 0.0;
386 WheelSlip = 0.0;
387 StrutForce = 0.0;
388 vWhlDisplVec.InitMatrix();
389
390 LMultiplier[ftRoll].value = 0.0;
391 LMultiplier[ftSide].value = 0.0;
392 LMultiplier[ftDynamic].value = 0.0;
393
394 // Return to neutral position between 1.0 and 0.8 gear pos.
395 SteerAngle *= max(gearPos-0.8, 0.0)/0.2;
396
397 ResetReporting();
398 }
399 }
400
401 if (!WOW) {
402 // Let wheel spin down slowly
403 vWhlVelVec(eX) -= 13.0 * in.TotalDeltaT;
404 if (vWhlVelVec(eX) < 0.0) vWhlVelVec(eX) = 0.0;
405 }
406
407 if (!fdmex->GetTrimStatus()) {
408 ReportTakeoffOrLanding();
409
410 // Require both WOW and LastWOW to be true before checking crash conditions
411 // to allow the WOW flag to be used in terminating a scripted run.
412 if (WOW && lastWOW) CrashDetect();
413
414 lastWOW = WOW;
415 }
416
417 return FGForce::GetBodyForces();
418 }
419
420 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 // Build a local "ground" coordinate system defined by
422 // eX : projection of the rolling direction on the ground
423 // eY : projection of the sliping direction on the ground
424 // eZ : normal to the ground
425
426 void FGLGear::ComputeGroundFrame(void)
427 {
428 FGColumnVector3 roll = mTGear * FGColumnVector3(cos(SteerAngle), sin(SteerAngle), 0.);
429 FGColumnVector3 side = vGroundNormal * roll;
430
431 roll -= DotProduct(roll, vGroundNormal) * vGroundNormal;
432 roll.Normalize();
433 side.Normalize();
434
435 mT(eX,eX) = roll(eX);
436 mT(eY,eX) = roll(eY);
437 mT(eZ,eX) = roll(eZ);
438 mT(eX,eY) = side(eX);
439 mT(eY,eY) = side(eY);
440 mT(eZ,eY) = side(eZ);
441 mT(eX,eZ) = vGroundNormal(eX);
442 mT(eY,eZ) = vGroundNormal(eY);
443 mT(eZ,eZ) = vGroundNormal(eZ);
444 }
445
446 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
447 // Calculate tire slip angle.
448
449 void FGLGear::ComputeSlipAngle(void)
450 {
451 // Check that the speed is non-null otherwise keep the current angle
452 if (vGroundWhlVel.Magnitude(eX,eY) > 1E-3)
453 WheelSlip = -atan2(vGroundWhlVel(eY), fabs(vGroundWhlVel(eX)))*radtodeg;
454 }
455
456 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
457 // Compute the steering angle in any case.
458 // This will also make sure that animations will look right.
459
460 void FGLGear::ComputeSteeringAngle(void)
461 {
462 if (Castered) {
463 // Check that the speed is non-null otherwise keep the current angle
464 if (vWhlVelVec.Magnitude(eX,eY) > 0.1)
465 SteerAngle = atan2(vWhlVelVec(eY), fabs(vWhlVelVec(eX)));
466 }
467 }
468
469 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
470 // Reset reporting functionality after takeoff
471
472 void FGLGear::ResetReporting(void)
473 {
474 if (in.DistanceAGL > 200.0) {
475 FirstContact = false;
476 StartedGroundRun = false;
477 LandingReported = false;
478 TakeoffReported = true;
479 LandingDistanceTraveled = 0.0;
480 MaximumStrutForce = MaximumStrutTravel = 0.0;
481 }
482 }
483
484 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
485
486 void FGLGear::InitializeReporting(void)
487 {
488 // If this is the first time the wheel has made contact, remember some values
489 // for later printout.
490
491 if (!FirstContact) {
492 FirstContact = true;
493 SinkRate = compressSpeed;
494 GroundSpeed = in.Vground;
495 TakeoffReported = false;
496 }
497
498 // If the takeoff run is starting, initialize.
499
500 if ((in.Vground > 0.1) &&
501 (in.BrakePos[bgLeft] == 0) &&
502 (in.BrakePos[bgRight] == 0) &&
503 (in.TakeoffThrottle && !StartedGroundRun))
504 {
505 TakeoffDistanceTraveled = 0;
506 TakeoffDistanceTraveled50ft = 0;
507 StartedGroundRun = true;
508 }
509 }
510
511 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512 // Takeoff and landing reporting functionality
513
514 void FGLGear::ReportTakeoffOrLanding(void)
515 {
516 if (FirstContact)
517 LandingDistanceTraveled += in.Vground * in.TotalDeltaT;
518
519 if (StartedGroundRun) {
520 TakeoffDistanceTraveled50ft += in.Vground * in.TotalDeltaT;
521 if (WOW) TakeoffDistanceTraveled += in.Vground * in.TotalDeltaT;
522 }
523
524 if ( ReportEnable
525 && in.Vground <= 0.05
526 && !LandingReported
527 && in.WOW)
528 {
529 if (debug_lvl > 0) Report(erLand);
530 }
531
532 if ( ReportEnable
533 && !TakeoffReported
534 && (in.DistanceAGL - vLocalGear(eZ)) > 50.0
535 && !in.WOW)
536 {
537 if (debug_lvl > 0) Report(erTakeoff);
538 }
539
540 // if (lastWOW != WOW)
541 // {
542 // cout << "GEAR_CONTACT: " << fdmex->GetSimTime() << " seconds: " << name
543 // << " " << WOW << endl;
544 // }
545 }
546
547 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548 // Crash detection logic (really out-of-bounds detection)
549
550 void FGLGear::CrashDetect(void)
551 {
552 if ( (compressLength > 500.0 ||
553 vFn.Magnitude() > 100000000.0 ||
554 GetMoments().Magnitude() > 5000000000.0 ||
555 SinkRate > 1.4666*30 ) && !fdmex->IntegrationSuspended())
556 {
557 cout << "*CRASH DETECTED* " << fdmex->GetSimTime() << " seconds: " << name;
558 // fdmex->SuspendIntegration();
559 }
560 }
561
562 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
563 // The following needs work regarding friction coefficients and braking and
564 // steering The BrakeFCoeff formula assumes that an anti-skid system is used.
565 // It also assumes that we won't be turning and braking at the same time.
566 // Will fix this later.
567 // [JSB] The braking force coefficients include normal rolling coefficient +
568 // a percentage of the static friction coefficient based on braking applied.
569
570 void FGLGear::ComputeBrakeForceCoefficient(void)
571 {
572 BrakeFCoeff = rollingFFactor * rollingFCoeff;
573
574 if (eBrakeGrp != bgNone)
575 BrakeFCoeff += in.BrakePos[eBrakeGrp] * staticFFactor * (staticFCoeff - rollingFCoeff);
576 }
577
578 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
579 // Compute the sideforce coefficients using Pacejka's Magic Formula.
580 //
581 // y(x) = D sin {C arctan [Bx - E(Bx - arctan Bx)]}
582 //
583 // Where: B = Stiffness Factor (0.06, here)
584 // C = Shape Factor (2.8, here)
585 // D = Peak Factor (0.8, here)
586 // E = Curvature Factor (1.03, here)
587
588 void FGLGear::ComputeSideForceCoefficient(void)
589 {
590 if (ForceY_Table) {
591 FCoeff = ForceY_Table->GetValue(WheelSlip);
592 } else {
593 double StiffSlip = Stiffness*WheelSlip;
594 FCoeff = Peak * sin(Shape*atan(StiffSlip - Curvature*(StiffSlip - atan(StiffSlip))));
595 }
596 FCoeff *= staticFFactor;
597 }
598
599 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
600 // Compute the vertical force on the wheel using square-law damping (per comment
601 // in paper AIAA-2000-4303 - see header prologue comments). We might consider
602 // allowing for both square and linear damping force calculation. Also need to
603 // possibly give a "rebound damping factor" that differs from the compression
604 // case.
605
606 void FGLGear::ComputeVerticalStrutForce()
607 {
608 if (fStrutForce)
609 StrutForce = min(fStrutForce->GetValue(), (double)0.0);
610 else {
611 double springForce = -compressLength * kSpring;
612 double dampForce = 0;
613
614 if (compressSpeed >= 0.0) {
615
616 if (eDampType == dtLinear)
617 dampForce = -compressSpeed * bDamp;
618 else
619 dampForce = -compressSpeed * compressSpeed * bDamp;
620
621 } else {
622
623 if (eDampTypeRebound == dtLinear)
624 dampForce = -compressSpeed * bDampRebound;
625 else
626 dampForce = compressSpeed * compressSpeed * bDampRebound;
627
628 }
629
630 StrutForce = min(springForce + dampForce, (double)0.0);
631 if (StrutForce > maximumForce) {
632 StrutForce = maximumForce;
633 compressLength = -StrutForce / kSpring;
634 }
635 }
636
637 // The reaction force of the wheel is always normal to the ground
638 switch (eContactType) {
639 case ctBOGEY:
640 // Project back the strut force in the local coordinate frame of the ground
641 vFn(eZ) = StrutForce / (mTGear.Transposed()*vGroundNormal)(eZ);
642 break;
643 case ctSTRUCTURE:
644 vFn(eZ) = -StrutForce;
645 break;
646 }
647
648 // Remember these values for reporting
649 MaximumStrutForce = max(MaximumStrutForce, fabs(StrutForce));
650 MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
651 }
652
653 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654
655 double FGLGear::GetGearUnitPos(void) const
656 {
657 // hack to provide backward compatibility to gear/gear-pos-norm property
658 if( useFCSGearPos || in.FCSGearPos != 1.0 ) {
659 useFCSGearPos = true;
660 return in.FCSGearPos;
661 }
662 return GearPos;
663 }
664
665 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
666 // Compute the jacobian entries for the friction forces resolution later
667 // in FGPropagate
668
669 void FGLGear::ComputeJacobian(const FGColumnVector3& vWhlContactVec)
670 {
671 // When the point of contact is moving, dynamic friction is used
672 // This type of friction is limited to ctSTRUCTURE elements because their
673 // friction coefficient is the same in every directions
674 if ((eContactType == ctSTRUCTURE) && (vGroundWhlVel.Magnitude(eX,eY) > 1E-3)) {
675
676 FGColumnVector3 velocityDirection = vGroundWhlVel;
677
678 StaticFriction = false;
679
680 velocityDirection(eZ) = 0.;
681 velocityDirection.Normalize();
682
683 LMultiplier[ftDynamic].ForceJacobian = mT * velocityDirection;
684 LMultiplier[ftDynamic].Max = 0.;
685 LMultiplier[ftDynamic].Min = -fabs(staticFFactor * dynamicFCoeff * vFn(eZ));
686 LMultiplier[ftDynamic].LeverArm = vWhlContactVec;
687
688 // The Lagrange multiplier value obtained from the previous iteration is
689 // kept. This is supposed to accelerate the convergence of the projected
690 // Gauss-Seidel algorithm. The code just below is to make sure that the
691 // initial value is consistent with the current friction coefficient and
692 // normal reaction.
693 LMultiplier[ftDynamic].value = Constrain(LMultiplier[ftDynamic].Min, LMultiplier[ftDynamic].value, LMultiplier[ftDynamic].Max);
694
695 GroundReactions->RegisterLagrangeMultiplier(&LMultiplier[ftDynamic]);
696 }
697 else {
698 // Static friction is used for ctSTRUCTURE when the contact point is not
699 // moving. It is always used for ctBOGEY elements because the friction
700 // coefficients of a tyre depend on the direction of the movement (roll &
701 // side directions). This cannot be handled properly by the so-called
702 // "dynamic friction".
703 StaticFriction = true;
704
705 LMultiplier[ftRoll].ForceJacobian = mT * FGColumnVector3(1.,0.,0.);
706 LMultiplier[ftSide].ForceJacobian = mT * FGColumnVector3(0.,1.,0.);
707 LMultiplier[ftRoll].LeverArm = vWhlContactVec;
708 LMultiplier[ftSide].LeverArm = vWhlContactVec;
709
710 switch(eContactType) {
711 case ctBOGEY:
712 LMultiplier[ftRoll].Max = fabs(BrakeFCoeff * vFn(eZ));
713 LMultiplier[ftSide].Max = fabs(FCoeff * vFn(eZ));
714 break;
715 case ctSTRUCTURE:
716 LMultiplier[ftRoll].Max = fabs(staticFFactor * staticFCoeff * vFn(eZ));
717 LMultiplier[ftSide].Max = LMultiplier[ftRoll].Max;
718 break;
719 }
720
721 LMultiplier[ftRoll].Min = -LMultiplier[ftRoll].Max;
722 LMultiplier[ftSide].Min = -LMultiplier[ftSide].Max;
723
724 // The Lagrange multiplier value obtained from the previous iteration is
725 // kept. This is supposed to accelerate the convergence of the projected
726 // Gauss-Seidel algorithm. The code just below is to make sure that the
727 // initial value is consistent with the current friction coefficient and
728 // normal reaction.
729 LMultiplier[ftRoll].value = Constrain(LMultiplier[ftRoll].Min, LMultiplier[ftRoll].value, LMultiplier[ftRoll].Max);
730 LMultiplier[ftSide].value = Constrain(LMultiplier[ftSide].Min, LMultiplier[ftSide].value, LMultiplier[ftSide].Max);
731
732 GroundReactions->RegisterLagrangeMultiplier(&LMultiplier[ftRoll]);
733 GroundReactions->RegisterLagrangeMultiplier(&LMultiplier[ftSide]);
734 }
735 }
736
737 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
738 // This routine is called after the Lagrange multiplier has been computed in
739 // the FGAccelerations class. The friction forces of the landing gear are then
740 // updated accordingly.
741 void FGLGear::UpdateForces(void)
742 {
743 if (StaticFriction) {
744 vFn(eX) = LMultiplier[ftRoll].value;
745 vFn(eY) = LMultiplier[ftSide].value;
746 }
747 else {
748 FGColumnVector3 forceDir = mT.Transposed() * LMultiplier[ftDynamic].ForceJacobian;
749 vFn(eX) = LMultiplier[ftDynamic].value * forceDir(eX);
750 vFn(eY) = LMultiplier[ftDynamic].value * forceDir(eY);
751 }
752 }
753
754 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
755
756 void FGLGear::SetstaticFCoeff(double coeff)
757 {
758 staticFCoeff = coeff;
759 Peak = coeff;
760 }
761
762 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
763
764 void FGLGear::bind(void)
765 {
766 string property_name;
767 string base_property_name;
768
769 switch(eContactType) {
770 case ctBOGEY:
771 base_property_name = CreateIndexedPropertyName("gear/unit", GearNumber);
772 break;
773 case ctSTRUCTURE:
774 base_property_name = CreateIndexedPropertyName("contact/unit", GearNumber);
775 break;
776 default:
777 return;
778 }
779
780 property_name = base_property_name + "/WOW";
781 PropertyManager->Tie( property_name.c_str(), &WOW );
782 property_name = base_property_name + "/x-position";
783 PropertyManager->Tie( property_name.c_str(), (FGForce*)this,
784 &FGForce::GetLocationX, &FGForce::SetLocationX);
785 property_name = base_property_name + "/y-position";
786 PropertyManager->Tie( property_name.c_str(), (FGForce*)this,
787 &FGForce::GetLocationY, &FGForce::SetLocationY);
788 property_name = base_property_name + "/z-position";
789 PropertyManager->Tie( property_name.c_str(), (FGForce*)this,
790 &FGForce::GetLocationZ, &FGForce::SetLocationZ);
791 property_name = base_property_name + "/compression-ft";
792 PropertyManager->Tie( property_name.c_str(), &compressLength );
793 property_name = base_property_name + "/compression-velocity-fps";
794 PropertyManager->Tie( property_name.c_str(), &compressSpeed );
795 property_name = base_property_name + "/static_friction_coeff";
796 PropertyManager->Tie( property_name.c_str(), (FGLGear*)this,
797 &FGLGear::GetstaticFCoeff, &FGLGear::SetstaticFCoeff);
798 property_name = base_property_name + "/dynamic_friction_coeff";
799 PropertyManager->Tie( property_name.c_str(), &dynamicFCoeff );
800
801 if (eContactType == ctBOGEY) {
802 property_name = base_property_name + "/slip-angle-deg";
803 PropertyManager->Tie( property_name.c_str(), &WheelSlip );
804 property_name = base_property_name + "/wheel-speed-fps";
805 PropertyManager->Tie( property_name.c_str(), (FGLGear*)this,
806 &FGLGear::GetWheelRollVel);
807 property_name = base_property_name + "/side_friction_coeff";
808 PropertyManager->Tie( property_name.c_str(), &FCoeff );
809 property_name = base_property_name + "/rolling_friction_coeff";
810 PropertyManager->Tie( property_name.c_str(), &rollingFCoeff );
811
812 if (eSteerType == stCaster) {
813 property_name = base_property_name + "/steering-angle-deg";
814 PropertyManager->Tie( property_name.c_str(), this, &FGLGear::GetSteerAngleDeg );
815 property_name = base_property_name + "/castered";
816 PropertyManager->Tie( property_name.c_str(), &Castered);
817 }
818 }
819
820 if( isRetractable ) {
821 property_name = base_property_name + "/pos-norm";
822 PropertyManager->Tie( property_name.c_str(), &GearPos );
823 }
824
825 if (eSteerType != stFixed) {
826 // This property allows the FCS to override the steering position angle that
827 // is set by the property fcs/steer-cmd-norm. The prefix fcs/ has been kept
828 // for backward compatibility.
829 string tmp = CreateIndexedPropertyName("fcs/steer-pos-deg", GearNumber);
830 PropertyManager->Tie(tmp.c_str(), this, &FGLGear::GetSteerAngleDeg, &FGLGear::SetSteerAngleDeg);
831 }
832
833 property_name = base_property_name + "/solid";
834 PropertyManager->Tie( property_name.c_str(), &isSolid);
835 property_name = base_property_name + "/bumpiness";
836 PropertyManager->Tie( property_name.c_str(), &bumpiness);
837 property_name = base_property_name + "/maximum-force-lbs";
838 PropertyManager->Tie( property_name.c_str(), &maximumForce);
839 property_name = base_property_name + "/rolling_friction-factor";
840 PropertyManager->Tie( property_name.c_str(), &rollingFFactor);
841 property_name = base_property_name + "/static-friction-factor";
842 PropertyManager->Tie( property_name.c_str(), &staticFFactor);
843 }
844
845 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
846
847 void FGLGear::Report(ReportType repType)
848 {
849 if (fabs(TakeoffDistanceTraveled) < 0.001) return; // Don't print superfluous reports
850
851 switch(repType) {
852 case erLand:
853 cout << endl << "Touchdown report for " << name << " (WOW at time: "
854 << fdmex->GetSimTime() << " seconds)" << endl;
855 cout << " Sink rate at contact: " << SinkRate << " fps, "
856 << SinkRate*0.3048 << " mps" << endl;
857 cout << " Contact ground speed: " << GroundSpeed*.5925 << " knots, "
858 << GroundSpeed*0.3048 << " mps" << endl;
859 cout << " Maximum contact force: " << MaximumStrutForce << " lbs, "
860 << MaximumStrutForce*4.448 << " Newtons" << endl;
861 cout << " Maximum strut travel: " << MaximumStrutTravel*12.0 << " inches, "
862 << MaximumStrutTravel*30.48 << " cm" << endl;
863 cout << " Distance traveled: " << LandingDistanceTraveled << " ft, "
864 << LandingDistanceTraveled*0.3048 << " meters" << endl;
865 LandingReported = true;
866 break;
867 case erTakeoff:
868 cout << endl << "Takeoff report for " << name << " (Liftoff at time: "
869 << fdmex->GetSimTime() << " seconds)" << endl;
870 cout << " Distance traveled: " << TakeoffDistanceTraveled
871 << " ft, " << TakeoffDistanceTraveled*0.3048 << " meters" << endl;
872 cout << " Distance traveled (over 50'): " << TakeoffDistanceTraveled50ft
873 << " ft, " << TakeoffDistanceTraveled50ft*0.3048 << " meters" << endl;
874 cout << " [Altitude (ASL): " << in.DistanceASL << " ft. / "
875 << in.DistanceASL*FGJSBBase::fttom << " m | Temperature: "
876 << in.Temperature - 459.67 << " F / "
877 << RankineToCelsius(in.Temperature) << " C]" << endl;
878 cout << " [Velocity (KCAS): " << in.VcalibratedKts << "]" << endl;
879 TakeoffReported = true;
880 break;
881 case erNone:
882 break;
883 }
884 }
885
886 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
887 // The bitmasked value choices are as follows:
888 // unset: In this case (the default) JSBSim would only print
889 // out the normally expected messages, essentially echoing
890 // the config files as they are read. If the environment
891 // variable is not set, debug_lvl is set to 1 internally
892 // 0: This requests JSBSim not to output any messages
893 // whatsoever.
894 // 1: This value explicity requests the normal JSBSim
895 // startup messages
896 // 2: This value asks for a message to be printed out when
897 // a class is instantiated
898 // 4: When this value is set, a message is displayed when a
899 // FGModel object executes its Run() method
900 // 8: When this value is set, various runtime state variables
901 // are printed out periodically
902 // 16: When set various parameters are sanity checked and
903 // a message is printed out when they go out of bounds
904
905 void FGLGear::Debug(int from)
906 {
907 static const char* sSteerType[] = {"STEERABLE", "FIXED", "CASTERED" };
908 static const char* sBrakeGroup[] = {"NONE", "LEFT", "RIGHT", "CENTER", "NOSE", "TAIL"};
909 static const char* sContactType[] = {"BOGEY", "STRUCTURE" };
910
911 if (debug_lvl <= 0) return;
912
913 if (debug_lvl & 1) { // Standard console startup message output
914 if (from == 0) { // Constructor - loading and initialization
915 cout << " " << sContactType[eContactType] << " " << name << endl;
916 cout << " Location: " << vXYZn << endl;
917 cout << " Spring Constant: " << kSpring << endl;
918
919 if (eDampType == dtLinear)
920 cout << " Damping Constant: " << bDamp << " (linear)" << endl;
921 else
922 cout << " Damping Constant: " << bDamp << " (square law)" << endl;
923
924 if (eDampTypeRebound == dtLinear)
925 cout << " Rebound Damping Constant: " << bDampRebound << " (linear)" << endl;
926 else
927 cout << " Rebound Damping Constant: " << bDampRebound << " (square law)" << endl;
928
929 cout << " Dynamic Friction: " << dynamicFCoeff << endl;
930 cout << " Static Friction: " << staticFCoeff << endl;
931 if (eContactType == ctBOGEY) {
932 cout << " Rolling Friction: " << rollingFCoeff << endl;
933 cout << " Steering Type: " << sSteerType[eSteerType] << endl;
934 cout << " Grouping: " << sBrakeGroup[eBrakeGrp] << endl;
935 cout << " Max Steer Angle: " << maxSteerAngle << endl;
936 cout << " Retractable: " << isRetractable << endl;
937 }
938 }
939 }
940 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
941 if (from == 0) cout << "Instantiated: FGLGear" << endl;
942 if (from == 1) cout << "Destroyed: FGLGear" << endl;
943 }
944 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
945 }
946 if (debug_lvl & 8 ) { // Runtime state variables
947 }
948 if (debug_lvl & 16) { // Sanity checking
949 }
950 if (debug_lvl & 64) {
951 if (from == 0) { // Constructor
952 }
953 }
954 }
955
956 } // namespace JSBSim