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