"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");
// 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 ) {
&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 );
+ }
}
// 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();
FGRunway r;
if ( runways->search(id, rwy, &r) ) {
- update_loc_position( (*loc), &r );
+ update_loc_position( (*loc), &r, threshold );
}
++loc;
}
// 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