]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGGroundReactions.cpp
Merge branch 'next' into comm-subsystem
[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 "FGLGear.h"
43 #include "input_output/FGPropertyManager.h"
44
45 using namespace std;
46
47 namespace JSBSim {
48
49 static const char *IdSrc = "$Id: FGGroundReactions.cpp,v 1.36 2011/08/21 15:13:22 bcoconni Exp $";
50 static const char *IdHdr = ID_GROUNDREACTIONS;
51
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 CLASS IMPLEMENTATION
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55
56 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
57 {
58   Name = "FGGroundReactions";
59
60   bind();
61
62   Debug(0);
63 }
64
65 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
67 FGGroundReactions::~FGGroundReactions(void)
68 {
69   for (unsigned int i=0; i<lGear.size();i++) delete lGear[i];
70   lGear.clear();
71
72   Debug(1);
73 }
74
75 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
77 bool FGGroundReactions::InitModel(void)
78 {
79   return true;
80 }
81
82 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83
84 bool FGGroundReactions::Run(bool Holding)
85 {
86   if (FGModel::Run(Holding)) return true;
87   if (Holding) return false;
88
89   RunPreFunctions();
90
91   vForces.InitMatrix();
92   vMoments.InitMatrix();
93
94   multipliers.clear();
95
96   // Sum forces and moments for all gear, here.
97   // Some optimizations may be made here - or rather in the gear code itself.
98   // The gear ::Run() method is called several times - once for each gear.
99   // Perhaps there is some commonality for things which only need to be
100   // calculated once.
101   for (unsigned int i=0; i<lGear.size(); i++) {
102     vForces  += lGear[i]->GetBodyForces();
103     vMoments += lGear[i]->GetMoments();
104   }
105
106   RunPostFunctions();
107
108   return false;
109 }
110
111 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112
113 bool FGGroundReactions::GetWOW(void) const
114 {
115   bool result = false;
116   for (unsigned int i=0; i<lGear.size(); i++) {
117     if (lGear[i]->IsBogey() && lGear[i]->GetWOW()) {
118       result = true;
119       break;
120     }
121   }
122   return result;
123 }
124
125 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126
127 bool FGGroundReactions::Load(Element* el)
128 {
129   int num=0;
130
131   Debug(2);
132
133   unsigned int numContacts = el->GetNumElements("contact");
134   lGear.resize(numContacts);
135   Element* contact_element = el->FindElement("contact");
136   for (unsigned int idx=0; idx<numContacts; idx++) {
137     lGear[idx] = new FGLGear(contact_element, FDMExec, num++, in);
138     contact_element = el->FindNextElement("contact");
139   }
140
141   FGModel::Load(el); // Perform base class Load
142
143   in.vWhlBodyVec.resize(lGear.size());
144
145   for (unsigned int i=0; i<lGear.size();i++) lGear[i]->bind();
146
147   PostLoad(el, PropertyManager);
148
149   return true;
150 }
151
152 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153
154 string FGGroundReactions::GetGroundReactionStrings(string delimeter) const
155 {
156   std::ostringstream buf;
157
158   for (unsigned int i=0;i<lGear.size();i++) {
159     if (lGear[i]->IsBogey()) {
160       string name = lGear[i]->GetName();
161       buf << name << " WOW" << delimeter
162           << name << " stroke (ft)" << delimeter
163           << name << " stroke velocity (ft/sec)" << delimeter
164           << name << " compress force (lbs)" << delimeter
165           << name << " wheel side force (lbs)" << delimeter
166           << name << " wheel roll force (lbs)" << delimeter
167           << name << " body X force (lbs)" << delimeter
168           << name << " body Y force (lbs)" << delimeter
169           << name << " wheel velocity vec X (ft/sec)" << delimeter
170           << name << " wheel velocity vec Y (ft/sec)" << delimeter
171           << name << " wheel rolling velocity (ft/sec)" << delimeter
172           << name << " wheel side velocity (ft/sec)" << delimeter
173           << name << " wheel slip (deg)" << delimeter;
174     }
175   }
176
177   buf << " Total Gear Force_X (lbs)" << delimeter
178       << " Total Gear Force_Y (lbs)" << delimeter
179       << " Total Gear Force_Z (lbs)" << delimeter
180       << " Total Gear Moment_L (ft-lbs)" << delimeter
181       << " Total Gear Moment_M (ft-lbs)" << delimeter
182       << " Total Gear Moment_N (ft-lbs)";
183
184   return buf.str();
185 }
186
187 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188
189 string FGGroundReactions::GetGroundReactionValues(string delimeter) const
190 {
191   std::ostringstream buf;
192
193   for (unsigned int i=0;i<lGear.size();i++) {
194     if (lGear[i]->IsBogey()) {
195       FGLGear *gear = lGear[i];
196       buf << (gear->GetWOW() ? "1" : "0") << delimeter
197           << setprecision(5) << gear->GetCompLen() << delimeter
198           << setprecision(6) << gear->GetCompVel() << delimeter
199           << setprecision(10) << gear->GetCompForce() << delimeter
200           << gear->GetWheelSideForce() << delimeter
201           << gear->GetWheelRollForce() << delimeter
202           << gear->GetBodyXForce() << delimeter
203           << gear->GetBodyYForce() << delimeter
204           << setprecision(6) << gear->GetWheelVel(eX) << delimeter
205           << gear->GetWheelVel(eY) << delimeter
206           << gear->GetWheelRollVel() << delimeter
207           << gear->GetWheelSideVel() << delimeter
208           << gear->GetWheelSlipAngle() << delimeter;
209     }
210   }
211
212   buf << vForces(eX) << delimeter
213       << vForces(eY) << delimeter
214       << vForces(eZ) << delimeter
215       << vMoments(eX) << delimeter
216       << vMoments(eY) << delimeter
217       << vMoments(eZ);
218
219   return buf.str();
220 }
221
222 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223
224 void FGGroundReactions::bind(void)
225 {
226   typedef double (FGGroundReactions::*PMF)(int) const;
227   PropertyManager->Tie("gear/num-units", this, &FGGroundReactions::GetNumGearUnits);
228   PropertyManager->Tie("gear/wow", this, &FGGroundReactions::GetWOW);
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 }