1
0
Fork 0

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.)
This commit is contained in:
curt 2001-02-07 04:16:12 +00:00
parent 8830f5c6a8
commit f780c27787
6 changed files with 63 additions and 19 deletions

View 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();
}

View 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; }

View 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;

View 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.
*/

View 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

View 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()
);