From 0975a42f49bf2ef9395c39f5e5c61261773065d5 Mon Sep 17 00:00:00 2001 From: tony Date: Sat, 8 Jun 2002 03:15:05 +0000 Subject: [PATCH] The external atmosphere fix. Really this time. --- src/FDM/JSBSim/FGAtmosphere.cpp | 63 ++++++++++++------- src/FDM/JSBSim/FGAtmosphere.h | 20 +++--- src/FDM/JSBSim/JSBSim.cxx | 108 ++++++++++++++------------------ src/FDM/JSBSim/JSBSim.hxx | 11 +++- 4 files changed, 106 insertions(+), 96 deletions(-) diff --git a/src/FDM/JSBSim/FGAtmosphere.cpp b/src/FDM/JSBSim/FGAtmosphere.cpp index c59fbc451..e2ea8131d 100644 --- a/src/FDM/JSBSim/FGAtmosphere.cpp +++ b/src/FDM/JSBSim/FGAtmosphere.cpp @@ -109,14 +109,18 @@ bool FGAtmosphere::InitModel(void) FGModel::InitModel(); Calculate(h); - SLtemperature = temperature; - SLpressure = pressure; - SLdensity = density; - SLsoundspeed = sqrt(SHRatio*Reng*temperature); - rSLtemperature = 1.0/temperature; - rSLpressure = 1.0/pressure; - rSLdensity = 1.0/density; + SLtemperature = intTemperature; + SLpressure = intPressure; + SLdensity = intDensity; + SLsoundspeed = sqrt(SHRatio*Reng*intTemperature); + rSLtemperature = 1.0/intTemperature; + rSLpressure = 1.0/intPressure; + rSLdensity = 1.0/intDensity; rSLsoundspeed = 1.0/SLsoundspeed; + temperature=&intTemperature; + pressure=&intPressure; + density=&intDensity; + useExternal=false; return true; @@ -131,11 +135,7 @@ bool FGAtmosphere::Run(void) if (!useExternal) { h = Position->Geth(); Calculate(h); - } else { - density = exDensity; - pressure = exPressure; - temperature = exTemperature; - } + } if (turbType != ttNone) { Turbulence(); @@ -146,7 +146,7 @@ bool FGAtmosphere::Run(void) if (psiw < 0) psiw += 2*M_PI; - soundspeed = sqrt(SHRatio*Reng*temperature); + soundspeed = sqrt(SHRatio*Reng*(*temperature)); State->Seta(soundspeed); @@ -240,18 +240,18 @@ void FGAtmosphere::Calculate(double altitude) } if (slope == 0) { - temperature = reftemp; - pressure = refpress*exp(-Inertial->SLgravity()/(reftemp*Reng)*(altitude-htab[i])); - //density = refdens*exp(-Inertial->SLgravity()/(reftemp*Reng)*(altitude-htab[i])); - density = pressure/(Reng*temperature); + intTemperature = reftemp; + intPressure = refpress*exp(-Inertial->SLgravity()/(reftemp*Reng)*(altitude-htab[i])); + //intDensity = refdens*exp(-Inertial->SLgravity()/(reftemp*Reng)*(altitude-htab[i])); + intDensity = intPressure/(Reng*intTemperature); } else { - temperature = reftemp+slope*(altitude-htab[i]); - pressure = refpress*pow(temperature/reftemp,-Inertial->SLgravity()/(slope*Reng)); - //density = refdens*pow(temperature/reftemp,-(Inertial->SLgravity()/(slope*Reng)+1)); - density = pressure/(Reng*temperature); + intTemperature = reftemp+slope*(altitude-htab[i]); + intPressure = refpress*pow(intTemperature/reftemp,-Inertial->SLgravity()/(slope*Reng)); + //intDensity = refdens*pow(intTemperature/reftemp,-(Inertial->SLgravity()/(slope*Reng)+1)); + intDensity = intPressure/(Reng*intTemperature); } lastIndex=i; - //cout << "Atmosphere: h=" << altitude << " rho= " << density << endl; + //cout << "Atmosphere: h=" << altitude << " rho= " << intDensity << endl; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -295,6 +295,25 @@ void FGAtmosphere::Turbulence(void) } } +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGAtmosphere::UseExternal(void) { + temperature=&exTemperature; + pressure=&exPressure; + density=&exDensity; + useExternal=true; +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGAtmosphere::UseInternal(void) { + temperature=&intTemperature; + pressure=&intPressure; + density=&intDensity; + useExternal=false; +} + + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGAtmosphere::bind(void) diff --git a/src/FDM/JSBSim/FGAtmosphere.h b/src/FDM/JSBSim/FGAtmosphere.h index 5dd820d34..43894a114 100644 --- a/src/FDM/JSBSim/FGAtmosphere.h +++ b/src/FDM/JSBSim/FGAtmosphere.h @@ -96,12 +96,12 @@ public: bool InitModel(void); /// Returns the temperature in degrees Rankine. - inline double GetTemperature(void) const {return temperature;} + inline double GetTemperature(void) const {return *temperature;} /** Returns the density in slugs/ft^3. This function may only be used if Run() is called first. */ - inline double GetDensity(void) const {return density;} + inline double GetDensity(void) const {return *density;} /// Returns the pressure in psf. - inline double GetPressure(void) const {return pressure;} + inline double GetPressure(void) const {return *pressure;} /// Returns the speed of sound in ft/sec. inline double GetSoundSpeed(void) const {return soundspeed;} @@ -115,18 +115,18 @@ public: inline double GetSoundSpeedSL(void) const { return SLsoundspeed; } /// Returns the ratio of at-altitude temperature over the sea level value. - inline double GetTemperatureRatio(void) const { return temperature*rSLtemperature; } + inline double GetTemperatureRatio(void) const { return (*temperature)*rSLtemperature; } /// Returns the ratio of at-altitude density over the sea level value. - inline double GetDensityRatio(void) const { return density*rSLdensity; } + inline double GetDensityRatio(void) const { return (*density)*rSLdensity; } /// Returns the ratio of at-altitude pressure over the sea level value. - inline double GetPressureRatio(void) const { return pressure*rSLpressure; } + inline double GetPressureRatio(void) const { return (*pressure)*rSLpressure; } /// Returns the ratio of at-altitude sound speed over the sea level value. inline double GetSoundSpeedRatio(void) const { return soundspeed*rSLsoundspeed; } /// Tells the simulator to use an externally calculated atmosphere model. - inline void UseExternal(void) { useExternal=true; } + void UseExternal(void); /// Tells the simulator to use the internal atmosphere model. - inline void UseInternal(void) { useExternal=false; } //this is the default + void UseInternal(void); //this is the default /// Gets the boolean that tells if the external atmosphere model is being used. bool External(void) { return useExternal; } @@ -166,9 +166,11 @@ private: double htab[8]; double SLtemperature,SLdensity,SLpressure,SLsoundspeed; double rSLtemperature,rSLdensity,rSLpressure,rSLsoundspeed; //reciprocals - double temperature,density,pressure,soundspeed; + double *temperature,*density,*pressure; + double soundspeed; bool useExternal; double exTemperature,exDensity,exPressure; + double intTemperature, intDensity, intPressure; double MagnitudedAccelDt, MagnitudeAccel, Magnitude; double TurbGain; diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index b7b1c76d9..95c81b037 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -85,20 +85,7 @@ FGJSBsim::FGJSBsim( double dt ) Position = fdmex->GetPosition(); Auxiliary = fdmex->GetAuxiliary(); Aerodynamics = fdmex->GetAerodynamics(); - GroundReactions = fdmex->GetGroundReactions(); - -#ifdef FG_WEATHERCM - Atmosphere->UseInternal(); -#else - if (fgGetBool("/environment/params/control-fdm-atmosphere")) { - Atmosphere->UseExternal(); - Atmosphere->SetExTemperature(get_Static_temperature()); - Atmosphere->SetExPressure(get_Static_pressure()); - Atmosphere->SetExDensity(get_Density()); - } else { - Atmosphere->UseInternal(); - } -#endif + GroundReactions = fdmex->GetGroundReactions(); fgic=new FGInitialCondition(fdmex); needTrim=true; @@ -185,6 +172,14 @@ FGJSBsim::FGJSBsim( double dt ) rudder_pos_pct->setDoubleValue(0); flap_pos_pct->setDoubleValue(0); + temperature = fgGetNode("/environment/temperature-degc",true); + pressure = fgGetNode("/environment/pressure-inhg",true); + density = fgGetNode("/environment/density-slugft3",true); + + wind_from_north= fgGetNode("/environment/wind-from-north-fps",true); + wind_from_east = fgGetNode("/environment/wind-from-east-fps" ,true); + wind_from_down = fgGetNode("/environment/wind-from-down-fps" ,true); + } /******************************************************************************/ @@ -203,11 +198,38 @@ FGJSBsim::~FGJSBsim(void) { void FGJSBsim::init() { SG_LOG( SG_FLIGHT, SG_INFO, "Starting and initializing JSBsim" ); - + // Explicitly call the superclass's // init method first. + +#ifdef FG_WEATHERCM + Atmosphere->UseInternal(); +#else + if (fgGetBool("/environment/params/control-fdm-atmosphere")) { + Atmosphere->UseExternal(); + Atmosphere->SetExTemperature( + 9.0/5.0*(temperature->getDoubleValue()+273.15) ); + Atmosphere->SetExPressure(pressure->getDoubleValue()*70.726566); + Atmosphere->SetExDensity(density->getDoubleValue()); + } else { + Atmosphere->UseInternal(); + } +#endif + + fgic->SetVnorthFpsIC( wind_from_north->getDoubleValue() ); + fgic->SetVeastFpsIC( wind_from_east->getDoubleValue() ); + fgic->SetVdownFpsIC( wind_from_down->getDoubleValue() ); + + //Atmosphere->SetExTemperature(get_Static_temperature()); + //Atmosphere->SetExPressure(get_Static_pressure()); + //Atmosphere->SetExDensity(get_Density()); + SG_LOG(SG_FLIGHT,SG_INFO,"T,p,rho: " << fdmex->GetAtmosphere()->GetTemperature() + << ", " << fdmex->GetAtmosphere()->GetPressure() + << ", " << fdmex->GetAtmosphere()->GetDensity() ); + common_init(); copy_to_JSBsim(); + fdmex->RunIC(fgic); //loop JSBSim once w/o integrating copy_from_JSBsim(); //update the bus @@ -285,8 +307,6 @@ FGJSBsim::update( double dt ) { trimmed->setBoolValue(false); - - if ( needTrim ) { if ( startup_trim->getBoolValue() ) { SG_LOG(SG_FLIGHT, SG_INFO, @@ -374,12 +394,14 @@ bool FGJSBsim::copy_to_JSBsim() { Position->SetRunwayRadius( get_Runway_altitude() + get_Sea_level_radius() ); - Atmosphere->SetExTemperature(get_Static_temperature()); - Atmosphere->SetExPressure(get_Static_pressure()); - Atmosphere->SetExDensity(get_Density()); - Atmosphere->SetWindNED(get_V_north_airmass(), - get_V_east_airmass(), - get_V_down_airmass()); + Atmosphere->SetExTemperature( + 9.0/5.0*(temperature->getDoubleValue()+273.15) ); + Atmosphere->SetExPressure(pressure->getDoubleValue()*70.726566); + Atmosphere->SetExDensity(density->getDoubleValue()); + + Atmosphere->SetWindNED( wind_from_north->getDoubleValue(), + wind_from_east->getDoubleValue(), + wind_from_down->getDoubleValue() ); // SG_LOG(SG_FLIGHT,SG_INFO, "Wind NED: " // << get_V_north_airmass() << ", " // << get_V_east_airmass() << ", " @@ -698,44 +720,6 @@ void FGJSBsim::set_Gamma_vert_rad( double gamma) { needTrim=true; } -// void FGJSBsim::set_Static_pressure(double p) { -// SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_pressure: " << p ); - -// update_ic(); -// Atmosphere->SetExPressure(p); -// if(Atmosphere->External() == true) -// needTrim=true; -// } - -// void FGJSBsim::set_Static_temperature(double T) { -// SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Static_temperature: " << T ); - -// Atmosphere->SetExTemperature(T); -// if(Atmosphere->External() == true) -// needTrim=true; -// } - - -// void FGJSBsim::set_Density(double rho) { -// SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Density: " << rho ); - -// Atmosphere->SetExDensity(rho); -// if(Atmosphere->External() == true) -// needTrim=true; -// } - -void FGJSBsim::set_Velocities_Local_Airmass (double wnorth, - double weast, - double wdown ) { - //SG_LOG(SG_FLIGHT,SG_INFO, "FGJSBsim::set_Velocities_Local_Airmass: " - // << wnorth << ", " << weast << ", " << wdown ); - - _set_Velocities_Local_Airmass( wnorth, weast, wdown ); - fgic->SetWindNEDFpsIC( wnorth, weast, wdown ); - if(Atmosphere->External() == true) - needTrim=true; -} - void FGJSBsim::init_gear(void ) { FGGroundReactions* gr=fdmex->GetGroundReactions(); @@ -770,7 +754,7 @@ void FGJSBsim::update_gear(void) { void FGJSBsim::do_trim(void) { FGTrim *fgtrim; - if(fgic->GetVcalibratedKtsIC() < 10 ) { + if( fgGetBool("/sim/startup/onground") ) { fgic->SetVcalibratedKtsIC(0.0); fgtrim=new FGTrim(fdmex,fgic,tGround); } else { diff --git a/src/FDM/JSBSim/JSBSim.hxx b/src/FDM/JSBSim/JSBSim.hxx index e727624ad..dbb294bda 100644 --- a/src/FDM/JSBSim/JSBSim.hxx +++ b/src/FDM/JSBSim/JSBSim.hxx @@ -199,9 +199,6 @@ public: @param wnorth velocity north in fps @param weast velocity east in fps @param wdown velocity down in fps*/ - void set_Velocities_Local_Airmass (double wnorth, - double weast, - double wdown ); /// @name Position Parameter Update //@{ @@ -259,6 +256,14 @@ private: SGPropertyNode *gear_pos_pct; + SGPropertyNode *temperature; + SGPropertyNode *pressure; + SGPropertyNode *density; + + SGPropertyNode *wind_from_north; + SGPropertyNode *wind_from_east; + SGPropertyNode *wind_from_down; + void init_gear(void); void update_gear(void); -- 2.39.2