]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGLGear.cpp
Check return value of FDM::init().
[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 static const char *IdSrc = "$Header$";
43 static const char *IdHdr = ID_LGEAR;
44
45 /*******************************************************************************
46 ************************************ CODE **************************************
47 *******************************************************************************/
48
49
50 FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : vXYZ(3),
51                                                            vMoment(3),
52                                                            vWhlBodyVec(3),
53                                                            Exec(fdmex)
54 {
55   string tmp;
56   *AC_cfg >> tmp >> name >> vXYZ(1) >> vXYZ(2) >> vXYZ(3)  
57             >> kSpring >> bDamp>> dynamicFCoeff >> staticFCoeff
58                   >> SteerType >> BrakeType >> GroupMember >> maxSteerAngle;
59     
60   cout << "    Name: " << name << endl;
61   cout << "      Location: " << vXYZ << endl;
62   cout << "      Spring Constant:  " << kSpring << endl;
63   cout << "      Damping Constant: " << bDamp << endl;
64   cout << "      Dynamic Friction: " << dynamicFCoeff << endl;
65   cout << "      Static Friction:  " << staticFCoeff << endl;
66   cout << "      Brake Type:       " << BrakeType << endl;
67   cout << "      Grouping:         " << GroupMember << endl;
68   cout << "      Steering Type:    " << SteerType << endl;
69   cout << "      Max Steer Angle:  " << maxSteerAngle << endl;
70   
71   State       = Exec->GetState();
72   Aircraft    = Exec->GetAircraft();
73   Position    = Exec->GetPosition();
74   Rotation    = Exec->GetRotation();
75   
76   WOW = false;
77   ReportEnable=true;
78   FirstContact = false;
79   Reported = false;
80   DistanceTraveled = 0.0;
81   MaximumStrutForce = MaximumStrutTravel = 0.0;
82 }
83
84
85 /******************************************************************************/
86
87 FGLGear::~FGLGear(void)
88 {
89   cout << "Destructing Landing Gear ..." << endl;
90 }
91
92 /******************************************************************************/
93
94 FGColumnVector FGLGear::Force(void)
95 {
96   FGColumnVector vForce(3);
97   FGColumnVector vLocalForce(3);
98   FGColumnVector vLocalGear(3);     // Vector: CG to this wheel (Local)
99   FGColumnVector vWhlVelVec(3);     // Velocity of this wheel (Local)
100   
101   vWhlBodyVec     = (vXYZ - Aircraft->GetXYZcg()) / 12.0;
102   vWhlBodyVec(eX) = -vWhlBodyVec(eX);
103   vWhlBodyVec(eZ) = -vWhlBodyVec(eZ);
104
105   vLocalGear = State->GetTb2l() * vWhlBodyVec;
106   
107   compressLength = vLocalGear(eZ) - Position->GetDistanceAGL();
108
109   if (compressLength > 0.00) {
110      
111     WOW = true;
112     vWhlVelVec      =  State->GetTb2l() * (Rotation->GetPQR() * vWhlBodyVec);
113     vWhlVelVec     +=  Position->GetVel();
114
115     compressSpeed   =  vWhlVelVec(eZ);
116
117     if (!FirstContact) {
118       FirstContact  = true;
119       SinkRate      =  compressSpeed;
120       GroundSpeed   =  Position->GetVel().Magnitude();
121     }
122
123     // The following code normalizes the wheel velocity vector, reverses it, and zeroes out
124     // the z component of the velocity. The question is, should the Z axis velocity be zeroed
125     // out first before the normalization takes place or not? Subsequent to that, the Wheel
126     // Velocity vector now points as a unit vector backwards and parallel to the wheel
127     // velocity vector. It acts AT the wheel.
128
129     vWhlVelVec      = -1.0 * vWhlVelVec.Normalize();
130     vWhlVelVec(eZ)  =  0.00;
131
132 // the following needs work regarding friction coefficients and braking and steering
133
134     vLocalForce(eZ) =  min(-compressLength * kSpring - compressSpeed * bDamp, (float)0.0);
135     vLocalForce(eX) =  fabs(vLocalForce(eZ) * staticFCoeff) * vWhlVelVec(eX);
136     vLocalForce(eY) =  fabs(vLocalForce(eZ) * staticFCoeff) * vWhlVelVec(eY);
137
138     MaximumStrutForce = max(MaximumStrutForce, fabs(vLocalForce(eZ)));
139     MaximumStrutTravel = max(MaximumStrutTravel, fabs(compressLength));
140
141     vForce  = State->GetTl2b() * vLocalForce ;
142     vMoment = vWhlBodyVec * vForce;
143
144   } else {
145
146     WOW = false;
147
148     if (Position->GetDistanceAGL() > 200.0) {
149       FirstContact = false;
150       Reported = false;
151       DistanceTraveled = 0.0;
152       MaximumStrutForce = MaximumStrutTravel = 0.0;
153     }
154
155     vForce.InitMatrix();
156     vMoment.InitMatrix();
157   }
158
159   if (FirstContact) {
160     DistanceTraveled += Position->GetVel().Magnitude()*State->Getdt()*Aircraft->GetRate();
161   }
162
163   if (ReportEnable && Position->GetVel().Magnitude() <= 0.05 && !Reported) {
164     Report();
165   }
166   return vForce;
167 }
168
169 /******************************************************************************/
170
171 void FGLGear::Report(void)
172 {
173   cout << endl << "Touchdown report for " << name << endl;
174   cout << "  Sink rate at contact:  " << SinkRate                << " fps,    "
175                               << SinkRate*0.3408          << " mps"     << endl;
176   cout << "  Contact ground speed:  " << GroundSpeed*.5925       << " knots,  "
177                               << GroundSpeed*0.3408       << " mps"     << endl;
178   cout << "  Maximum contact force: " << MaximumStrutForce       << " lbs,    "
179                               << MaximumStrutForce*4.448  << " Newtons" << endl;
180   cout << "  Maximum strut travel:  " << MaximumStrutTravel*12.0 << " inches, "
181                               << MaximumStrutTravel*30.48 << " cm"      << endl;
182   cout << "  Distance traveled:     " << DistanceTraveled        << " ft,     "
183                               << DistanceTraveled*0.3408  << " meters"  << endl;
184   Reported = true;
185 }
186