]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGLGear.h
Merge branch 'next' of gitorious.org:fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / FGLGear.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGLGear.h
4  Author:       Jon S. Berndt
5  Date started: 11/18/99
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 11/18/99   JSB   Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGLGEAR_H
35 #define FGLGEAR_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include <string>
42
43 #include "models/propulsion/FGForce.h"
44 #include "math/FGColumnVector3.h"
45 #include "math/LagrangeMultiplier.h"
46
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 DEFINITIONS
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50
51 #define ID_LGEAR "$Id: FGLGear.h,v 1.54 2012/04/01 17:05:51 bcoconni Exp $"
52
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 FORWARD DECLARATIONS
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
57 namespace JSBSim {
58
59 class FGTable;
60 class Element;
61 class FGPropertyManager;
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 CLASS DOCUMENTATION
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 /** Landing gear model.
68     Calculates forces and moments due to landing gear reactions. This is done in
69     several steps, and is dependent on what kind of gear is being modeled. Here
70     are the parameters that can be specified in the config file for modeling
71     landing gear:
72     <p>
73     <h3>Physical Characteristics</h3>
74     <ol>
75     <li>X, Y, Z location, in inches in structural coordinate frame</li>
76     <li>Spring constant, in lbs/ft</li>
77     <li>Damping coefficient, in lbs/ft/sec</li>
78     <li>Dynamic Friction Coefficient</li>
79     <li>Static Friction Coefficient</li>
80     </ol></p><p>
81     <h3>Operational Properties</h3>
82     <ol>
83     <li>Name</li>
84     <li>Brake Group Membership {one of LEFT | CENTER | RIGHT | NOSE | TAIL | NONE}</li>
85     <li>Max Steer Angle, in degrees</li>
86     </ol></p>
87     <p>
88     <h3>Algorithm and Approach to Modeling</h3>
89     <ol>
90     <li>Find the location of the uncompressed landing gear relative to the CG of
91     the aircraft. Remember, the structural coordinate frame that the aircraft is
92     defined in is: X positive towards the tail, Y positive out the right side, Z
93     positive upwards. The locations of the various parts are given in inches in
94     the config file.</li>
95     <li>The vector giving the location of the gear (relative to the cg) is
96     rotated 180 degrees about the Y axis to put the coordinates in body frame (X
97     positive forwards, Y positive out the right side, Z positive downwards, with
98     the origin at the cg). The lengths are also now given in feet.</li>
99     <li>The new gear location is now transformed to the local coordinate frame
100     using the body-to-local matrix. (Mb2l).</li>
101     <li>Knowing the location of the center of gravity relative to the ground
102     (height above ground level or AGL) now enables gear deflection to be
103     calculated. The gear compression value is the local frame gear Z location
104     value minus the height AGL. [Currently, we make the assumption that the gear
105     is oriented - and the deflection occurs in - the Z axis only. Additionally,
106     the vector to the landing gear is currently not modified - which would
107     (correctly) move the point of contact to the actual compressed-gear point of
108     contact. Eventually, articulated gear may be modeled, but initially an
109     effort must be made to model a generic system.] As an example, say the
110     aircraft left main gear location (in local coordinates) is Z = 3 feet
111     (positive) and the height AGL is 2 feet. This tells us that the gear is
112     compressed 1 foot.</li>
113     <li>If the gear is compressed, a Weight-On-Wheels (WOW) flag is set.</li>
114     <li>With the compression length calculated, the compression velocity may now
115     be calculated. This will be used to determine the damping force in the
116     strut. The aircraft rotational rate is multiplied by the vector to the wheel
117     to get a wheel velocity in body frame. That velocity vector is then
118     transformed into the local coordinate frame.</li>
119     <li>The aircraft cg velocity in the local frame is added to the
120     just-calculated wheel velocity (due to rotation) to get a total wheel
121     velocity in the local frame.</li>
122     <li>The compression speed is the Z-component of the vector.</li>
123     <li>With the wheel velocity vector no longer needed, it is normalized and
124     multiplied by a -1 to reverse it. This will be used in the friction force
125     calculation.</li>
126     <li>Since the friction force takes place solely in the runway plane, the Z
127     coordinate of the normalized wheel velocity vector is set to zero.</li>
128     <li>The gear deflection force (the force on the aircraft acting along the
129     local frame Z axis) is now calculated given the spring and damper
130     coefficients, and the gear deflection speed and stroke length. Keep in mind
131     that gear forces always act in the negative direction (in both local and
132     body frames), and are not capable of generating a force in the positive
133     sense (one that would attract the aircraft to the ground). So, the gear
134     forces are always negative - they are limited to values of zero or less. The
135     gear force is simply the negative of the sum of the spring compression
136     length times the spring coefficient and the gear velocity times the damping
137     coefficient.</li>
138     <li>The lateral/directional force acting on the aircraft through the landing
139
140     gear (along the local frame X and Y axes) is calculated next. First, the
141     friction coefficient is multiplied by the recently calculated Z-force. This
142     is the friction force. It must be given direction in addition to magnitude.
143     We want the components in the local frame X and Y axes. From step 9, above,
144     the conditioned wheel velocity vector is taken and the X and Y parts are
145     multiplied by the friction force to get the X and Y components of friction.
146     </li>
147     <li>The wheel force in local frame is next converted to body frame.</li>
148     <li>The moment due to the gear force is calculated by multiplying r x F
149     (radius to wheel crossed into the wheel force). Both of these operands are
150     in body frame.</li>
151     </ol>
152
153     <h3>Configuration File Format:</h3>
154 @code
155         <contact type="{BOGEY | STRUCTURE}" name="{string}">
156             <location unit="{IN | M}">
157                 <x> {number} </x>
158                 <y> {number} </y>
159                 <z> {number} </z>
160             </location>
161             <orientation unit="{RAD | DEG}">
162                 <pitch> {number} </pitch>
163                 <roll> {number} </roll>
164                 <yaw> {number} </yaw>
165             </orientation>
166             <static_friction> {number} </static_friction>
167             <dynamic_friction> {number} </dynamic_friction>
168             <rolling_friction> {number} </rolling_friction>
169             <spring_coeff unit="{LBS/FT | N/M}"> {number} </spring_coeff>
170             <damping_coeff [type="SQUARE"] unit="{LBS/FT/SEC | N/M/SEC}"> {number} </damping_coeff>
171             <damping_coeff_rebound [type="SQUARE"] unit="{LBS/FT/SEC | N/M/SEC}"> {number} </damping_coeff_rebound>
172             <max_steer unit="DEG"> {number | 0 | 360} </max_steer>
173             <brake_group> {NONE | LEFT | RIGHT | CENTER | NOSE | TAIL} </brake_group>
174             <retractable>{0 | 1}</retractable>
175             <table type="{CORNERING_COEFF}">
176             </table>
177         </contact>
178 @endcode
179     @author Jon S. Berndt
180     @version $Id: FGLGear.h,v 1.54 2012/04/01 17:05:51 bcoconni Exp $
181     @see Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
182      NASA-Ames", NASA CR-2497, January 1975
183     @see Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
184      Wiley & Sons, 1979 ISBN 0-471-03032-5
185     @see W. A. Ragsdale, "A Generic Landing Gear Dynamics Model for LASRS++",
186      AIAA-2000-4303
187 */
188
189 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 CLASS DECLARATION
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
192
193 class FGLGear : public FGForce
194 {
195 public:
196   struct Inputs {
197     double Vground;
198     double VcalibratedKts;
199     double Temperature;
200     double DistanceAGL;
201     double DistanceASL;
202     double TotalDeltaT;
203     bool TakeoffThrottle;
204     bool WOW;
205     FGMatrix33 Tb2l;
206     FGMatrix33 Tec2l;
207     FGMatrix33 Tec2b;
208     FGColumnVector3 PQR;
209     FGColumnVector3 UVW;
210     FGColumnVector3 vXYZcg; // CG coordinates expressed in the structural frame
211     FGLocation Location;
212     std::vector <double> SteerPosDeg;
213     std::vector <double> BrakePos;
214     double FCSGearPos;
215     double EmptyWeight;
216   };
217
218   /// Brake grouping enumerators
219   enum BrakeGroup {bgNone=0, bgLeft, bgRight, bgCenter, bgNose, bgTail, bgNumBrakeGroups };
220   /// Steering group membership enumerators
221   enum SteerType {stSteer, stFixed, stCaster};
222   /// Contact point type
223   enum ContactType {ctBOGEY, ctSTRUCTURE};
224   /// Report type enumerators
225   enum ReportType {erNone=0, erTakeoff, erLand};
226   /// Damping types
227   enum DampType {dtLinear=0, dtSquare};
228   /// Friction types
229   enum FrictionType {ftRoll=0, ftSide, ftDynamic};
230   /** Constructor
231       @param el a pointer to the XML element that contains the CONTACT info.
232       @param Executive a pointer to the parent executive object
233       @param number integer identifier for this instance of FGLGear
234   */
235   FGLGear(Element* el, FGFDMExec* Executive, int number, const struct Inputs& input);
236   /// Destructor
237   ~FGLGear();
238
239   /// The Force vector for this gear
240   const FGColumnVector3& GetBodyForces(void);
241
242   /// Gets the location of the gear in Body axes
243   FGColumnVector3 GetBodyLocation(void) const {
244     return Ts2b * (vXYZn - in.vXYZcg);
245   }
246   double GetBodyLocation(int idx) const {
247     FGColumnVector3 vWhlBodyVec = Ts2b * (vXYZn - in.vXYZcg);
248     return vWhlBodyVec(idx);
249   }
250
251   const FGColumnVector3& GetLocalGear(void) const { return vLocalGear; }
252   double GetLocalGear(int idx) const { return vLocalGear(idx); }
253
254   /// Gets the name of the gear
255   const string& GetName(void) const {return name; }
256   /// Gets the Weight On Wheels flag value
257   bool    GetWOW(void) const {return WOW; }
258   /// Gets the current compressed length of the gear in feet
259   double  GetCompLen(void) const {return compressLength;}
260   /// Gets the current gear compression velocity in ft/sec
261   double  GetCompVel(void) const {return compressSpeed; }
262   /// Gets the gear compression force in pounds
263   double  GetCompForce(void) const {return StrutForce;   }
264
265   /// Sets the weight-on-wheels flag.
266   void SetWOW(bool wow) {WOW = wow;}
267
268   /** Set the console touchdown reporting feature
269       @param flag true turns on touchdown reporting, false turns it off */
270   void SetReport(bool flag) { ReportEnable = flag; }
271   /** Get the console touchdown reporting feature
272       @return true if reporting is turned on */
273   bool GetReport(void) const  { return ReportEnable; }
274   double GetSteerNorm(void) const { return radtodeg/maxSteerAngle*SteerAngle; }
275   double GetDefaultSteerAngle(double cmd) const { return cmd*maxSteerAngle; }
276   double GetstaticFCoeff(void) const { return staticFCoeff; }
277
278   int  GetBrakeGroup(void) const   { return (int)eBrakeGrp; }
279   int  GetSteerType(void) const    { return (int)eSteerType; }
280
281   bool GetSteerable(void) const    { return eSteerType != stFixed; }
282   bool GetRetractable(void) const  { return isRetractable;   }
283   bool GetGearUnitUp(void) const   { return isRetractable ? (GetGearUnitPos() < 0.01) : false; }
284   bool GetGearUnitDown(void) const { return isRetractable ? (GetGearUnitPos() > 0.99) : true; }
285
286   double GetWheelRollForce(void) {
287     UpdateForces();
288     FGColumnVector3 vForce = mTGear.Transposed() * FGForce::GetBodyForces();
289     return vForce(eX)*cos(SteerAngle) + vForce(eY)*sin(SteerAngle); }
290   double GetWheelSideForce(void) {
291     UpdateForces();
292     FGColumnVector3 vForce = mTGear.Transposed() * FGForce::GetBodyForces();
293     return vForce(eY)*cos(SteerAngle) - vForce(eX)*sin(SteerAngle); }
294   double GetWheelRollVel(void) const   { return vWhlVelVec(eX)*cos(SteerAngle)
295                                               + vWhlVelVec(eY)*sin(SteerAngle);  }
296   double GetWheelSideVel(void) const   { return vWhlVelVec(eY)*cos(SteerAngle)
297                                               - vWhlVelVec(eX)*sin(SteerAngle);  }
298   double GetWheelSlipAngle(void) const { return WheelSlip;       }
299   double GetWheelVel(int axis) const   { return vWhlVelVec(axis);}
300   bool IsBogey(void) const             { return (eContactType == ctBOGEY);}
301   double GetGearUnitPos(void) const;
302   double GetSteerAngleDeg(void) const { return radtodeg*SteerAngle; }
303
304   const struct Inputs& in;
305
306   void bind(void);
307
308 private:
309   int GearNumber;
310   static const FGMatrix33 Tb2s, Ts2b;
311   FGMatrix33 mTGear;
312   FGColumnVector3 vLocalGear;
313   FGColumnVector3 vWhlVelVec, vGroundWhlVel;     // Velocity of this wheel
314   FGColumnVector3 vGroundNormal;
315   FGTable *ForceY_Table;
316   double SteerAngle;
317   double kSpring;
318   double bDamp;
319   double bDampRebound;
320   double compressLength;
321   double compressSpeed;
322   double staticFCoeff, dynamicFCoeff, rollingFCoeff;
323   double Stiffness, Shape, Peak, Curvature; // Pacejka factors
324   double BrakeFCoeff;
325   double maxCompLen;
326   double SinkRate;
327   double GroundSpeed;
328   double TakeoffDistanceTraveled;
329   double TakeoffDistanceTraveled50ft;
330   double LandingDistanceTraveled;
331   double MaximumStrutForce, StrutForce;
332   double MaximumStrutTravel;
333   double FCoeff;
334   double WheelSlip;
335   double GearPos;
336   bool WOW;
337   bool lastWOW;
338   bool FirstContact;
339   bool StartedGroundRun;
340   bool LandingReported;
341   bool TakeoffReported;
342   bool ReportEnable;
343   bool isRetractable;
344   bool Castered;
345   bool StaticFriction;
346   std::string name;
347
348   BrakeGroup  eBrakeGrp;
349   ContactType eContactType;
350   SteerType   eSteerType;
351   DampType    eDampType;
352   DampType    eDampTypeRebound;
353   double  maxSteerAngle;
354
355   LagrangeMultiplier LMultiplier[3];
356
357   FGGroundReactions* GroundReactions;
358   FGPropertyManager* PropertyManager;
359
360   mutable bool useFCSGearPos;
361
362   void ComputeBrakeForceCoefficient(void);
363   void ComputeSteeringAngle(void);
364   void ComputeSlipAngle(void);
365   void ComputeSideForceCoefficient(void);
366   void ComputeVerticalStrutForce(void);
367   void ComputeGroundFrame(void);
368   void ComputeJacobian(const FGColumnVector3& vWhlContactVec);
369   void UpdateForces(void);
370   void CrashDetect(void);
371   void InitializeReporting(void);
372   void ResetReporting(void);
373   void ReportTakeoffOrLanding(void);
374   void Report(ReportType rt);
375   void Debug(int from);
376 };
377 }
378
379 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380
381 #endif