X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2Fmodels%2FFGGroundReactions.cpp;h=9126c9f812ec768d4a50468a347ab027585cc8d0;hb=4a817a63079733469d76905902509a40af019535;hp=c8bf6ab9e589ab85d0b19411692eda4ba0cf595b;hpb=3cda82e0a9b3ff5eb6d21408328c5f864be31e0d;p=flightgear.git diff --git a/src/FDM/JSBSim/models/FGGroundReactions.cpp b/src/FDM/JSBSim/models/FGGroundReactions.cpp index c8bf6ab9e..9126c9f81 100644 --- a/src/FDM/JSBSim/models/FGGroundReactions.cpp +++ b/src/FDM/JSBSim/models/FGGroundReactions.cpp @@ -5,7 +5,7 @@ Date started: 09/13/00 Purpose: Encapsulates the ground reaction forces (gear and collision) - ------------- Copyright (C) 2000 Jon S. Berndt (jsb@hal-pc.org) ------------- + ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) ------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -39,17 +39,59 @@ INCLUDES #include #include "FGGroundReactions.h" -#include +#include "FGFCS.h" +#include "input_output/FGPropertyManager.h" + +using namespace std; namespace JSBSim { -static const char *IdSrc = "$Id$"; +static const char *IdSrc = "$Id: FGGroundReactions.cpp,v 1.31 2010/11/18 12:38:06 jberndt Exp $"; static const char *IdHdr = ID_GROUNDREACTIONS; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -CLASS IMPLEMENTATION +CLASS IMPLEMENTATION for MultiplierIterator (See below for FGGroundReactions) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +MultiplierIterator::MultiplierIterator(FGGroundReactions* GndReactions) +: GroundReactions(GndReactions), + multiplier(NULL), + gearNum(0), + entry(0) +{ + for (int i=0; i < GroundReactions->GetNumGearUnits(); i++) { + FGLGear* gear = GroundReactions->GetGearUnit(i); + + if (!gear->GetWOW()) continue; + + gearNum = i; + multiplier = gear->GetMultiplierEntry(0); + break; + } +} + +MultiplierIterator& MultiplierIterator::operator++() +{ + for (int i=gearNum; i < GroundReactions->GetNumGearUnits(); i++) { + FGLGear* gear = GroundReactions->GetGearUnit(i); + + if (!gear->GetWOW()) continue; + + multiplier = gear->GetMultiplierEntry(++entry); + if (multiplier) { + gearNum = i; + break; + } + else + entry = -1; + } + + return *this; +} + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +CLASS IMPLEMENTATION +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex) { @@ -64,50 +106,55 @@ FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex) FGGroundReactions::~FGGroundReactions(void) { - for (unsigned int i=0; iHolding()) return false; + RunPreFunctions(); + vForces.InitMatrix(); vMoments.InitMatrix(); - if ( Propagate->GetDistanceAGL() < 300.0 ) { // Only execute gear code below 300 feet - vector ::iterator iGear = lGear.begin(); - - // Sum forces and moments for all gear, here. - // Some optimizations may be made here - or rather in the gear code itself. - // The gear ::Run() method is called several times - once for each gear. - // Perhaps there is some commonality for things which only need to be - // calculated once. - - while (iGear != lGear.end()) { - vForces += iGear->Force(); - vMoments += iGear->Moment(); - iGear++; - } - + // Sum forces and moments for all gear, here. + // Some optimizations may be made here - or rather in the gear code itself. + // The gear ::Run() method is called several times - once for each gear. + // Perhaps there is some commonality for things which only need to be + // calculated once. + for (unsigned int i=0; iGetBodyForces(); + vMoments += lGear[i]->GetMoments(); } + RunPostFunctions(); + return false; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -bool FGGroundReactions::GetWOW(void) +bool FGGroundReactions::GetWOW(void) const { bool result = false; for (unsigned int i=0; iIsBogey() && lGear[i]->GetWOW()) { result = true; break; } @@ -115,6 +162,20 @@ bool FGGroundReactions::GetWOW(void) return result; } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// This function must be called after friction forces are resolved in order to +// include them in the ground reactions total force and moment. +void FGGroundReactions::UpdateForcesAndMoments(void) +{ + vForces.InitMatrix(); + vMoments.InitMatrix(); + + for (unsigned int i=0; iUpdateForces(); + vMoments += lGear[i]->GetMoments(); + } +} + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% bool FGGroundReactions::Load(Element* el) @@ -125,25 +186,29 @@ bool FGGroundReactions::Load(Element* el) Element* contact_element = el->FindElement("contact"); while (contact_element) { - lGear.push_back(FGLGear(contact_element, FDMExec, num++)); - FCS->AddGear(); // make the FCS aware of the landing gear + lGear.push_back(new FGLGear(contact_element, FDMExec, num++)); + FDMExec->GetFCS()->AddGear(); // make the FCS aware of the landing gear contact_element = el->FindNextElement("contact"); } + + FGModel::Load(el); // Perform base class Load - for (unsigned int i=0; ibind(); + + PostLoad(el, PropertyManager); return true; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGGroundReactions::GetGroundReactionStrings(string delimeter) +string FGGroundReactions::GetGroundReactionStrings(string delimeter) const { std::ostringstream buf; for (unsigned int i=0;iIsBogey()) { + string name = lGear[i]->GetName(); buf << name << " WOW" << delimeter << name << " stroke (ft)" << delimeter << name << " stroke velocity (ft/sec)" << delimeter @@ -172,26 +237,26 @@ string FGGroundReactions::GetGroundReactionStrings(string delimeter) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGGroundReactions::GetGroundReactionValues(string delimeter) +string FGGroundReactions::GetGroundReactionValues(string delimeter) const { std::ostringstream buf; for (unsigned int i=0;iIsBogey()) { + FGLGear *gear = lGear[i]; + buf << (gear->GetWOW() ? "1" : "0") << delimeter + << setprecision(5) << gear->GetCompLen() << delimeter + << setprecision(6) << gear->GetCompVel() << delimeter + << setprecision(10) << gear->GetCompForce() << delimeter + << gear->GetWheelSideForce() << delimeter + << gear->GetWheelRollForce() << delimeter + << gear->GetBodyXForce() << delimeter + << gear->GetBodyYForce() << delimeter + << setprecision(6) << gear->GetWheelVel(eX) << delimeter + << gear->GetWheelVel(eY) << delimeter + << gear->GetWheelRollVel() << delimeter + << gear->GetWheelSideVel() << delimeter + << gear->GetWheelSlipAngle() << delimeter; } } @@ -211,6 +276,7 @@ void FGGroundReactions::bind(void) { typedef double (FGGroundReactions::*PMF)(int) const; PropertyManager->Tie("gear/num-units", this, &FGGroundReactions::GetNumGearUnits); + PropertyManager->Tie("gear/wow", this, &FGGroundReactions::GetWOW); PropertyManager->Tie("moments/l-gear-lbsft", this, eL, (PMF)&FGGroundReactions::GetMoments); PropertyManager->Tie("moments/m-gear-lbsft", this, eM, (PMF)&FGGroundReactions::GetMoments); PropertyManager->Tie("moments/n-gear-lbsft", this, eN, (PMF)&FGGroundReactions::GetMoments); @@ -219,19 +285,6 @@ void FGGroundReactions::bind(void) PropertyManager->Tie("forces/fbz-gear-lbs", this, eZ, (PMF)&FGGroundReactions::GetForces); } -//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -void FGGroundReactions::unbind(void) -{ - PropertyManager->Untie("gear/num-units"); - PropertyManager->Untie("moments/l-gear-lbsft"); - PropertyManager->Untie("moments/m-gear-lbsft"); - PropertyManager->Untie("moments/n-gear-lbsft"); - PropertyManager->Untie("forces/fbx-gear-lbs"); - PropertyManager->Untie("forces/fby-gear-lbs"); - PropertyManager->Untie("forces/fbz-gear-lbs"); -} - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // The bitmasked value choices are as follows: // unset: In this case (the default) JSBSim would only print