From ac50500e80decf3053526dd6538173203f54d61b Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 24 Nov 2001 22:13:04 +0000 Subject: [PATCH] Sync with latest JSBSim CVS. --- aclocal.m4 | 2 +- src/FDM/JSBSim/FGAtmosphere.cpp | 100 ++++++++++++++++++++++---- src/FDM/JSBSim/FGAtmosphere.h | 17 +++++ src/FDM/JSBSim/FGColumnVector3.cpp | 12 ++-- src/FDM/JSBSim/FGFDMExec.cpp | 2 +- src/FDM/JSBSim/FGInitialCondition.cpp | 3 +- src/FDM/JSBSim/FGJSBBase.cpp | 1 + src/FDM/JSBSim/FGJSBBase.h | 5 +- src/FDM/JSBSim/FGPiston.cpp | 2 +- src/FDM/JSBSim/FGPiston.h | 2 + src/FDM/JSBSim/FGState.cpp | 13 ++++ src/FDM/JSBSim/FGTrim.h | 4 ++ src/FDM/Makefile.am | 1 + src/Include/config.h.in | 2 +- src/Sound/fg_fx.cxx | 4 +- 15 files changed, 142 insertions(+), 28 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index 78a4037e5..7d5836b91 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,4 +1,4 @@ -dnl aclocal.m4 generated automatically by aclocal 1.4 +dnl aclocal.m4 generated automatically by aclocal 1.4-p4 dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation diff --git a/src/FDM/JSBSim/FGAtmosphere.cpp b/src/FDM/JSBSim/FGAtmosphere.cpp index 407d5dfd4..acc7613cb 100644 --- a/src/FDM/JSBSim/FGAtmosphere.cpp +++ b/src/FDM/JSBSim/FGAtmosphere.cpp @@ -69,7 +69,14 @@ CLASS IMPLEMENTATION FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex), - vWindNED(3) + vWindNED(3), + vDirectiondAccelDt(3), + vDirectionAccel(3), + vDirection(3), + vTurbulence(3), + vTurbulenceGrad(3), + vBodyTurbGrad(3), + vTurbPQR(3) { Name = "FGAtmosphere"; lastIndex=0; @@ -83,6 +90,11 @@ FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex), htab[6]=200131.234; htab[7]=259186.352; //ft. + MagnitudedAccelDt = MagnitudeAccel = Magnitude = 0.0; +// turbType = ttNone; + turbType = ttBerndt; // temporarily disable turbulence until fully tested + TurbGain = 100.0; + if (debug_lvl & 2) cout << "Instantiated: " << Name << endl; } @@ -128,6 +140,11 @@ bool FGAtmosphere::Run(void) temperature = exTemperature; } + if (turbType != ttNone) { + Turbulence(); + vWindNED += vTurbulence; + } + if (vWindNED(1) != 0.0) psiw = atan2( vWindNED(2), vWindNED(1) ); if (psiw < 0) psiw += 2*M_PI; @@ -135,6 +152,9 @@ bool FGAtmosphere::Run(void) soundspeed = sqrt(SHRatio*Reng*temperature); State->Seta(soundspeed); + + if (debug_lvl > 1) Debug(); + } else { // skip Run() execution this time } @@ -142,28 +162,31 @@ bool FGAtmosphere::Run(void) } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +// +// See reference 1 void FGAtmosphere::Calculate(double altitude) { - //see reference [1] + double slope, reftemp, refpress; + int i = 0; + bool lookup = false; - double slope,reftemp,refpress; - int i=0; bool lookup = false; - // cout << "Atmosphere: h=" << altitude << " rho= " << density << endl; - i=lastIndex; - if(altitude < htab[lastIndex]) { + i = lastIndex; + if (altitude < htab[lastIndex]) { if (altitude <= 0) { - i=0; altitude=0; + i = 0; + altitude=0; } else { - i=lastIndex-1; - while (htab[i] > altitude) { i--; } + i = lastIndex-1; + while (htab[i] > altitude) i--; } } else if (altitude > htab[lastIndex+1]){ if (altitude >= htab[7]){ - i = 7; altitude = htab[7]; + i = 7; + altitude = htab[7]; } else { - i=lastIndex+1; - while(htab[i+1] < altitude) { i++; } + i = lastIndex+1; + while(htab[i+1] < altitude) i++; } } @@ -235,8 +258,57 @@ void FGAtmosphere::Calculate(double altitude) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +void FGAtmosphere::Turbulence(void) +{ + switch (turbType) { + case ttBerndt: + vDirectiondAccelDt(eX) = 1 - 2.0*(((double)(rand()))/RAND_MAX); + vDirectiondAccelDt(eY) = 1 - 2.0*(((double)(rand()))/RAND_MAX); + vDirectiondAccelDt(eZ) = 1 - 2.0*(((double)(rand()))/RAND_MAX); + + MagnitudedAccelDt = 1 - 2.0*(((double)(rand()))/RAND_MAX); + MagnitudeAccel += MagnitudedAccelDt*rate*State->Getdt(); + Magnitude += MagnitudeAccel*rate*State->Getdt(); + + vDirectiondAccelDt.Normalize(); + vDirectionAccel += vDirectiondAccelDt*rate*State->Getdt(); + vDirectionAccel.Normalize(); + vDirection += vDirectionAccel*rate*State->Getdt(); + vDirection.Normalize(); + + vTurbulence = TurbGain*Magnitude * vDirection; + vTurbulenceGrad = TurbGain*MagnitudeAccel * vDirection; + + vBodyTurbGrad = State->GetTl2b()*vTurbulenceGrad; + vTurbPQR(eP) = vBodyTurbGrad(eY)/Aircraft->GetWingSpan(); + if (Aircraft->GetHTailArm() != 0.0) + vTurbPQR(eQ) = vBodyTurbGrad(eZ)/Aircraft->GetHTailArm(); + else + vTurbPQR(eQ) = vBodyTurbGrad(eZ)/10.0; + + if (Aircraft->GetVTailArm()) + vTurbPQR(eR) = vBodyTurbGrad(eX)/Aircraft->GetVTailArm(); + else + vTurbPQR(eR) = vBodyTurbGrad(eX)/10.0; + + break; + default: + break; + } +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + void FGAtmosphere::Debug(void) { - //TODO: Add your source code here + if (frame == 0) { + cout << "vTurbulence(X), vTurbulence(Y), vTurbulence(Z), " + << "vTurbulenceGrad(X), vTurbulenceGrad(Y), vTurbulenceGrad(Z), " + << "vDirection(X), vDirection(Y), vDirection(Z), " + << "Magnitude, " + << "vTurbPQR(P), vTurbPQR(Q), vTurbPQR(R), " << endl; + } else { + cout << vTurbulence << ", " << vTurbulenceGrad << ", " << vDirection << ", " << Magnitude << ", " << vTurbPQR << endl; + } } diff --git a/src/FDM/JSBSim/FGAtmosphere.h b/src/FDM/JSBSim/FGAtmosphere.h index fe0fe322b..faa74ea44 100644 --- a/src/FDM/JSBSim/FGAtmosphere.h +++ b/src/FDM/JSBSim/FGAtmosphere.h @@ -142,9 +142,15 @@ public: increases counterclockwise. The wind heading is returned in radians.*/ inline double GetWindPsi(void) { return psiw; } + inline void SetTurbGain(double tt) {TurbGain = tt;} + + inline double GetTurbPQR(int idx) {return vTurbPQR(idx);} + private: double rho; + enum tType {ttBerndt, ttNone} turbType; + int lastIndex; double h; double htab[8]; @@ -154,10 +160,21 @@ private: bool useExternal; double exTemperature,exDensity,exPressure; + double MagnitudedAccelDt, MagnitudeAccel, Magnitude; + double TurbGain; + FGColumnVector3 vDirectiondAccelDt; + FGColumnVector3 vDirectionAccel; + FGColumnVector3 vDirection; + FGColumnVector3 vTurbulence; + FGColumnVector3 vTurbulenceGrad; + FGColumnVector3 vBodyTurbGrad; + FGColumnVector3 vTurbPQR; + FGColumnVector3 vWindNED; double psiw; void Calculate(double altitude); + void Turbulence(void); void Debug(void); }; diff --git a/src/FDM/JSBSim/FGColumnVector3.cpp b/src/FDM/JSBSim/FGColumnVector3.cpp index 070ea5e71..0c27fa4d0 100644 --- a/src/FDM/JSBSim/FGColumnVector3.cpp +++ b/src/FDM/JSBSim/FGColumnVector3.cpp @@ -32,8 +32,9 @@ CLASS IMPLEMENTATION FGColumnVector3::FGColumnVector3(void) { rowCtr = 1; - //cout << "Allocated: " << data << endl; - //if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl; + data[0]=0; data[1]=0; data[2]=0; data[3]=0; + + if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -41,16 +42,15 @@ FGColumnVector3::FGColumnVector3(void) FGColumnVector3::FGColumnVector3(int m) { rowCtr = 1; - data[1]=0;data[2]=0;data[3]=0; - //cout << "Allocated: " << data << endl; - //if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl; + data[0]=0; data[1]=0; data[2]=0; data[3]=0; + + if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGColumnVector3::~FGColumnVector3(void) { - //cout << "Freed: " << data << endl; if (debug_lvl & 2) cout << "Destroyed: FGColumnVector3" << endl; } diff --git a/src/FDM/JSBSim/FGFDMExec.cpp b/src/FDM/JSBSim/FGFDMExec.cpp index f6e10e0ff..1031a17b0 100644 --- a/src/FDM/JSBSim/FGFDMExec.cpp +++ b/src/FDM/JSBSim/FGFDMExec.cpp @@ -349,7 +349,7 @@ bool FGFDMExec::Run(void) if (model_iterator == 0L) break; } - Frame++; + frame = Frame++; State->IncrTime(); return true; diff --git a/src/FDM/JSBSim/FGInitialCondition.cpp b/src/FDM/JSBSim/FGInitialCondition.cpp index 31be45a1e..b407f0375 100644 --- a/src/FDM/JSBSim/FGInitialCondition.cpp +++ b/src/FDM/JSBSim/FGInitialCondition.cpp @@ -664,7 +664,8 @@ bool FGInitialCondition::solve(double *y,double x) i=0; while ((fabs(d) > eps) && (i < 100)) { d=(x3-x1)/d0; - x2=x1-d*d0*f1/(f3-f1); + if (f3-f1 != 0.0) x2 = x1-d*d0*f1/(f3-f1); + else x2 = x1-d*d0*f1/0.01; // TONY: What is correct? This is a WAG. f2=(this->*sfunc)(x2)-x; //cout << "solve x1,x2,x3: " << x1 << "," << x2 << "," << x3 << endl; diff --git a/src/FDM/JSBSim/FGJSBBase.cpp b/src/FDM/JSBSim/FGJSBBase.cpp index 786b57c31..9e1f67636 100644 --- a/src/FDM/JSBSim/FGJSBBase.cpp +++ b/src/FDM/JSBSim/FGJSBBase.cpp @@ -70,6 +70,7 @@ const string FGJSBBase::JSBSim_version = "0.9.1"; queue FGJSBBase::Messages; struct FGJSBBase::Message FGJSBBase::localMsg; unsigned int FGJSBBase::messageId = 0; +unsigned int FGJSBBase::frame = 0; short FGJSBBase::debug_lvl = 0; diff --git a/src/FDM/JSBSim/FGJSBBase.h b/src/FDM/JSBSim/FGJSBBase.h index 6408fa2c7..93e40fe24 100644 --- a/src/FDM/JSBSim/FGJSBBase.h +++ b/src/FDM/JSBSim/FGJSBBase.h @@ -94,6 +94,9 @@ enum eParam { FG_PITCHRATE, FG_ROLLRATE, FG_YAWRATE, + FG_AEROP, + FG_AEROQ, + FG_AEROR, FG_CL_SQRD, FG_MACH, FG_ALTITUDE, @@ -260,7 +263,7 @@ protected: virtual void Debug(void) {}; static short debug_lvl; - static int frame; + static unsigned int frame; static unsigned int messageId; static const double radtodeg; diff --git a/src/FDM/JSBSim/FGPiston.cpp b/src/FDM/JSBSim/FGPiston.cpp index 299f225a3..1a6a62bc3 100644 --- a/src/FDM/JSBSim/FGPiston.cpp +++ b/src/FDM/JSBSim/FGPiston.cpp @@ -96,6 +96,7 @@ FGPiston::FGPiston(FGFDMExec* exec, FGConfigFile* Eng_cfg) } Type = etPiston; + crank_counter = 0; EngineNumber = 0; // FIXME: this should be the actual number OilTemp_degK = 298; // FIXME: should be initialized in FGEngine @@ -211,7 +212,6 @@ void FGPiston::doEngineStartup(void) // (spark, fuel, starter motor etc) bool spark; bool fuel; - static int crank_counter = 0; // Check for spark Magneto_Left = false; diff --git a/src/FDM/JSBSim/FGPiston.h b/src/FDM/JSBSim/FGPiston.h index 9e2dc476a..7aab17ebb 100644 --- a/src/FDM/JSBSim/FGPiston.h +++ b/src/FDM/JSBSim/FGPiston.h @@ -88,6 +88,8 @@ public: double GetPowerAvailable(void) {return PowerAvailable;} private: + int crank_counter; + double BrakeHorsePower; double SpeedSlope; double SpeedIntercept; diff --git a/src/FDM/JSBSim/FGState.cpp b/src/FDM/JSBSim/FGState.cpp index 7a63758fe..5a341b329 100644 --- a/src/FDM/JSBSim/FGState.cpp +++ b/src/FDM/JSBSim/FGState.cpp @@ -47,6 +47,10 @@ INCLUDES # endif #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "FGState.h" static const char *IdSrc = "$Id$"; @@ -115,6 +119,9 @@ FGState::FGState(FGFDMExec* fdex) : mTb2l(3,3), RegisterVariable(FG_PITCHRATE, " pitch_rate " ); RegisterVariable(FG_ROLLRATE, " roll_rate " ); RegisterVariable(FG_YAWRATE, " yaw_rate " ); + RegisterVariable(FG_AEROQ, " aero_pitch_rate "); + RegisterVariable(FG_AEROP, " aero_roll_rate " ); + RegisterVariable(FG_AEROR, " aero_yaw_rate " ); RegisterVariable(FG_CL_SQRD, " Clift_sqrd " ); RegisterVariable(FG_MACH, " mach " ); RegisterVariable(FG_ALTITUDE, " altitude " ); @@ -216,6 +223,12 @@ double FGState::GetParameter(eParam val_idx) { return Rotation->GetPQR(eP); case FG_YAWRATE: return Rotation->GetPQR(eR); + case FG_AEROQ: + return Rotation->GetPQR(eQ) + Atmosphere->GetTurbPQR(eQ); // add aero turbulence effects + case FG_AEROP: + return Rotation->GetPQR(eP) + Atmosphere->GetTurbPQR(eP); // add aero turbulence effects + case FG_AEROR: + return Rotation->GetPQR(eR) + Atmosphere->GetTurbPQR(eR); // add aero turbulence effects case FG_CL_SQRD: if (Translation->Getqbar() > 0.00) scratch = Aerodynamics->GetvLastFs(eLift)/(Aircraft->GetWingArea()*Translation->Getqbar()); diff --git a/src/FDM/JSBSim/FGTrim.h b/src/FDM/JSBSim/FGTrim.h index acbff2fba..810e385d8 100644 --- a/src/FDM/JSBSim/FGTrim.h +++ b/src/FDM/JSBSim/FGTrim.h @@ -72,6 +72,10 @@ DEFINITIONS typedef enum { tLongitudinal, tFull, tGround, tCustom, tNone } TrimMode; +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ diff --git a/src/FDM/Makefile.am b/src/FDM/Makefile.am index 485dbf5d8..c711e0b85 100644 --- a/src/FDM/Makefile.am +++ b/src/FDM/Makefile.am @@ -6,6 +6,7 @@ libFlight_a_SOURCES = \ ADA.cxx ADA.hxx \ Balloon.cxx Balloon.h \ External.cxx External.hxx \ + ExternalNet.cxx ExternalNet.hxx \ flight.cxx flight.hxx \ IO360.cxx IO360.hxx \ JSBSim.cxx JSBSim.hxx \ diff --git a/src/Include/config.h.in b/src/Include/config.h.in index 3c18956c7..553a55a5a 100644 --- a/src/Include/config.h.in +++ b/src/Include/config.h.in @@ -1,4 +1,4 @@ -/* src/Include/config.h.in. Generated automatically from configure.in by autoheader. */ +/* src/Include/config.h.in. Generated automatically from configure.in by autoheader 2.13. */ /* Define to empty if the keyword does not work. */ #undef const diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index bd80790a2..c780807d9 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -211,7 +211,7 @@ FGFX::update () float rel_wind = cur_fdm_state->get_V_rel_wind(); // FPS if (rel_wind > 60.0) { // a little off 30kt - float volume = rel_wind/1200.0; // FIXME!!! + float volume = rel_wind/600.0; // FIXME!!! _wind->set_volume(volume); set_playing("wind", true); } else { @@ -273,7 +273,7 @@ FGFX::update () // if the velocity is under 6kt. double speed = cur_fdm_state->get_V_equiv_kts(); if (gearOnGround > 0 && speed >= 6.0) { - double volume = (gearOnGround/totalGear) * (speed/60.0); + double volume = 2.0 * (gearOnGround/totalGear) * (speed/60.0); _rumble->set_volume(volume); set_playing("rumble", true); } else { -- 2.39.5