1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGGroundReactions.cpp
6 Purpose: Encapsulates the ground reaction forces (gear and collision)
8 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
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
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
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.
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.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
31 --------------------------------------------------------------------------------
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 #include "FGGroundReactions.h"
43 #include "input_output/FGPropertyManager.h"
49 static const char *IdSrc = "$Id: FGGroundReactions.cpp,v 1.32 2011/05/20 03:18:36 jberndt Exp $";
50 static const char *IdHdr = ID_GROUNDREACTIONS;
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 CLASS IMPLEMENTATION for MultiplierIterator (See below for FGGroundReactions)
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 MultiplierIterator::MultiplierIterator(FGGroundReactions* GndReactions)
57 : GroundReactions(GndReactions),
62 for (int i=0; i < GroundReactions->GetNumGearUnits(); i++) {
63 FGLGear* gear = GroundReactions->GetGearUnit(i);
65 if (!gear->GetWOW()) continue;
68 multiplier = gear->GetMultiplierEntry(0);
73 MultiplierIterator& MultiplierIterator::operator++()
75 for (int i=gearNum; i < GroundReactions->GetNumGearUnits(); i++) {
76 FGLGear* gear = GroundReactions->GetGearUnit(i);
78 if (!gear->GetWOW()) continue;
80 multiplier = gear->GetMultiplierEntry(++entry);
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96 FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex)
98 Name = "FGGroundReactions";
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 FGGroundReactions::~FGGroundReactions(void)
109 for (unsigned int i=0; i<lGear.size();i++) delete lGear[i];
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 bool FGGroundReactions::InitModel(void)
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 bool FGGroundReactions::Run(bool Holding)
126 if (FGModel::Run(Holding)) return true;
127 if (Holding) return false;
131 vForces.InitMatrix();
132 vMoments.InitMatrix();
134 // Sum forces and moments for all gear, here.
135 // Some optimizations may be made here - or rather in the gear code itself.
136 // The gear ::Run() method is called several times - once for each gear.
137 // Perhaps there is some commonality for things which only need to be
139 for (unsigned int i=0; i<lGear.size(); i++) {
140 vForces += lGear[i]->GetBodyForces();
141 vMoments += lGear[i]->GetMoments();
149 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 bool FGGroundReactions::GetWOW(void) const
154 for (unsigned int i=0; i<lGear.size(); i++) {
155 if (lGear[i]->IsBogey() && lGear[i]->GetWOW()) {
163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 // This function must be called after friction forces are resolved in order to
165 // include them in the ground reactions total force and moment.
166 void FGGroundReactions::UpdateForcesAndMoments(void)
168 vForces.InitMatrix();
169 vMoments.InitMatrix();
171 for (unsigned int i=0; i<lGear.size(); i++) {
172 vForces += lGear[i]->UpdateForces();
173 vMoments += lGear[i]->GetMoments();
177 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 bool FGGroundReactions::Load(Element* el)
185 Element* contact_element = el->FindElement("contact");
186 while (contact_element) {
187 lGear.push_back(new FGLGear(contact_element, FDMExec, num++));
188 FDMExec->GetFCS()->AddGear(); // make the FCS aware of the landing gear
189 contact_element = el->FindNextElement("contact");
192 FGModel::Load(el); // Perform base class Load
194 for (unsigned int i=0; i<lGear.size();i++) lGear[i]->bind();
196 PostLoad(el, PropertyManager);
201 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 string FGGroundReactions::GetGroundReactionStrings(string delimeter) const
205 std::ostringstream buf;
207 for (unsigned int i=0;i<lGear.size();i++) {
208 if (lGear[i]->IsBogey()) {
209 string name = lGear[i]->GetName();
210 buf << name << " WOW" << delimeter
211 << name << " stroke (ft)" << delimeter
212 << name << " stroke velocity (ft/sec)" << delimeter
213 << name << " compress force (lbs)" << delimeter
214 << name << " wheel side force (lbs)" << delimeter
215 << name << " wheel roll force (lbs)" << delimeter
216 << name << " body X force (lbs)" << delimeter
217 << name << " body Y force (lbs)" << delimeter
218 << name << " wheel velocity vec X (ft/sec)" << delimeter
219 << name << " wheel velocity vec Y (ft/sec)" << delimeter
220 << name << " wheel rolling velocity (ft/sec)" << delimeter
221 << name << " wheel side velocity (ft/sec)" << delimeter
222 << name << " wheel slip (deg)" << delimeter;
226 buf << " Total Gear Force_X (lbs)" << delimeter
227 << " Total Gear Force_Y (lbs)" << delimeter
228 << " Total Gear Force_Z (lbs)" << delimeter
229 << " Total Gear Moment_L (ft-lbs)" << delimeter
230 << " Total Gear Moment_M (ft-lbs)" << delimeter
231 << " Total Gear Moment_N (ft-lbs)";
236 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 string FGGroundReactions::GetGroundReactionValues(string delimeter) const
240 std::ostringstream buf;
242 for (unsigned int i=0;i<lGear.size();i++) {
243 if (lGear[i]->IsBogey()) {
244 FGLGear *gear = lGear[i];
245 buf << (gear->GetWOW() ? "1" : "0") << delimeter
246 << setprecision(5) << gear->GetCompLen() << delimeter
247 << setprecision(6) << gear->GetCompVel() << delimeter
248 << setprecision(10) << gear->GetCompForce() << delimeter
249 << gear->GetWheelSideForce() << delimeter
250 << gear->GetWheelRollForce() << delimeter
251 << gear->GetBodyXForce() << delimeter
252 << gear->GetBodyYForce() << delimeter
253 << setprecision(6) << gear->GetWheelVel(eX) << delimeter
254 << gear->GetWheelVel(eY) << delimeter
255 << gear->GetWheelRollVel() << delimeter
256 << gear->GetWheelSideVel() << delimeter
257 << gear->GetWheelSlipAngle() << delimeter;
261 buf << vForces(eX) << delimeter
262 << vForces(eY) << delimeter
263 << vForces(eZ) << delimeter
264 << vMoments(eX) << delimeter
265 << vMoments(eY) << delimeter
271 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273 void FGGroundReactions::bind(void)
275 typedef double (FGGroundReactions::*PMF)(int) const;
276 PropertyManager->Tie("gear/num-units", this, &FGGroundReactions::GetNumGearUnits);
277 PropertyManager->Tie("gear/wow", this, &FGGroundReactions::GetWOW);
278 PropertyManager->Tie("moments/l-gear-lbsft", this, eL, (PMF)&FGGroundReactions::GetMoments);
279 PropertyManager->Tie("moments/m-gear-lbsft", this, eM, (PMF)&FGGroundReactions::GetMoments);
280 PropertyManager->Tie("moments/n-gear-lbsft", this, eN, (PMF)&FGGroundReactions::GetMoments);
281 PropertyManager->Tie("forces/fbx-gear-lbs", this, eX, (PMF)&FGGroundReactions::GetForces);
282 PropertyManager->Tie("forces/fby-gear-lbs", this, eY, (PMF)&FGGroundReactions::GetForces);
283 PropertyManager->Tie("forces/fbz-gear-lbs", this, eZ, (PMF)&FGGroundReactions::GetForces);
286 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 // The bitmasked value choices are as follows:
288 // unset: In this case (the default) JSBSim would only print
289 // out the normally expected messages, essentially echoing
290 // the config files as they are read. If the environment
291 // variable is not set, debug_lvl is set to 1 internally
292 // 0: This requests JSBSim not to output any messages
294 // 1: This value explicity requests the normal JSBSim
296 // 2: This value asks for a message to be printed out when
297 // a class is instantiated
298 // 4: When this value is set, a message is displayed when a
299 // FGModel object executes its Run() method
300 // 8: When this value is set, various runtime state variables
301 // are printed out periodically
302 // 16: When set various parameters are sanity checked and
303 // a message is printed out when they go out of bounds
305 void FGGroundReactions::Debug(int from)
307 if (debug_lvl <= 0) return;
309 if (debug_lvl & 1) { // Standard console startup message output
310 if (from == 2) { // Loading
311 cout << endl << " Ground Reactions: " << endl;
314 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
315 if (from == 0) cout << "Instantiated: FGGroundReactions" << endl;
316 if (from == 1) cout << "Destroyed: FGGroundReactions" << endl;
318 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
320 if (debug_lvl & 8 ) { // Runtime state variables
322 if (debug_lvl & 16) { // Sanity checking
324 if (debug_lvl & 64) {
325 if (from == 0) { // Constructor
326 cout << IdSrc << endl;
327 cout << IdHdr << endl;