]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGGroundReactions.cpp
Latest JSBSim changes.
[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   Debug(0);
53 }
54
55 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
57 FGGroundReactions::~FGGroundReactions(void)
58 {
59   Debug(1);
60 }
61
62 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 bool FGGroundReactions::Run(void)
64 {
65   double steerAngle = 0.0;
66   double xForces = 0.0, yForces = 0.0;
67
68   if (!FGModel::Run()) {
69     vForces.InitMatrix();
70     vMoments.InitMatrix();
71
72     // Only execute gear force code below 300 feet
73     if ( Position->GetDistanceAGL() < 300.0 ) {
74       vector <FGLGear>::iterator iGear = lGear.begin();
75       // Sum forces and moments for all gear, here.
76       // Some optimizations may be made here - or rather in the gear code itself.
77       // The gear ::Run() method is called several times - once for each gear.
78       // Perhaps there is some commonality for things which only need to be
79       // calculated once.
80       while (iGear != lGear.end()) {
81         vForces  += iGear->Force();
82         vMoments += iGear->Moment();
83         iGear++;
84       }
85
86       // Only execute this code when the aircraft ground speed is very, very small.
87       /*
88       if (fabs(Translation->GetUVW(eX)) < 0.1 &&
89           fabs(Translation->GetUVW(eZ)) < 0.1)
90       {
91         // Initialize the comparison matrices.
92         vMaxStaticGrip.InitMatrix();
93         vMaxMomentResist.InitMatrix();
94         iGear = lGear.begin();
95         // For each gear that is touching the ground (which had better be all of them!)
96         // calculate the X and Y direction maximum "gripping" power. Also, keep track
97         // of the number of gear that have weight on wheels. This is probably unnecessary.
98         while (iGear != lGear.end()) {
99           // calculate maximum gripping power for each gear here based on brake
100           // and steering settings
101           // also calculate total number of wheels with WOW set true?
102           if (iGear->GetWOW()) {
103             steerAngle = iGear->GetSteerAngle();
104             vMaxStaticGrip(eX) += (iGear->GetBrakeFCoeff()*cos(steerAngle) - 
105                  iGear->GetstaticFCoeff()*sin(steerAngle))*iGear->GetCompForce();
106             vMaxStaticGrip(eY) += iGear->GetBrakeFCoeff()*sin(steerAngle) + 
107                   iGear->GetstaticFCoeff()*cos(steerAngle)*iGear->GetCompForce();
108             vMaxStaticGrip(eZ)  = 0.0;
109 //            vMaxMomentResist += 1;
110           }
111           iGear++;
112         }
113
114         // Calculate the X and Y direction non-gear forces to counteract if needed.
115         xForces =  -1.0 * ( Aerodynamics->GetForces(eX)
116                           + Propulsion->GetForces(eX)
117                           + Inertial->GetForces(eX));
118
119         yForces =  -1.0 * ( Aerodynamics->GetForces(eY)
120                           + Propulsion->GetForces(eY)
121                           + Inertial->GetForces(eY));
122
123         // These if statement comparisons probably need some validation and work
124         if (fabs(xForces) < fabs(vMaxStaticGrip(eX))) { // forces exceed gear power
125           vForces(eX) = xForces;
126         }
127
128         if (fabs(yForces) < fabs(vMaxStaticGrip(eY))) { // forces exceed gear power
129           vForces(eY) = yForces;
130         }
131
132         vMoments(eZ) = -(Aerodynamics->GetMoments(eZ) + Propulsion->GetMoments(eZ));
133       }
134       */
135     } else {
136       // Crash Routine
137     }
138
139     return false;
140   } else {
141     return true;
142   }
143 }
144
145 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146
147 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
148 {
149   string token;
150
151   AC_cfg->GetNextConfigLine();
152
153   while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
154     lGear.push_back(FGLGear(AC_cfg, FDMExec));
155   }
156
157   return true;
158 }
159
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161
162 string FGGroundReactions::GetGroundReactionStrings(void)
163 {
164   string GroundReactionStrings = "";
165   bool firstime = true;
166
167   for (unsigned int i=0;i<lGear.size();i++) {
168     if (!firstime) GroundReactionStrings += ", ";
169     GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
170     GroundReactionStrings += (lGear[i].GetName() + "_compressLength, ");
171     GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, ");
172     GroundReactionStrings += (lGear[i].GetName() + "_Force");
173
174     firstime = false;
175   }
176
177   return GroundReactionStrings;
178 }
179
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181
182 string FGGroundReactions::GetGroundReactionValues(void)
183 {
184   char buff[20];
185   string GroundReactionValues = "";
186
187   bool firstime = true;
188
189   for (unsigned int i=0;i<lGear.size();i++) {
190     if (!firstime) GroundReactionValues += ", ";
191     GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
192     GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(),    5, buff)) + ", ");
193     GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(),    6, buff)) + ", ");
194     GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)));
195
196     firstime = false;
197   }
198
199   return GroundReactionValues;
200 }
201
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 //    The bitmasked value choices are as follows:
204 //    unset: In this case (the default) JSBSim would only print
205 //       out the normally expected messages, essentially echoing
206 //       the config files as they are read. If the environment
207 //       variable is not set, debug_lvl is set to 1 internally
208 //    0: This requests JSBSim not to output any messages
209 //       whatsoever.
210 //    1: This value explicity requests the normal JSBSim
211 //       startup messages
212 //    2: This value asks for a message to be printed out when
213 //       a class is instantiated
214 //    4: When this value is set, a message is displayed when a
215 //       FGModel object executes its Run() method
216 //    8: When this value is set, various runtime state variables
217 //       are printed out periodically
218 //    16: When set various parameters are sanity checked and
219 //       a message is printed out when they go out of bounds
220
221 void FGGroundReactions::Debug(int from)
222 {
223   if (debug_lvl <= 0) return;
224
225   if (debug_lvl & 1) { // Standard console startup message output
226     if (from == 0) { // Constructor
227
228     }
229   }
230   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
231     if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
232     if (from == 1) cout << "Destroyed:    FGGroundReactions" << endl;
233   }
234   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
235   }
236   if (debug_lvl & 8 ) { // Runtime state variables
237   }
238   if (debug_lvl & 16) { // Sanity checking
239   }
240 }
241