diff --git a/src/Autopilot/newauto.cxx b/src/Autopilot/newauto.cxx index b021a7860..8c3d575fc 100644 --- a/src/Autopilot/newauto.cxx +++ b/src/Autopilot/newauto.cxx @@ -375,10 +375,11 @@ int FGAutopilot::run() { // localizers radials are "true" tgt_radial = current_radiostack->get_nav1_radial(); } else { - tgt_radial = current_radiostack->get_nav1_radial() - + FGBFI::getMagVar(); + tgt_radial = current_radiostack->get_nav1_radial() + + current_radiostack->get_nav1_magvar(); } - cur_radial = current_radiostack->get_nav1_heading(); + cur_radial = current_radiostack->get_nav1_heading() + + current_radiostack->get_nav1_magvar(); // cout << "target rad (true) = " << tgt_radial // << " current rad (true) = " << cur_radial // << endl; @@ -394,6 +395,7 @@ int FGAutopilot::run() { TargetHeading = cur_radial - diff; while ( TargetHeading < 0.0 ) { TargetHeading += 360.0; } while ( TargetHeading > 360.0 ) { TargetHeading -= 360.0; } + MakeTargetHeadingStr( TargetHeading ); // cout << "target course (true) = " << TargetHeading << endl; } else if ( heading_mode == FG_HEADING_WAYPOINT ) { // update target heading to waypoint diff --git a/src/Cockpit/radiostack.cxx b/src/Cockpit/radiostack.cxx index da63eeef4..da20288aa 100644 --- a/src/Cockpit/radiostack.cxx +++ b/src/Cockpit/radiostack.cxx @@ -209,7 +209,7 @@ FGRadioStack::update() geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG, nav1_loclat, nav1_loclon, &az1, &az2, &s ); - cout << "az1 = " << az1 << " magvar = " << nav1_magvar << endl; + // cout << "az1 = " << az1 << " magvar = " << nav1_magvar << endl; nav1_heading = az1 - nav1_magvar; // Alex: nav1_heading = - (az1 - FGBFI::getMagVar() / RAD_TO_DEG); diff --git a/src/Cockpit/radiostack.hxx b/src/Cockpit/radiostack.hxx index 432b8cf90..401494318 100644 --- a/src/Cockpit/radiostack.hxx +++ b/src/Cockpit/radiostack.hxx @@ -202,6 +202,7 @@ public: inline double get_nav1_heading() const { return nav1_heading; } inline double get_nav1_radial() const { return nav1_radial; } inline double get_nav1_target_gs() const { return nav1_target_gs; } + inline double get_nav1_magvar() const { return nav1_magvar; } inline bool get_nav2_inrange() const { return nav2_inrange; } bool get_nav2_to_flag () const; @@ -225,6 +226,7 @@ public: inline double get_nav2_heading() const { return nav2_heading; } inline double get_nav2_radial() const { return nav2_radial; } inline double get_nav2_target_gs() const { return nav2_target_gs; } + inline double get_nav2_magvar() const { return nav2_magvar; } inline bool get_adf_inrange() const { return adf_inrange; } inline double get_adf_lon() const { return adf_lon; } diff --git a/src/Cockpit/steam.cxx b/src/Cockpit/steam.cxx index 3c4f93b62..7b4802709 100644 --- a/src/Cockpit/steam.cxx +++ b/src/Cockpit/steam.cxx @@ -130,9 +130,6 @@ void FGSteam::update ( int timesteps ) _UpdatesPending += timesteps; } -#undef DF1 -#undef DF2 - /* tc should be (elapsed_time_between_updates / desired_smoothing_time) */ void FGSteam::set_lowpass ( double *outthe, double inthe, double tc ) @@ -169,11 +166,10 @@ void FGSteam::set_lowpass ( double *outthe, double inthe, double tc ) double pressInHgToAltFt(double p_inhg) { // Ref. Aviation Formulary, Ed Williams, www.best.com/~williams/avform.htm - const double P_0 = 29.92126; // Std. MSL pressure, inHg. (=10135.25 mb) + const double P_0 = 29.92126; // Std. MSL pressure, inHg. (=1013.25 mb) const double p_Tr = 0.2233609 * P_0; // Pressure at tropopause, same units. const double h_Tr = 36089.24; // Alt of tropopause, ft. (=11.0 km) - // return (P_0 - p_inhg) * 1000.0; // ### crude approx. for low alt's if (p_inhg > p_Tr) // 0.0 to 11.0 km return (1.0 - pow((p_inhg / P_0), 1.0 / 5.2558797)) / 6.8755856e-6; return h_Tr + log10(p_inhg / p_Tr) / -4.806346e-5; // 11.0 to 20.0 km @@ -181,6 +177,21 @@ double pressInHgToAltFt(double p_inhg) } +// Convert altitude to air pressure by ICAO Standard Atmosphere +double altFtToPressInHg(double alt_ft) +{ + // Ref. Aviation Formulary, Ed Williams, www.best.com/~williams/avform.htm + const double P_0 = 29.92126; // Std. MSL pressure, inHg. (=1013.25 mb) + const double p_Tr = 0.2233609 * P_0; // Pressure at tropopause, same units. + const double h_Tr = 36089.24; // Alt of tropopause, ft. (=11.0 km) + + if (alt_ft < h_Tr) // 0.0 to 11.0 km + return P_0 * pow(1.0 - 6.8755856e-6 * alt_ft, 5.2558797); + return p_Tr * exp(-4.806346e-5 * (alt_ft - h_Tr)); // 11.0 to 20.0 km + // We could put more code for higher altitudes here. +} + + //////////////////////////////////////////////////////////////////////// // Here the fun really begins @@ -322,13 +333,7 @@ void FGSteam::_CatchUp() We filter the actual value by one second to account for the line impedance of the plumbing. */ - double static_inhg = 29.92; - i = (int) FGBFI::getAltitude(); - while ( i > 9000 ) - { static_inhg *= 0.707; - i -= 9000; - } - static_inhg *= ( 1.0 - 0.293 * i / 9000.0 ); + double static_inhg = altFtToPressInHg(FGBFI::getAltitude()); set_lowpass ( & the_STATIC_inhg, static_inhg, dt ); /* @@ -429,9 +434,9 @@ double FGSteam::get_HackVOR1_deg () { if ( current_radiostack->get_nav1_inrange() ) { r = current_radiostack->get_nav1_heading() - current_radiostack->get_nav1_radial(); - cout << "Radial = " << current_radiostack->get_nav1_radial() - << " Bearing = " << current_radiostack->get_nav1_heading() - << endl; + // cout << "Radial = " << current_radiostack->get_nav1_radial() + // << " Bearing = " << current_radiostack->get_nav1_heading() + // << endl; if (r> 180.0) r-=360.0; else if (r<-180.0) r+=360.0; diff --git a/src/Navaids/Makefile.am b/src/Navaids/Makefile.am index 2f893375a..057daf917 100644 --- a/src/Navaids/Makefile.am +++ b/src/Navaids/Makefile.am @@ -8,6 +8,9 @@ libNavaids_a_SOURCES = \ nav.hxx navlist.hxx navlist.cxx testnavs_SOURCES = testnavs.cxx -testnavs_LDADD = libNavaids.a -lsgmath -lsgmisc -lsgdebug -lsgmagvar -lz +testnavs_LDADD = \ + libNavaids.a \ + -lsgtiming -lsgmath -lsgmisc -lsgdebug -lsgmagvar \ + -lz INCLUDES += -I$(top_srcdir) -I$(top_srcdir)/src diff --git a/src/Navaids/nav.hxx b/src/Navaids/nav.hxx index 84bd8132e..a845e31ca 100644 --- a/src/Navaids/nav.hxx +++ b/src/Navaids/nav.hxx @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef FG_HAVE_STD_INCLUDES # include @@ -95,7 +96,16 @@ operator >> ( istream& in, FGNav& n ) double f; char c /* , magvar_dir */ ; string magvar_s; - + + static SGTime time_params; + static bool first_time = true; + static double julian_date = 0; + if ( first_time ) { + time_params.update( 0.0, 0.0, 0 ); + julian_date = time_params.getJD(); + first_time = false; + } + in >> n.type >> n.lat >> n.lon >> n.elev >> f >> n.range >> c >> n.ident >> magvar_s; @@ -110,9 +120,12 @@ operator >> ( istream& in, FGNav& n ) // cout << "Calculating magvar for navaid " << n.ident << endl; if (magvar_s == "XXX") { // default to mag var as of 1990-01-01 (Julian 2447892.5) - n.magvar = -sgGetMagVar(n.lon * DEG_TO_RAD, n.lat * DEG_TO_RAD, + // cout << "lat = " << n.lat << " lon = " << n.lon << " elev = " + // << n.elev << " JD = " + // << julian_date << endl; + n.magvar = sgGetMagVar(n.lon * DEG_TO_RAD, n.lat * DEG_TO_RAD, n.elev * FEET_TO_METER, - 2447892.5) * RAD_TO_DEG; + julian_date) * RAD_TO_DEG; // cout << "Default variation at " << n.lon << ',' << n.lat // << " is " << var << endl; #if 0 @@ -134,7 +147,7 @@ operator >> ( istream& in, FGNav& n ) n.magvar = 0 - n.magvar; // cout << "Explicit magvar of " << n.magvar << endl; } - cout << n.ident << " " << n.magvar << endl; + // cout << n.ident << " " << n.magvar << endl; // generate cartesian coordinates Point3D geod( n.lon * DEG_TO_RAD, n.lat * DEG_TO_RAD, n.elev ); diff --git a/src/Navaids/navlist.cxx b/src/Navaids/navlist.cxx index 7c3c21d04..abf7e104c 100644 --- a/src/Navaids/navlist.cxx +++ b/src/Navaids/navlist.cxx @@ -45,9 +45,6 @@ FGNavList::~FGNavList( void ) { bool FGNavList::init( FGPath path ) { FGNav n; - SGTime time_params; - time_params.update( 0.0, 0.0, 0 ); - navaids.erase( navaids.begin(), navaids.end() ); fg_gzifstream in( path.str() );