]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGGroundReactions.cpp
Clean up header file use of iostream and "using" declarations
[flightgear.git] / src / FDM / JSBSim / models / 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 Lesser 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 Lesser General Public License for more
18  details.
19
20  You should have received a copy of the GNU Lesser 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 Lesser 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 <input_output/FGPropertyManager.h>
43
44 namespace JSBSim {
45
46 static const char *IdSrc = "$Id$";
47 static const char *IdHdr = ID_GROUNDREACTIONS;
48
49 using std::ostringstream;
50 using std::setprecision;
51
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 CLASS IMPLEMENTATION
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55
56
57 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
58 {
59   Name = "FGGroundReactions";
60
61   bind();
62
63   Debug(0);
64 }
65
66 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
68 FGGroundReactions::~FGGroundReactions(void)
69 {
70   for (unsigned int i=0; i<lGear.size();i++) lGear[i].unbind();
71   lGear.clear();
72
73   unbind();
74   Debug(1);
75 }
76
77 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
79 bool FGGroundReactions::Run(void)
80 {
81   if (FGModel::Run()) return true;
82   if (FDMExec->Holding()) return false;
83
84   vForces.InitMatrix();
85   vMoments.InitMatrix();
86
87   if ( Propagate->GetDistanceAGL() < 300.0 ) { // Only execute gear code below 300 feet
88     vector <FGLGear>::iterator iGear = lGear.begin();
89
90     // Sum forces and moments for all gear, here.
91     // Some optimizations may be made here - or rather in the gear code itself.
92     // The gear ::Run() method is called several times - once for each gear.
93     // Perhaps there is some commonality for things which only need to be
94     // calculated once.
95
96     while (iGear != lGear.end()) {
97       vForces  += iGear->Force();
98       vMoments += iGear->Moment();
99       iGear++;
100     }
101
102   }
103
104   return false;
105 }
106
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109 bool FGGroundReactions::GetWOW(void)
110 {
111   bool result = false;
112   for (unsigned int i=0; i<lGear.size(); i++) {
113     if (lGear[i].IsBogey() && lGear[i].GetWOW()) {
114       result = true;
115       break;
116     }
117   }
118   return result;
119 }
120
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122
123 bool FGGroundReactions::Load(Element* el)
124 {
125   int num=0;
126
127   Debug(2);
128
129   Element* contact_element = el->FindElement("contact");
130   while (contact_element) {
131     lGear.push_back(FGLGear(contact_element, FDMExec, num++));
132     FCS->AddGear(); // make the FCS aware of the landing gear
133     contact_element = el->FindNextElement("contact");
134   }
135
136   for (unsigned int i=0; i<lGear.size();i++) lGear[i].bind();
137
138   return true;
139 }
140
141 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142
143 string FGGroundReactions::GetGroundReactionStrings(string delimeter)
144 {
145   ostringstream buf;
146
147   for (unsigned int i=0;i<lGear.size();i++) {
148     if (lGear[i].IsBogey()) {
149       string name = lGear[i].GetName();
150       buf << name << " WOW" << delimeter
151           << name << " stroke (ft)" << delimeter
152           << name << " stroke velocity (ft/sec)" << delimeter
153           << name << " compress force (lbs)" << delimeter
154           << name << " wheel side force (lbs)" << delimeter
155           << name << " wheel roll force (lbs)" << delimeter
156           << name << " body X force (lbs)" << delimeter
157           << name << " body Y force (lbs)" << delimeter
158           << name << " wheel velocity vec X (ft/sec)" << delimeter
159           << name << " wheel velocity vec Y (ft/sec)" << delimeter
160           << name << " wheel rolling velocity (ft/sec)" << delimeter
161           << name << " wheel side velocity (ft/sec)" << delimeter
162           << name << " wheel slip (deg)" << delimeter;
163     }
164   }
165
166   buf << " Total Gear Force_X (lbs)" << delimeter
167       << " Total Gear Force_Y (lbs)" << delimeter
168       << " Total Gear Force_Z (lbs)" << delimeter
169       << " Total Gear Moment_L (ft-lbs)" << delimeter
170       << " Total Gear Moment_M (ft-lbs)" << delimeter
171       << " Total Gear Moment_N (ft-lbs)";
172
173   return buf.str();
174 }
175
176 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177
178 string FGGroundReactions::GetGroundReactionValues(string delimeter)
179 {
180   std::ostringstream buf;
181
182   for (unsigned int i=0;i<lGear.size();i++) {
183     if (lGear[i].IsBogey()) {
184       FGLGear& gear = lGear[i];
185       buf << (gear.GetWOW() ? "1, " : "0, ")
186           << setprecision(5) << gear.GetCompLen() << delimeter
187           << setprecision(6) << gear.GetCompVel() << delimeter
188           << setprecision(10) << gear.GetCompForce() << delimeter
189           << gear.GetWheelSideForce() << delimeter
190           << gear.GetWheelRollForce() << delimeter
191           << gear.GetBodyXForce() << delimeter
192           << gear.GetBodyYForce() << delimeter
193           << setprecision(6) << gear.GetWheelVel(eX) << delimeter
194           << gear.GetWheelVel(eY) << delimeter
195           << gear.GetWheelRollVel() << delimeter
196           << gear.GetWheelSideVel() << delimeter
197           << gear.GetWheelSlipAngle() << delimeter;
198     }
199   }
200
201   buf << vForces(eX) << delimeter
202       << vForces(eY) << delimeter
203       << vForces(eZ) << delimeter
204       << vMoments(eX) << delimeter
205       << vMoments(eY) << delimeter
206       << vMoments(eZ);
207
208   return buf.str();
209 }
210
211 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212
213 void FGGroundReactions::bind(void)
214 {
215   typedef double (FGGroundReactions::*PMF)(int) const;
216   PropertyManager->Tie("gear/num-units", this, &FGGroundReactions::GetNumGearUnits);
217   PropertyManager->Tie("moments/l-gear-lbsft", this, eL, (PMF)&FGGroundReactions::GetMoments);
218   PropertyManager->Tie("moments/m-gear-lbsft", this, eM, (PMF)&FGGroundReactions::GetMoments);
219   PropertyManager->Tie("moments/n-gear-lbsft", this, eN, (PMF)&FGGroundReactions::GetMoments);
220   PropertyManager->Tie("forces/fbx-gear-lbs", this, eX, (PMF)&FGGroundReactions::GetForces);
221   PropertyManager->Tie("forces/fby-gear-lbs", this, eY, (PMF)&FGGroundReactions::GetForces);
222   PropertyManager->Tie("forces/fbz-gear-lbs", this, eZ, (PMF)&FGGroundReactions::GetForces);
223 }
224
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226
227 void FGGroundReactions::unbind(void)
228 {
229   PropertyManager->Untie("gear/num-units");
230   PropertyManager->Untie("moments/l-gear-lbsft");
231   PropertyManager->Untie("moments/m-gear-lbsft");
232   PropertyManager->Untie("moments/n-gear-lbsft");
233   PropertyManager->Untie("forces/fbx-gear-lbs");
234   PropertyManager->Untie("forces/fby-gear-lbs");
235   PropertyManager->Untie("forces/fbz-gear-lbs");
236 }
237
238 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 //    The bitmasked value choices are as follows:
240 //    unset: In this case (the default) JSBSim would only print
241 //       out the normally expected messages, essentially echoing
242 //       the config files as they are read. If the environment
243 //       variable is not set, debug_lvl is set to 1 internally
244 //    0: This requests JSBSim not to output any messages
245 //       whatsoever.
246 //    1: This value explicity requests the normal JSBSim
247 //       startup messages
248 //    2: This value asks for a message to be printed out when
249 //       a class is instantiated
250 //    4: When this value is set, a message is displayed when a
251 //       FGModel object executes its Run() method
252 //    8: When this value is set, various runtime state variables
253 //       are printed out periodically
254 //    16: When set various parameters are sanity checked and
255 //       a message is printed out when they go out of bounds
256
257 void FGGroundReactions::Debug(int from)
258 {
259   if (debug_lvl <= 0) return;
260
261   if (debug_lvl & 1) { // Standard console startup message output
262     if (from == 2) { // Loading
263       cout << endl << "  Ground Reactions: " << endl;
264     }
265   }
266   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
267     if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
268     if (from == 1) cout << "Destroyed:    FGGroundReactions" << endl;
269   }
270   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
271   }
272   if (debug_lvl & 8 ) { // Runtime state variables
273   }
274   if (debug_lvl & 16) { // Sanity checking
275   }
276   if (debug_lvl & 64) {
277     if (from == 0) { // Constructor
278       cout << IdSrc << endl;
279       cout << IdHdr << endl;
280     }
281   }
282 }
283 }