]> git.mxchange.org Git - flightgear.git/commitdiff
More altitude hold tweaks.
authorcurt <curt>
Thu, 1 Oct 1998 00:37:57 +0000 (00:37 +0000)
committercurt <curt>
Thu, 1 Oct 1998 00:37:57 +0000 (00:37 +0000)
Autopilot/autopilot.cxx
Autopilot/autopilot.hxx
Main/GLUTkey.cxx

index 5fa5fbf8b81bc017c4b6e217146f7a499942aec4..e9c3b9c88edef37532cb9c40ceaf2204a482661f 100644 (file)
@@ -294,27 +294,41 @@ int fgAPRun( void )
        fgRudderSet(0.0);
     }
 
-    // altitude hold enabled?
-    if ( APData->altitude_hold == 1 ) {
-       double error;
+    // altitude hold or terrain follow enabled?
+    if ( (APData->altitude_hold == 1) || (APData->terrain_follow == 1) ) {
+       double speed, max_climb, error;
        double prop_error, int_error;
        double prop_adj, int_adj, total_adj;
 
-       // normal altitude hold
-       APData->TargetClimbRate = 
-           (APData->TargetAltitude - fgAPget_altitude()) * 8.0;
-       
-       // brain dead ground hugging with no look ahead
-       // APData->TargetClimbRate = ( 250 - fgAPget_agl() ) * 8.0;
+       if (APData->altitude_hold == 1) {
+           // normal altitude hold
+           APData->TargetClimbRate = 
+               (APData->TargetAltitude - fgAPget_altitude()) * 8.0;
+       } else if (APData->terrain_follow == 1) {
+           // brain dead ground hugging with no look ahead
+           APData->TargetClimbRate = 
+               ( APData->TargetAGL - fgAPget_agl() ) * 16.0;
+       } else {
+           // just try to zero out rate of climb ...
+           APData->TargetClimbRate = 0.0;
+       }
 
-       // just try to zero out rate of climb ...
-       // APData->TargetClimbRate = 0.0;
+       speed = get_speed();
 
-       if ( APData->TargetClimbRate > 200.0 ) {
-           APData->TargetClimbRate = 200.0;
+       if ( speed < 90.0 ) {
+           max_climb = 0.0;
+       } else if ( speed < 100.0 ) {
+           max_climb = (speed - 90.0) * 20;
+       } else {
+           max_climb = ( speed - 100.0 ) * 4.0 + 200.0;
        }
-       if ( APData->TargetClimbRate < -200.0 ) {
-           APData->TargetClimbRate = -200.0;
+
+       if ( APData->TargetClimbRate > max_climb ) {
+           APData->TargetClimbRate = max_climb;
+       }
+
+       if ( APData->TargetClimbRate < -400.0 ) {
+           APData->TargetClimbRate = -400.0;
        }
 
        error = fgAPget_climb() - APData->TargetClimbRate;
@@ -342,8 +356,8 @@ int fgAPRun( void )
        prop_adj = prop_error / 2000.0;
 
        total_adj = 0.9 * prop_adj + 0.1 * int_adj;
-       if ( total_adj >  0.4 ) { total_adj =  0.4; }
-       if ( total_adj < -0.3 ) { total_adj = -0.3; }
+       if ( total_adj >  0.6 ) { total_adj =  0.6; }
+       if ( total_adj < -0.2 ) { total_adj = -0.2; }
 
        fgElevSet( total_adj );
     }
@@ -432,6 +446,7 @@ void fgAPToggleAltitude( void )
     } else {
        // turn on altitude hold, lock at current altitude
        APData->altitude_hold = 1;
+       APData->terrain_follow = 0;
        APData->TargetAltitude = fgAPget_altitude();
        APData->alt_error_accum = 0.0;
        // alt_error_queue.erase( alt_error_queue.begin(), 
@@ -444,6 +459,30 @@ void fgAPToggleAltitude( void )
 }
                 
 
+void fgAPToggleTerrainFollow( void )
+{
+    // Remove at a later date
+    fgAPDataPtr APData;
+
+    APData = APDataGlobal;
+    // end section
+
+    if ( APData->terrain_follow ) {
+       // turn off altitude hold
+       APData->terrain_follow = 0;
+    } else {
+       // turn on terrain follow, lock at current agl
+       APData->terrain_follow = 1;
+       APData->altitude_hold = 0;
+       APData->TargetAGL = fgAPget_agl();
+       APData->alt_error_accum = 0.0;
+    }
+
+    fgPrintf( FG_COCKPIT, FG_INFO, " fgAPSetTerrainFollow: (%d) %.2f\n",
+             APData->terrain_follow,
+             APData->TargetAGL);
+}
+
 double LinearExtrapolate( double x,double x1,double y1,double x2,double y2)
 {
     // This procedure extrapolates the y value for the x posistion on a line defined by x1,y1; x2,y2
index d6e58ebc2d05bf8ada52a4e8d7c28441ee48900e..73ec8884b45a9c23b3dba1ee84fb84c83e2100b1 100644 (file)
@@ -39,14 +39,17 @@ extern "C" {
 
 // Structures
 typedef struct {
-    int heading_hold;  // the current state of the heading hold
-    int altitude_hold; // the current state of the altitude hold
+    int heading_hold;   // the current state of the heading hold
+    int altitude_hold;  // the current state of the altitude hold
+    int terrain_follow; // the current state of the terrain follower
 
     double TargetHeading;     // the heading the AP should steer to.
     double TargetAltitude;    // altitude to hold
     double TargetClimbRate;   // climb rate to shoot for
     double alt_error_accum;   // altitude error accumulator
 
+    double TargetAGL;         // the terrain separation
+
     double TargetSlope; // the glide slope hold value
     
     double MaxRoll ; // the max the plane can roll for the turn
@@ -69,6 +72,7 @@ void fgAPInit( fgAIRCRAFT *current_aircraft );
 int fgAPRun( void );
 void fgAPToggleHeading( void );
 void fgAPToggleAltitude( void );
+void fgAPToggleTerrainFollow( void );
 
 
 #ifdef __cplusplus
index 7af29356030e4909f22896128e7ee5ab7d481b2c..638f2af1bb54bd076b1b3a4f1fe839e28605ae56 100644 (file)
@@ -94,6 +94,9 @@ void GLUTkey(unsigned char k, int x, int y) {
        case 8: // Ctrl-H key
            fgAPToggleHeading();
            return;
+       case 20: // Ctrl-T key
+           fgAPToggleTerrainFollow();
+           return;
        case 49: // numeric keypad 1
            v->goal_view_offset = FG_PI * 0.75;
            return;
@@ -375,6 +378,9 @@ void GLUTspecialkey(int k, int x, int y) {
 
 
 // $Log$
+// Revision 1.26  1998/10/01 00:38:04  curt
+// More altitude hold tweaks.
+//
 // Revision 1.25  1998/09/29 02:03:36  curt
 // Autopilot mods.
 //