]> git.mxchange.org Git - flightgear.git/commitdiff
Updated FGILSList api to better match the FGNavList api.
authorcurt <curt>
Mon, 3 Feb 2003 20:05:27 +0000 (20:05 +0000)
committercurt <curt>
Mon, 3 Feb 2003 20:05:27 +0000 (20:05 +0000)
src/Navaids/ilslist.cxx
src/Navaids/ilslist.hxx
src/Navaids/navlist.cxx
src/Navaids/testnavs.cxx

index 151c87b89aa0c898fe9f86230990ad5492180aeb..abbff312acf783eec938d90c568b9cfddf7f0ed4 100644 (file)
@@ -72,10 +72,10 @@ bool FGILSList::init( SGPath path ) {
 #else
     while ( ! in.eof() ) {
 #endif
-
-        FGILS ils;
-        in >> ils;
-        if ( ils.get_ilstype() == '[' ) {
+        
+        FGILS *ils = new FGILS;
+        in >> (*ils);
+        if ( ils->get_ilstype() == '[' ) {
             break;
         }
 
@@ -85,7 +85,7 @@ bool FGILSList::init( SGPath path ) {
         cout << " locfreq = " << ils.get_locfreq() << endl;
         cout << " locident = " << ils.get_locident() << endl << endl; */
 
-        ilslist[ils.get_locfreq()].push_back(ils);
+        ilslist[ils->get_locfreq()].push_back(ils);
         in >> skipcomment;
 
        /* if ( ils.get_locfreq() < min ) {
@@ -96,20 +96,20 @@ bool FGILSList::init( SGPath path ) {
        } */
 
        // update the marker beacon list
-       if ( fabs(ils.get_omlon()) > SG_EPSILON ||
-            fabs(ils.get_omlat()) > SG_EPSILON ) {
-           current_beacons->add( ils.get_omlon(), ils.get_omlat(),
-                                 ils.get_gselev(), FGMkrBeacon::OUTER );
+       if ( fabs(ils->get_omlon()) > SG_EPSILON ||
+            fabs(ils->get_omlat()) > SG_EPSILON ) {
+           current_beacons->add( ils->get_omlon(), ils->get_omlat(),
+                                 ils->get_gselev(), FGMkrBeacon::OUTER );
        }
-       if ( fabs(ils.get_mmlon()) > SG_EPSILON ||
-            fabs(ils.get_mmlat()) > SG_EPSILON ) {
-           current_beacons->add( ils.get_mmlon(), ils.get_mmlat(),
-                                 ils.get_gselev(), FGMkrBeacon::MIDDLE );
+       if ( fabs(ils->get_mmlon()) > SG_EPSILON ||
+            fabs(ils->get_mmlat()) > SG_EPSILON ) {
+           current_beacons->add( ils->get_mmlon(), ils->get_mmlat(),
+                                 ils->get_gselev(), FGMkrBeacon::MIDDLE );
        }
-       if ( fabs(ils.get_imlon()) > SG_EPSILON ||
-            fabs(ils.get_imlat()) > SG_EPSILON ) {
-           current_beacons->add( ils.get_imlon(), ils.get_imlat(),
-                                 ils.get_gselev(), FGMkrBeacon::INNER );
+       if ( fabs(ils->get_imlon()) > SG_EPSILON ||
+            fabs(ils->get_imlat()) > SG_EPSILON ) {
+           current_beacons->add( ils->get_imlon(), ils->get_imlat(),
+                                 ils->get_gselev(), FGMkrBeacon::INNER );
        }
     }
 
@@ -120,32 +120,32 @@ bool FGILSList::init( SGPath path ) {
 }
 
 
-// query the database for the specified frequency, lon and lat are in
-// degrees, elev is in meters
-bool FGILSList::query( double lon, double lat, double elev, double freq,
-                      FGILS *ils )
+// Query the database for the specified frequency.  It is assumed that
+// there will be multiple stations with matching frequencies so a
+// position must be specified.  Lon and lat are in degrees, elev is in
+// meters.
+FGILS *FGILSList::findByFreq( double freq,
+                              double lon, double lat, double elev )
 {
-    ils_list_type stations = ilslist[(int)(freq*100.0 + 0.5)];
+    FGILS *ils = NULL;
 
-    ils_list_iterator current = stations.begin();
-    ils_list_iterator last = stations.end();
+    ils_list_type stations = ilslist[(int)(freq*100.0 + 0.5)];
 
     double best_angle = 362.0;
-    bool found_one = false;
 
     // double az1, az2, s;
     Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
     Point3D station;
-    double d;
-    for ( ; current != last ; ++current ) {
+    double d2;
+    for ( unsigned int i = 1; i < stations.size(); ++i ) {
        // cout << "  testing " << current->get_locident() << endl;
-       station = Point3D(current->get_x(), 
-                         current->get_y(),
-                         current->get_z());
+       station = Point3D(stations[i]->get_x(), 
+                         stations[i]->get_y(),
+                         stations[i]->get_z());
        // cout << "    aircraft = " << aircraft << " station = " << station 
        //      << endl;
 
-       d = aircraft.distance3Dsquared( station );
+       d2 = aircraft.distance3Dsquared( station );
        // cout << "  distance = " << d << " (" 
        //      << FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER 
        //         * FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER
@@ -154,34 +154,36 @@ bool FGILSList::query( double lon, double lat, double elev, double freq,
        // cout << "  dist = " << s << endl;
 
        // match up to twice the published range so we can model
-       // reduced signal strength
-       if ( d < (2* FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER 
-                 * 2 * FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER) ) {
-
-            found_one = true;
+       // reduced signal strength.  The assumption is that there will
+       // be maximum of two possbile stations of a particular
+       // frequency in range.  If two exist, one will be associated
+       // with each end of the runway.  In this case, pick the
+       // station pointing most directly at us.
+       if ( d2 < (2* FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER 
+                   * 2 * FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER) ) {
 
             // Get our bearing from this station.
             double reciprocal_bearing, dummy;
             double a_lat_deg = lat * SGD_RADIANS_TO_DEGREES;
             double a_lon_deg = lon * SGD_RADIANS_TO_DEGREES;
             // Locator beam direction
-            double s_ils_deg = current->get_locheading() - 180.0;
+            double s_ils_deg = stations[i]->get_locheading() - 180.0;
             if ( s_ils_deg < 0.0 ) { s_ils_deg += 360.0; }
             double angle_to_beam_deg;
 
             // printf("**ALI geting geo_inverse_wgs_84 with elev = %.2f, a.lat = %.2f, a.lon = %.2f,
-            // s.lat = %.2f, s.lon = %.2f\n", elev,a_lat_deg,a_lon_deg,current->get_loclat(),current->get_loclon());
+            // s.lat = %.2f, s.lon = %.2f\n", elev,a_lat_deg,a_lon_deg,stations[i]->get_loclat(),stations[i]->get_loclon());
 
-            geo_inverse_wgs_84( elev, current->get_loclat(),
-                                current->get_loclon(), a_lat_deg, a_lon_deg,
+            geo_inverse_wgs_84( elev, stations[i]->get_loclat(),
+                                stations[i]->get_loclon(), a_lat_deg, a_lon_deg,
                                 &reciprocal_bearing, &dummy, &dummy );
             angle_to_beam_deg = fabs(reciprocal_bearing - s_ils_deg);
             if ( angle_to_beam_deg <= best_angle ) {
-                *ils = *current;
+                *ils = *stations[i];
                 best_angle = angle_to_beam_deg;
             }
        }
     }
 
-    return found_one;
+    return ils;
 }
index 8d13a58798b090fe1613f6f5981a4afde0f67229..1538b14d80b4f25fe16593bd9a67443cbd6ae51e 100644 (file)
@@ -40,7 +40,7 @@ SG_USING_STD(vector);
 class FGILSList {
 
     // convenience types
-    typedef vector < FGILS > ils_list_type;
+    typedef vector < FGILS* > ils_list_type;
     typedef ils_list_type::iterator ils_list_iterator;
     typedef ils_list_type::const_iterator ils_list_const_iterator;
 
@@ -61,7 +61,14 @@ public:
 
     // query the database for the specified frequency, lon and lat are
     // in degrees, elev is in meters
-    bool query( double lon, double lat, double elev, double freq, FGILS *i );
+    // bool query( double lon, double lat, double elev, double freq, FGILS *i );
+
+    // Query the database for the specified frequency.  It is assumed
+    // that there will be multiple stations with matching frequencies
+    // so a position must be specified.  Lon and lat are in degrees,
+    // elev is in meters.
+    FGILS *findByFreq( double freq, double lon, double lat, double elev );
+
 };
 
 
index 09395daa490fb60863efb958aef62ca8f0cefa67..44c830166bf7937aebc0d31a52deb61fd87e8021 100644 (file)
@@ -162,7 +162,7 @@ FGNav *FGNavList::findNavFromList( const Point3D &aircraft,
     FGNav *nav = NULL;
     Point3D station;
     double d2;
-    double min_dist;
+    double min_dist = 999999999.0;
 
     // prime the pump with info from stations[0]
     if ( stations.size() > 0 ) {
@@ -174,8 +174,9 @@ FGNav *FGNavList::findNavFromList( const Point3D &aircraft,
     // check if any of the remaining stations are closer
     for ( unsigned int i = 1; i < stations.size(); ++i ) {
        // cout << "testing " << current->get_ident() << endl;
-       station = Point3D( stations[i]->get_x(), stations[i]->get_y(),
-                           stations[i]->get_z());
+       station = Point3D( stations[i]->get_x(),
+                           stations[i]->get_y(),
+                           stations[i]->get_z() );
 
        d2 = aircraft.distance3Dsquared( station );
 
index b18455bf115c3eb42a76e9e6d7185d4ae95138c6..6afc189335f78da190d79d3126f7aa7f4fb0e2b9 100644 (file)
@@ -48,14 +48,13 @@ int main() {
     current_ilslist = new FGILSList;
     SGPath p_ils( FG_DATA_DIR + "/Navaids/default.ils" );
     current_ilslist->init( p_ils );
-    FGILS i;
-    if ( current_ilslist->query( -93.1 * SG_DEGREES_TO_RADIANS,
-                                 45.24 * SG_DEGREES_TO_RADIANS,
-                                 3000, 110.30, &i) )
-    {
+    FGILS *i = current_ilslist->findByFreq( -93.1 * SG_DEGREES_TO_RADIANS,
+                                            45.24 * SG_DEGREES_TO_RADIANS,
+                                            3000, 110.30);
+    if ( i != NULL ) {
        cout << "Found an ils station in range" << endl;
-       cout << " apt = " << i.get_aptcode() << endl;
-       cout << " rwy = " << i.get_rwyno() << endl;
+       cout << " apt = " << i->get_aptcode() << endl;
+       cout << " rwy = " << i->get_rwyno() << endl;
     } else {
        cout << "not picking up ils. :-(" << endl;
     }