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);
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;
}
+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
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
void fgAPToggleHeading( void );
void fgAPToggleAltitude( void );
void fgAPToggleTerrainFollow( void );
+void fgAPToggleAutoThrottle( void );
#ifdef __cplusplus
case 8: // Ctrl-H key
fgAPToggleHeading();
return;
+ case 19: // Ctrl-S key
+ fgAPToggleAutoThrottle();
+ return;
case 20: // Ctrl-T key
fgAPToggleTerrainFollow();
return;
// $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.
//
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
// $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.
//
// 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( ¤t_aircraft )) {
// Cockpit initialized ok.
// $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.
//
/* temporarily remove the code of this do-nothing routine */
-#ifdef FG_WEATHER_UPDATE
+// #ifdef FG_WEATHER_UPDATE
fgFLIGHT *f;
struct fgWEATHER *w;
w = ¤t_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
}
/* $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.