]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGLGear.cpp
Updates from Jon's official CVS tree.
[flightgear.git] / src / FDM / JSBSim / FGLGear.cpp
1 /*******************************************************************************
2
3  Module:       FGLGear.cpp
4  Author:       Jon S. Berndt
5  Date started: 11/18/99
6  Purpose:      Encapsulates the landing gear elements
7  Called by:    FGAircraft
8
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  details.
20
21  You should have received a copy of the GNU General Public License along with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA  02111-1307, USA.
24
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30
31 HISTORY
32 --------------------------------------------------------------------------------
33 11/18/99   JSB   Created
34
35 ********************************************************************************
36 INCLUDES
37 *******************************************************************************/
38
39 #include "FGLGear.h"
40 #include <algorithm>
41
42 /*******************************************************************************
43 ************************************ CODE **************************************
44 *******************************************************************************/
45
46
47 FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : vXYZ(3),
48                                                            vMoment(3),
49                                                            Exec(fdmex)
50 {
51   string tmp;
52   *AC_cfg >> tmp >> name >> vXYZ(1) >> vXYZ(2) >> vXYZ(3) >> kSpring >> bDamp
53                                                     >> statFCoeff >> brakeCoeff;
54   State       = Exec->GetState();
55   Aircraft    = Exec->GetAircraft();
56   Position    = Exec->GetPosition();
57   Rotation    = Exec->GetRotation();
58
59   WOW = false;
60   FirstContact = false;
61   Reported = false;
62   DistanceTraveled = 0.0;
63   MaximumStrutForce = MaximumStrutTravel = 0.0;
64 }
65
66
67 /******************************************************************************/
68
69 FGLGear::~FGLGear(void)
70 {
71 }
72
73 /******************************************************************************/
74
75 FGColumnVector FGLGear::Force(void)
76 {
77   static FGColumnVector vForce(3);
78   static FGColumnVector vLocalForce(3);
79   static FGColumnVector vLocalGear(3);     // Vector: CG to this wheel (Local)
80   static FGColumnVector vWhlBodyVec(3);    // Vector: CG to this wheel (Body)
81   static FGColumnVector vWhlVelVec(3);     // Velocity of this wheel (Local)
82
83   vWhlBodyVec     = (vXYZ - Aircraft->GetXYZcg()) / 12.0;
84   vWhlBodyVec(eX) = -vWhlBodyVec(eX);
85   vWhlBodyVec(eZ) = -vWhlBodyVec(eZ);
86
87   vLocalGear = State->GetTb2l() * vWhlBodyVec;
88
89   compressLength = vLocalGear(eZ) - Position->GetDistanceAGL();
90
91   if (compressLength > 0.00) {
92
93     WOW = true;
94     vWhlVelVec      =  State->GetTb2l() * (Rotation->GetPQR() * vWhlBodyVec);
95     vWhlVelVec     +=  Position->GetVel();
96
97     compressSpeed   =  vWhlVelVec(eZ);
98
99     if (!FirstContact) {
100       FirstContact  = true;
101       SinkRate      =  compressSpeed;
102       GroundSpeed   =  Position->GetVel().Magnitude();
103     }
104
105     vWhlVelVec      = -1.0 * vWhlVelVec.Normalize();
106     vWhlVelVec(eZ)  =  0.00;
107
108     vLocalForce(eZ) =  min(-compressLength * kSpring - compressSpeed * bDamp, (float)0.0);
109     vLocalForce(eX) =  fabs(vLocalForce(eZ) * statFCoeff) * vWhlVelVec(eX);
110     vLocalForce(eY) =  fabs(vLocalForce(eZ) * statFCoeff) * vWhlVelVec(eY);
111
112     MaximumStrutForce = max(MaximumStrutForce, fabs(vLocalForce(eZ)));
113     MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
114
115     vForce  = State->GetTl2b() * vLocalForce ;
116     vMoment = vWhlBodyVec * vForce;
117
118   } else {
119
120     WOW = false;
121
122     if (Position->GetDistanceAGL() > 200.0) {
123       FirstContact = false;
124       Reported = false;
125       DistanceTraveled = 0.0;
126       MaximumStrutForce = MaximumStrutTravel = 0.0;
127     }
128
129     vForce.InitMatrix();
130     vMoment.InitMatrix();
131   }
132
133   if (FirstContact) {
134     DistanceTraveled += Position->GetVel().Magnitude()*State->Getdt()*Aircraft->GetRate();
135   }
136
137   if (Position->GetVel().Magnitude() <= 0.05 && !Reported) {
138     Report();
139   }
140
141   return vForce;
142 }
143
144 /******************************************************************************/
145
146 void FGLGear::Report(void)
147 {
148   cout << endl << "Touchdown report for " << name << endl;
149   cout << "  Sink rate at contact:  " << SinkRate                << " fps,    "
150                               << SinkRate*0.3408          << " mps"     << endl;
151   cout << "  Contact ground speed:  " << GroundSpeed*.5925       << " knots,  "
152                               << GroundSpeed*0.3408       << " mps"     << endl;
153   cout << "  Maximum contact force: " << MaximumStrutForce       << " lbs,    "
154                               << MaximumStrutForce*4.448  << " Newtons" << endl;
155   cout << "  Maximum strut travel:  " << MaximumStrutTravel*12.0 << " inches, "
156                               << MaximumStrutTravel*30.48 << " cm"      << endl;
157   cout << "  Distance traveled:     " << DistanceTraveled        << " ft,     "
158                               << DistanceTraveled*0.3408  << " meters"  << endl;
159   Reported = true;
160 }
161