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