]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/navrecord.cxx
Reduce severity of a failure to create a marker beacon due to an unknown runway from...
[flightgear.git] / src / Navaids / navrecord.cxx
1 // navrecord.cxx -- generic vor/dme/ndb class
2 //
3 // Written by Curtis Olson, started May 2004.
4 //
5 // Copyright (C) 2004  Curtis L. Olson - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24   #include "config.h"
25 #endif
26
27 #include <istream>
28
29 #include <simgear/misc/sgstream.hxx>
30 #include <simgear/misc/sg_path.hxx>
31 #include <simgear/structure/exception.hxx>
32 #include <simgear/debug/logstream.hxx>
33 #include <simgear/sg_inlines.h>
34 #include <simgear/props/props.hxx>
35
36
37 #include <Navaids/navrecord.hxx>
38 #include <Navaids/navdb.hxx>
39 #include <Airports/runways.hxx>
40 #include <Airports/simple.hxx>
41 #include <Airports/xmlloader.hxx>
42 #include <Main/fg_props.hxx>
43
44 FGNavRecord::FGNavRecord(Type aTy, const std::string& aIdent, 
45   const std::string& aName, const SGGeod& aPos,
46   int aFreq, int aRange, double aMultiuse) :
47   FGPositioned(aTy, aIdent, aPos),
48   freq(aFreq),
49   range(aRange),
50   multiuse(aMultiuse),
51   _name(aName),
52   mRunway(NULL),
53   serviceable(true)
54
55   initAirportRelation();
56
57   // Ranges are included with the latest data format, no need to
58   // assign our own defaults, unless the range is not set for some
59   // reason.
60   if (range < 0.1) {
61     SG_LOG(SG_GENERAL, SG_DEBUG, "navaid " << ident() << " has no range set, using defaults");
62     switch (type()) {
63     case NDB:
64     case VOR:
65       range = FG_NAV_DEFAULT_RANGE;
66       break;
67     
68     case LOC:
69     case ILS:
70     case GS:
71       range = FG_LOC_DEFAULT_RANGE;
72       break;
73       
74     case DME:
75       range = FG_DME_DEFAULT_RANGE;
76       break;
77     
78     default:
79       range = FG_LOC_DEFAULT_RANGE;
80     }
81   }
82   
83   init(true); // init FGPositioned (now position is adjusted)
84 }
85
86 void FGNavRecord::initAirportRelation()
87 {
88   if ((type() < ILS) || (type() > GS)) {
89     return; // not airport-located
90   }
91   
92   mRunway = getRunwayFromName(_name);  
93   if (!mRunway) {
94     return;
95   }
96   
97   if (type() != GS) {
98     SGPropertyNode* ilsData = ilsDataForRunwayAndNavaid(mRunway, ident());
99     if (ilsData) {
100       processSceneryILS(ilsData);
101     }
102   }
103         
104   // fudge elevation to the runway elevation if it's not specified
105   if (fabs(elevation()) < 0.01) {
106     mPosition.setElevationFt(mRunway->elevation());
107   }
108   
109   if (type() == ILS || type() == LOC) {
110     mRunway->setILS(this);
111   }
112   
113   // align localizers with their runway
114   if ((type() == ILS) || (type() == LOC)) {
115     if (!fgGetBool("/sim/navdb/localizers/auto-align", true)) {
116       return;
117     }
118     
119    double threshold 
120      = fgGetDouble( "/sim/navdb/localizers/auto-align-threshold-deg", 5.0 );
121     alignLocaliserWithRunway(threshold);
122   }
123 }
124
125 void FGNavRecord::processSceneryILS(SGPropertyNode* aILSNode)
126 {
127   double hdgDeg = aILSNode->getDoubleValue("hdg-deg"),
128     lon = aILSNode->getDoubleValue("lon"),
129     lat = aILSNode->getDoubleValue("lat"),
130     elevM = aILSNode->getDoubleValue("elev-m");
131     
132   mPosition = SGGeod::fromDegM(lon, lat, elevM);
133   multiuse = hdgDeg;
134 }
135
136 void FGNavRecord::alignLocaliserWithRunway(double aThreshold)
137 {
138 // find the distance from the threshold to the localizer
139   double dist = SGGeodesy::distanceM(mPosition, mRunway->threshold());
140
141 // back project that distance along the runway center line
142   SGGeod newPos = mRunway->pointOnCenterline(dist);
143
144   double hdg_diff = get_multiuse() - mRunway->headingDeg();
145   SG_NORMALIZE_RANGE(hdg_diff, -180.0, 180.0);
146
147   if ( fabs(hdg_diff) <= aThreshold ) {
148     mPosition = SGGeod::fromGeodFt(newPos, mPosition.getElevationFt());
149     set_multiuse( mRunway->headingDeg() );
150   } else {
151     SG_LOG(SG_GENERAL, SG_DEBUG, "localizer:" << ident() << ", aligning with runway " 
152       << mRunway->ident() << " exceeded heading threshold");
153   }
154 }
155
156 double FGNavRecord::localizerWidth() const
157 {
158   if (!mRunway) {
159     return 6.0;
160   }
161   
162   SGVec3d thresholdCart(SGVec3d::fromGeod(mRunway->threshold()));
163   double axisLength = dist(cart(), thresholdCart);
164   double landingLength = dist(thresholdCart, SGVec3d::fromGeod(mRunway->end()));
165   
166 // Reference: http://dcaa.slv.dk:8000/icaodocs/
167 // ICAO standard width at threshold is 210 m = 689 feet = approx 700 feet.
168 // ICAO 3.1.1 half course = DDM = 0.0775
169 // ICAO 3.1.3.7.1 Sensitivity 0.00145 DDM/m at threshold
170 //  implies peg-to-peg of 214 m ... we will stick with 210.
171 // ICAO 3.1.3.7.1 "Course sector angle shall not exceed 6 degrees."
172               
173 // Very short runway:  less than 1200 m (4000 ft) landing length:
174   if (landingLength < 1200.0) {
175 // ICAO fudges localizer sensitivity for very short runways.
176 // This produces a non-monotonic sensitivity-versus length relation.
177     axisLength += 1050.0;
178   }
179
180 // Example: very short: San Diego   KMYF (Montgomery Field) ILS RWY 28R
181 // Example: short:      Tom's River KMJX (Robert J. Miller) ILS RWY 6
182 // Example: very long:  Denver      KDEN (Denver)           ILS RWY 16R
183   double raw_width = 210.0 / axisLength * SGD_RADIANS_TO_DEGREES;
184   return raw_width < 6.0? raw_width : 6.0;
185
186 }
187
188 FGTACANRecord::FGTACANRecord(void) :
189     channel(""),
190     freq(0)
191     
192 {
193 }
194
195 std::istream&
196 operator >> ( std::istream& in, FGTACANRecord& n )
197 {
198     in >> n.channel >> n.freq ;
199     //getline( in, n.name );
200
201     return in;
202 }