X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fnavradio.cxx;h=073e28621429d085fdf99d366a31770e8f368e67;hb=7e8ee5a3a86ada7050b7255309ee044cebf21051;hp=fe0533d8cad3f379574e032ec1541b8735eed8d5;hpb=9fa790bcac7e535bb06cd228ae15178f1b10b26f;p=flightgear.git diff --git a/src/Instrumentation/navradio.cxx b/src/Instrumentation/navradio.cxx index fe0533d8c..073e28621 100644 --- a/src/Instrumentation/navradio.cxx +++ b/src/Instrumentation/navradio.cxx @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -34,6 +35,7 @@ #include #include #include +#include #include #include @@ -96,14 +98,15 @@ SGPropertyNode_ptr createServiceableProp(SGPropertyNode* aParent, return n; } +static std::auto_ptr static_terminalRangeInterp, + static_lowRangeInterp, static_highRangeInterp; + // Constructor FGNavRadio::FGNavRadio(SGPropertyNode *node) : - term_tbl(NULL), - low_tbl(NULL), - high_tbl(NULL), _operable(false), play_count(0), - last_time(0), + _nav_search(true), + _last_freq(0.0), target_radial(0.0), effective_range(0.0), target_gs(0.0), @@ -127,18 +130,21 @@ FGNavRadio::FGNavRadio(SGPropertyNode *node) : _gsNeedleDeflectionNorm(0.0), _audioIdent(NULL) { - SGPath path( globals->get_fg_root() ); - SGPath term = path; - term.append( "Navaids/range.term" ); - SGPath low = path; - low.append( "Navaids/range.low" ); - SGPath high = path; - high.append( "Navaids/range.high" ); - - term_tbl = new SGInterpTable( term.str() ); - low_tbl = new SGInterpTable( low.str() ); - high_tbl = new SGInterpTable( high.str() ); - + if (!static_terminalRangeInterp.get()) { + // one-time interpolator init + SGPath path( globals->get_fg_root() ); + SGPath term = path; + term.append( "Navaids/range.term" ); + SGPath low = path; + low.append( "Navaids/range.low" ); + SGPath high = path; + high.append( "Navaids/range.high" ); + + static_terminalRangeInterp.reset(new SGInterpTable(term.str())); + static_lowRangeInterp.reset(new SGInterpTable(low.str())); + static_highRangeInterp.reset(new SGInterpTable(high.str())); + } + string branch("/instrumentation/" + _name); _radio_node = fgGetNode(branch.c_str(), _num, true); } @@ -155,10 +161,6 @@ FGNavRadio::~FGNavRadio() nav_slaved_to_gps_node->removeChangeListener(this); } - delete term_tbl; - delete low_tbl; - delete high_tbl; - delete _audioIdent; } @@ -168,7 +170,7 @@ FGNavRadio::init () { SGPropertyNode* node = _radio_node.get(); bus_power_node = - fgGetNode(("/systems/electrical/outputs/" + _name).c_str(), true); + fgGetNode(("/systems/electrical/outputs/" + _name).c_str(), true); // inputs is_valid_node = node->getChild("data-is-valid", 0, true); @@ -267,6 +269,12 @@ FGNavRadio::init () node->getNode( "dme-in-range", true )->alias( fgGetNode("/instrumentation/dme[0]/in-range", true ) ); } +void +FGNavRadio::reinit () +{ + _time_before_search_sec = -1.0; +} + void FGNavRadio::bind () { @@ -303,17 +311,17 @@ double FGNavRadio::adjustNavRange( double stationElev, double aircraftElev, // << " station elev = " << stationElev << endl; if ( nominalRange < 25.0 + SG_EPSILON ) { - // Standard Terminal Service Volume - return term_tbl->interpolate( alt ) * usability_factor; + // Standard Terminal Service Volume + return static_terminalRangeInterp->interpolate( alt ) * usability_factor; } else if ( nominalRange < 50.0 + SG_EPSILON ) { // Standard Low Altitude Service Volume // table is based on range of 40, scale to actual range - return low_tbl->interpolate( alt ) * nominalRange / 40.0 + return static_lowRangeInterp->interpolate( alt ) * nominalRange / 40.0 * usability_factor; } else { // Standard High Altitude Service Volume // table is based on range of 130, scale to actual range - return high_tbl->interpolate( alt ) * nominalRange / 130.0 + return static_highRangeInterp->interpolate( alt ) * nominalRange / 130.0 * usability_factor; } } @@ -453,6 +461,8 @@ void FGNavRadio::updateReceiver(double dt) heading_node->setDoubleValue(0.0); inrange_node->setBoolValue(false); signal_quality_norm_node->setDoubleValue(0.0); + gs_dist_node->setDoubleValue( 0.0 ); + gs_inrange_node->setBoolValue(false); return; } @@ -562,7 +572,7 @@ void FGNavRadio::updateReceiver(double dt) } // of false courses disabled const double VOR_FULL_ARC = 20.0; // VOR is -10 .. 10 degree swing - _cdiDeflection *= VOR_FULL_ARC / _localizerWidth; // increased localiser sensitivity + _cdiDeflection *= VOR_FULL_ARC / _localizerWidth; // increased localizer sensitivity if (backcourse_node->getBoolValue()) { _cdiDeflection = -_cdiDeflection; @@ -573,12 +583,12 @@ void FGNavRadio::updateReceiver(double dt) r = ( r<0.0 ? -r-180.0 : -r+180.0 ); } _cdiDeflection = r; - } // of non-localiser case + } // of non-localizer case SG_CLAMP_RANGE(_cdiDeflection, -10.0, 10.0 ); _cdiDeflection *= signal_quality_norm; - // cross-track error (in metres) + // cross-track error (in meters) _cdiCrossTrackErrorM = loc_dist * sin(r * SGD_DEGREES_TO_RADIANS); updateGlideSlope(dt, aircraft, signal_quality_norm); @@ -586,22 +596,25 @@ void FGNavRadio::updateReceiver(double dt) void FGNavRadio::updateGlideSlope(double dt, const SGVec3d& aircraft, double signal_quality_norm) { - _gsNeedleDeflection = 0.0; - if (!_gs || !inrange_node->getBoolValue()) { - gs_dist_node->setDoubleValue( 0.0 ); - gs_inrange_node->setBoolValue(false); + bool gsInRange = (_gs && inrange_node->getBoolValue()); + double gsDist = 0; + + if (gsInRange) + { + gsDist = dist(aircraft, _gsCart); + gsInRange = (gsDist < (_gs->get_range() * SG_NM_TO_METER)); + } + + gs_inrange_node->setBoolValue(gsInRange); + gs_dist_node->setDoubleValue( gsDist ); + + if (!gsInRange) + { _gsNeedleDeflection = 0.0; _gsNeedleDeflectionNorm = 0.0; return; } - double gsDist = dist(aircraft, _gsCart); - gs_dist_node->setDoubleValue(gsDist); - bool gsInRange = (gsDist < (_gs->get_range() * SG_NM_TO_METER)); - gs_inrange_node->setBoolValue(gsInRange); - - if (!gsInRange) return; - SGVec3d pos = aircraft - _gsCart; // relative vector from gs antenna to aircraft // The positive GS axis points along the runway in the landing direction, // toward the far end, not toward the approach area, so we need a - sign here: @@ -792,7 +805,7 @@ void FGNavRadio::updateCDI(double dt) SG_CLAMP_RANGE( adjustment, -30.0, 30.0 ); // determine the target heading to fly to intercept the - // tgt_radial = target radial (true) + cdi offset adjustmest - + // tgt_radial = target radial (true) + cdi offset adjustment - // xtrack heading error adjustment double nta_hdg; double trtrue = target_radial_true_node->getDoubleValue(); @@ -860,26 +873,60 @@ void FGNavRadio::updateAudio( double dt ) FGNavRecord* FGNavRadio::findPrimaryNavaid(const SGGeod& aPos, double aFreqMHz) { - FGNavRecord* nav = globals->get_navlist()->findByFreq(aFreqMHz, aPos); - if (nav) { - return nav; - } - - return globals->get_loclist()->findByFreq(aFreqMHz, aPos); + return FGNavList::findByFreq(aFreqMHz, aPos, FGNavList::navFilter()); } -// Update current nav/adf radio stations based on current postition +// Update current nav/adf radio stations based on current position void FGNavRadio::search() { + // set delay for next search _time_before_search_sec = 1.0; + double freq = freq_node->getDoubleValue(); - - FGNavRecord* nav = findPrimaryNavaid(globals->get_aircraft_position(), freq); - if (nav == _navaid) { - return; // found the same as last search, we're done + + // immediate NAV search when frequency has changed (toggle between nav and g/s search otherwise) + _nav_search |= (_last_freq != freq); + + // do we need to search a new NAV station in this iteration? + if (_nav_search) + { + _last_freq = freq; + FGNavRecord* nav = findPrimaryNavaid(globals->get_aircraft_position(), freq); + if (nav == _navaid) { + if (nav && (nav->type() != FGPositioned::VOR)) + _nav_search = false; // search glideslope on next iteration + return; // nav hasn't changed, we're done + } + // remember new navaid station + _navaid = nav; } - - _navaid = nav; + + // search glideslope station + if ((_navaid.valid()) && (_navaid->type() != FGPositioned::VOR)) + { + FGNavList::TypeFilter gsFilter(FGPositioned::GS); + FGNavRecord* gs = FGNavList::findByFreq(freq, globals->get_aircraft_position(), + &gsFilter); + if ((!_nav_search) && (gs == _gs)) + { + _nav_search = true; // search NAV on next iteration + return; // g/s hasn't changed, neither has nav - we're done + } + // remember new glideslope station + _gs = gs; + } + + _nav_search = true; // search NAV on next iteration + + // nav or gs station has changed + updateNav(); +} + +// Update current nav/adf/glideslope outputs when station has changed +void FGNavRadio::updateNav() +{ + // update necessary, nav and/or gs has changed + FGNavRecord* nav = _navaid; string identBuffer(4, ' '); if (nav) { nav_id_node->setStringValue(nav->get_ident()); @@ -892,17 +939,14 @@ void FGNavRadio::search() if (nav->type() == FGPositioned::VOR) { target_radial = sel_radial_node->getDoubleValue(); _gs = NULL; - has_gs_node->setBoolValue(false); } else { // ILS or LOC - _gs = globals->get_gslist()->findByFreq(freq, globals->get_aircraft_position()); - has_gs_node->setBoolValue(_gs != NULL); _localizerWidth = nav->localizerWidth(); twist = 0.0; - effective_range = nav->get_range(); + effective_range = nav->get_range(); target_radial = nav->get_multiuse(); SG_NORMALIZE_RANGE(target_radial, 0.0, 360.0); - + if (_gs) { int tmp = (int)(_gs->get_multiuse() / 1000.0); target_gs = (double)tmp / 100.0; @@ -916,7 +960,7 @@ void FGNavRadio::search() _gsAxis = tangentVector(_gs->geod(), gs_radial); // GS baseline unit tangent vector - // (transverse to the runay along the ground) + // (transverse to the runway along the ground) _gsBaseline = tangentVector(_gs->geod(), gs_radial + 90.0); _gsVertical = cross(_gsBaseline, _gsAxis); } // of have glideslope @@ -926,10 +970,10 @@ void FGNavRadio::search() _gs = NULL; nav_id_node->setStringValue(""); loc_node->setBoolValue(false); - has_gs_node->setBoolValue(false); _audioIdent->setIdent("", 0.0 ); } + has_gs_node->setBoolValue(_gs != NULL); is_valid_node->setBoolValue(nav != NULL); id_c1_node->setIntValue( (int)identBuffer[0] ); id_c2_node->setIntValue( (int)identBuffer[1] );