From: curt Date: Thu, 1 Oct 1998 00:37:57 +0000 (+0000) Subject: More altitude hold tweaks. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=49b5ce80c5e2b0d17270765ec501c4d799b5c621;p=flightgear.git More altitude hold tweaks. --- diff --git a/Autopilot/autopilot.cxx b/Autopilot/autopilot.cxx index 5fa5fbf8b..e9c3b9c88 100644 --- a/Autopilot/autopilot.cxx +++ b/Autopilot/autopilot.cxx @@ -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 diff --git a/Autopilot/autopilot.hxx b/Autopilot/autopilot.hxx index d6e58ebc2..73ec8884b 100644 --- a/Autopilot/autopilot.hxx +++ b/Autopilot/autopilot.hxx @@ -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 diff --git a/Main/GLUTkey.cxx b/Main/GLUTkey.cxx index 7af293560..638f2af1b 100644 --- a/Main/GLUTkey.cxx +++ b/Main/GLUTkey.cxx @@ -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. //