From f780c27787836a552f5dd13a980228e3ae6e711e Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 7 Feb 2001 04:16:12 +0000 Subject: [PATCH] Changes to make the default autopilot heading hold work much more like a C172 DG heading hold (i.e. it will follow the gyro drift.) --- src/Autopilot/newauto.cxx | 36 ++++++++++++++++++++++++++---------- src/Autopilot/newauto.hxx | 14 +++++++++----- src/Cockpit/steam.cxx | 4 ++-- src/Main/bfi.cxx | 21 +++++++++++++++++++++ src/Main/bfi.hxx | 3 +++ src/Main/keyboard.cxx | 4 ++-- 6 files changed, 63 insertions(+), 19 deletions(-) diff --git a/src/Autopilot/newauto.cxx b/src/Autopilot/newauto.cxx index 8c3d575fc..e5a22ce7f 100644 --- a/src/Autopilot/newauto.cxx +++ b/src/Autopilot/newauto.cxx @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -365,8 +366,15 @@ int FGAutopilot::run() { // heading hold if ( heading_hold == true ) { + if ( heading_mode == FG_DG_HEADING_LOCK ) { + // cout << "DG heading = " << FGSteam::get_DG_deg() + // << " DG error = " << FGSteam::get_DG_err() << endl; - if ( heading_mode == FG_HEADING_LOCK ) { + TargetHeading = DGTargetHeading + FGSteam::get_DG_err(); + while ( TargetHeading < 0.0 ) { TargetHeading += 360.0; } + while ( TargetHeading > 360.0 ) { TargetHeading -= 360.0; } + MakeTargetHeadingStr( TargetHeading ); + } else if ( heading_mode == FG_HEADING_LOCK ) { // leave target heading alone } else if ( heading_mode == FG_HEADING_NAV1 ) { double tgt_radial; @@ -376,7 +384,7 @@ int FGAutopilot::run() { tgt_radial = current_radiostack->get_nav1_radial(); } else { tgt_radial = current_radiostack->get_nav1_radial() + - current_radiostack->get_nav1_magvar(); + current_radiostack->get_nav1_magvar(); } cur_radial = current_radiostack->get_nav1_heading() + current_radiostack->get_nav1_magvar(); @@ -718,7 +726,10 @@ int FGAutopilot::run() { void FGAutopilot::set_HeadingMode( fgAutoHeadingMode mode ) { heading_mode = mode; - if ( heading_mode == FG_HEADING_LOCK ) { + if ( heading_mode == FG_DG_HEADING_LOCK ) { + // set heading hold to current heading (as read from DG) + DGTargetHeading = FGSteam::get_DG_deg(); + } else if ( heading_mode == FG_HEADING_LOCK ) { // set heading hold to current heading TargetHeading = FGBFI::getHeading(); } else if ( heading_mode == FG_HEADING_WAYPOINT ) { @@ -923,14 +934,19 @@ void FGAutopilot::AltitudeAdjust( double inc ) void FGAutopilot::HeadingAdjust( double inc ) { - heading_mode = FG_HEADING_LOCK; - - double target = ( int ) ( TargetHeading / inc ) * inc + inc; + if ( heading_mode != FG_DG_HEADING_LOCK && heading_mode != FG_HEADING_LOCK ) + { + heading_mode = FG_DG_HEADING_LOCK; + } + + if ( heading_mode == FG_DG_HEADING_LOCK ) { + double target = ( int ) ( DGTargetHeading / inc ) * inc + inc; + DGTargetHeading = NormalizeDegrees( target ); + } else { + double target = ( int ) ( TargetHeading / inc ) * inc + inc; + TargetHeading = NormalizeDegrees( target ); + } - TargetHeading = NormalizeDegrees( target ); - // following cast needed ambiguous plib - // ApHeadingDialogInput -> setValue ((float)TargetHeading ); - MakeTargetHeadingStr( TargetHeading ); update_old_control_values(); } diff --git a/src/Autopilot/newauto.hxx b/src/Autopilot/newauto.hxx index 1670b71bf..9efd67eba 100644 --- a/src/Autopilot/newauto.hxx +++ b/src/Autopilot/newauto.hxx @@ -36,10 +36,11 @@ class FGAutopilot { public: enum fgAutoHeadingMode { - FG_HEADING_LOCK = 0, - FG_HEADING_NAV1 = 1, - FG_HEADING_NAV2 = 2, - FG_HEADING_WAYPOINT = 3 + FG_DG_HEADING_LOCK = 0, + FG_HEADING_LOCK = 1, + FG_HEADING_NAV1 = 2, + FG_HEADING_NAV2 = 3, + FG_HEADING_WAYPOINT = 4 }; enum fgAutoAltitudeMode { @@ -63,7 +64,8 @@ private: // double TargetLatitude; // the latitude the AP should steer to. // double TargetLongitude; // the longitude the AP should steer to. double TargetDistance; // the distance to Target. - double TargetHeading; // the heading the AP should steer to. + double DGTargetHeading; // the apparent DG heading to steer towards. + double TargetHeading; // the true heading the AP should steer to. double TargetAltitude; // altitude to hold double TargetAGL; // the terrain separation double TargetClimbRate; // climb rate to shoot for @@ -151,6 +153,8 @@ public: inline void set_old_lon( double val ) { old_lon = val; } inline double get_TargetHeading() const { return TargetHeading; } inline void set_TargetHeading( double val ) { TargetHeading = val; } + inline double get_DGTargetHeading() const { return DGTargetHeading; } + inline void set_DGTargetHeading( double val ) { DGTargetHeading = val; } inline double get_TargetDistance() const { return TargetDistance; } inline void set_TargetDistance( double val ) { TargetDistance = val; } inline double get_TargetAltitude() const { return TargetAltitude; } diff --git a/src/Cockpit/steam.cxx b/src/Cockpit/steam.cxx index 7b4802709..1132e0859 100644 --- a/src/Cockpit/steam.cxx +++ b/src/Cockpit/steam.cxx @@ -123,8 +123,8 @@ void FGSteam::update ( int timesteps ) fgTie("/steam/glidescope1", FGSteam::get_HackGS_deg); fgTie("/steam/adf", FGSteam::get_HackADF_deg); fgTie("/steam/gyro-compass-error", - FGSteam::get_DG_err, - FGSteam::set_DG_err); + FGSteam::get_DG_err, FGSteam::set_DG_err, + false); /* don't modify the value */ fgTie("/steam/mag-compass", FGSteam::get_MH_deg); } _UpdatesPending += timesteps; diff --git a/src/Main/bfi.cxx b/src/Main/bfi.cxx index 531250958..8b749b2bd 100644 --- a/src/Main/bfi.cxx +++ b/src/Main/bfi.cxx @@ -197,6 +197,7 @@ FGBFI::init () fgTie("/autopilot/settings/altitude", getAPAltitude, setAPAltitude); fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock); fgTie("/autopilot/settings/heading", getAPHeading, setAPHeading); + fgTie("/autopilot/settings/heading-dg", getAPHeadingDG, setAPHeadingDG); fgTie("/autopilot/settings/heading-magnetic", getAPHeadingMag, setAPHeadingMag); fgTie("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock); @@ -1049,6 +1050,26 @@ FGBFI::setAPHeading (double heading) } +/** + * Get the autopilot DG target heading in degrees. + */ +double +FGBFI::getAPHeadingDG () +{ + return current_autopilot->get_DGTargetHeading(); +} + + +/** + * Set the autopilot DG target heading in degrees. + */ +void +FGBFI::setAPHeadingDG (double heading) +{ + current_autopilot->set_DGTargetHeading( heading ); +} + + /** * Get the autopilot target heading in degrees. */ diff --git a/src/Main/bfi.hxx b/src/Main/bfi.hxx index 24b38ebe6..1e8141637 100644 --- a/src/Main/bfi.hxx +++ b/src/Main/bfi.hxx @@ -137,6 +137,9 @@ public: static double getAPHeading (); // degrees static void setAPHeading (double heading); // degrees + static double getAPHeadingDG (); // degrees + static void setAPHeadingDG (double heading); // degrees + static double getAPHeadingMag (); // degrees static void setAPHeadingMag (double heading); // degrees diff --git a/src/Main/keyboard.cxx b/src/Main/keyboard.cxx index f17aaae45..22c937da7 100644 --- a/src/Main/keyboard.cxx +++ b/src/Main/keyboard.cxx @@ -108,8 +108,8 @@ void GLUTkey(unsigned char k, int x, int y) { ); return; case 8: // Ctrl-H key - current_autopilot->set_HeadingMode( - FGAutopilot::FG_HEADING_LOCK ); + current_autopilot->set_HeadingMode( + FGAutopilot::FG_DG_HEADING_LOCK ); current_autopilot->set_HeadingEnabled( ! current_autopilot->get_HeadingEnabled() ); -- 2.39.5