]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGGroundReactions.cpp
Sync. w. JSBSim cvs
[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 (unsigned int i=0; i<lGear.size();i++) delete lGear[i];
68   lGear.clear();
69
70   Debug(1);
71 }
72
73 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74
75 bool FGGroundReactions::InitModel(void)
76 {
77   if (!FGModel::InitModel()) return false;
78
79   return true;
80 }
81
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84 bool FGGroundReactions::Run(void)
85 {
86   if (FGModel::Run()) return true;
87   if (FDMExec->Holding()) return false;
88
89   vForces.InitMatrix();
90   vMoments.InitMatrix();
91
92   // Sum forces and moments for all gear, here.
93   // Some optimizations may be made here - or rather in the gear code itself.
94   // The gear ::Run() method is called several times - once for each gear.
95   // Perhaps there is some commonality for things which only need to be
96   // calculated once.
97   for (unsigned int i=0; i<lGear.size(); i++) {
98     vForces  += lGear[i]->Force();
99     vMoments += lGear[i]->Moment();
100   }
101
102   return false;
103 }
104
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106
107 bool FGGroundReactions::GetWOW(void)
108 {
109   bool result = false;
110   for (unsigned int i=0; i<lGear.size(); i++) {
111     if (lGear[i]->IsBogey() && lGear[i]->GetWOW()) {
112       result = true;
113       break;
114     }
115   }
116   return result;
117 }
118
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
121 bool FGGroundReactions::Load(Element* el)
122 {
123   int num=0;
124
125   Debug(2);
126
127   Element* contact_element = el->FindElement("contact");
128   while (contact_element) {
129     lGear.push_back(new FGLGear(contact_element, FDMExec, num++));
130     FCS->AddGear(); // make the FCS aware of the landing gear
131     contact_element = el->FindNextElement("contact");
132   }
133
134   for (unsigned int i=0; i<lGear.size();i++) lGear[i]->bind();
135
136   return true;
137 }
138
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140
141 string FGGroundReactions::GetGroundReactionStrings(string delimeter)
142 {
143   std::ostringstream buf;
144
145   for (unsigned int i=0;i<lGear.size();i++) {
146     if (lGear[i]->IsBogey()) {
147       string name = lGear[i]->GetName();
148       buf << name << " WOW" << delimeter
149           << name << " stroke (ft)" << delimeter
150           << name << " stroke velocity (ft/sec)" << delimeter
151           << name << " compress force (lbs)" << delimeter
152           << name << " wheel side force (lbs)" << delimeter
153           << name << " wheel roll force (lbs)" << delimeter
154           << name << " body X force (lbs)" << delimeter
155           << name << " body Y force (lbs)" << delimeter
156           << name << " wheel velocity vec X (ft/sec)" << delimeter
157           << name << " wheel velocity vec Y (ft/sec)" << delimeter
158           << name << " wheel rolling velocity (ft/sec)" << delimeter
159           << name << " wheel side velocity (ft/sec)" << delimeter
160           << name << " wheel slip (deg)" << delimeter;
161     }
162   }
163
164   buf << " Total Gear Force_X (lbs)" << delimeter
165       << " Total Gear Force_Y (lbs)" << delimeter
166       << " Total Gear Force_Z (lbs)" << delimeter
167       << " Total Gear Moment_L (ft-lbs)" << delimeter
168       << " Total Gear Moment_M (ft-lbs)" << delimeter
169       << " Total Gear Moment_N (ft-lbs)";
170
171   return buf.str();
172 }
173
174 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175
176 string FGGroundReactions::GetGroundReactionValues(string delimeter)
177 {
178   std::ostringstream buf;
179
180   for (unsigned int i=0;i<lGear.size();i++) {
181     if (lGear[i]->IsBogey()) {
182       FGLGear *gear = lGear[i];
183       buf << (gear->GetWOW() ? "1, " : "0, ")
184           << setprecision(5) << gear->GetCompLen() << delimeter
185           << setprecision(6) << gear->GetCompVel() << delimeter
186           << setprecision(10) << gear->GetCompForce() << delimeter
187           << gear->GetWheelSideForce() << delimeter
188           << gear->GetWheelRollForce() << delimeter
189           << gear->GetBodyXForce() << delimeter
190           << gear->GetBodyYForce() << delimeter
191           << setprecision(6) << gear->GetWheelVel(eX) << delimeter
192           << gear->GetWheelVel(eY) << delimeter
193           << gear->GetWheelRollVel() << delimeter
194           << gear->GetWheelSideVel() << delimeter
195           << gear->GetWheelSlipAngle() << delimeter;
196     }
197   }
198
199   buf << vForces(eX) << delimeter
200       << vForces(eY) << delimeter
201       << vForces(eZ) << delimeter
202       << vMoments(eX) << delimeter
203       << vMoments(eY) << delimeter
204       << vMoments(eZ);
205
206   return buf.str();
207 }
208
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210
211 void FGGroundReactions::bind(void)
212 {
213   typedef double (FGGroundReactions::*PMF)(int) const;
214   PropertyManager->Tie("gear/num-units", this, &FGGroundReactions::GetNumGearUnits);
215   PropertyManager->Tie("moments/l-gear-lbsft", this, eL, (PMF)&FGGroundReactions::GetMoments);
216   PropertyManager->Tie("moments/m-gear-lbsft", this, eM, (PMF)&FGGroundReactions::GetMoments);
217   PropertyManager->Tie("moments/n-gear-lbsft", this, eN, (PMF)&FGGroundReactions::GetMoments);
218   PropertyManager->Tie("forces/fbx-gear-lbs", this, eX, (PMF)&FGGroundReactions::GetForces);
219   PropertyManager->Tie("forces/fby-gear-lbs", this, eY, (PMF)&FGGroundReactions::GetForces);
220   PropertyManager->Tie("forces/fbz-gear-lbs", this, eZ, (PMF)&FGGroundReactions::GetForces);
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 == 2) { // Loading
248       cout << endl << "  Ground Reactions: " << endl;
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 }