]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGLGear.cpp
Oct 2, 2000 JSBSim sync.
[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                                                            vWhlBodyVec(3),
50                                                            Exec(fdmex)
51 {
52   string tmp;
53   *AC_cfg >> tmp >> name >> vXYZ(1) >> vXYZ(2) >> vXYZ(3)  
54             >> kSpring >> bDamp >> statFCoeff >> brakeCoeff;
55   
56   
57   cout << "    Name: " << name << endl;
58   cout << "      Location: " << vXYZ << endl;
59   cout << "      Spring Constant: " << kSpring << endl;
60   cout << "      Damping Constant: " << bDamp << endl;
61   cout << "      Rolling Resistance: " << statFCoeff << endl;
62   cout << "      Braking Coeff: " << brakeCoeff << endl;
63   
64   State       = Exec->GetState();
65   Aircraft    = Exec->GetAircraft();
66   Position    = Exec->GetPosition();
67   Rotation    = Exec->GetRotation();
68   
69   
70   WOW = false;
71   ReportEnable=true;
72   FirstContact = false;
73   Reported = false;
74   DistanceTraveled = 0.0;
75   MaximumStrutForce = MaximumStrutTravel = 0.0;
76 }
77
78
79 /******************************************************************************/
80
81 FGLGear::~FGLGear(void)
82 {
83 }
84
85 /******************************************************************************/
86
87 FGColumnVector FGLGear::Force(void)
88 {
89   FGColumnVector vForce(3);
90   FGColumnVector vLocalForce(3);
91   FGColumnVector vLocalGear(3);     // Vector: CG to this wheel (Local)
92   FGColumnVector vWhlVelVec(3);     // Velocity of this wheel (Local)
93   
94   vWhlBodyVec     = (vXYZ - Aircraft->GetXYZcg()) / 12.0;
95   vWhlBodyVec(eX) = -vWhlBodyVec(eX);
96   vWhlBodyVec(eZ) = -vWhlBodyVec(eZ);
97
98   vLocalGear = State->GetTb2l() * vWhlBodyVec;
99   
100   compressLength = vLocalGear(eZ) - Position->GetDistanceAGL();
101
102   if (compressLength > 0.00) {
103      
104     WOW = true;
105     vWhlVelVec      =  State->GetTb2l() * (Rotation->GetPQR() * vWhlBodyVec);
106     vWhlVelVec     +=  Position->GetVel();
107
108     compressSpeed   =  vWhlVelVec(eZ);
109
110     if (!FirstContact) {
111       FirstContact  = true;
112       SinkRate      =  compressSpeed;
113       GroundSpeed   =  Position->GetVel().Magnitude();
114     }
115
116     vWhlVelVec      = -1.0 * vWhlVelVec.Normalize();
117     vWhlVelVec(eZ)  =  0.00;
118
119     vLocalForce(eZ) =  min(-compressLength * kSpring - compressSpeed * bDamp, (float)0.0);
120     vLocalForce(eX) =  fabs(vLocalForce(eZ) * statFCoeff) * vWhlVelVec(eX);
121     vLocalForce(eY) =  fabs(vLocalForce(eZ) * statFCoeff) * vWhlVelVec(eY);
122
123     MaximumStrutForce = max(MaximumStrutForce, fabs(vLocalForce(eZ)));
124     MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
125
126     vForce  = State->GetTl2b() * vLocalForce ;
127     vMoment = vWhlBodyVec * vForce;
128     cout << "      Force: " << vForce << endl;
129     cout << "      Moment: " << vMoment << endl;
130
131
132   } else {
133
134     WOW = false;
135
136     if (Position->GetDistanceAGL() > 200.0) {
137       FirstContact = false;
138       Reported = false;
139       DistanceTraveled = 0.0;
140       MaximumStrutForce = MaximumStrutTravel = 0.0;
141     }
142
143     vForce.InitMatrix();
144     vMoment.InitMatrix();
145   }
146
147   if (FirstContact) {
148     DistanceTraveled += Position->GetVel().Magnitude()*State->Getdt()*Aircraft->GetRate();
149   }
150
151   if (ReportEnable && Position->GetVel().Magnitude() <= 0.05 && !Reported) {
152     Report();
153   }
154   return vForce;
155 }
156
157 /******************************************************************************/
158
159 void FGLGear::Report(void)
160 {
161   cout << endl << "Touchdown report for " << name << endl;
162   cout << "  Sink rate at contact:  " << SinkRate                << " fps,    "
163                               << SinkRate*0.3408          << " mps"     << endl;
164   cout << "  Contact ground speed:  " << GroundSpeed*.5925       << " knots,  "
165                               << GroundSpeed*0.3408       << " mps"     << endl;
166   cout << "  Maximum contact force: " << MaximumStrutForce       << " lbs,    "
167                               << MaximumStrutForce*4.448  << " Newtons" << endl;
168   cout << "  Maximum strut travel:  " << MaximumStrutTravel*12.0 << " inches, "
169                               << MaximumStrutTravel*30.48 << " cm"      << endl;
170   cout << "  Distance traveled:     " << DistanceTraveled        << " ft,     "
171                               << DistanceTraveled*0.3408  << " meters"  << endl;
172   Reported = true;
173 }
174