From 9eca656a98acf694d0a54972910762a73fdb6302 Mon Sep 17 00:00:00 2001 From: Dave Luff Date: Tue, 7 Dec 2010 17:34:30 +0000 Subject: [PATCH] KLN89: Remove several bugs related to OBS mode --- src/Instrumentation/KLN89/kln89.cxx | 7 +++- src/Instrumentation/KLN89/kln89_page_nav.cxx | 4 +- src/Instrumentation/dclgps.cxx | 40 +++++++++++++++++--- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/Instrumentation/KLN89/kln89.cxx b/src/Instrumentation/KLN89/kln89.cxx index 7e0a1834e..67ab0e99f 100644 --- a/src/Instrumentation/KLN89/kln89.cxx +++ b/src/Instrumentation/KLN89/kln89.cxx @@ -606,8 +606,11 @@ void KLN89::AltPressed() {} void KLN89::OBSPressed() { ToggleOBSMode(); if(_obsMode) { - // if(ORS 02) - _mode = KLN89_MODE_CRSR; + if(!fgGetBool("/instrumentation/nav/slaved-to-gps")) { + // NOTE: this only applies to ORS 02 firmware, in ORS 01 + // CRSR mode is not automatically set when OBS is started. + _mode = KLN89_MODE_CRSR; + } _activePage->OBSPressed(); } } diff --git a/src/Instrumentation/KLN89/kln89_page_nav.cxx b/src/Instrumentation/KLN89/kln89_page_nav.cxx index 7804878cf..f376c9384 100644 --- a/src/Instrumentation/KLN89/kln89_page_nav.cxx +++ b/src/Instrumentation/KLN89/kln89_page_nav.cxx @@ -83,7 +83,9 @@ void KLN89NavPage::Update(double dt) { } _kln89->DrawText(awp->id, 2, 10, 3); if(!_kln89->_dto && !_kln89->_obsMode && !_kln89->_fromWaypoint.id.empty()) { - _kln89->DrawText(_kln89->_fromWaypoint.id, 2, 1, 3); + if(_kln89->_fromWaypoint.type != GPS_WP_VIRT) { // Don't draw the virtual waypoint names + _kln89->DrawText(_kln89->_fromWaypoint.id, 2, 1, 3); + } } if(!(crsr && blink && _uLinePos == 1)) { if(_cdiFormat == 0) { diff --git a/src/Instrumentation/dclgps.cxx b/src/Instrumentation/dclgps.cxx index f9b4610f5..92aa558cf 100644 --- a/src/Instrumentation/dclgps.cxx +++ b/src/Instrumentation/dclgps.cxx @@ -489,8 +489,7 @@ void DCLGPS::update(double dt) { _fromWaypoint = _activeWaypoint; _activeWaypoint = *_activeFP->waypoints[idx + 1]; _dto = false; - // TODO - course alteration message format is dependent on whether we are slaved HSI/CDI indicator or not. - // For now assume we are not. + // Course alteration message format is dependent on whether we are slaved HSI/CDI indicator or not. string s; if(fgGetBool("/instrumentation/nav[0]/slaved-to-gps")) { // TODO - avoid the hardwiring on nav[0] @@ -1010,7 +1009,7 @@ void DCLGPS::DtoInitiate(const string& s) { _fromWaypoint.lat = _gpsLat; _fromWaypoint.lon = _gpsLon; _fromWaypoint.type = GPS_WP_VIRT; - _fromWaypoint.id = "DTOWP"; + _fromWaypoint.id = "_DTOWP_"; delete wp; } else { // TODO - Should bring up the user waypoint page. @@ -1030,9 +1029,37 @@ void DCLGPS::DtoCancel() { void DCLGPS::ToggleOBSMode() { _obsMode = !_obsMode; if(_obsMode) { - if(!_activeWaypoint.id.empty()) { - _obsHeading = static_cast(_dtkMag); + // We need to set the OBS heading. The rules for this are: + // + // If the KLN89 is connected to an external HSI or CDI, then the OBS heading must be set + // to the OBS radial on the external indicator, and cannot be changed in the KLN89. + // + // If the KLN89 is not connected to an external indicator, then: + // If there is an active waypoint, the OBS heading is set such that the + // deviation indicator remains at the same deviation (i.e. set to DTK, + // although there may be some small difference). + // + // If there is not an active waypoint, I am not sure what value should be + // set. + // + if(fgGetBool("/instrumentation/nav/slaved-to-gps")) { + _obsHeading = static_cast(fgGetDouble("/instrumentation/nav/radials/selected-deg") + 0.5); + } else if(!_activeWaypoint.id.empty()) { + // NOTE: I am not sure if this is completely correct. There are sometimes small differences + // between DTK and default OBS heading in the simulator (~ 1 or 2 degrees). It might also + // be that OBS heading should be stored as float and only displayed as int, in order to maintain + // the initial bar deviation? + _obsHeading = static_cast(_dtkMag + 0.5); + //cout << "_dtkMag = " << _dtkMag << ", _dtkTrue = " << _dtkTrue << ", _obsHeading = " << _obsHeading << '\n'; + } else { + // TODO - what should we really do here? + _obsHeading = 0; } + + // Valid OBS heading values are 0 -> 359 degrees inclusive (from kln89 simulator). + if(_obsHeading > 359) _obsHeading -= 360; + if(_obsHeading < 0) _obsHeading += 360; + // TODO - the _fromWaypoint location will change as the OBS heading changes. // Might need to store the OBS initiation position somewhere in case it is needed again. SetOBSFromWaypoint(); @@ -1046,7 +1073,8 @@ void DCLGPS::SetOBSFromWaypoint() { // TODO - base the 180 deg correction on the to/from flag. _fromWaypoint = GetPositionOnMagRadial(_activeWaypoint, 10, _obsHeading + 180.0); - _fromWaypoint.id = "OBSWP"; + _fromWaypoint.type = GPS_WP_VIRT; + _fromWaypoint.id = "_OBSWP_"; } void DCLGPS::CDIFSDIncrease() { -- 2.39.5