]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/navrecord.cxx
Merge branch 'next' of D:\Git_New\flightgear into next
[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
43 #include <Main/fg_props.hxx>
44 #include <Navaids/PositionedBinding.hxx>
45
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),
50   freq(aFreq),
51   range(aRange),
52   multiuse(aMultiuse),
53   _name(aName),
54   mRunway(NULL),
55   serviceable(true),
56   trans_ident(aIdent)
57
58   initAirportRelation();
59
60   // Ranges are included with the latest data format, no need to
61   // assign our own defaults, unless the range is not set for some
62   // reason.
63   if (range < 0.1) {
64     SG_LOG(SG_GENERAL, SG_WARN, "navaid " << ident() << " has no range set, using defaults");
65     switch (type()) {
66     case NDB:
67     case VOR:
68       range = FG_NAV_DEFAULT_RANGE;
69       break;
70     
71     case LOC:
72     case ILS:
73     case GS:
74       range = FG_LOC_DEFAULT_RANGE;
75       break;
76       
77     case DME:
78       range = FG_DME_DEFAULT_RANGE;
79       break;
80     
81     default:
82       range = FG_LOC_DEFAULT_RANGE;
83     }
84   }
85   
86   init(true); // init FGPositioned (now position is adjusted)
87 }
88
89 void FGNavRecord::initAirportRelation()
90 {
91   if ((type() < ILS) || (type() > GS)) {
92     return; // not airport-located
93   }
94   
95   mRunway = getRunwayFromName(_name);  
96   if (!mRunway) {
97     return;
98   }
99   
100   if (type() != GS) {
101     SGPropertyNode* ilsData = ilsDataForRunwayAndNavaid(mRunway, ident());
102     if (ilsData) {
103       processSceneryILS(ilsData);
104     }
105   }
106         
107   // fudge elevation to the runway elevation if it's not specified
108   if (fabs(elevation()) < 0.01) {
109     mPosition.setElevationFt(mRunway->elevation());
110   }
111   
112   if (type() == ILS || type() == LOC) {
113     mRunway->setILS(this);
114   }
115   
116   // align localizers with their runway
117   if ((type() == ILS) || (type() == LOC)) {
118     if (!fgGetBool("/sim/navdb/localizers/auto-align", true)) {
119       return;
120     }
121     
122    double threshold 
123      = fgGetDouble( "/sim/navdb/localizers/auto-align-threshold-deg", 5.0 );
124     alignLocaliserWithRunway(threshold);
125   }
126 }
127
128 void FGNavRecord::processSceneryILS(SGPropertyNode* aILSNode)
129 {
130   double hdgDeg = aILSNode->getDoubleValue("hdg-deg"),
131     lon = aILSNode->getDoubleValue("lon"),
132     lat = aILSNode->getDoubleValue("lat"),
133     elevM = aILSNode->getDoubleValue("elev-m");
134     
135   mPosition = SGGeod::fromDegM(lon, lat, elevM);
136   multiuse = hdgDeg;
137 }
138
139 void FGNavRecord::alignLocaliserWithRunway(double aThreshold)
140 {
141 // find the distance from the threshold to the localizer
142   double dist = SGGeodesy::distanceM(mPosition, mRunway->threshold());
143
144 // back project that distance along the runway center line
145   SGGeod newPos = mRunway->pointOnCenterline(dist);
146
147   double hdg_diff = get_multiuse() - mRunway->headingDeg();
148   SG_NORMALIZE_RANGE(hdg_diff, -180.0, 180.0);
149
150   if ( fabs(hdg_diff) <= aThreshold ) {
151     mPosition = SGGeod::fromGeodFt(newPos, mPosition.getElevationFt());
152     set_multiuse( mRunway->headingDeg() );
153   } else {
154     SG_LOG(SG_GENERAL, SG_DEBUG, "localizer:" << ident() << ", aligning with runway " 
155       << mRunway->ident() << " exceeded heading threshold");
156   }
157 }
158
159 double FGNavRecord::localizerWidth() const
160 {
161   if (!mRunway) {
162     return 6.0;
163   }
164   
165   SGVec3d thresholdCart(SGVec3d::fromGeod(mRunway->threshold()));
166   double axisLength = dist(cart(), thresholdCart);
167   double landingLength = dist(thresholdCart, SGVec3d::fromGeod(mRunway->end()));
168   
169 // Reference: http://dcaa.slv.dk:8000/icaodocs/
170 // ICAO standard width at threshold is 210 m = 689 feet = approx 700 feet.
171 // ICAO 3.1.1 half course = DDM = 0.0775
172 // ICAO 3.1.3.7.1 Sensitivity 0.00145 DDM/m at threshold
173 //  implies peg-to-peg of 214 m ... we will stick with 210.
174 // ICAO 3.1.3.7.1 "Course sector angle shall not exceed 6 degrees."
175               
176 // Very short runway:  less than 1200 m (4000 ft) landing length:
177   if (landingLength < 1200.0) {
178 // ICAO fudges localizer sensitivity for very short runways.
179 // This produces a non-monotonic sensitivity-versus length relation.
180     axisLength += 1050.0;
181   }
182
183 // Example: very short: San Diego   KMYF (Montgomery Field) ILS RWY 28R
184 // Example: short:      Tom's River KMJX (Robert J. Miller) ILS RWY 6
185 // Example: very long:  Denver      KDEN (Denver)           ILS RWY 16R
186   double raw_width = 210.0 / axisLength * SGD_RADIANS_TO_DEGREES;
187   return raw_width < 6.0? raw_width : 6.0;
188
189 }
190
191 flightgear::PositionedBinding*
192 FGNavRecord::createBinding(SGPropertyNode* nd) const
193 {
194     return new flightgear::NavaidBinding(this, nd);
195 }
196
197
198 FGTACANRecord::FGTACANRecord(void) :
199     channel(""),
200     freq(0)
201     
202 {
203 }
204
205 std::istream&
206 operator >> ( std::istream& in, FGTACANRecord& n )
207 {
208     in >> n.channel >> n.freq ;
209     //getline( in, n.name );
210
211     return in;
212 }