#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>
// 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;
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();
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 ) {
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();
}
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 {
// 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
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; }
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;
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);
}
+/**
+ * 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.
*/
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
);
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()
);