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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38 #include "FGGroundReactions.h"
39 #include "FGPropertyManager.h"
41 static const char *IdSrc = "$Id$";
42 static const char *IdHdr = ID_GROUNDREACTIONS;
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
51 Name = "FGGroundReactions";
58 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 FGGroundReactions::~FGGroundReactions(void)
67 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 bool FGGroundReactions::Run(void)
71 if (!FGModel::Run()) {
73 vMoments.InitMatrix();
75 // Only execute gear force code below 300 feet
76 if ( Position->GetDistanceAGL() < 300.0 ) {
77 vector <FGLGear>::iterator iGear = lGear.begin();
78 // Sum forces and moments for all gear, here.
79 // Some optimizations may be made here - or rather in the gear code itself.
80 // The gear ::Run() method is called several times - once for each gear.
81 // Perhaps there is some commonality for things which only need to be
83 while (iGear != lGear.end()) {
84 vForces += iGear->Force();
85 vMoments += iGear->Moment();
99 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 bool FGGroundReactions::Load(FGConfigFile* AC_cfg)
105 AC_cfg->GetNextConfigLine();
107 while ((token = AC_cfg->GetValue()) != string("/UNDERCARRIAGE")) {
108 lGear.push_back(FGLGear(AC_cfg, FDMExec));
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 string FGGroundReactions::GetGroundReactionStrings(void)
118 string GroundReactionStrings = "";
119 bool firstime = true;
121 for (unsigned int i=0;i<lGear.size();i++) {
122 if (!firstime) GroundReactionStrings += ", ";
123 GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
124 GroundReactionStrings += (lGear[i].GetName() + "_stroke, ");
125 GroundReactionStrings += (lGear[i].GetName() + "_strokeVel, ");
126 GroundReactionStrings += (lGear[i].GetName() + "_CompressForce, ");
127 GroundReactionStrings += (lGear[i].GetName() + "_WhlSideForce, ");
128 GroundReactionStrings += (lGear[i].GetName() + "_WhlRollForce, ");
129 GroundReactionStrings += (lGear[i].GetName() + "_BodyXForce, ");
130 GroundReactionStrings += (lGear[i].GetName() + "_BodyYForce, ");
131 GroundReactionStrings += (lGear[i].GetName() + "_WhlSlipDegrees");
136 return GroundReactionStrings;
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 string FGGroundReactions::GetGroundReactionValues(void)
144 string GroundReactionValues = "";
146 bool firstime = true;
148 for (unsigned int i=0;i<lGear.size();i++) {
149 if (!firstime) GroundReactionValues += ", ";
150 GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
151 GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(), 5, buff)) + ", ");
152 GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(), 6, buff)) + ", ");
153 GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)) + ", ");
154 GroundReactionValues += (string(gcvt(lGear[i].GetWheelSideForce(), 6, buff)) + ", ");
155 GroundReactionValues += (string(gcvt(lGear[i].GetWheelRollForce(), 6, buff)) + ", ");
156 GroundReactionValues += (string(gcvt(lGear[i].GetBodyXForce(), 6, buff)) + ", ");
157 GroundReactionValues += (string(gcvt(lGear[i].GetBodyYForce(), 6, buff)) + ", ");
158 GroundReactionValues += (string(gcvt(lGear[i].GetWheelSlipAngle(), 6, buff)));
163 return GroundReactionValues;
166 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 void FGGroundReactions::bind(void)
170 typedef double (FGGroundReactions::*PMF)(int) const;
171 PropertyManager->Tie("gear/num-units", this,
172 &FGGroundReactions::GetNumGearUnits);
173 PropertyManager->Tie("moments/l-gear-lbsft", this,1,
174 (PMF)&FGGroundReactions::GetMoments);
175 PropertyManager->Tie("moments/m-gear-lbsft", this,2,
176 (PMF)&FGGroundReactions::GetMoments);
177 PropertyManager->Tie("moments/n-gear-lbsft", this,3,
178 (PMF)&FGGroundReactions::GetMoments);
179 PropertyManager->Tie("forces/fbx-gear-lbs", this,1,
180 (PMF)&FGGroundReactions::GetForces);
181 PropertyManager->Tie("forces/fby-gear-lbs", this,2,
182 (PMF)&FGGroundReactions::GetForces);
183 PropertyManager->Tie("forces/fbz-gear-lbs", this,3,
184 (PMF)&FGGroundReactions::GetForces);
187 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 void FGGroundReactions::unbind(void)
191 PropertyManager->Untie("gear/num-units");
192 PropertyManager->Untie("moments/l-gear-lbsft");
193 PropertyManager->Untie("moments/m-gear-lbsft");
194 PropertyManager->Untie("moments/n-gear-lbsft");
195 PropertyManager->Untie("forces/fbx-gear-lbs");
196 PropertyManager->Untie("forces/fby-gear-lbs");
197 PropertyManager->Untie("forces/fbz-gear-lbs");
200 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 // The bitmasked value choices are as follows:
202 // unset: In this case (the default) JSBSim would only print
203 // out the normally expected messages, essentially echoing
204 // the config files as they are read. If the environment
205 // variable is not set, debug_lvl is set to 1 internally
206 // 0: This requests JSBSim not to output any messages
208 // 1: This value explicity requests the normal JSBSim
210 // 2: This value asks for a message to be printed out when
211 // a class is instantiated
212 // 4: When this value is set, a message is displayed when a
213 // FGModel object executes its Run() method
214 // 8: When this value is set, various runtime state variables
215 // are printed out periodically
216 // 16: When set various parameters are sanity checked and
217 // a message is printed out when they go out of bounds
219 void FGGroundReactions::Debug(int from)
221 if (debug_lvl <= 0) return;
223 if (debug_lvl & 1) { // Standard console startup message output
224 if (from == 0) { // Constructor
228 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
229 if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
230 if (from == 1) cout << "Destroyed: FGGroundReactions" << endl;
232 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
234 if (debug_lvl & 8 ) { // Runtime state variables
236 if (debug_lvl & 16) { // Sanity checking
238 if (debug_lvl & 64) {
239 if (from == 0) { // Constructor
240 cout << IdSrc << endl;
241 cout << IdHdr << endl;