]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGGroundReactions.cpp
Sync. w. JSBSim CVS.
[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 <sstream>
39 #include <iomanip>
40
41 #include "FGGroundReactions.h"
42 #include "FGPropertyManager.h"
43
44 namespace JSBSim {
45
46 static const char *IdSrc = "$Id$";
47 static const char *IdHdr = ID_GROUNDREACTIONS;
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 CLASS IMPLEMENTATION
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53
54 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
55 {
56   Name = "FGGroundReactions";
57
58   bind();
59
60   Debug(0);
61 }
62
63 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64
65 FGGroundReactions::~FGGroundReactions(void)
66 {
67   unbind();
68
69   Debug(1);
70 }
71
72 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73
74 bool FGGroundReactions::Run(void)
75 {
76   if (!FGModel::Run()) {
77     vForces.InitMatrix();
78     vMoments.InitMatrix();
79
80     // Only execute gear force code below 300 feet
81     if ( Propagate->GetDistanceAGL() < 300.0 ) {
82       vector <FGLGear>::iterator iGear = lGear.begin();
83       // Sum forces and moments for all gear, here.
84       // Some optimizations may be made here - or rather in the gear code itself.
85       // The gear ::Run() method is called several times - once for each gear.
86       // Perhaps there is some commonality for things which only need to be
87       // calculated once.
88       while (iGear != lGear.end()) {
89         vForces  += iGear->Force();
90         vMoments += iGear->Moment();
91         iGear++;
92       }
93
94     } else {
95       // Crash Routine
96     }
97
98     return false;
99   } else {
100     return true;
101   }
102 }
103
104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105
106 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
107 {
108   string token;
109
110   AC_cfg->GetNextConfigLine();
111
112   while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
113     string type;
114     *AC_cfg >> type;
115     if (type == "AC_GEAR") {
116       int num = lGear.size();
117       lGear.push_back(FGLGear(AC_cfg, FDMExec, num));
118       FCS->AddGear();
119     } else {
120       cerr << "Unknown undercarriage type \"" << type << "\"" << endl;
121     }
122   }
123
124   return true;
125 }
126
127 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128
129 string FGGroundReactions::GetGroundReactionStrings(string delimeter)
130 {
131   std::ostringstream buf;
132
133   for (unsigned int i=0;i<lGear.size();i++) {
134     string name = lGear[i].GetName();
135     buf << name << "_WOW" << delimeter
136         << name << "_stroke" << delimeter
137         << name << "_strokeVel" << delimeter
138         << name << "_CompressForce" << delimeter
139         << name << "_WhlSideForce" << delimeter
140         << name << "_WhlVelVecX" << delimeter
141         << name << "_WhlVelVecY" << delimeter
142         << name << "_WhlRollForce" << delimeter
143         << name << "_BodyXForce" << delimeter
144         << name << "_BodyYForce" << delimeter
145         << name << "_WhlSlipDegrees" << delimeter;
146   }
147
148   buf << "TotalGearForce_X" << delimeter
149       << "TotalGearForce_Y" << delimeter
150       << "TotalGearForce_Z" << delimeter
151       << "TotalGearMoment_L" << delimeter
152       << "TotalGearMoment_M" << delimeter
153       << "TotalGearMoment_N";
154
155   return buf.str();
156 }
157
158 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159
160 string FGGroundReactions::GetGroundReactionValues(string delimeter)
161 {
162   std::ostringstream buf;
163
164   for (unsigned int i=0;i<lGear.size();i++) {
165     FGLGear& gear = lGear[i];
166     buf << (gear.GetWOW() ? "1, " : "0, ")
167         << setprecision(5) << gear.GetCompLen() << delimeter
168         << setprecision(6) << gear.GetCompVel() << delimeter
169         << setprecision(10) << gear.GetCompForce() << delimeter
170         << setprecision(6) << gear.GetWheelVel(eX) << delimeter
171         << gear.GetWheelVel(eY) << delimeter
172         << gear.GetWheelSideForce() << delimeter
173         << gear.GetWheelRollForce() << delimeter
174         << gear.GetBodyXForce() << delimeter
175         << gear.GetBodyYForce() << delimeter
176         << gear.GetWheelSlipAngle() << delimeter;
177   }
178
179   buf << vForces(eX) << delimeter
180       << vForces(eY) << delimeter
181       << vForces(eZ) << delimeter
182       << vMoments(eX) << delimeter
183       << vMoments(eY) << delimeter
184       << vMoments(eZ);
185
186   return buf.str();
187 }
188
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190
191 void FGGroundReactions::bind(void)
192 {
193   typedef double (FGGroundReactions::*PMF)(int) const;
194   PropertyManager->Tie("gear/num-units", this,
195                        &FGGroundReactions::GetNumGearUnits);
196   PropertyManager->Tie("moments/l-gear-lbsft", this,1,
197                        (PMF)&FGGroundReactions::GetMoments);
198   PropertyManager->Tie("moments/m-gear-lbsft", this,2,
199                        (PMF)&FGGroundReactions::GetMoments);
200   PropertyManager->Tie("moments/n-gear-lbsft", this,3,
201                        (PMF)&FGGroundReactions::GetMoments);
202   PropertyManager->Tie("forces/fbx-gear-lbs", this,1,
203                        (PMF)&FGGroundReactions::GetForces);
204   PropertyManager->Tie("forces/fby-gear-lbs", this,2,
205                        (PMF)&FGGroundReactions::GetForces);
206   PropertyManager->Tie("forces/fbz-gear-lbs", this,3,
207                        (PMF)&FGGroundReactions::GetForces);
208 }
209
210 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211
212 void FGGroundReactions::unbind(void)
213 {
214   PropertyManager->Untie("gear/num-units");
215   PropertyManager->Untie("moments/l-gear-lbsft");
216   PropertyManager->Untie("moments/m-gear-lbsft");
217   PropertyManager->Untie("moments/n-gear-lbsft");
218   PropertyManager->Untie("forces/fbx-gear-lbs");
219   PropertyManager->Untie("forces/fby-gear-lbs");
220   PropertyManager->Untie("forces/fbz-gear-lbs");
221 }
222
223 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 //    The bitmasked value choices are as follows:
225 //    unset: In this case (the default) JSBSim would only print
226 //       out the normally expected messages, essentially echoing
227 //       the config files as they are read. If the environment
228 //       variable is not set, debug_lvl is set to 1 internally
229 //    0: This requests JSBSim not to output any messages
230 //       whatsoever.
231 //    1: This value explicity requests the normal JSBSim
232 //       startup messages
233 //    2: This value asks for a message to be printed out when
234 //       a class is instantiated
235 //    4: When this value is set, a message is displayed when a
236 //       FGModel object executes its Run() method
237 //    8: When this value is set, various runtime state variables
238 //       are printed out periodically
239 //    16: When set various parameters are sanity checked and
240 //       a message is printed out when they go out of bounds
241
242 void FGGroundReactions::Debug(int from)
243 {
244   if (debug_lvl <= 0) return;
245
246   if (debug_lvl & 1) { // Standard console startup message output
247     if (from == 0) { // Constructor
248
249     }
250   }
251   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
252     if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
253     if (from == 1) cout << "Destroyed:    FGGroundReactions" << endl;
254   }
255   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
256   }
257   if (debug_lvl & 8 ) { // Runtime state variables
258   }
259   if (debug_lvl & 16) { // Sanity checking
260   }
261   if (debug_lvl & 64) {
262     if (from == 0) { // Constructor
263       cout << IdSrc << endl;
264       cout << IdHdr << endl;
265     }
266   }
267 }
268 }