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