]> git.mxchange.org Git - flightgear.git/commitdiff
Working on ironing out issues with VOR navigation. It think we are "as
authorcurt <curt>
Fri, 2 Feb 2001 05:25:45 +0000 (05:25 +0000)
committercurt <curt>
Fri, 2 Feb 2001 05:25:45 +0000 (05:25 +0000)
good as we can get" until we find a data source with actual VOR magnetic
offsets.  We can use VOR offsets from some fixed date, but not all VOR's
were installed on the same day so no matter what date we pick we will be off on most of them.

src/Autopilot/newauto.cxx
src/Cockpit/radiostack.cxx
src/Cockpit/radiostack.hxx
src/Cockpit/steam.cxx
src/Navaids/Makefile.am
src/Navaids/nav.hxx
src/Navaids/navlist.cxx

index b021a786097717fb9ce0dffc5b30ece563cc8b7b..8c3d575fcccf64140eddefda88a2f755a116ec4e 100644 (file)
@@ -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
index da63eeef4c1a74bf8170e9893295e8bde89041b8..da20288aa0302ed2a85f5abb55dcd2237090f318 100644 (file)
@@ -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);
 
index 432b8cf90e718747424ffc83b388da9d3c7bf552..4014943185924daef911f0f4fdcee2e5e5d0bd28 100644 (file)
@@ -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; }
index 3c4f93b62e38cbdafa6a86f6531d2147199dd421..7b4802709d104489c848fc890f47f9fc2df085de 100644 (file)
@@ -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.
+}
+
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // 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;
index 2f893375ae681646643fb71ee7bb22ce09cce4d0..057daf917ca84a7afca648c3178c1e8e31bea5a7 100644 (file)
@@ -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
index 84bd8132ee28f67cf3c9bf18d44c9c9bdfcf36b7..a845e31cad3bcd4a4c61d147b7ad1212f4574432 100644 (file)
@@ -30,6 +30,7 @@
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/fgstream.hxx>
 #include <simgear/magvar/magvar.hxx>
+#include <simgear/timing/sg_time.hxx>
 
 #ifdef FG_HAVE_STD_INCLUDES
 #  include <istream>
@@ -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 );
index 7c3c21d0424ce4a8c09c1702ea7c6a405069d157..abf7e104cb1599b341513b10ec2bf66a30f915a2 100644 (file)
@@ -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() );