]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGGroundReactions.cpp
Syncing with most recent JSBSim.
[flightgear.git] / src / FDM / JSBSim / FGGroundReactions.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGGroundReactions.cpp
4  Author:       Jon S. Berndt
5  Date started: 09/13/00
6  Purpose:      Encapsulates the ground reaction forces (gear and collision)
7
8  ------------- Copyright (C) 2000  Jon S. Berndt (jsb@hal-pc.org) -------------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 HISTORY
31 --------------------------------------------------------------------------------
32 09/13/00   JSB   Created
33
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 INCLUDES
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38 #include "FGGroundReactions.h"
39
40 static const char *IdSrc = "$Id$";
41 static const char *IdHdr = ID_GROUNDREACTIONS;
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 CLASS IMPLEMENTATION
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47
48 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
49 {
50   Name = "FGGroundReactions";
51
52   if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
53 }
54
55 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
57 bool FGGroundReactions::Run(void)
58 {
59   double steerAngle = 0.0;
60   double xForces = 0.0, yForces = 0.0;
61
62   if (!FGModel::Run()) {
63     vForces.InitMatrix();
64     vMoments.InitMatrix();
65
66     // Only execute gear force code below 300 feet
67     if ( Position->GetDistanceAGL() < 300.0 ) {
68       vector <FGLGear>::iterator iGear = lGear.begin();
69       // Sum forces and moments for all gear, here.
70       // Some optimizations may be made here - or rather in the gear code itself.
71       // The gear ::Run() method is called several times - once for each gear.
72       // Perhaps there is some commonality for things which only need to be
73       // calculated once.
74       while (iGear != lGear.end()) {
75         vForces  += iGear->Force();
76         vMoments += iGear->Moment();
77         iGear++;
78       }
79
80       // Only execute this code when the aircraft ground speed is very, very small.
81       if (fabs(Translation->GetUVW(eX)) < 0.1 &&
82           fabs(Translation->GetUVW(eZ)) < 0.1)
83       {
84         // Initialize the comparison matrices.
85         vMaxStaticGrip.InitMatrix();
86         vMaxMomentResist.InitMatrix();
87         iGear = lGear.begin();
88         // For each gear that is touching the ground (which had better be all of them!)
89         // calculate the X and Y direction maximum "gripping" power. Also, keep track
90         // of the number of gear that have weight on wheels. This is probably unnecessary.
91         while (iGear != lGear.end()) {
92           // calculate maximum gripping power for each gear here based on brake
93           // and steering settings
94           // also calculate total number of wheels with WOW set true?
95           if (iGear->GetWOW()) {
96             steerAngle = iGear->GetSteerAngle();
97             vMaxStaticGrip(eX) += (iGear->GetBrakeFCoeff()*cos(steerAngle) - 
98                  iGear->GetstaticFCoeff()*sin(steerAngle))*iGear->GetCompForce();
99             vMaxStaticGrip(eY) += iGear->GetBrakeFCoeff()*sin(steerAngle) + 
100                   iGear->GetstaticFCoeff()*cos(steerAngle)*iGear->GetCompForce();
101             vMaxStaticGrip(eZ)  = 0.0;
102 //            vMaxMomentResist += 1;
103           }
104           iGear++;
105         }
106
107         // Calculate the X and Y direction non-gear forces to counteract if needed.
108         xForces =  -1.0 * ( Aerodynamics->GetForces(eX)
109                           + Propulsion->GetForces(eX)
110                           + Inertial->GetForces(eX));
111
112         yForces =  -1.0 * ( Aerodynamics->GetForces(eY)
113                           + Propulsion->GetForces(eY)
114                           + Inertial->GetForces(eY));
115
116         // These if statement comparisons probably need some validation and work
117         if (fabs(xForces) < fabs(vMaxStaticGrip(eX))) { // forces exceed gear power
118           vForces(eX) = xForces;
119         }
120
121         if (fabs(yForces) < fabs(vMaxStaticGrip(eY))) { // forces exceed gear power
122           vForces(eY) = yForces;
123         }
124
125         vMoments(eZ) = -(Aerodynamics->GetMoments(eZ) + Propulsion->GetMoments(eZ));
126       }
127     } else {
128       // Crash Routine
129     }
130
131     return false;
132   } else {
133     return true;
134   }
135 }
136
137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138
139 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
140 {
141   string token;
142
143   AC_cfg->GetNextConfigLine();
144
145   while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
146     lGear.push_back(FGLGear(AC_cfg, FDMExec));
147   }
148
149   return true;
150 }
151
152 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153
154 string FGGroundReactions::GetGroundReactionStrings(void)
155 {
156   string GroundReactionStrings = "";
157   bool firstime = true;
158
159   for (unsigned int i=0;i<lGear.size();i++) {
160     if (!firstime) GroundReactionStrings += ", ";
161     GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
162     GroundReactionStrings += (lGear[i].GetName() + "_compressLength, ");
163     GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, ");
164     GroundReactionStrings += (lGear[i].GetName() + "_Force");
165
166     firstime = false;
167   }
168
169   return GroundReactionStrings;
170 }
171
172 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173
174 string FGGroundReactions::GetGroundReactionValues(void)
175 {
176   char buff[20];
177   string GroundReactionValues = "";
178
179   bool firstime = true;
180
181   for (unsigned int i=0;i<lGear.size();i++) {
182     if (!firstime) GroundReactionValues += ", ";
183     GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
184     GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(),    5, buff)) + ", ");
185     GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(),    6, buff)) + ", ");
186     GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)));
187
188     firstime = false;
189   }
190
191   return GroundReactionValues;
192 }
193
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195
196 void FGGroundReactions::Debug(void)
197 {
198     //TODO: Add your source code here
199 }
200