1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGGroundReactions.cpp
6 Purpose: Encapsulates the ground reaction forces (gear and collision)
8 ------------- Copyright (C) 2000 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
31 --------------------------------------------------------------------------------
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 #include "FGGroundReactions.h"
42 #include "FGPropertyManager.h"
46 static const char *IdSrc = "$Id$";
47 static const char *IdHdr = ID_GROUNDREACTIONS;
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
56 Name = "FGGroundReactions";
63 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 FGGroundReactions::~FGGroundReactions(void)
72 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 bool FGGroundReactions::Run(void)
76 if (!FGModel::Run()) {
78 vMoments.InitMatrix();
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
88 while (iGear != lGear.end()) {
89 vForces += iGear->Force();
90 vMoments += iGear->Moment();
104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
110 AC_cfg->GetNextConfigLine();
112 while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
113 int num = lGear.size();
114 lGear.push_back(FGLGear(AC_cfg, FDMExec, num));
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 string FGGroundReactions::GetGroundReactionStrings(void)
125 std::ostringstream buf;
127 for (unsigned int i=0;i<lGear.size();i++) {
128 string name = lGear[i].GetName();
129 buf << name << "_WOW, "
130 << name << "_stroke, "
131 << name << "_strokeVel, "
132 << name << "_CompressForce, "
133 << name << "_WhlSideForce, "
134 << name << "_WhlVelVecX, "
135 << name << "_WhlVelVecY, "
136 << name << "_WhlRollForce, "
137 << name << "_BodyXForce, "
138 << name << "_BodyYForce, "
139 << name << "_WhlSlipDegrees, ";
142 buf << "TotalGearForce_X, "
143 << "TotalGearForce_Y, "
144 << "TotalGearForce_Z, "
145 << "TotalGearMoment_L, "
146 << "TotalGearMoment_M, "
147 << "TotalGearMoment_N";
152 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 string FGGroundReactions::GetGroundReactionValues(void)
156 std::ostringstream buf;
158 for (unsigned int i=0;i<lGear.size();i++) {
159 FGLGear& gear = lGear[i];
160 buf << (gear.GetWOW() ? "1, " : "0, ")
161 << setprecision(5) << gear.GetCompLen() << ", "
162 << setprecision(6) << gear.GetCompVel() << ", "
163 << setprecision(10) << gear.GetCompForce() << ", "
164 << setprecision(6) << gear.GetWheelVel(eX) << ", "
165 << gear.GetWheelVel(eY) << ", "
166 << gear.GetWheelSideForce() << ", "
167 << gear.GetWheelRollForce() << ", "
168 << gear.GetBodyXForce() << ", "
169 << gear.GetBodyYForce() << ", "
170 << gear.GetWheelSlipAngle() << ", ";
173 buf << vForces(eX) << ", "
174 << vForces(eY) << ", "
175 << vForces(eZ) << ", "
176 << vMoments(eX) << ", "
177 << vMoments(eY) << ", "
183 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 void FGGroundReactions::bind(void)
187 typedef double (FGGroundReactions::*PMF)(int) const;
188 PropertyManager->Tie("gear/num-units", this,
189 &FGGroundReactions::GetNumGearUnits);
190 PropertyManager->Tie("moments/l-gear-lbsft", this,1,
191 (PMF)&FGGroundReactions::GetMoments);
192 PropertyManager->Tie("moments/m-gear-lbsft", this,2,
193 (PMF)&FGGroundReactions::GetMoments);
194 PropertyManager->Tie("moments/n-gear-lbsft", this,3,
195 (PMF)&FGGroundReactions::GetMoments);
196 PropertyManager->Tie("forces/fbx-gear-lbs", this,1,
197 (PMF)&FGGroundReactions::GetForces);
198 PropertyManager->Tie("forces/fby-gear-lbs", this,2,
199 (PMF)&FGGroundReactions::GetForces);
200 PropertyManager->Tie("forces/fbz-gear-lbs", this,3,
201 (PMF)&FGGroundReactions::GetForces);
204 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 void FGGroundReactions::unbind(void)
208 PropertyManager->Untie("gear/num-units");
209 PropertyManager->Untie("moments/l-gear-lbsft");
210 PropertyManager->Untie("moments/m-gear-lbsft");
211 PropertyManager->Untie("moments/n-gear-lbsft");
212 PropertyManager->Untie("forces/fbx-gear-lbs");
213 PropertyManager->Untie("forces/fby-gear-lbs");
214 PropertyManager->Untie("forces/fbz-gear-lbs");
217 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 // The bitmasked value choices are as follows:
219 // unset: In this case (the default) JSBSim would only print
220 // out the normally expected messages, essentially echoing
221 // the config files as they are read. If the environment
222 // variable is not set, debug_lvl is set to 1 internally
223 // 0: This requests JSBSim not to output any messages
225 // 1: This value explicity requests the normal JSBSim
227 // 2: This value asks for a message to be printed out when
228 // a class is instantiated
229 // 4: When this value is set, a message is displayed when a
230 // FGModel object executes its Run() method
231 // 8: When this value is set, various runtime state variables
232 // are printed out periodically
233 // 16: When set various parameters are sanity checked and
234 // a message is printed out when they go out of bounds
236 void FGGroundReactions::Debug(int from)
238 if (debug_lvl <= 0) return;
240 if (debug_lvl & 1) { // Standard console startup message output
241 if (from == 0) { // Constructor
245 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
246 if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
247 if (from == 1) cout << "Destroyed: FGGroundReactions" << endl;
249 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
251 if (debug_lvl & 8 ) { // Runtime state variables
253 if (debug_lvl & 16) { // Sanity checking
255 if (debug_lvl & 64) {
256 if (from == 0) { // Constructor
257 cout << IdSrc << endl;
258 cout << IdHdr << endl;