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 <input_output/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)
67 for (int i=0; i<lGear.size();i++) lGear[i].unbind();
74 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 bool FGGroundReactions::Run(void)
78 if (FGModel::Run()) return true;
79 if (FDMExec->Holding()) return false;
82 vMoments.InitMatrix();
84 if ( Propagate->GetDistanceAGL() < 300.0 ) { // Only execute gear code below 300 feet
85 vector <FGLGear>::iterator iGear = lGear.begin();
87 // Sum forces and moments for all gear, here.
88 // Some optimizations may be made here - or rather in the gear code itself.
89 // The gear ::Run() method is called several times - once for each gear.
90 // Perhaps there is some commonality for things which only need to be
93 while (iGear != lGear.end()) {
94 vForces += iGear->Force();
95 vMoments += iGear->Moment();
104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 bool FGGroundReactions::GetWOW(void)
109 for (int i=0; i<lGear.size(); i++) {
110 if (lGear[i].IsBogey() && lGear[i].GetWOW()) {
118 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 bool FGGroundReactions::Load(Element* el)
126 Element* contact_element = el->FindElement("contact");
127 while (contact_element) {
128 lGear.push_back(FGLGear(contact_element, FDMExec, num++));
129 FCS->AddGear(); // make the FCS aware of the landing gear
130 contact_element = el->FindNextElement("contact");
133 for (int i=0; i<lGear.size();i++) lGear[i].bind();
138 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 string FGGroundReactions::GetGroundReactionStrings(string delimeter)
142 std::ostringstream buf;
144 for (unsigned int i=0;i<lGear.size();i++) {
145 string name = lGear[i].GetName();
146 buf << name << "_WOW" << delimeter
147 << name << "_stroke" << delimeter
148 << name << "_strokeVel" << delimeter
149 << name << "_CompressForce" << delimeter
150 << name << "_WhlSideForce" << delimeter
151 << name << "_WhlVelVecX" << delimeter
152 << name << "_WhlVelVecY" << delimeter
153 << name << "_WhlRollForce" << delimeter
154 << name << "_BodyXForce" << delimeter
155 << name << "_BodyYForce" << delimeter
156 << name << "_WhlSlipDegrees" << delimeter;
159 buf << "TotalGearForce_X" << delimeter
160 << "TotalGearForce_Y" << delimeter
161 << "TotalGearForce_Z" << delimeter
162 << "TotalGearMoment_L" << delimeter
163 << "TotalGearMoment_M" << delimeter
164 << "TotalGearMoment_N";
169 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 string FGGroundReactions::GetGroundReactionValues(string delimeter)
173 std::ostringstream buf;
175 for (unsigned int i=0;i<lGear.size();i++) {
176 FGLGear& gear = lGear[i];
177 buf << (gear.GetWOW() ? "1, " : "0, ")
178 << setprecision(5) << gear.GetCompLen() << delimeter
179 << setprecision(6) << gear.GetCompVel() << delimeter
180 << setprecision(10) << gear.GetCompForce() << delimeter
181 << setprecision(6) << gear.GetWheelVel(eX) << delimeter
182 << gear.GetWheelVel(eY) << delimeter
183 << gear.GetWheelSideForce() << delimeter
184 << gear.GetWheelRollForce() << delimeter
185 << gear.GetBodyXForce() << delimeter
186 << gear.GetBodyYForce() << delimeter
187 << gear.GetWheelSlipAngle() << delimeter;
190 buf << vForces(eX) << delimeter
191 << vForces(eY) << delimeter
192 << vForces(eZ) << delimeter
193 << vMoments(eX) << delimeter
194 << vMoments(eY) << delimeter
200 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 void FGGroundReactions::bind(void)
204 typedef double (FGGroundReactions::*PMF)(int) const;
205 PropertyManager->Tie("gear/num-units", this, &FGGroundReactions::GetNumGearUnits);
206 PropertyManager->Tie("moments/l-gear-lbsft", this, eL, (PMF)&FGGroundReactions::GetMoments);
207 PropertyManager->Tie("moments/m-gear-lbsft", this, eM, (PMF)&FGGroundReactions::GetMoments);
208 PropertyManager->Tie("moments/n-gear-lbsft", this, eN, (PMF)&FGGroundReactions::GetMoments);
209 PropertyManager->Tie("forces/fbx-gear-lbs", this, eX, (PMF)&FGGroundReactions::GetForces);
210 PropertyManager->Tie("forces/fby-gear-lbs", this, eY, (PMF)&FGGroundReactions::GetForces);
211 PropertyManager->Tie("forces/fbz-gear-lbs", this, eZ, (PMF)&FGGroundReactions::GetForces);
214 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216 void FGGroundReactions::unbind(void)
218 PropertyManager->Untie("gear/num-units");
219 PropertyManager->Untie("moments/l-gear-lbsft");
220 PropertyManager->Untie("moments/m-gear-lbsft");
221 PropertyManager->Untie("moments/n-gear-lbsft");
222 PropertyManager->Untie("forces/fbx-gear-lbs");
223 PropertyManager->Untie("forces/fby-gear-lbs");
224 PropertyManager->Untie("forces/fbz-gear-lbs");
227 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 // The bitmasked value choices are as follows:
229 // unset: In this case (the default) JSBSim would only print
230 // out the normally expected messages, essentially echoing
231 // the config files as they are read. If the environment
232 // variable is not set, debug_lvl is set to 1 internally
233 // 0: This requests JSBSim not to output any messages
235 // 1: This value explicity requests the normal JSBSim
237 // 2: This value asks for a message to be printed out when
238 // a class is instantiated
239 // 4: When this value is set, a message is displayed when a
240 // FGModel object executes its Run() method
241 // 8: When this value is set, various runtime state variables
242 // are printed out periodically
243 // 16: When set various parameters are sanity checked and
244 // a message is printed out when they go out of bounds
246 void FGGroundReactions::Debug(int from)
248 if (debug_lvl <= 0) return;
250 if (debug_lvl & 1) { // Standard console startup message output
251 if (from == 2) { // Loading
252 cout << endl << " Ground Reactions: " << endl;
255 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
256 if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
257 if (from == 1) cout << "Destroyed: FGGroundReactions" << endl;
259 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
261 if (debug_lvl & 8 ) { // Runtime state variables
263 if (debug_lvl & 16) { // Sanity checking
265 if (debug_lvl & 64) {
266 if (from == 0) { // Constructor
267 cout << IdSrc << endl;
268 cout << IdHdr << endl;