Added an "auto throttle"
This commit is contained in:
parent
49b5ce80c5
commit
3e24bc7e23
6 changed files with 91 additions and 26 deletions
|
@ -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
|
||||
|
|
|
@ -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 TargetClimbRate; // climb rate to shoot for
|
||||
double alt_error_accum; // altitude error accumulator
|
||||
|
||||
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 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
|
||||
|
|
|
@ -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.
|
||||
//
|
||||
|
|
|
@ -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.
|
||||
//
|
||||
|
|
|
@ -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( ¤t_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.
|
||||
//
|
||||
|
|
|
@ -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 = ¤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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue