1 // navcom.cxx -- class to manage a navcom instance
3 // Written by Curtis Olson, started April 2000.
5 // Copyright (C) 2000 - 2002 Curtis L. Olson - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <stdio.h> // snprintf
30 #include <simgear/compiler.h>
31 #include <simgear/math/sg_random.h>
32 #include <simgear/math/vector.hxx>
34 #include <Aircraft/aircraft.hxx>
35 #include <Navaids/ilslist.hxx>
36 #include <Navaids/navlist.hxx>
37 #include <Time/FGEventMgr.hxx>
46 FGNavCom::FGNavCom() :
47 lon_node(fgGetNode("/position/longitude-deg", true)),
48 lat_node(fgGetNode("/position/latitude-deg", true)),
49 alt_node(fgGetNode("/position/altitude-ft", true)),
62 nav_target_radial(0.0),
66 SGPath path( globals->get_fg_root() );
68 term.append( "Navaids/range.term" );
70 low.append( "Navaids/range.low" );
72 high.append( "Navaids/range.high" );
74 term_tbl = new SGInterpTable( term.str() );
75 low_tbl = new SGInterpTable( low.str() );
76 high_tbl = new SGInterpTable( high.str() );
95 // We assume that index is valid now (it must be set before init()
98 // FIXME: Get rid of snprintf
100 snprintf(propname, 256, "/systems/electrical/outputs/navcom[%d]", index);
101 // default to true in case no electrical system defined.
102 fgSetDouble( propname, 60.0 );
103 bus_power = fgGetNode( propname, true );
105 snprintf(propname, 256, "/instrumentation/comm[%d]/serviceable", index);
106 com_serviceable = fgGetNode( propname, true );
107 com_serviceable->setBoolValue( true );
109 snprintf(propname, 256, "/instrumentation/nav[%d]/serviceable", index);
110 nav_serviceable = fgGetNode( propname, true );
111 nav_serviceable->setBoolValue( true );
113 snprintf(propname, 256, "/instrumentation/vor[%d]/cdi/serviceable", index);
114 cdi_serviceable = fgGetNode( propname, true );
115 cdi_serviceable->setBoolValue( true );
117 snprintf(propname, 256, "/instrumentation/vor[%d]/gs/serviceable", index);
118 gs_serviceable = fgGetNode( propname, true );
119 gs_serviceable->setBoolValue( true );
121 snprintf(propname, 256, "/instrumentation/vor[%d]/to-from/serviceable", index);
122 tofrom_serviceable = fgGetNode( propname, true );
123 tofrom_serviceable->setBoolValue( true );
130 // FIXME: Get rid of snprintf
133 snprintf(propname, 256, "/radios/comm[%d]/inputs/power-btn", index);
134 fgTie( propname, this,
135 &FGNavCom::get_power_btn, &FGNavCom::set_power_btn );
136 fgSetArchivable( propname );
138 snprintf(propname, 256, "/radios/comm[%d]/frequencies/selected-mhz", index);
139 fgTie( propname, this, &FGNavCom::get_comm_freq, &FGNavCom::set_comm_freq );
140 fgSetArchivable( propname );
142 snprintf(propname, 256, "/radios/comm[%d]/frequencies/standby-mhz", index);
143 fgTie( propname, this,
144 &FGNavCom::get_comm_alt_freq, &FGNavCom::set_comm_alt_freq );
145 fgSetArchivable( propname );
147 snprintf(propname, 256, "/radios/comm[%d]/volume", index);
148 fgTie( propname, this,
149 &FGNavCom::get_comm_vol_btn, &FGNavCom::set_comm_vol_btn );
150 fgSetArchivable( propname );
152 snprintf(propname, 256, "/radios/nav[%d]/frequencies/selected-mhz", index);
153 fgTie( propname, this,
154 &FGNavCom::get_nav_freq, &FGNavCom::set_nav_freq );
155 fgSetArchivable( propname );
157 snprintf(propname, 256, "/radios/nav[%d]/frequencies/standby-mhz", index);
158 fgTie( propname , this,
159 &FGNavCom::get_nav_alt_freq, &FGNavCom::set_nav_alt_freq);
160 fgSetArchivable( propname );
162 snprintf(propname, 256, "/radios/nav[%d]/radials/selected-deg", index);
163 fgTie( propname, this,
164 &FGNavCom::get_nav_sel_radial, &FGNavCom::set_nav_sel_radial );
165 fgSetArchivable( propname );
167 snprintf(propname, 256, "/radios/nav[%d]/volume", index);
168 fgTie( propname, this,
169 &FGNavCom::get_nav_vol_btn, &FGNavCom::set_nav_vol_btn );
170 fgSetArchivable( propname );
172 snprintf(propname, 256, "/radios/nav[%d]/ident", index);
173 fgTie( propname, this,
174 &FGNavCom::get_nav_ident_btn, &FGNavCom::set_nav_ident_btn );
175 fgSetArchivable( propname );
178 snprintf(propname, 256, "/radios/nav[%d]/audio-btn", index);
179 fgTie( propname, this,
180 &FGNavCom::get_audio_btn, &FGNavCom::set_audio_btn );
181 fgSetArchivable( propname );
183 snprintf(propname, 256, "/radios/nav[%d]/radials/actual-deg", index);
184 fgTie( propname, this, &FGNavCom::get_nav_radial );
186 snprintf(propname, 256, "/radios/nav[%d]/to-flag", index);
187 fgTie( propname, this, &FGNavCom::get_nav_to_flag );
189 snprintf(propname, 256, "/radios/nav[%d]/from-flag", index);
190 fgTie( propname, this, &FGNavCom::get_nav_from_flag );
192 snprintf(propname, 256, "/radios/nav[%d]/in-range", index);
193 fgTie( propname, this, &FGNavCom::get_nav_inrange );
195 snprintf(propname, 256, "/radios/nav[%d]/heading-needle-deflection", index);
196 fgTie( propname, this, &FGNavCom::get_nav_cdi_deflection );
198 snprintf(propname, 256, "/radios/nav[%d]/has-gs", index);
199 fgTie( propname, this, &FGNavCom::get_nav_has_gs );
201 snprintf(propname, 256, "/radios/nav[%d]/nav-loc", index);
202 fgTie( propname, this, &FGNavCom::get_nav_loc );
204 snprintf(propname, 256, "/radios/nav[%d]/gs-needle-deflection", index);
205 fgTie( propname, this, &FGNavCom::get_nav_gs_deflection );
207 snprintf(propname, 256, "/radios/nav[%d]/nav-id", index);
208 fgTie( propname, this, &FGNavCom::get_nav_id );
210 // put nav_id characters into seperate properties for instrument displays
211 snprintf(propname, 256, "/radios/nav[%d]/nav-id_asc1", index);
212 fgTie( propname, this, &FGNavCom::get_nav_id_c1 );
214 snprintf(propname, 256, "/radios/nav[%d]/nav-id_asc2", index);
215 fgTie( propname, this, &FGNavCom::get_nav_id_c2 );
217 snprintf(propname, 256, "/radios/nav[%d]/nav-id_asc3", index);
218 fgTie( propname, this, &FGNavCom::get_nav_id_c3 );
220 snprintf(propname, 256, "/radios/nav[%d]/nav-id_asc4", index);
221 fgTie( propname, this, &FGNavCom::get_nav_id_c4 );
231 // FIXME: Get rid of snprintf
233 snprintf(propname, 256, "/radios/comm[%d]/inputs/power-btn", index);
235 snprintf(propname, 256, "/radios/comm[%d]/frequencies/selected-mhz", index);
237 snprintf(propname, 256, "/radios/comm[%d]/frequencies/standby-mhz", index);
240 snprintf(propname, 256, "/radios/nav[%d]/frequencies/selected-mhz", index);
242 snprintf(propname, 256, "/radios/nav[%d]/frequencies/standby-mhz", index);
244 snprintf(propname, 256, "/radios/nav[%d]/radials/actual-deg", index);
246 snprintf(propname, 256, "/radios/nav[%d]/radials/selected-deg", index);
248 snprintf(propname, 256, "/radios/nav[%d]/ident", index);
250 snprintf(propname, 256, "/radios/nav[%d]/to-flag", index);
252 snprintf(propname, 256, "/radios/nav[%d]/from-flag", index);
254 snprintf(propname, 256, "/radios/nav[%d]/in-range", index);
256 snprintf(propname, 256, "/radios/nav[%d]/heading-needle-deflection", index);
258 snprintf(propname, 256, "/radios/nav[%d]/gs-needle-deflection", index);
263 // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
264 double FGNavCom::adjustNavRange( double stationElev, double aircraftElev,
265 double nominalRange )
267 // extend out actual usable range to be 1.3x the published safe range
268 const double usability_factor = 1.3;
270 // assumptions we model the standard service volume, plus
271 // ... rather than specifying a cylinder, we model a cone that
272 // contains the cylinder. Then we put an upside down cone on top
273 // to model diminishing returns at too-high altitudes.
275 // altitude difference
276 double alt = ( aircraftElev * SG_METER_TO_FEET - stationElev );
277 // cout << "aircraft elev = " << aircraftElev * SG_METER_TO_FEET
278 // << " station elev = " << stationElev << endl;
280 if ( nominalRange < 25.0 + SG_EPSILON ) {
281 // Standard Terminal Service Volume
282 return term_tbl->interpolate( alt ) * usability_factor;
283 } else if ( nominalRange < 50.0 + SG_EPSILON ) {
284 // Standard Low Altitude Service Volume
285 // table is based on range of 40, scale to actual range
286 return low_tbl->interpolate( alt ) * nominalRange / 40.0
289 // Standard High Altitude Service Volume
290 // table is based on range of 130, scale to actual range
291 return high_tbl->interpolate( alt ) * nominalRange / 130.0
297 // model standard ILS service volumes as per AIM 1-1-9
298 double FGNavCom::adjustILSRange( double stationElev, double aircraftElev,
299 double offsetDegrees, double distance )
301 // assumptions we model the standard service volume, plus
303 // altitude difference
304 // double alt = ( aircraftElev * SG_METER_TO_FEET - stationElev );
305 // double offset = fabs( offsetDegrees );
307 // if ( offset < 10 ) {
308 // return FG_ILS_DEFAULT_RANGE;
309 // } else if ( offset < 35 ) {
310 // return 10 + (35 - offset) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
311 // } else if ( offset < 45 ) {
312 // return (45 - offset);
313 // } else if ( offset > 170 ) {
314 // return FG_ILS_DEFAULT_RANGE;
315 // } else if ( offset > 145 ) {
316 // return 10 + (offset - 145) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
317 // } else if ( offset > 135 ) {
318 // return (offset - 135);
322 return FG_ILS_DEFAULT_RANGE;
326 // Update the various nav values based on position and valid tuned in navs
328 FGNavCom::update(double dt)
330 double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
331 double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
332 double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
336 Point3D aircraft = sgGeodToCart( Point3D( lon, lat, elev ) );
340 ////////////////////////////////////////////////////////////////////////
342 ////////////////////////////////////////////////////////////////////////
344 if ( nav_valid && power_btn && (bus_power->getDoubleValue() > 1.0)
345 && nav_serviceable->getBoolValue() )
347 station = Point3D( nav_x, nav_y, nav_z );
348 nav_loc_dist = aircraft.distance3D( station );
351 // find closest distance to the gs base line
353 sgdSetVec3( p, aircraft.x(), aircraft.y(), aircraft.z() );
355 sgdSetVec3( p0, nav_gs_x, nav_gs_y, nav_gs_z );
356 double dist = sgdClosestPointToLineDistSquared( p, p0,
358 nav_gs_dist = sqrt( dist );
359 // cout << nav_gs_dist;
361 // Point3D tmp( nav_gs_x, nav_gs_y, nav_gs_z );
362 // cout << " (" << aircraft.distance3D( tmp ) << ")" << endl;
364 // wgs84 heading to glide slope (to determine sign of distance)
365 geo_inverse_wgs_84( elev,
366 lat * SGD_RADIANS_TO_DEGREES,
367 lon * SGD_RADIANS_TO_DEGREES,
368 nav_gslat, nav_gslon,
370 double r = az1 - nav_target_radial;
371 while ( r > 180.0 ) { r -= 360.0;}
372 while ( r < -180.0 ) { r += 360.0;}
373 if ( r >= -90.0 && r <= 90.0 ) {
374 nav_gs_dist_signed = nav_gs_dist;
376 nav_gs_dist_signed = -nav_gs_dist;
378 /* cout << "Target Radial = " << nav_target_radial
379 << " Bearing = " << az1
380 << " dist (signed) = " << nav_gs_dist_signed
387 // wgs84 heading to localizer
388 geo_inverse_wgs_84( elev,
389 lat * SGD_RADIANS_TO_DEGREES,
390 lon * SGD_RADIANS_TO_DEGREES,
391 nav_loclat, nav_loclon,
393 // cout << "az1 = " << az1 << " magvar = " << nav_magvar << endl;
394 nav_radial = az2 - nav_twist;
395 // cout << " heading = " << nav_heading
396 // << " dist = " << nav_dist << endl;
399 double offset = nav_radial - nav_target_radial;
400 while ( offset < -180.0 ) { offset += 360.0; }
401 while ( offset > 180.0 ) { offset -= 360.0; }
402 // cout << "ils offset = " << offset << endl;
403 nav_effective_range = adjustILSRange(nav_elev, elev, offset,
404 nav_loc_dist * SG_METER_TO_NM );
406 nav_effective_range = adjustNavRange(nav_elev, elev, nav_range);
408 // cout << "nav range = " << nav_effective_range
409 // << " (" << nav_range << ")" << endl;
411 if ( nav_loc_dist < nav_effective_range * SG_NM_TO_METER ) {
413 } else if ( nav_loc_dist < 2 * nav_effective_range * SG_NM_TO_METER ) {
414 nav_inrange = sg_random() <
415 ( 2 * nav_effective_range * SG_NM_TO_METER - nav_loc_dist ) /
416 (nav_effective_range * SG_NM_TO_METER);
422 nav_target_radial = nav_sel_radial;
426 // cout << "not picking up vor. :-(" << endl;
429 if ( nav_valid && nav_inrange && nav_serviceable->getBoolValue() ) {
430 // play station ident via audio system if on + ident,
431 // otherwise turn it off
432 if ( power_btn && (bus_power->getDoubleValue() > 1.0)
433 && nav_ident_btn && audio_btn )
435 SGSimpleSound *sound;
436 sound = globals->get_soundmgr()->find( nav_fx_name );
437 if ( sound != NULL ) {
438 sound->set_volume( nav_vol_btn );
440 SG_LOG( SG_COCKPIT, SG_ALERT,
441 "Can't find nav-vor-ident sound" );
443 sound = globals->get_soundmgr()->find( dme_fx_name );
444 if ( sound != NULL ) {
445 sound->set_volume( nav_vol_btn );
447 SG_LOG( SG_COCKPIT, SG_ALERT,
448 "Can't find nav-dme-ident sound" );
450 // cout << "nav_last_time = " << nav_last_time << " ";
451 // cout << "cur_time = "
452 // << globals->get_time_params()->get_cur_time();
454 globals->get_time_params()->get_cur_time() - 30 ) {
455 nav_last_time = globals->get_time_params()->get_cur_time();
458 // cout << " nav_play_count = " << nav_play_count << endl;
459 // cout << "playing = "
460 // << globals->get_soundmgr()->is_playing(nav_fx_name)
462 if ( nav_play_count < 4 ) {
464 if ( !globals->get_soundmgr()->is_playing(nav_fx_name) ) {
465 globals->get_soundmgr()->play_once( nav_fx_name );
468 } else if ( nav_play_count < 5 && nav_has_dme ) {
470 if ( !globals->get_soundmgr()->is_playing(nav_fx_name) &&
471 !globals->get_soundmgr()->is_playing(dme_fx_name) ) {
472 globals->get_soundmgr()->play_once( dme_fx_name );
477 globals->get_soundmgr()->stop( nav_fx_name );
478 globals->get_soundmgr()->stop( dme_fx_name );
484 // Update current nav/adf radio stations based on current postition
485 void FGNavCom::search()
487 double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
488 double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
489 double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
494 ////////////////////////////////////////////////////////////////////////
496 ////////////////////////////////////////////////////////////////////////
498 if ( (ils = current_ilslist->findByFreq(nav_freq, lon, lat, elev)) != NULL ) {
499 nav_id = ils->get_locident();
501 if ( last_nav_id != nav_id || last_nav_vor ) {
502 nav_trans_ident = ils->get_trans_ident();
503 last_nav_id = nav_id;
504 last_nav_vor = false;
506 nav_has_dme = ils->get_has_dme();
507 nav_has_gs = ils->get_has_gs();
509 nav_loclon = ils->get_loclon();
510 nav_loclat = ils->get_loclat();
511 nav_gslon = ils->get_gslon();
512 nav_gslat = ils->get_gslat();
513 nav_elev = ils->get_gselev();
515 nav_range = FG_ILS_DEFAULT_RANGE;
516 nav_effective_range = nav_range;
517 nav_target_gs = ils->get_gsangle();
518 nav_target_radial = ils->get_locheading();
519 while ( nav_target_radial < 0.0 ) { nav_target_radial += 360.0; }
520 while ( nav_target_radial > 360.0 ) { nav_target_radial -= 360.0; }
521 nav_x = ils->get_x();
522 nav_y = ils->get_y();
523 nav_z = ils->get_z();
524 nav_gs_x = ils->get_gs_x();
525 nav_gs_y = ils->get_gs_y();
526 nav_gs_z = ils->get_gs_z();
528 // derive GS baseline
529 double tlon, tlat, taz;
530 geo_direct_wgs_84 ( 0.0, nav_gslat, nav_gslon, nav_target_radial + 90,
531 100.0, &tlat, &tlon, &taz );
532 // cout << nav_gslon << "," << nav_gslat << " "
533 // << tlon << "," << tlat << " (" << nav_elev << ")" << endl;
534 Point3D p1 = sgGeodToCart( Point3D(tlon*SGD_DEGREES_TO_RADIANS,
535 tlat*SGD_DEGREES_TO_RADIANS,
536 nav_elev*SG_FEET_TO_METER) );
537 // cout << nav_gs_x << "," << nav_gs_y << "," << nav_gs_z << endl;
538 // cout << p1 << endl;
539 sgdSetVec3( gs_base_vec,
540 p1.x()-nav_gs_x, p1.y()-nav_gs_y, p1.z()-nav_gs_z );
541 // cout << gs_base_vec[0] << "," << gs_base_vec[1] << ","
542 // << gs_base_vec[2] << endl;
544 if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
545 globals->get_soundmgr()->remove( nav_fx_name );
547 SGSimpleSound *sound;
548 sound = morse.make_ident( nav_trans_ident, LO_FREQUENCY );
549 sound->set_volume( 0.3 );
550 globals->get_soundmgr()->add( sound, nav_fx_name );
552 if ( globals->get_soundmgr()->exists( dme_fx_name ) ) {
553 globals->get_soundmgr()->remove( dme_fx_name );
555 sound = morse.make_ident( nav_trans_ident, HI_FREQUENCY );
556 sound->set_volume( 0.3 );
557 globals->get_soundmgr()->add( sound, dme_fx_name );
559 int offset = (int)(sg_random() * 30.0);
560 nav_play_count = offset / 4;
561 nav_last_time = globals->get_time_params()->get_cur_time() -
563 // cout << "offset = " << offset << " play_count = "
565 // << " nav_last_time = " << nav_last_time
566 // << " current time = "
567 // << globals->get_time_params()->get_cur_time() << endl;
569 // cout << "Found an ils station in range" << endl;
570 // cout << " id = " << ils->get_locident() << endl;
572 } else if ( (nav = current_navlist->findByFreq(nav_freq, lon, lat, elev)) != NULL ) {
573 nav_id = nav->get_ident();
574 nav_valid = (nav->get_type() == 'V');
575 if ( last_nav_id != nav_id || !last_nav_vor ) {
576 last_nav_id = nav_id;
578 nav_trans_ident = nav->get_trans_ident();
580 nav_has_dme = nav->get_has_dme();
582 nav_loclon = nav->get_lon();
583 nav_loclat = nav->get_lat();
584 nav_elev = nav->get_elev();
585 nav_twist = nav->get_magvar();
586 nav_range = nav->get_range();
587 nav_effective_range = adjustNavRange(nav_elev, elev, nav_range);
589 nav_target_radial = nav_sel_radial;
590 nav_x = nav->get_x();
591 nav_y = nav->get_y();
592 nav_z = nav->get_z();
594 if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
595 globals->get_soundmgr()->remove( nav_fx_name );
597 SGSimpleSound *sound;
598 sound = morse.make_ident( nav_trans_ident, LO_FREQUENCY );
599 sound->set_volume( 0.3 );
600 if ( globals->get_soundmgr()->add( sound, nav_fx_name ) ) {
601 // cout << "Added nav-vor-ident sound" << endl;
603 SG_LOG(SG_COCKPIT, SG_WARN, "Failed to add v1-vor-ident sound");
606 if ( globals->get_soundmgr()->exists( dme_fx_name ) ) {
607 globals->get_soundmgr()->remove( dme_fx_name );
609 sound = morse.make_ident( nav_trans_ident, HI_FREQUENCY );
610 sound->set_volume( 0.3 );
611 globals->get_soundmgr()->add( sound, dme_fx_name );
613 int offset = (int)(sg_random() * 30.0);
614 nav_play_count = offset / 4;
615 nav_last_time = globals->get_time_params()->get_cur_time() -
617 // cout << "offset = " << offset << " play_count = "
618 // << nav_play_count << " nav_last_time = "
619 // << nav_last_time << " current time = "
620 // << globals->get_time_params()->get_cur_time() << endl;
622 // cout << "Found a vor station in range" << endl;
623 // cout << " id = " << nav->get_ident() << endl;
628 nav_target_radial = 0;
629 nav_trans_ident = "";
631 if ( ! globals->get_soundmgr()->remove( nav_fx_name ) ) {
632 SG_LOG(SG_COCKPIT, SG_WARN, "Failed to remove nav-vor-ident sound");
634 globals->get_soundmgr()->remove( dme_fx_name );
635 // cout << "not picking up vor1. :-(" << endl;
640 // return the amount of heading needle deflection, returns a value
641 // clamped to the range of ( -10 , 10 )
642 double FGNavCom::get_nav_cdi_deflection() const {
646 && nav_serviceable->getBoolValue() && cdi_serviceable->getBoolValue() )
648 r = nav_radial - nav_target_radial;
649 // cout << "Target radial = " << nav_target_radial
650 // << " Actual radial = " << nav_radial << endl;
652 while ( r > 180.0 ) { r -= 360.0;}
653 while ( r < -180.0 ) { r += 360.0;}
654 if ( fabs(r) > 90.0 )
655 r = ( r<0.0 ? -r-180.0 : -r+180.0 );
657 // According to Robin Peel, the ILS is 4x more sensitive than a vor
658 r = -r; // reverse, since radial is outbound
659 if ( nav_loc ) { r *= 4.0; }
660 if ( r < -10.0 ) { r = -10.0; }
661 if ( r > 10.0 ) { r = 10.0; }
670 // return the amount of glide slope needle deflection (.i.e. the
671 // number of degrees we are off the glide slope * 5.0
672 double FGNavCom::get_nav_gs_deflection() const {
673 if ( nav_inrange && nav_has_gs
674 && nav_serviceable->getBoolValue() && gs_serviceable->getBoolValue() )
676 double x = nav_gs_dist;
677 double y = (fgGetDouble("/position/altitude-ft") - nav_elev)
679 // cout << "dist = " << x << " height = " << y << endl;
680 double angle = asin( y / x ) * SGD_RADIANS_TO_DEGREES;
681 return (nav_target_gs - angle) * 5.0;
689 * Return true if the NAV TO flag should be active.
692 FGNavCom::get_nav_to_flag () const
695 && nav_serviceable->getBoolValue()
696 && tofrom_serviceable->getBoolValue() )
698 double offset = fabs(nav_radial - nav_target_radial);
702 return !(offset <= 90.0 || offset >= 270.0);
711 * Return true if the NAV FROM flag should be active.
714 FGNavCom::get_nav_from_flag () const
717 && nav_serviceable->getBoolValue()
718 && tofrom_serviceable->getBoolValue() ) {
719 double offset = fabs(nav_radial - nav_target_radial);
723 return !(offset > 90.0 && offset < 270.0);
732 * Return the current radial.
735 FGNavCom::get_nav_radial () const
741 FGNavCom::get_nav_reciprocal_radial () const
743 double recip = nav_radial + 180;
744 if ( recip >= 360 ) {