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