X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2Fmodels%2FFGInertial.cpp;h=94aa291c3346653f8f37024f4bad96b49bdd3141;hb=cd24f7b6aaaa54f81655fb574bb050620c900dfe;hp=6db0555e0caadb99f7f71b04eec9ef7dab84db59;hpb=a6db6d89ff41a619569e6433409e8bf62ff98499;p=flightgear.git diff --git a/src/FDM/JSBSim/models/FGInertial.cpp b/src/FDM/JSBSim/models/FGInertial.cpp index 6db0555e0..94aa291c3 100644 --- a/src/FDM/JSBSim/models/FGInertial.cpp +++ b/src/FDM/JSBSim/models/FGInertial.cpp @@ -36,14 +36,16 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGInertial.h" -#include +#include "FGFDMExec.h" #include "FGPropagate.h" -#include "FGState.h" #include "FGMassBalance.h" +#include + +using namespace std; namespace JSBSim { -static const char *IdSrc = "$Id$"; +static const char *IdSrc = "$Id: FGInertial.cpp,v 1.20 2010/11/18 12:38:06 jberndt Exp $"; static const char *IdHdr = ID_INERTIAL; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -111,10 +113,14 @@ bool FGInertial::Run(void) if (FGModel::Run()) return true; if (FDMExec->Holding()) return false; + RunPreFunctions(); + // Gravitation accel - double r = Propagate->GetRadius(); + double r = FDMExec->GetPropagate()->GetRadius(); gAccel = GetGAccel(r); - earthPosAngle += State->Getdt()*RotationRate; + earthPosAngle += FDMExec->GetDeltaT()*RotationRate; + + RunPostFunctions(); return false; } @@ -126,6 +132,35 @@ double FGInertial::GetGAccel(double r) const return GM/(r*r); } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// +// Calculate the WGS84 gravitation value in ECEF frame. Pass in the ECEF position +// via the position parameter. The J2Gravity value returned is in ECEF frame, +// and therefore may need to be expressed (transformed) in another frame, +// depending on how it is used. See Stevens and Lewis eqn. 1.4-16. + +FGColumnVector3 FGInertial::GetGravityJ2(FGColumnVector3 position) const +{ + FGColumnVector3 J2Gravity; + + // Gravitation accel + double r = position.Magnitude(); + double lat = FDMExec->GetPropagate()->GetLatitude(); + double sinLat = sin(lat); + + double adivr = a/r; + double preCommon = 1.5*J2*adivr*adivr; + double xy = 1.0 - 5.0*(sinLat*sinLat); + double z = 3.0 - 5.0*(sinLat*sinLat); + double GMOverr2 = GM/(r*r); + + J2Gravity(1) = -GMOverr2 * ((1.0 + (preCommon * xy)) * position(eX)/r); + J2Gravity(2) = -GMOverr2 * ((1.0 + (preCommon * xy)) * position(eY)/r); + J2Gravity(3) = -GMOverr2 * ((1.0 + (preCommon * z)) * position(eZ)/r); + + return J2Gravity; +} + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGInertial::bind(void)