]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/navcom.cxx
Removed some depricated code snippets.
[flightgear.git] / src / Cockpit / navcom.cxx
1 // navcom.cxx -- class to manage a navcom instance
2 //
3 // Written by Curtis Olson, started April 2000.
4 //
5 // Copyright (C) 2000 - 2002  Curtis L. Olson - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #include <stdio.h>      // snprintf
29
30 #include <simgear/compiler.h>
31 #include <simgear/math/sg_random.h>
32
33 #include <Aircraft/aircraft.hxx>
34 #include <Navaids/ilslist.hxx>
35 #include <Navaids/navlist.hxx>
36 #include <Time/FGEventMgr.hxx>
37
38 #include "navcom.hxx"
39
40 #include <string>
41 SG_USING_STD(string);
42
43
44 /**
45  * Boy, this is ugly!  Make the VOR range vary by altitude difference.
46  */
47 static double kludgeRange ( double stationElev, double aircraftElev,
48                             double nominalRange)
49 {
50     // Assume that the nominal range (usually 50nm) applies at a 5,000
51     // ft difference.  Just a wild guess!
52     double factor = ((aircraftElev*SG_METER_TO_FEET) - stationElev) / 5000.0;
53     double range = fabs(nominalRange * factor);
54
55     // Clamp the range to keep it sane; for now, never less than 25%
56     // or more than 500% of nominal range.
57     if (range < nominalRange/4.0) {
58         range = nominalRange/4.0;
59     } else if (range > nominalRange*5.0) {
60         range = nominalRange*5.0;
61     }
62
63     return range;
64 }
65
66
67 // Constructor
68 FGNavCom::FGNavCom() :
69     lon_node(fgGetNode("/position/longitude-deg", true)),
70     lat_node(fgGetNode("/position/latitude-deg", true)),
71     alt_node(fgGetNode("/position/altitude-ft", true)),
72     last_nav_id(""),
73     last_nav_vor(false),
74     nav_play_count(0),
75     nav_last_time(0),
76     need_update(true),
77     power_btn(true),
78     comm_freq(0.0),
79     comm_alt_freq(0.0),
80     comm_vol_btn(0.0),
81     nav_freq(0.0),
82     nav_alt_freq(0.0),
83     nav_radial(0.0),
84     nav_vol_btn(0.0),
85     nav_ident_btn(true)
86 {
87     SGPath path( globals->get_fg_root() );
88     SGPath term = path;
89     term.append( "Navaids/range.term" );
90     SGPath low = path;
91     low.append( "Navaids/range.low" );
92     SGPath high = path;
93     high.append( "Navaids/range.high" );
94
95     term_tbl = new SGInterpTable( term.str() );
96     low_tbl = new SGInterpTable( low.str() );
97     high_tbl = new SGInterpTable( high.str() );
98
99 }
100
101
102 // Destructor
103 FGNavCom::~FGNavCom() 
104 {
105     delete term_tbl;
106     delete low_tbl;
107     delete high_tbl;
108 }
109
110
111 void
112 FGNavCom::init ()
113 {
114     morse.init();
115
116     search();
117
118     update(0);                  // FIXME: use dt
119 }
120
121 void
122 FGNavCom::bind ()
123 {
124     char propname[256];
125
126                                 // User inputs
127     sprintf( propname, "/radios/comm[%d]/inputs/power-btn", index );
128     fgTie( propname, this,
129            &FGNavCom::get_power_btn, &FGNavCom::set_power_btn );
130     fgSetArchivable( propname );
131
132     sprintf( propname, "/radios/comm[%d]/frequencies/selected-mhz", index );
133     fgTie( propname, this, &FGNavCom::get_comm_freq, &FGNavCom::set_comm_freq );
134     fgSetArchivable( propname );
135
136     sprintf( propname, "/radios/comm[%d]/frequencies/standby-mhz", index );
137     fgTie( propname, this,
138            &FGNavCom::get_comm_alt_freq, &FGNavCom::set_comm_alt_freq );
139     fgSetArchivable( propname );
140
141     sprintf( propname, "/radios/comm[%d]/volume", index );
142     fgTie( propname, this,
143            &FGNavCom::get_comm_vol_btn, &FGNavCom::set_comm_vol_btn );
144     fgSetArchivable( propname );
145
146     sprintf( propname, "/radios/nav[%d]/frequencies/selected-mhz", index );
147     fgTie( propname, this,
148           &FGNavCom::get_nav_freq, &FGNavCom::set_nav_freq );
149     fgSetArchivable( propname );
150
151     sprintf( propname, "/radios/nav[%d]/frequencies/standby-mhz", index );
152     fgTie( propname , this,
153            &FGNavCom::get_nav_alt_freq, &FGNavCom::set_nav_alt_freq);
154     fgSetArchivable( propname );
155
156     sprintf( propname, "/radios/nav[%d]/radials/selected-deg", index );
157     fgTie( propname, this,
158            &FGNavCom::get_nav_sel_radial, &FGNavCom::set_nav_sel_radial );
159     fgSetArchivable( propname );
160
161     sprintf( propname, "/radios/nav[%d]/volume", index );
162     fgTie( propname, this,
163            &FGNavCom::get_nav_vol_btn, &FGNavCom::set_nav_vol_btn );
164     fgSetArchivable( propname );
165
166     sprintf( propname, "/radios/nav[%d]/ident", index );
167     fgTie( propname, this,
168            &FGNavCom::get_nav_ident_btn, &FGNavCom::set_nav_ident_btn );
169     fgSetArchivable( propname );
170
171                                 // Radio outputs
172     sprintf( propname, "/radios/nav[%d]/radials/actual-deg", index );
173     fgTie( propname,  this, &FGNavCom::get_nav_radial );
174
175     sprintf( propname, "/radios/nav[%d]/to-flag", index );
176     fgTie( propname, this, &FGNavCom::get_nav_to_flag );
177
178     sprintf( propname, "/radios/nav[%d]/from-flag", index );
179     fgTie( propname, this, &FGNavCom::get_nav_from_flag );
180
181     sprintf( propname, "/radios/nav[%d]/in-range", index );
182     fgTie( propname, this, &FGNavCom::get_nav_inrange );
183
184     sprintf( propname, "/radios/nav[%d]/heading-needle-deflection", index );
185     fgTie( propname, this, &FGNavCom::get_nav_heading_needle_deflection );
186
187     sprintf( propname, "/radios/nav[%d]/gs-needle-deflection", index );
188     fgTie( propname, this, &FGNavCom::get_nav_gs_needle_deflection );
189 }
190
191
192 void
193 FGNavCom::unbind ()
194 {
195     char propname[256];
196
197     sprintf( propname, "/radios/comm[%d]/inputs/power-btn", index );
198     fgUntie( propname );
199     sprintf( propname, "/radios/comm[%d]/frequencies/selected-mhz", index );
200     fgUntie( propname );
201     sprintf( propname, "/radios/comm[%d]/frequencies/standby-mhz", index );
202     fgUntie( propname );
203
204     sprintf( propname, "/radios/nav[%d]/frequencies/selected-mhz", index );
205     fgUntie( propname );
206     sprintf( propname, "/radios/nav[%d]/frequencies/standby-mhz", index );
207     fgUntie( propname );
208     sprintf( propname, "/radios/nav[%d]/radials/actual-deg", index );
209     fgUntie( propname );
210     sprintf( propname, "/radios/nav[%d]/radials/selected-deg", index );
211     fgUntie( propname );
212     sprintf( propname, "/radios/nav[%d]/ident", index );
213     fgUntie( propname );
214     sprintf( propname, "/radios/nav[%d]/to-flag", index );
215     fgUntie( propname );
216     sprintf( propname, "/radios/nav[%d]/from-flag", index );
217     fgUntie( propname );
218     sprintf( propname, "/radios/nav[%d]/in-range", index );
219     fgUntie( propname );
220     sprintf( propname, "/radios/nav[%d]/heading-needle-deflection", index );
221     fgUntie( propname );
222     sprintf( propname, "/radios/nav[%d]/gs-needle-deflection", index );
223     fgUntie( propname );
224 }
225
226
227 // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
228 double FGNavCom::adjustNavRange( double stationElev, double aircraftElev,
229                               double nominalRange )
230 {
231     // extend out actual usable range to be 1.3x the published safe range
232     const double usability_factor = 1.3;
233
234     // assumptions we model the standard service volume, plus
235     // ... rather than specifying a cylinder, we model a cone that
236     // contains the cylinder.  Then we put an upside down cone on top
237     // to model diminishing returns at too-high altitudes.
238
239     // altitude difference
240     double alt = ( aircraftElev * SG_METER_TO_FEET - stationElev );
241     // cout << "aircraft elev = " << aircraftElev * SG_METER_TO_FEET
242     //      << " station elev = " << stationElev << endl;
243
244     if ( nominalRange < 25.0 + SG_EPSILON ) {
245         // Standard Terminal Service Volume
246         return term_tbl->interpolate( alt ) * usability_factor;
247     } else if ( nominalRange < 50.0 + SG_EPSILON ) {
248         // Standard Low Altitude Service Volume
249         // table is based on range of 40, scale to actual range
250         return low_tbl->interpolate( alt ) * nominalRange / 40.0
251             * usability_factor;
252     } else {
253         // Standard High Altitude Service Volume
254         // table is based on range of 130, scale to actual range
255         return high_tbl->interpolate( alt ) * nominalRange / 130.0
256             * usability_factor;
257     }
258 }
259
260
261 // model standard ILS service volumes as per AIM 1-1-9
262 double FGNavCom::adjustILSRange( double stationElev, double aircraftElev,
263                                      double offsetDegrees, double distance )
264 {
265     // assumptions we model the standard service volume, plus
266
267     // altitude difference
268     // double alt = ( aircraftElev * SG_METER_TO_FEET - stationElev );
269     double offset = fabs( offsetDegrees );
270
271     if ( offset < 10 ) {
272         return FG_ILS_DEFAULT_RANGE;
273     } else if ( offset < 35 ) {
274         return 10 + (35 - offset) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
275     } else if ( offset < 45 ) {
276         return (45 - offset);
277     } else if ( offset > 170 ) {
278         return FG_ILS_DEFAULT_RANGE;
279     } else if ( offset > 145 ) {
280         return 10 + (offset - 145) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
281     } else if ( offset > 135 ) {
282         return (offset - 135);
283     } else {
284         return 0;
285     }
286 }
287
288
289 // Update the various nav values based on position and valid tuned in navs
290 void 
291 FGNavCom::update(double dt) 
292 {
293     double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
294     double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
295     double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
296
297     need_update = false;
298
299     Point3D aircraft = sgGeodToCart( Point3D( lon, lat, elev ) );
300     Point3D station;
301     double az1, az2, s;
302
303     ////////////////////////////////////////////////////////////////////////
304     // Nav.
305     ////////////////////////////////////////////////////////////////////////
306
307     if ( nav_valid && power_btn ) {
308         station = Point3D( nav_x, nav_y, nav_z );
309         nav_loc_dist = aircraft.distance3D( station );
310
311         if ( nav_has_gs ) {
312             station = Point3D( nav_gs_x, nav_gs_y, nav_gs_z );
313             nav_gs_dist = aircraft.distance3D( station );
314         } else {
315             nav_gs_dist = 0.0;
316         }
317         
318         // wgs84 heading
319         geo_inverse_wgs_84( elev, lat * SGD_RADIANS_TO_DEGREES, lon * SGD_RADIANS_TO_DEGREES, 
320                             nav_loclat, nav_loclon,
321                             &az1, &az2, &s );
322         // cout << "az1 = " << az1 << " magvar = " << nav_magvar << endl;
323         nav_heading = az1 - nav_magvar;
324         // cout << " heading = " << nav_heading
325         //      << " dist = " << nav_dist << endl;
326
327         if ( nav_loc ) {
328             double offset = nav_heading - nav_radial;
329             while ( offset < -180.0 ) { offset += 360.0; }
330             while ( offset > 180.0 ) { offset -= 360.0; }
331             // cout << "ils offset = " << offset << endl;
332             nav_effective_range = adjustILSRange(nav_elev, elev, offset,
333                                                   nav_loc_dist * SG_METER_TO_NM );
334         } else {
335             nav_effective_range = adjustNavRange(nav_elev, elev, nav_range);
336         }
337         // cout << "nav range = " << nav_effective_range
338         //      << " (" << nav_range << ")" << endl;
339
340         if ( nav_loc_dist < nav_effective_range * SG_NM_TO_METER ) {
341             nav_inrange = true;
342         } else if ( nav_loc_dist < 2 * nav_effective_range * SG_NM_TO_METER ) {
343             nav_inrange = sg_random() < 
344                 ( 2 * nav_effective_range * SG_NM_TO_METER - nav_loc_dist ) /
345                 (nav_effective_range * SG_NM_TO_METER);
346         } else {
347             nav_inrange = false;
348         }
349
350         if ( !nav_loc ) {
351             nav_radial = nav_sel_radial;
352         }
353     } else {
354         nav_inrange = false;
355         // cout << "not picking up vor. :-(" << endl;
356     }
357
358 #ifdef ENABLE_AUDIO_SUPPORT
359     if ( nav_valid && nav_inrange ) {
360         // play station ident via audio system if on + ident,
361         // otherwise turn it off
362         if ( power_btn && nav_ident_btn ) {
363             FGSimpleSound *sound;
364             sound = globals->get_soundmgr()->find( nav_fx_name );
365             if ( sound != NULL ) {
366                 sound->set_volume( nav_vol_btn );
367             } else {
368                 SG_LOG( SG_COCKPIT, SG_ALERT,
369                         "Can't find nav-vor-ident sound" );
370             }
371             sound = globals->get_soundmgr()->find( dme_fx_name );
372             if ( sound != NULL ) {
373                 sound->set_volume( nav_vol_btn );
374             } else {
375                 SG_LOG( SG_COCKPIT, SG_ALERT,
376                         "Can't find nav-dme-ident sound" );
377             }
378             // cout << "nav_last_time = " << nav_last_time << " ";
379             // cout << "cur_time = "
380             //      << globals->get_time_params()->get_cur_time();
381             if ( nav_last_time <
382                  globals->get_time_params()->get_cur_time() - 30 ) {
383                 nav_last_time = globals->get_time_params()->get_cur_time();
384                 nav_play_count = 0;
385             }
386             // cout << " nav_play_count = " << nav_play_count << endl;
387             // cout << "playing = "
388             //      << globals->get_soundmgr()->is_playing(nav_fx_name)
389             //      << endl;
390             if ( nav_play_count < 4 ) {
391                 // play VOR ident
392                 if ( !globals->get_soundmgr()->is_playing(nav_fx_name) ) {
393                     globals->get_soundmgr()->play_once( nav_fx_name );
394                     ++nav_play_count;
395                 }
396             } else if ( nav_play_count < 5 && nav_has_dme ) {
397                 // play DME ident
398                 if ( !globals->get_soundmgr()->is_playing(nav_fx_name) &&
399                      !globals->get_soundmgr()->is_playing(dme_fx_name) ) {
400                     globals->get_soundmgr()->play_once( dme_fx_name );
401                     ++nav_play_count;
402                 }
403             }
404         } else {
405             globals->get_soundmgr()->stop( nav_fx_name );
406             globals->get_soundmgr()->stop( dme_fx_name );
407         }
408     }
409 #endif
410
411 }
412
413
414 // Update current nav/adf radio stations based on current postition
415 void FGNavCom::search() 
416 {
417     double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
418     double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
419     double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
420
421     FGILS ils;
422     FGNav nav;
423
424     ////////////////////////////////////////////////////////////////////////
425     // Nav.
426     ////////////////////////////////////////////////////////////////////////
427
428     if ( current_ilslist->query( lon, lat, elev, nav_freq, &ils ) ) {
429         nav_id = ils.get_locident();
430         nav_valid = true;
431         if ( last_nav_id != nav_id || last_nav_vor ) {
432             nav_trans_ident = ils.get_trans_ident();
433             last_nav_id = nav_id;
434             last_nav_vor = false;
435             nav_loc = true;
436             nav_has_dme = ils.get_has_dme();
437             nav_has_gs = ils.get_has_gs();
438
439             nav_loclon = ils.get_loclon();
440             nav_loclat = ils.get_loclat();
441             nav_gslon = ils.get_gslon();
442             nav_gslat = ils.get_gslat();
443             nav_elev = ils.get_gselev();
444             nav_magvar = 0;
445             nav_range = FG_ILS_DEFAULT_RANGE;
446             nav_effective_range = nav_range;
447             nav_target_gs = ils.get_gsangle();
448             nav_radial = ils.get_locheading();
449             while ( nav_radial <   0.0 ) { nav_radial += 360.0; }
450             while ( nav_radial > 360.0 ) { nav_radial -= 360.0; }
451             nav_x = ils.get_x();
452             nav_y = ils.get_y();
453             nav_z = ils.get_z();
454             nav_gs_x = ils.get_gs_x();
455             nav_gs_y = ils.get_gs_y();
456             nav_gs_z = ils.get_gs_z();
457
458 #ifdef ENABLE_AUDIO_SUPPORT
459             if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
460                 globals->get_soundmgr()->remove( nav_fx_name );
461             }
462             FGSimpleSound *sound;
463             sound = morse.make_ident( nav_trans_ident, LO_FREQUENCY );
464             sound->set_volume( 0.3 );
465             globals->get_soundmgr()->add( sound, nav_fx_name );
466
467             if ( globals->get_soundmgr()->exists( dme_fx_name ) ) {
468                 globals->get_soundmgr()->remove( dme_fx_name );
469             }
470             sound = morse.make_ident( nav_trans_ident, HI_FREQUENCY );
471             sound->set_volume( 0.3 );
472             globals->get_soundmgr()->add( sound, dme_fx_name );
473
474             int offset = (int)(sg_random() * 30.0);
475             nav_play_count = offset / 4;
476             nav_last_time = globals->get_time_params()->get_cur_time() -
477                 offset;
478             // cout << "offset = " << offset << " play_count = "
479             //      << nav_play_count
480             //      << " nav_last_time = " << nav_last_time
481             //      << " current time = "
482             //      << globals->get_time_params()->get_cur_time() << endl;
483 #endif
484
485             // cout << "Found an ils station in range" << endl;
486             // cout << " id = " << ils.get_locident() << endl;
487         }
488     } else if ( current_navlist->query( lon, lat, elev, nav_freq, &nav ) ) {
489         nav_id = nav.get_ident();
490         nav_valid = true;
491         if ( last_nav_id != nav_id || !last_nav_vor ) {
492             last_nav_id = nav_id;
493             last_nav_vor = true;
494             nav_trans_ident = nav.get_trans_ident();
495             nav_loc = false;
496             nav_has_dme = nav.get_has_dme();
497             nav_has_gs = false;
498             nav_loclon = nav.get_lon();
499             nav_loclat = nav.get_lat();
500             nav_elev = nav.get_elev();
501             nav_magvar = nav.get_magvar();
502             nav_range = nav.get_range();
503             nav_effective_range = adjustNavRange(nav_elev, elev, nav_range);
504             nav_target_gs = 0.0;
505             nav_radial = nav_sel_radial;
506             nav_x = nav.get_x();
507             nav_y = nav.get_y();
508             nav_z = nav.get_z();
509
510 #ifdef ENABLE_AUDIO_SUPPORT
511             if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
512                 globals->get_soundmgr()->remove( nav_fx_name );
513             }
514             FGSimpleSound *sound;
515             sound = morse.make_ident( nav_trans_ident, LO_FREQUENCY );
516             sound->set_volume( 0.3 );
517             if ( globals->get_soundmgr()->add( sound, nav_fx_name ) ) {
518                 // cout << "Added nav-vor-ident sound" << endl;
519             } else {
520                 cout << "Failed to add v1-vor-ident sound" << endl;
521             }
522
523             if ( globals->get_soundmgr()->exists( dme_fx_name ) ) {
524                 globals->get_soundmgr()->remove( dme_fx_name );
525             }
526             sound = morse.make_ident( nav_trans_ident, HI_FREQUENCY );
527             sound->set_volume( 0.3 );
528             globals->get_soundmgr()->add( sound, dme_fx_name );
529
530             int offset = (int)(sg_random() * 30.0);
531             nav_play_count = offset / 4;
532             nav_last_time = globals->get_time_params()->get_cur_time() -
533                 offset;
534             // cout << "offset = " << offset << " play_count = "
535             //      << nav_play_count << " nav_last_time = "
536             //      << nav_last_time << " current time = "
537             //      << globals->get_time_params()->get_cur_time() << endl;
538 #endif
539
540             // cout << "Found a vor station in range" << endl;
541             // cout << " id = " << nav.get_ident() << endl;
542         }
543     } else {
544         nav_valid = false;
545         nav_id = "";
546         nav_radial = 0;
547         nav_trans_ident = "";
548         last_nav_id = "";
549 #ifdef ENABLE_AUDIO_SUPPORT
550         if ( ! globals->get_soundmgr()->remove( nav_fx_name ) ) {
551             cout << "Failed to remove nav-vor-ident sound" << endl;
552         }
553         globals->get_soundmgr()->remove( dme_fx_name );
554 #endif
555         // cout << "not picking up vor1. :-(" << endl;
556     }
557 }
558
559
560 // return the amount of heading needle deflection, returns a value
561 // clamped to the range of ( -10 , 10 )
562 double FGNavCom::get_nav_heading_needle_deflection() const {
563     double r;
564
565     if ( nav_inrange ) {
566         r = nav_heading - nav_radial;
567         // cout << "Radial = " << nav_radial 
568         //      << "  Bearing = " << nav_heading << endl;
569     
570         while ( r >  180.0 ) { r -= 360.0;}
571         while ( r < -180.0 ) { r += 360.0;}
572         if ( fabs(r) > 90.0 ) {
573             r = ( r<0.0 ? -r-180.0 : -r+180.0 );
574             if ( nav_loc ) {
575                 r = -r;
576             }
577         }
578
579         // According to Robin Peel, the ILS is 4x more sensitive than a vor
580         if ( nav_loc ) { r *= 4.0; }
581         if ( r < -10.0 ) { r = -10.0; }
582         if ( r >  10.0 ) { r = 10.0; }
583     } else {
584         r = 0.0;
585     }
586
587     return r;
588 }
589
590
591 // return the amount of glide slope needle deflection (.i.e. the
592 // number of degrees we are off the glide slope * 5.0
593 double FGNavCom::get_nav_gs_needle_deflection() const {
594     if ( nav_inrange && nav_has_gs ) {
595         double x = nav_gs_dist;
596         double y = (fgGetDouble("/position/altitude-ft") - nav_elev)
597             * SG_FEET_TO_METER;
598         double angle = atan2( y, x ) * SGD_RADIANS_TO_DEGREES;
599         return (nav_target_gs - angle) * 5.0;
600     } else {
601         return 0.0;
602     }
603 }
604
605
606 /**
607  * Return true if the NAV TO flag should be active.
608  */
609 bool 
610 FGNavCom::get_nav_to_flag () const
611 {
612   if (nav_inrange) {
613     double offset = fabs(nav_heading - nav_radial);
614     if (nav_loc)
615       return true;
616     else
617       return (offset <= 90.0 || offset >= 270.0);
618   } else {
619     return false;
620   }
621 }
622
623
624 /**
625  * Return true if the NAV FROM flag should be active.
626  */
627 bool
628 FGNavCom::get_nav_from_flag () const
629 {
630   if (nav_inrange) {
631     double offset = fabs(nav_heading - nav_radial);
632     if (nav_loc)
633       return false;
634     else
635       return (offset > 90.0 && offset < 270.0);
636   } else {
637     return false;
638   }
639 }