]> git.mxchange.org Git - flightgear.git/commitdiff
Added an "auto throttle"
authorcurt <curt>
Fri, 2 Oct 1998 12:46:43 +0000 (12:46 +0000)
committercurt <curt>
Fri, 2 Oct 1998 12:46:43 +0000 (12:46 +0000)
Autopilot/autopilot.cxx
Autopilot/autopilot.hxx
Main/GLUTkey.cxx
Main/GLUTmain.cxx
Main/fg_init.cxx
Weather/weather.c

index e9c3b9c88edef37532cb9c40ceaf2204a482661f..f5a64710f286a4bc9ca17a8286e4c0c6aae8c32b 100644 (file)
@@ -333,19 +333,10 @@ int fgAPRun( void )
 
        error = fgAPget_climb() - APData->TargetClimbRate;
 
-       // push current error onto queue and add into accumulator
-       // alt_error_queue.push_back(error);
+       // accumulate the error under the curve ... this really should
+       // be *= delta t
        APData->alt_error_accum += error;
 
-       // if queue size larger than 60 ... pop front and subtract
-       // from accumulator
-       // size = alt_error_queue.size();
-       // if ( size > 300 ) {
-           // APData->alt_error_accum -= alt_error_queue.front();
-           // alt_error_queue.pop_front();
-           // size--;
-       // }
-
        // calculate integral error, and adjustment amount
        int_error = APData->alt_error_accum;
        // printf("error = %.2f  int_error = %.2f\n", error, int_error);
@@ -362,7 +353,42 @@ int fgAPRun( void )
        fgElevSet( total_adj );
     }
 
-    /*
+    // auto throttle enabled?
+    if ( APData->auto_throttle == 1 ) {
+       double error;
+       double prop_error, int_error;
+       double prop_adj, int_adj, total_adj;
+
+       error = APData->TargetSpeed - get_speed();
+
+       // accumulate the error under the curve ... this really should
+       // be *= delta t
+       APData->speed_error_accum += error;
+       if ( APData->speed_error_accum > 2000.0 ) {
+           APData->speed_error_accum = 2000.0;
+       }
+       if ( APData->speed_error_accum < -2000.0 ) {
+           APData->speed_error_accum = -2000.0;
+       }
+
+       // calculate integral error, and adjustment amount
+       int_error = APData->speed_error_accum;
+
+       // printf("error = %.2f  int_error = %.2f\n", error, int_error);
+       int_adj = int_error / 200.0;
+       
+       // caclulate proportional error
+       prop_error = error;
+       prop_adj = 0.5 + prop_error / 50.0;
+
+       total_adj = 0.9 * prop_adj + 0.1 * int_adj;
+       if ( total_adj > 1.0 ) { total_adj = 1.0; }
+       if ( total_adj < 0.0 ) { total_adj = 0.0; }
+
+       fgThrottleSet( 0, total_adj );
+    }
+
+     /*
     if (APData->Mode == 2) // Glide slope hold
     {
        double RelSlope;
@@ -459,6 +485,29 @@ void fgAPToggleAltitude( void )
 }
                 
 
+void fgAPToggleAutoThrottle ( void )
+{
+    // Remove at a later date
+    fgAPDataPtr APData;
+
+    APData = APDataGlobal;
+    // end section
+
+    if ( APData->auto_throttle ) {
+       // turn off altitude hold
+       APData->auto_throttle = 0;
+    } else {
+       // turn on terrain follow, lock at current agl
+       APData->auto_throttle = 1;
+       APData->TargetSpeed = get_speed();
+       APData->speed_error_accum = 0.0;
+    }
+
+    fgPrintf( FG_COCKPIT, FG_INFO, " fgAPSetAutoThrottle: (%d) %.2f\n",
+             APData->auto_throttle,
+             APData->TargetSpeed);
+}
+
 void fgAPToggleTerrainFollow( void )
 {
     // Remove at a later date
index 73ec8884b45a9c23b3dba1ee84fb84c83e2100b1..f2574a697717a1a014128e2bdc971d19900fffa2 100644 (file)
@@ -42,13 +42,15 @@ typedef struct {
     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
+    int auto_throttle;  // the current state of the auto throttle
 
     double TargetHeading;     // the heading the AP should steer to.
     double TargetAltitude;    // altitude to hold
+    double TargetAGL;         // the terrain separation
     double TargetClimbRate;   // climb rate to shoot for
+    double TargetSpeed;       // speed to shoot for
     double alt_error_accum;   // altitude error accumulator
-
-    double TargetAGL;         // the terrain separation
+    double speed_error_accum; // speed error accumulator
 
     double TargetSlope; // the glide slope hold value
     
@@ -73,6 +75,7 @@ int fgAPRun( void );
 void fgAPToggleHeading( void );
 void fgAPToggleAltitude( void );
 void fgAPToggleTerrainFollow( void );
+void fgAPToggleAutoThrottle( void );
 
 
 #ifdef __cplusplus
index 638f2af1bb54bd076b1b3a4f1fe839e28605ae56..286a584a753050ecd469425e252d7615ba6c9320 100644 (file)
@@ -94,6 +94,9 @@ void GLUTkey(unsigned char k, int x, int y) {
        case 8: // Ctrl-H key
            fgAPToggleHeading();
            return;
+       case 19: // Ctrl-S key
+           fgAPToggleAutoThrottle();
+           return;
        case 20: // Ctrl-T key
            fgAPToggleTerrainFollow();
            return;
@@ -378,6 +381,9 @@ void GLUTspecialkey(int k, int x, int y) {
 
 
 // $Log$
+// Revision 1.27  1998/10/02 12:46:46  curt
+// Added an "auto throttle"
+//
 // Revision 1.26  1998/10/01 00:38:04  curt
 // More altitude hold tweaks.
 //
index 64fddcd13af8cb43ecc37ee12b1d261d749d5934..ac622dda1607f7b360ff469fb721b2734d1e881f 100644 (file)
@@ -475,6 +475,8 @@ static void fgMainLoop( void ) {
     fgPrintf( FG_ALL, FG_DEBUG, "Running Main Loop\n");
     fgPrintf( FG_ALL, FG_DEBUG, "======= ==== ====\n");
 
+    fgWeatherUpdate();
+
     // Fix elevation.  I'm just sticking this here for now, it should
     // probably move eventually
 
@@ -892,6 +894,9 @@ int main( int argc, char **argv ) {
 
 
 // $Log$
+// Revision 1.56  1998/10/02 12:46:47  curt
+// Added an "auto throttle"
+//
 // Revision 1.55  1998/09/29 14:58:18  curt
 // Use working() instead of !not_working() for audio.
 //
index bccb25ccf5ddc70768ea6aeebbbd07ee67cd4424..c908e8c49aaf9437f0c37c5f9baa2935073c67c7 100644 (file)
@@ -347,10 +347,6 @@ int fgInitSubsystems( void )
     // Initialize the weather modeling subsystem
     fgWeatherInit();
 
-    // update the weather for our current position
-    global_events.Register( "fgWeatherUpdate()", fgWeatherUpdate,
-                           fgEVENT::FG_EVENT_READY, 120000 );
-
     // Initialize the Cockpit subsystem
     if( fgCockpitInit( &current_aircraft )) {
        // Cockpit initialized ok.
@@ -398,6 +394,9 @@ int fgInitSubsystems( void )
 
 
 // $Log$
+// Revision 1.40  1998/10/02 12:46:49  curt
+// Added an "auto throttle"
+//
 // Revision 1.39  1998/09/29 02:03:39  curt
 // Autopilot mods.
 //
index a22e594f2f12b1aa0336c422062e5e13998b588b..5a472395dff63bcefe4dba038ff5248ea5c7998a 100644 (file)
@@ -69,7 +69,7 @@ void fgWeatherUpdate( void ) {
 
     /* temporarily remove the code of this do-nothing routine */
 
-#ifdef FG_WEATHER_UPDATE
+// #ifdef FG_WEATHER_UPDATE
     fgFLIGHT *f;
     struct fgWEATHER *w;
 
@@ -77,10 +77,10 @@ void fgWeatherUpdate( void ) {
     w = &current_weather;
 
     /* Add some random turbulence */
-    /* FG_U_gust = fg_random() * 1.0 - 0.5;
-    FG_V_gust = fg_random() * 1.0 - 0.5;
-    FG_W_gust = fg_random() * 1.0 - 0.5; */
-#endif FG_WEATHER_UPDATE
+    // FG_U_gust = fg_random() * 5.0 - 2.5;
+    // FG_V_gust = fg_random() * 5.0 - 2.5;
+    // FG_W_gust = fg_random() * 5.0 - 2.5;
+// #endif FG_WEATHER_UPDATE
 }
 
 
@@ -108,9 +108,12 @@ void fgWeatherSetVisibility( float visibility ) {
 
 
 /* $Log$
-/* Revision 1.17  1998/07/20 12:51:57  curt
-/* Default visibility to about 20 miles.
+/* Revision 1.18  1998/10/02 12:46:50  curt
+/* Added an "auto throttle"
 /*
+ * Revision 1.17  1998/07/20 12:51:57  curt
+ * Default visibility to about 20 miles.
+ *
  * Revision 1.16  1998/06/12 01:00:59  curt
  * Build only static libraries.
  * Declare memmove/memset for Sloaris.