]> git.mxchange.org Git - flightgear.git/commitdiff
Changes to make the default autopilot heading hold work much more like a C172
authorcurt <curt>
Wed, 7 Feb 2001 04:16:12 +0000 (04:16 +0000)
committercurt <curt>
Wed, 7 Feb 2001 04:16:12 +0000 (04:16 +0000)
DG heading hold (i.e. it will follow the gyro drift.)

src/Autopilot/newauto.cxx
src/Autopilot/newauto.hxx
src/Cockpit/steam.cxx
src/Main/bfi.cxx
src/Main/bfi.hxx
src/Main/keyboard.cxx

index 8c3d575fcccf64140eddefda88a2f755a116ec4e..e5a22ce7fa4d1b458407f422c647b19b0fe03dd9 100644 (file)
@@ -33,6 +33,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 
+#include <Cockpit/steam.hxx>
 #include <Cockpit/radiostack.hxx>
 #include <Controls/controls.hxx>
 #include <FDM/flight.hxx>
@@ -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();
 }
 
index 1670b71bf9ee4f4a6dd834331f9836f6761e3f7e..9efd67ebaac5d1a14d95ff4429aeb3c3d055d39b 100644 (file)
@@ -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; }
index 7b4802709d104489c848fc890f47f9fc2df085de..1132e0859debead34e9fa43d5f24d08f58e123e4 100644 (file)
@@ -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;
index 531250958fe358ff716784cd3cf6cce5464d359b..8b749b2bdee84887e6d8021057b00c9a946b2ca7 100644 (file)
@@ -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.
  */
index 24b38ebe65bb9dbd4f64fec517c61c4bcd44d8fc..1e81416379669754112b6da4a4ee205a9f093bf7 100644 (file)
@@ -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
 
index f17aaae4527e88ae4a74276d6f4bba8bbfc9d4a1..22c937da7c98a4d716b51b47020d0eeec758b895 100644 (file)
@@ -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()
                );