From a08f4c084b7d8bd21ac446aa536bf3d0ed0f57c0 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 28 May 2004 20:57:05 +0000 Subject: [PATCH] Allow a "threshold" value to determine which localizers to snap to the runway heading or not. --- src/Main/fg_init.cxx | 7 +++++-- src/Navaids/navdb.cxx | 29 +++++++++++++++++++++-------- src/Navaids/navdb.hxx | 3 ++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index a9c583d7a..43f699fd6 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1062,12 +1062,15 @@ fgInitNav () "Problems loading one or more navigational database" ); } - if ( fgGetBool("/sim/navdb/auto-align-localizers", true) ) { + if ( fgGetBool("/sim/navdb/localizers/auto-align", true) ) { // align all the localizers with their corresponding runways // since data sources are good for cockpit navigation // purposes, but not always to the error tolerances needed to // exactly place these items. - fgNavDBAlignLOCwithRunway( runways, loclist ); + double threshold + = fgGetDouble( "/sim/navdb/localizers/auto-align-threshold-deg", + 5.0 ); + fgNavDBAlignLOCwithRunway( runways, loclist, threshold ); } SG_LOG(SG_GENERAL, SG_INFO, " Fixes"); diff --git a/src/Navaids/navdb.cxx b/src/Navaids/navdb.cxx index f26791120..92253f357 100644 --- a/src/Navaids/navdb.cxx +++ b/src/Navaids/navdb.cxx @@ -121,8 +121,9 @@ bool fgNavDBInit( FGNavList *navlist, FGNavList *loclist, FGNavList *gslist, // Given a localizer record and it's corresponding runway record, // adjust the localizer position so it is in perfect alignment with // the runway. -static void update_loc_position( FGNavRecord *loc, FGRunway *rwy ) { - +static void update_loc_position( FGNavRecord *loc, FGRunway *rwy, + double threshold ) +{ double hdg = rwy->heading; hdg += 180.0; if ( hdg > 360.0 ) { @@ -155,12 +156,23 @@ static void update_loc_position( FGNavRecord *loc, FGRunway *rwy ) { &az1, &az2, &dist_m ); // cout << "Distance moved = " << dist_m << endl; - loc->set_lat( nloc_lat ); - loc->set_lon( nloc_lon ); - loc->set_multiuse( rwy->heading ); - // cout << "orig heading = " << loc->get_multiuse() << endl; // cout << "new heading = " << rwy->heading << endl; + + double hdg_diff = loc->get_multiuse() - rwy->heading; + + // clamp to [-180.0 ... 180.0] + if ( hdg_diff < -180.0 ) { + hdg_diff += 360.0; + } else if ( hdg_diff > 180.0 ) { + hdg_diff -= 360.0; + } + + if ( fabs(hdg_diff) <= threshold ) { + loc->set_lat( nloc_lat ); + loc->set_lon( nloc_lon ); + loc->set_multiuse( rwy->heading ); + } } @@ -169,7 +181,8 @@ static void update_loc_position( FGNavRecord *loc, FGRunway *rwy ) { // it then "moves" the localizer and updates it's heading so it // *perfectly* aligns with the runway, but is still the same distance // from the runway threshold. -void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist ) { +void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist, + double threshold ) { nav_map_type navmap = loclist->get_navaids(); nav_map_iterator freq = navmap.begin(); @@ -186,7 +199,7 @@ void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist ) { FGRunway r; if ( runways->search(id, rwy, &r) ) { - update_loc_position( (*loc), &r ); + update_loc_position( (*loc), &r, threshold ); } ++loc; } diff --git a/src/Navaids/navdb.hxx b/src/Navaids/navdb.hxx index 36f1bdc42..5f0c39ff9 100644 --- a/src/Navaids/navdb.hxx +++ b/src/Navaids/navdb.hxx @@ -50,7 +50,8 @@ bool fgNavDBInit( FGNavList *navlist, FGNavList *loclist, FGNavList *gslist, // it then "moves" the localizer and updates it's heading so it // *perfectly* aligns with the runway, but is still the same distance // from the runway threshold. -void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist ); +void fgNavDBAlignLOCwithRunway( FGRunwayList *runways, FGNavList *loclist, + double threshold ); #endif // _FG_NAVDB_HXX