1 // navradio.cxx -- class to manage a nav radio instance
3 // Written by Curtis Olson, started April 2000.
5 // Copyright (C) 2000 - 2002 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., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include <simgear/compiler.h>
33 #include <simgear/sg_inlines.h>
34 #include <simgear/math/sg_random.h>
35 #include <simgear/math/vector.hxx>
37 #include <Aircraft/aircraft.hxx>
38 #include <Navaids/navlist.hxx>
40 #include "navradio.hxx"
47 FGNavRadio::FGNavRadio(SGPropertyNode *node) :
48 lon_node(fgGetNode("/position/longitude-deg", true)),
49 lat_node(fgGetNode("/position/latitude-deg", true)),
50 alt_node(fgGetNode("/position/altitude-ft", true)),
55 fmt_alt_freq_node(NULL),
56 sel_radial_node(NULL),
60 nav_serviceable_node(NULL),
61 cdi_serviceable_node(NULL),
62 gs_serviceable_node(NULL),
63 tofrom_serviceable_node(NULL),
66 recip_radial_node(NULL),
67 target_radial_true_node(NULL),
68 target_auto_hdg_node(NULL),
72 cdi_deflection_node(NULL),
73 cdi_xtrack_error_node(NULL),
77 gs_deflection_node(NULL),
78 gs_rate_of_climb_node(NULL),
85 nav_slaved_to_gps_node(NULL),
86 gps_cdi_deflection_node(NULL),
87 gps_to_flag_node(NULL),
88 gps_from_flag_node(NULL),
99 _time_before_search_sec(-1.0)
101 SGPath path( globals->get_fg_root() );
103 term.append( "Navaids/range.term" );
105 low.append( "Navaids/range.low" );
107 high.append( "Navaids/range.high" );
109 term_tbl = new SGInterpTable( term.str() );
110 low_tbl = new SGInterpTable( low.str() );
111 high_tbl = new SGInterpTable( high.str() );
114 for ( i = 0; i < node->nChildren(); ++i ) {
115 SGPropertyNode *child = node->getChild(i);
116 string cname = child->getName();
117 string cval = child->getStringValue();
118 if ( cname == "name" ) {
120 } else if ( cname == "number" ) {
121 num = child->getIntValue();
123 SG_LOG( SG_INSTR, SG_WARN,
124 "Error in nav radio config logic" );
125 if ( name.length() ) {
126 SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
135 FGNavRadio::~FGNavRadio()
149 branch = "/instrumentation/" + name;
151 SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
154 fgGetNode(("/systems/electrical/outputs/" + name).c_str(), true);
157 power_btn_node = node->getChild("power-btn", 0, true);
158 power_btn_node->setBoolValue( true );
159 vol_btn_node = node->getChild("volume", 0, true);
160 ident_btn_node = node->getChild("ident", 0, true);
161 ident_btn_node->setBoolValue( true );
162 audio_btn_node = node->getChild("audio-btn", 0, true);
163 audio_btn_node->setBoolValue( true );
164 nav_serviceable_node = node->getChild("serviceable", 0, true);
165 cdi_serviceable_node = (node->getChild("cdi", 0, true))
166 ->getChild("serviceable", 0, true);
167 gs_serviceable_node = (node->getChild("gs", 0, true))
168 ->getChild("serviceable");
169 tofrom_serviceable_node = (node->getChild("to-from", 0, true))
170 ->getChild("serviceable", 0, true);
173 SGPropertyNode *subnode = node->getChild("frequencies", 0, true);
174 freq_node = subnode->getChild("selected-mhz", 0, true);
175 alt_freq_node = subnode->getChild("standby-mhz", 0, true);
176 fmt_freq_node = subnode->getChild("selected-mhz-fmt", 0, true);
177 fmt_alt_freq_node = subnode->getChild("standby-mhz-fmt", 0, true);
180 subnode = node->getChild("radials", 0, true);
181 sel_radial_node = subnode->getChild("selected-deg", 0, true);
182 radial_node = subnode->getChild("actual-deg", 0, true);
183 recip_radial_node = subnode->getChild("reciprocal-radial-deg", 0, true);
184 target_radial_true_node = subnode->getChild("target-radial-deg", 0, true);
185 target_auto_hdg_node = subnode->getChild("target-auto-hdg-deg", 0, true);
188 heading_node = node->getChild("heading-deg", 0, true);
189 to_flag_node = node->getChild("to-flag", 0, true);
190 from_flag_node = node->getChild("from-flag", 0, true);
191 inrange_node = node->getChild("in-range", 0, true);
192 cdi_deflection_node = node->getChild("heading-needle-deflection", 0, true);
193 cdi_xtrack_error_node = node->getChild("crosstrack-error-m", 0, true);
194 has_gs_node = node->getChild("has-gs", 0, true);
195 loc_node = node->getChild("nav-loc", 0, true);
196 loc_dist_node = node->getChild("nav-distance", 0, true);
197 gs_deflection_node = node->getChild("gs-needle-deflection", 0, true);
198 gs_rate_of_climb_node = node->getChild("gs-rate-of-climb", 0, true);
199 gs_dist_node = node->getChild("gs-distance", 0, true);
200 nav_id_node = node->getChild("nav-id", 0, true);
201 id_c1_node = node->getChild("nav-id_asc1", 0, true);
202 id_c2_node = node->getChild("nav-id_asc2", 0, true);
203 id_c3_node = node->getChild("nav-id_asc3", 0, true);
204 id_c4_node = node->getChild("nav-id_asc4", 0, true);
206 // gps slaving support
207 nav_slaved_to_gps_node = node->getChild("slaved-to-gps", 0, true);
208 gps_cdi_deflection_node = fgGetNode("/instrumentation/gps/cdi-deflection", true);
209 gps_to_flag_node = fgGetNode("/instrumentation/gps/to-flag", true);
210 gps_from_flag_node = fgGetNode("/instrumentation/gps/from-flag", true);
212 std::ostringstream temp;
213 temp << name << "nav-ident" << num;
214 nav_fx_name = temp.str();
215 temp << name << "dme-ident" << num;
216 dme_fx_name = temp.str();
222 std::ostringstream temp;
225 branch = "/instrumentation/" + name + "[" + temp.str() + "]";
230 FGNavRadio::unbind ()
232 std::ostringstream temp;
235 branch = "/instrumentation/" + name + "[" + temp.str() + "]";
239 // model standard VOR/DME/TACAN service volumes as per AIM 1-1-8
240 double FGNavRadio::adjustNavRange( double stationElev, double aircraftElev,
241 double nominalRange )
243 // extend out actual usable range to be 1.3x the published safe range
244 const double usability_factor = 1.3;
246 // assumptions we model the standard service volume, plus
247 // ... rather than specifying a cylinder, we model a cone that
248 // contains the cylinder. Then we put an upside down cone on top
249 // to model diminishing returns at too-high altitudes.
251 // altitude difference
252 double alt = ( aircraftElev * SG_METER_TO_FEET - stationElev );
253 // cout << "aircraft elev = " << aircraftElev * SG_METER_TO_FEET
254 // << " station elev = " << stationElev << endl;
256 if ( nominalRange < 25.0 + SG_EPSILON ) {
257 // Standard Terminal Service Volume
258 return term_tbl->interpolate( alt ) * usability_factor;
259 } else if ( nominalRange < 50.0 + SG_EPSILON ) {
260 // Standard Low Altitude Service Volume
261 // table is based on range of 40, scale to actual range
262 return low_tbl->interpolate( alt ) * nominalRange / 40.0
265 // Standard High Altitude Service Volume
266 // table is based on range of 130, scale to actual range
267 return high_tbl->interpolate( alt ) * nominalRange / 130.0
273 // model standard ILS service volumes as per AIM 1-1-9
274 double FGNavRadio::adjustILSRange( double stationElev, double aircraftElev,
275 double offsetDegrees, double distance )
277 // assumptions we model the standard service volume, plus
279 // altitude difference
280 // double alt = ( aircraftElev * SG_METER_TO_FEET - stationElev );
281 // double offset = fabs( offsetDegrees );
283 // if ( offset < 10 ) {
284 // return FG_ILS_DEFAULT_RANGE;
285 // } else if ( offset < 35 ) {
286 // return 10 + (35 - offset) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
287 // } else if ( offset < 45 ) {
288 // return (45 - offset);
289 // } else if ( offset > 170 ) {
290 // return FG_ILS_DEFAULT_RANGE;
291 // } else if ( offset > 145 ) {
292 // return 10 + (offset - 145) * (FG_ILS_DEFAULT_RANGE - 10) / 25;
293 // } else if ( offset > 135 ) {
294 // return (offset - 135);
298 return FG_LOC_DEFAULT_RANGE;
302 // Update the various nav values based on position and valid tuned in navs
304 FGNavRadio::update(double dt)
306 // cache values locally for speed
307 double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
308 double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
309 double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
310 bool power_btn = power_btn_node->getBoolValue();
311 bool nav_serviceable = nav_serviceable_node->getBoolValue();
312 bool cdi_serviceable = cdi_serviceable_node->getBoolValue();
313 bool tofrom_serviceable = tofrom_serviceable_node->getBoolValue();
314 bool inrange = inrange_node->getBoolValue();
315 bool has_gs = has_gs_node->getBoolValue();
316 bool is_loc = loc_node->getBoolValue();
317 double loc_dist = loc_dist_node->getDoubleValue();
319 // SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
321 Point3D aircraft = sgGeodToCart( Point3D( lon, lat, elev ) );
325 // Create "formatted" versions of the nav frequencies for
326 // consistant display output.
328 sprintf( tmp, "%.2f", freq_node->getDoubleValue() );
329 fmt_freq_node->setStringValue(tmp);
330 sprintf( tmp, "%.2f", alt_freq_node->getDoubleValue() );
331 fmt_alt_freq_node->setStringValue(tmp);
333 // On timeout, scan again
334 _time_before_search_sec -= dt;
335 if ( _time_before_search_sec < 0 ) {
339 ////////////////////////////////////////////////////////////////////////
341 ////////////////////////////////////////////////////////////////////////
343 // cout << "is_valid = " << is_valid
344 // << " power_btn = " << power_btn
345 // << " bus_power = " << bus_power_node->getDoubleValue()
346 // << " nav_serviceable = " << nav_serviceable
349 if ( is_valid && power_btn
350 && (bus_power_node->getDoubleValue() > 1.0)
353 station = Point3D( nav_x, nav_y, nav_z );
354 loc_dist = aircraft.distance3D( station );
355 loc_dist_node->setDoubleValue( loc_dist );
356 // cout << "station = " << station << " dist = " << loc_dist << endl;
359 // find closest distance to the gs base line
361 sgdSetVec3( p, aircraft.x(), aircraft.y(), aircraft.z() );
363 sgdSetVec3( p0, gs_x, gs_y, gs_z );
364 double dist = sgdClosestPointToLineDistSquared( p, p0,
366 gs_dist_node->setDoubleValue( sqrt( dist ) );
367 // cout << "gs_dist = " << gs_dist_node->getDoubleValue()
370 Point3D tmp( gs_x, gs_y, gs_z );
371 // cout << " (" << aircraft.distance3D( tmp ) << ")" << endl;
373 // wgs84 heading to glide slope (to determine sign of distance)
374 geo_inverse_wgs_84( elev,
375 lat * SGD_RADIANS_TO_DEGREES,
376 lon * SGD_RADIANS_TO_DEGREES,
379 double r = az1 - target_radial;
380 while ( r > 180.0 ) { r -= 360.0;}
381 while ( r < -180.0 ) { r += 360.0;}
382 if ( r >= -90.0 && r <= 90.0 ) {
383 gs_dist_signed = gs_dist_node->getDoubleValue();
385 gs_dist_signed = -gs_dist_node->getDoubleValue();
387 /* cout << "Target Radial = " << target_radial
388 << " Bearing = " << az1
389 << " dist (signed) = " << gs_dist_signed
393 gs_dist_node->setDoubleValue( 0.0 );
396 // wgs84 heading to localizer
398 geo_inverse_wgs_84( elev,
399 lat * SGD_RADIANS_TO_DEGREES,
400 lon * SGD_RADIANS_TO_DEGREES,
403 // cout << "az1 = " << az1 << " magvar = " << nav_magvar << endl;
404 heading_node->setDoubleValue( hdg );
405 radial = az2 - twist;
406 double recip = radial + 180.0;
407 if ( recip >= 360.0 ) { recip -= 360.0; }
408 radial_node->setDoubleValue( radial );
409 recip_radial_node->setDoubleValue( recip );
410 // cout << " heading = " << heading_node->getDoubleValue()
411 // << " dist = " << nav_dist << endl;
414 double offset = radial - target_radial;
415 while ( offset < -180.0 ) { offset += 360.0; }
416 while ( offset > 180.0 ) { offset -= 360.0; }
417 // cout << "ils offset = " << offset << endl;
419 = adjustILSRange( nav_elev, elev, offset,
420 loc_dist * SG_METER_TO_NM );
422 effective_range = adjustNavRange( nav_elev, elev, range );
424 // cout << "nav range = " << effective_range
425 // << " (" << range << ")" << endl;
427 if ( loc_dist < effective_range * SG_NM_TO_METER ) {
429 } else if ( loc_dist < 2 * effective_range * SG_NM_TO_METER ) {
430 inrange = sg_random() < ( 2 * effective_range * SG_NM_TO_METER
432 / (effective_range * SG_NM_TO_METER);
436 inrange_node->setBoolValue( inrange );
439 target_radial = sel_radial_node->getDoubleValue();
442 // Calculate some values for the nav/ils hold autopilot
444 double cur_radial = recip;
446 // ILS localizers radials are already "true" in our
451 if ( from_flag_node->getBoolValue() ) {
453 while ( cur_radial >= 360.0 ) { cur_radial -= 360.0; }
456 // AUTOPILOT/FLIGHT-DIRECTOR HELPERS
458 // determine the target radial in "true" heading
461 // ILS localizers radials are already "true" in our
463 trtrue = target_radial;
465 // VOR radials need to have that vor's offset added in
466 trtrue = target_radial + twist;
469 while ( trtrue < 0.0 ) { trtrue += 360.0; }
470 while ( trtrue > 360.0 ) { trtrue -= 360.0; }
471 target_radial_true_node->setDoubleValue( trtrue );
473 // FIXME: this smells odd, there must be a better (or more
476 // determine the heading adjustment needed.
477 // over 8km scale by 3.0
478 // (3 is chosen because max deflection is 10
479 // and 30 is clamped angle to radial)
480 // under 8km scale by 10.0
481 // because the overstated error helps drive it to the radial in a
482 // moderate cross wind.
483 double adjustment = 0.0;
484 if ( loc_dist > 8000 ) {
485 adjustment = cdi_deflection_node->getDoubleValue() * 3.0;
487 adjustment = cdi_deflection_node->getDoubleValue() * 10.0;
489 SG_CLAMP_RANGE( adjustment, -30.0, 30.0 );
491 // determine the target heading to fly to intercept the
493 double nta_hdg = trtrue + adjustment;
494 while ( nta_hdg < 0.0 ) { nta_hdg += 360.0; }
495 while ( nta_hdg > 360.0 ) { nta_hdg -= 360.0; }
496 target_auto_hdg_node->setDoubleValue( nta_hdg );
501 // Calculate desired rate of climb for intercepting the GS
502 double x = gs_dist_node->getDoubleValue();
503 double y = (alt_node->getDoubleValue() - nav_elev)
505 double current_angle = atan2( y, x ) * SGD_RADIANS_TO_DEGREES;
507 double target_angle = target_gs;
508 double gs_diff = target_angle - current_angle;
510 // convert desired vertical path angle into a climb rate
511 double des_angle = current_angle - 10 * gs_diff;
513 // estimate horizontal speed towards ILS in meters per minute
514 double dist = last_x - x;
518 double new_vel = ( dist / dt );
520 horiz_vel = 0.75 * horiz_vel + 0.25 * new_vel;
521 // double horiz_vel = cur_fdm_state->get_V_ground_speed()
522 // * SG_FEET_TO_METER * 60.0;
523 // double horiz_vel = airspeed_node->getFloatValue()
524 // * SG_FEET_TO_METER * 60.0;
526 gs_rate_of_climb_node
527 ->setDoubleValue( -sin( des_angle * SGD_DEGREES_TO_RADIANS )
528 * horiz_vel * SG_METER_TO_FEET );
531 inrange_node->setBoolValue( false );
532 // cout << "not picking up vor. :-(" << endl;
535 // compute to/from flag status
536 double value = false;
537 double offset = fabs(radial - target_radial);
538 if ( nav_slaved_to_gps_node->getBoolValue() ) {
539 value = gps_to_flag_node->getBoolValue();
540 } else if ( inrange && nav_serviceable && tofrom_serviceable ) {
544 value = !(offset <= 90.0 || offset >= 270.0);
547 to_flag_node->setBoolValue( value );
550 if ( nav_slaved_to_gps_node->getBoolValue() ) {
551 value = gps_from_flag_node->getBoolValue();
552 } else if ( inrange && nav_serviceable && tofrom_serviceable ) {
556 value = !(offset > 90.0 && offset < 270.0);
559 from_flag_node->setBoolValue( value );
561 // compute the deflection of the CDI needle, clamped to the range
564 if ( nav_slaved_to_gps_node->getBoolValue() ) {
565 r = gps_cdi_deflection_node->getDoubleValue();
566 // We want +- 5 dots deflection for the gps, so clamp to -12.5/12.5
567 if ( r < -12.5 ) { r = -12.5; }
568 if ( r > 12.5 ) { r = 12.5; }
569 } else if ( inrange && nav_serviceable && cdi_serviceable ) {
570 r = radial - target_radial;
571 // cout << "Target radial = " << target_radial
572 // << " Actual radial = " << radial << endl;
574 while ( r > 180.0 ) { r -= 360.0;}
575 while ( r < -180.0 ) { r += 360.0;}
576 if ( fabs(r) > 90.0 ) {
577 r = ( r<0.0 ? -r-180.0 : -r+180.0 );
580 // According to Robin Peel, the ILS is 4x more sensitive than a vor
581 r = -r; // reverse, since radial is outbound
582 if ( is_loc ) { r *= 4.0; }
583 if ( r < -10.0 ) { r = -10.0; }
584 if ( r > 10.0 ) { r = 10.0; }
588 cdi_deflection_node->setDoubleValue( r );
590 // compute the amount of cross track distance error in meters
592 if ( inrange && nav_serviceable && cdi_serviceable ) {
593 r = radial - target_radial;
594 // cout << "Target radial = " << target_radial
595 // << " Actual radial = " << radial
596 // << " r = " << r << endl;
598 while ( r > 180.0 ) { r -= 360.0;}
599 while ( r < -180.0 ) { r += 360.0;}
600 if ( fabs(r) > 90.0 ) {
601 r = ( r<0.0 ? -r-180.0 : -r+180.0 );
604 r = -r; // reverse, since radial is outbound
606 m = loc_dist * sin(r * SGD_DEGREES_TO_RADIANS);
611 cdi_xtrack_error_node->setDoubleValue( m );
613 // compute the amount of glide slope needle deflection (.i.e. the
614 // number of degrees we are off the glide slope * 5.0
616 if ( nav_slaved_to_gps_node->getBoolValue() ) {
617 // FIXME, what should be set here?
618 } else if ( inrange && nav_serviceable
619 && has_gs && gs_serviceable_node->getBoolValue() )
621 double x = gs_dist_node->getDoubleValue();
622 double y = (fgGetDouble("/position/altitude-ft") - nav_elev)
624 // cout << "dist = " << x << " height = " << y << endl;
625 double angle = asin( y / x ) * SGD_RADIANS_TO_DEGREES;
626 r = (target_gs - angle) * 5.0;
628 gs_deflection_node->setDoubleValue( r );
631 if ( is_valid && inrange && nav_serviceable ) {
632 // play station ident via audio system if on + ident,
633 // otherwise turn it off
635 && (bus_power_node->getDoubleValue() > 1.0)
636 && ident_btn_node->getBoolValue()
637 && audio_btn_node->getBoolValue() )
639 SGSoundSample *sound;
640 sound = globals->get_soundmgr()->find( nav_fx_name );
641 double vol = vol_btn_node->getDoubleValue();
642 if ( vol < 0.0 ) { vol = 0.0; }
643 if ( vol > 1.0 ) { vol = 1.0; }
644 if ( sound != NULL ) {
645 sound->set_volume( vol );
647 SG_LOG( SG_COCKPIT, SG_ALERT,
648 "Can't find nav-vor-ident sound" );
650 sound = globals->get_soundmgr()->find( dme_fx_name );
651 if ( sound != NULL ) {
652 sound->set_volume( vol );
654 SG_LOG( SG_COCKPIT, SG_ALERT,
655 "Can't find nav-dme-ident sound" );
657 // cout << "last_time = " << last_time << " ";
658 // cout << "cur_time = "
659 // << globals->get_time_params()->get_cur_time();
661 globals->get_time_params()->get_cur_time() - 30 ) {
662 last_time = globals->get_time_params()->get_cur_time();
665 // cout << " play_count = " << play_count << endl;
666 // cout << "playing = "
667 // << globals->get_soundmgr()->is_playing(nav_fx_name)
669 if ( play_count < 4 ) {
671 if ( !globals->get_soundmgr()->is_playing(nav_fx_name) ) {
672 globals->get_soundmgr()->play_once( nav_fx_name );
675 } else if ( play_count < 5 && has_dme ) {
677 if ( !globals->get_soundmgr()->is_playing(nav_fx_name) &&
678 !globals->get_soundmgr()->is_playing(dme_fx_name) ) {
679 globals->get_soundmgr()->play_once( dme_fx_name );
684 globals->get_soundmgr()->stop( nav_fx_name );
685 globals->get_soundmgr()->stop( dme_fx_name );
691 // Update current nav/adf radio stations based on current postition
692 void FGNavRadio::search()
696 _time_before_search_sec = 1.0;
698 // cache values locally for speed
699 double lon = lon_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
700 double lat = lat_node->getDoubleValue() * SGD_DEGREES_TO_RADIANS;
701 double elev = alt_node->getDoubleValue() * SG_FEET_TO_METER;
703 FGNavRecord *nav = NULL;
704 FGNavRecord *loc = NULL;
705 FGNavRecord *dme = NULL;
706 FGNavRecord *gs = NULL;
708 ////////////////////////////////////////////////////////////////////////
710 ////////////////////////////////////////////////////////////////////////
712 double freq = freq_node->getDoubleValue();
713 nav = globals->get_navlist()->findByFreq(freq, lon, lat, elev);
714 dme = globals->get_dmelist()->findByFreq(freq, lon, lat, elev);
716 loc = globals->get_loclist()->findByFreq(freq, lon, lat, elev);
717 gs = globals->get_gslist()->findByFreq(freq, lon, lat, elev);
723 nav_id = loc->get_ident();
724 nav_id_node->setStringValue( nav_id.c_str() );
725 // cout << "localizer = " << nav_id_node->getStringValue() << endl;
727 if ( last_nav_id != nav_id || last_nav_vor ) {
728 trans_ident = loc->get_trans_ident();
729 target_radial = loc->get_multiuse();
730 while ( target_radial < 0.0 ) { target_radial += 360.0; }
731 while ( target_radial > 360.0 ) { target_radial -= 360.0; }
732 loc_lon = loc->get_lon();
733 loc_lat = loc->get_lat();
734 nav_x = loc->get_x();
735 nav_y = loc->get_y();
736 nav_z = loc->get_z();
737 last_nav_id = nav_id;
738 last_nav_vor = false;
739 loc_node->setBoolValue( true );
740 has_dme = (dme != NULL);
742 has_gs_node->setBoolValue( true );
743 gs_lon = gs->get_lon();
744 gs_lat = gs->get_lat();
745 nav_elev = gs->get_elev_ft();
746 int tmp = (int)(gs->get_multiuse() / 1000.0);
747 target_gs = (double)tmp / 100.0;
752 // derive GS baseline (perpendicular to the runay
754 double tlon, tlat, taz;
755 geo_direct_wgs_84 ( 0.0, gs_lat, gs_lon,
757 100.0, &tlat, &tlon, &taz );
758 // cout << "target_radial = " << target_radial << endl;
759 // cout << "nav_loc = " << loc_node->getBoolValue() << endl;
760 // cout << gs_lon << "," << gs_lat << " "
761 // << tlon << "," << tlat << " (" << nav_elev << ")"
763 Point3D p1 = sgGeodToCart( Point3D(tlon*SGD_DEGREES_TO_RADIANS,
764 tlat*SGD_DEGREES_TO_RADIANS,
765 nav_elev*SG_FEET_TO_METER)
767 // cout << gs_x << "," << gs_y << "," << gs_z
769 // cout << p1 << endl;
770 sgdSetVec3( gs_base_vec,
771 p1.x()-gs_x, p1.y()-gs_y, p1.z()-gs_z );
772 // cout << gs_base_vec[0] << "," << gs_base_vec[1] << ","
773 // << gs_base_vec[2] << endl;
775 has_gs_node->setBoolValue( false );
776 nav_elev = loc->get_elev_ft();
779 range = FG_LOC_DEFAULT_RANGE;
780 effective_range = range;
782 if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
783 globals->get_soundmgr()->remove( nav_fx_name );
785 SGSoundSample *sound;
786 sound = morse.make_ident( trans_ident, LO_FREQUENCY );
787 sound->set_volume( 0.3 );
788 globals->get_soundmgr()->add( sound, nav_fx_name );
790 if ( globals->get_soundmgr()->exists( dme_fx_name ) ) {
791 globals->get_soundmgr()->remove( dme_fx_name );
793 sound = morse.make_ident( trans_ident, HI_FREQUENCY );
794 sound->set_volume( 0.3 );
795 globals->get_soundmgr()->add( sound, dme_fx_name );
797 int offset = (int)(sg_random() * 30.0);
798 play_count = offset / 4;
799 last_time = globals->get_time_params()->get_cur_time() -
801 // cout << "offset = " << offset << " play_count = "
803 // << " last_time = " << last_time
804 // << " current time = "
805 // << globals->get_time_params()->get_cur_time() << endl;
807 // cout << "Found an loc station in range" << endl;
808 // cout << " id = " << loc->get_locident() << endl;
810 } else if ( nav != NULL ) {
811 nav_id = nav->get_ident();
812 nav_id_node->setStringValue( nav_id.c_str() );
813 // cout << "nav = " << nav_id << endl;
815 if ( last_nav_id != nav_id || !last_nav_vor ) {
816 last_nav_id = nav_id;
818 trans_ident = nav->get_trans_ident();
819 loc_node->setBoolValue( false );
820 has_dme = (dme != NULL);
821 has_gs_node->setBoolValue( false );
822 loc_lon = nav->get_lon();
823 loc_lat = nav->get_lat();
824 nav_elev = nav->get_elev_ft();
825 twist = nav->get_multiuse();
826 range = nav->get_range();
827 effective_range = adjustNavRange(nav_elev, elev, range);
829 target_radial = sel_radial_node->getDoubleValue();
830 nav_x = nav->get_x();
831 nav_y = nav->get_y();
832 nav_z = nav->get_z();
834 if ( globals->get_soundmgr()->exists( nav_fx_name ) ) {
835 globals->get_soundmgr()->remove( nav_fx_name );
837 SGSoundSample *sound;
838 sound = morse.make_ident( trans_ident, LO_FREQUENCY );
839 sound->set_volume( 0.3 );
840 if ( globals->get_soundmgr()->add( sound, nav_fx_name ) ) {
841 // cout << "Added nav-vor-ident sound" << endl;
843 SG_LOG(SG_COCKPIT, SG_WARN, "Failed to add v1-vor-ident sound");
846 if ( globals->get_soundmgr()->exists( dme_fx_name ) ) {
847 globals->get_soundmgr()->remove( dme_fx_name );
849 sound = morse.make_ident( trans_ident, HI_FREQUENCY );
850 sound->set_volume( 0.3 );
851 globals->get_soundmgr()->add( sound, dme_fx_name );
853 int offset = (int)(sg_random() * 30.0);
854 play_count = offset / 4;
855 last_time = globals->get_time_params()->get_cur_time() - offset;
856 // cout << "offset = " << offset << " play_count = "
857 // << play_count << " last_time = "
858 // << last_time << " current time = "
859 // << globals->get_time_params()->get_cur_time() << endl;
861 // cout << "Found a vor station in range" << endl;
862 // cout << " id = " << nav->get_ident() << endl;
866 nav_id_node->setStringValue( "" );
870 if ( ! globals->get_soundmgr()->remove( nav_fx_name ) ) {
871 SG_LOG(SG_COCKPIT, SG_WARN, "Failed to remove nav-vor-ident sound");
873 globals->get_soundmgr()->remove( dme_fx_name );
874 // cout << "not picking up vor1. :-(" << endl;
878 strncpy( tmpid, nav_id.c_str(), 5 );
879 id_c1_node->setIntValue( (int)tmpid[0] );
880 id_c2_node->setIntValue( (int)tmpid[1] );
881 id_c3_node->setIntValue( (int)tmpid[2] );
882 id_c4_node->setIntValue( (int)tmpid[3] );