From 5151f7f5e0ba7c7e6688bdfbc4cea365196e1ed3 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sun, 2 Mar 2014 01:34:04 +0100 Subject: [PATCH] TACAN improvements. - Make search interval for new mobile tacan larger. - Continuous update of mobile tacan position. --- src/Instrumentation/tacan.cxx | 2 +- src/Navaids/navrecord.cxx | 51 ++++++++++++++++++++--------------- src/Navaids/navrecord.hxx | 6 ++++- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/Instrumentation/tacan.cxx b/src/Instrumentation/tacan.cxx index f9b463f50..ca0320abb 100644 --- a/src/Instrumentation/tacan.cxx +++ b/src/Instrumentation/tacan.cxx @@ -208,7 +208,7 @@ void TACAN::disabled() void TACAN::search (double frequency_mhz,const SGGeod& pos) { // reset search time - _time_before_search_sec = 1.0; + _time_before_search_sec = 5; // Get first matching mobile station (carriers/tankers/etc.) // TODO do we need to check for mobile stations with same frequency? Currently diff --git a/src/Navaids/navrecord.cxx b/src/Navaids/navrecord.cxx index bfc78f632..37bd5a194 100644 --- a/src/Navaids/navrecord.cxx +++ b/src/Navaids/navrecord.cxx @@ -119,7 +119,8 @@ FGMobileNavRecord::FGMobileNavRecord( PositionedID aGuid, int range, double multiuse, PositionedID aRunway ): - FGNavRecord(aGuid, type, ident, name, aPos, freq, range, multiuse, aRunway) + FGNavRecord(aGuid, type, ident, name, aPos, freq, range, multiuse, aRunway), + _initial_elevation_ft(aPos.getElevationFt()) { } @@ -139,12 +140,9 @@ const SGVec3d& FGMobileNavRecord::cart() const } //------------------------------------------------------------------------------ -void FGMobileNavRecord::updatePos() +void FGMobileNavRecord::updateVehicle() { - SGTimeStamp now = SGTimeStamp::now(); - if( (now - _last_position_update).toSecs() < 1 ) - return; - _last_position_update = now; + _vehicle_node.clear(); SGPropertyNode* ai_branch = fgGetNode("ai/models"); if( !ai_branch ) @@ -155,7 +153,6 @@ void FGMobileNavRecord::updatePos() return; } - serviceable = true; const std::string& nav_name = name(); // Try any aircraft carriers first @@ -168,11 +165,7 @@ void FGMobileNavRecord::updatePos() || nav_name.find(carrier_name) == std::string::npos ) continue; - modifyPosition(SGGeod::fromDegFt( - carrier[i]->getDoubleValue("position/longitude-deg"), - carrier[i]->getDoubleValue("position/latitude-deg"), - get_elev_ft() - )); + _vehicle_node = carrier[i]; return; } @@ -195,22 +188,38 @@ void FGMobileNavRecord::updatePos() || nav_name.find(callsign) == std::string::npos ) continue; - modifyPosition(SGGeod::fromDegFt( - tanker[j]->getDoubleValue("position/longitude-deg"), - tanker[j]->getDoubleValue("position/latitude-deg"), - tanker[j]->getDoubleValue("position/altitude-ft") - )); + _vehicle_node = tanker[j]; return; } } +} + +//------------------------------------------------------------------------------ +void FGMobileNavRecord::updatePos() +{ + SGTimeStamp now = SGTimeStamp::now(); + if( (now - _last_vehicle_update).toSecs() > (_vehicle_node.valid() ? 5 : 2) ) + { + updateVehicle(); + _last_vehicle_update = now; + } - // If no match was found set 'invalid' position (lat = lon = alt = 0) - modifyPosition(SGGeod()); + if( _vehicle_node.valid() ) + modifyPosition(SGGeod::fromDegFt( + _vehicle_node->getDoubleValue("position/longitude-deg"), + _vehicle_node->getDoubleValue("position/latitude-deg"), + _vehicle_node->getNameString() == "carrier" + ? _initial_elevation_ft + : _vehicle_node->getDoubleValue("position/altitude-ft") + )); + else + // If no match was found set 'invalid' position (lat = lon = 0) + modifyPosition(SGGeod()); - // It's mobile but we do not know where it is... - serviceable = false; + serviceable = _vehicle_node.valid(); } +//------------------------------------------------------------------------------ FGTACANRecord::FGTACANRecord(void) : channel(""), freq(0) diff --git a/src/Navaids/navrecord.hxx b/src/Navaids/navrecord.hxx index f7400ba8f..8aa6fb1bd 100644 --- a/src/Navaids/navrecord.hxx +++ b/src/Navaids/navrecord.hxx @@ -30,6 +30,7 @@ #include "positioned.hxx" #include +#include #include const double FG_NAV_DEFAULT_RANGE = 50; // nm @@ -122,10 +123,13 @@ class FGMobileNavRecord: virtual const SGGeod& geod() const; virtual const SGVec3d& cart() const; + void updateVehicle(); void updatePos(); protected: - SGTimeStamp _last_position_update; + SGTimeStamp _last_vehicle_update; + SGPropertyNode_ptr _vehicle_node; + double _initial_elevation_ft; // Elevation as given in the config file }; class FGTACANRecord : public SGReferenced { -- 2.39.5