1 // navrecord.cxx -- generic vor/dme/ndb class
3 // Written by Curtis Olson, started May 2004.
5 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
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>
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>
43 #include <Main/fg_props.hxx>
44 #include <Navaids/PositionedBinding.hxx>
46 FGNavRecord::FGNavRecord(Type aTy, const std::string& aIdent,
47 const std::string& aName, const SGGeod& aPos,
48 int aFreq, int aRange, double aMultiuse) :
49 FGPositioned(aTy, aIdent, aPos),
57 initAirportRelation();
59 // Ranges are included with the latest data format, no need to
60 // assign our own defaults, unless the range is not set for some
63 SG_LOG(SG_GENERAL, SG_DEBUG, "navaid " << ident() << " has no range set, using defaults");
67 range = FG_NAV_DEFAULT_RANGE;
73 range = FG_LOC_DEFAULT_RANGE;
77 range = FG_DME_DEFAULT_RANGE;
81 range = FG_LOC_DEFAULT_RANGE;
85 init(true); // init FGPositioned (now position is adjusted)
88 void FGNavRecord::initAirportRelation()
90 if ((type() < ILS) || (type() > GS)) {
91 return; // not airport-located
94 mRunway = getRunwayFromName(_name);
100 SGPropertyNode* ilsData = ilsDataForRunwayAndNavaid(mRunway, ident());
102 processSceneryILS(ilsData);
106 // fudge elevation to the runway elevation if it's not specified
107 if (fabs(elevation()) < 0.01) {
108 mPosition.setElevationFt(mRunway->elevation());
111 if (type() == ILS || type() == LOC) {
112 mRunway->setILS(this);
115 // align localizers with their runway
116 if ((type() == ILS) || (type() == LOC)) {
117 if (!fgGetBool("/sim/navdb/localizers/auto-align", true)) {
122 = fgGetDouble( "/sim/navdb/localizers/auto-align-threshold-deg", 5.0 );
123 alignLocaliserWithRunway(threshold);
127 void FGNavRecord::processSceneryILS(SGPropertyNode* aILSNode)
129 double hdgDeg = aILSNode->getDoubleValue("hdg-deg"),
130 lon = aILSNode->getDoubleValue("lon"),
131 lat = aILSNode->getDoubleValue("lat"),
132 elevM = aILSNode->getDoubleValue("elev-m");
134 mPosition = SGGeod::fromDegM(lon, lat, elevM);
138 void FGNavRecord::alignLocaliserWithRunway(double aThreshold)
140 // find the distance from the threshold to the localizer
141 double dist = SGGeodesy::distanceM(mPosition, mRunway->threshold());
143 // back project that distance along the runway center line
144 SGGeod newPos = mRunway->pointOnCenterline(dist);
146 double hdg_diff = get_multiuse() - mRunway->headingDeg();
147 SG_NORMALIZE_RANGE(hdg_diff, -180.0, 180.0);
149 if ( fabs(hdg_diff) <= aThreshold ) {
150 mPosition = SGGeod::fromGeodFt(newPos, mPosition.getElevationFt());
151 set_multiuse( mRunway->headingDeg() );
153 SG_LOG(SG_GENERAL, SG_DEBUG, "localizer:" << ident() << ", aligning with runway "
154 << mRunway->ident() << " exceeded heading threshold");
158 double FGNavRecord::localizerWidth() const
164 SGVec3d thresholdCart(SGVec3d::fromGeod(mRunway->threshold()));
165 double axisLength = dist(cart(), thresholdCart);
166 double landingLength = dist(thresholdCart, SGVec3d::fromGeod(mRunway->end()));
168 // Reference: http://dcaa.slv.dk:8000/icaodocs/
169 // ICAO standard width at threshold is 210 m = 689 feet = approx 700 feet.
170 // ICAO 3.1.1 half course = DDM = 0.0775
171 // ICAO 3.1.3.7.1 Sensitivity 0.00145 DDM/m at threshold
172 // implies peg-to-peg of 214 m ... we will stick with 210.
173 // ICAO 3.1.3.7.1 "Course sector angle shall not exceed 6 degrees."
175 // Very short runway: less than 1200 m (4000 ft) landing length:
176 if (landingLength < 1200.0) {
177 // ICAO fudges localizer sensitivity for very short runways.
178 // This produces a non-monotonic sensitivity-versus length relation.
179 axisLength += 1050.0;
182 // Example: very short: San Diego KMYF (Montgomery Field) ILS RWY 28R
183 // Example: short: Tom's River KMJX (Robert J. Miller) ILS RWY 6
184 // Example: very long: Denver KDEN (Denver) ILS RWY 16R
185 double raw_width = 210.0 / axisLength * SGD_RADIANS_TO_DEGREES;
186 return raw_width < 6.0? raw_width : 6.0;
190 flightgear::PositionedBinding*
191 FGNavRecord::createBinding(SGPropertyNode* nd) const
193 return new flightgear::NavaidBinding(this, nd);
197 FGTACANRecord::FGTACANRecord(void) :
205 operator >> ( std::istream& in, FGTACANRecord& n )
207 in >> n.channel >> n.freq ;
208 //getline( in, n.name );