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