From: curt Date: Wed, 17 Jan 2001 02:37:12 +0000 (+0000) Subject: More "delta-t" and fdm interface timing tweaks. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=26dca370280eff3dab0af3cb425dd2c2e94941bd;p=flightgear.git More "delta-t" and fdm interface timing tweaks. --- diff --git a/src/FDM/ADA.cxx b/src/FDM/ADA.cxx index 61385090e..b2dc15c26 100644 --- a/src/FDM/ADA.cxx +++ b/src/FDM/ADA.cxx @@ -158,9 +158,6 @@ void FGADA::init() { char Buffer[numberofbytes]; - // set valid time for this record - stamp_time(); - printf("\nInitialising UDP sockets\n"); // initialise a "udp" socket fdmsock = new SGSocket( "reddy_pc", "5001", "udp" ); diff --git a/src/FDM/External.cxx b/src/FDM/External.cxx index f196afa48..b0406dc38 100644 --- a/src/FDM/External.cxx +++ b/src/FDM/External.cxx @@ -37,9 +37,6 @@ FGExternal::~FGExternal() { // for each subsequent iteration through the EOM void FGExternal::init() { // cout << "FGExternal::init()" << endl; - - // set valid time for this record - stamp_time(); } diff --git a/src/FDM/LaRCsim.cxx b/src/FDM/LaRCsim.cxx index 3de7f911f..0dceba1e2 100644 --- a/src/FDM/LaRCsim.cxx +++ b/src/FDM/LaRCsim.cxx @@ -40,6 +40,7 @@ FGLaRCsim::FGLaRCsim( double dt ) { set_delta_t( dt ); + cout << "dt = " << get_delta_t() << endl; ls_toplevel_init( 0.0, (char *)fgGetString("/sim/aircraft").c_str() ); @@ -101,9 +102,6 @@ void FGLaRCsim::init() { if ( save_alt < -9000.0 ) { set_Altitude( save_alt ); } - - // set valid time for this record - stamp_time(); } diff --git a/src/FDM/MagicCarpet.cxx b/src/FDM/MagicCarpet.cxx index 67aeea398..0e8f8b308 100644 --- a/src/FDM/MagicCarpet.cxx +++ b/src/FDM/MagicCarpet.cxx @@ -44,8 +44,6 @@ FGMagicCarpet::~FGMagicCarpet() { // Initialize the Magic Carpet flight model, dt is the time increment // for each subsequent iteration through the EOM void FGMagicCarpet::init() { - // set valid time for this record - stamp_time(); } diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index 5e3dac21d..c015ee032 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -164,20 +164,16 @@ FGInterface::bind () { // Time management fgTie("/fdm/time/delta_t", this, - &(FGInterface::get_delta_t), - &(FGInterface::set_delta_t)); + &(FGInterface::get_delta_t)); // The following two can't be uncommented until we have support for // the "long" data type in the property manager /* fgTie("/fdm/time/elapsed", this, - &(FGInterface::get_elapsed), - &(FGInterface::set_elapsed)); + &(FGInterface::get_elapsed)); fgTie("/fdm/time/remainder", this, - &(FGInterface::get_remainder), - &(FGInterface::set_remainder)); */ + &(FGInterface::get_remainder); */ fgTie("/fdm/time/multi_loop", this, - &(FGInterface::get_multi_loop), - &(FGInterface::set_multi_loop)); + &(FGInterface::get_multi_loop)); // Aircraft position fgTie("/position/latitude", this, diff --git a/src/FDM/flight.hxx b/src/FDM/flight.hxx index 205e442aa..cd8a2c705 100644 --- a/src/FDM/flight.hxx +++ b/src/FDM/flight.hxx @@ -178,6 +178,7 @@ private: // jitter ( < dt ) but in practice seems to work well. double delta_t; // delta "t" + SGTimeStamp time_stamp; // time stamp of last run long elapsed; // time elapsed since last run long remainder; // remainder time from last run int multi_loop; // number of iterations of "delta_t" to run @@ -272,11 +273,11 @@ private: // Engine list engine_list engines; - SGTimeStamp valid_stamp; // time this record is valid - SGTimeStamp next_stamp; // time this record is valid + // SGTimeStamp valid_stamp; // time this record is valid + // SGTimeStamp next_stamp; // time this record is valid protected: - void _busdump(void); + void _busdump(void); void _updatePosition( double lat_geoc, double lon, double alt ); void _updateWeather( void ); @@ -474,6 +475,9 @@ public: // time and update management values inline double get_delta_t() const { return delta_t; } inline void set_delta_t( double dt ) { delta_t = dt; } + inline SGTimeStamp get_time_stamp() const { return time_stamp; } + inline void set_time_stamp( SGTimeStamp s ) { time_stamp = s; } + inline void stamp() { time_stamp.stamp(); } inline long get_elapsed() const { return elapsed; } inline void set_elapsed( long e ) { elapsed = e; } inline long get_remainder() const { return remainder; } @@ -1047,8 +1051,8 @@ public: inline double get_Climb_Rate() const { return climb_rate; } - inline SGTimeStamp get_time_stamp() const { return valid_stamp; } - inline void stamp_time() { valid_stamp = next_stamp; next_stamp.stamp(); } + // inline SGTimeStamp get_time_stamp() const { return valid_stamp; } + // inline void stamp_time() { valid_stamp = next_stamp; next_stamp.stamp(); } // Extrapolate FDM based on time_offset (in usec) void extrapolate( int time_offset ); diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 43bd1d326..0783faec9 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -489,6 +489,7 @@ bool fgInitSubsystems( void ) { scenery.cur_elev ); double dt = 1.0 / fgGetInt("/sim/model-hz"); + // cout << "dt = " << dt << endl; const string &model = fgGetString("/sim/flight-model"); if (model == "larcsim") { @@ -509,6 +510,8 @@ bool fgInitSubsystems( void ) { << ", can't init aircraft"); exit(-1); } + cur_fdm_state->stamp(); + cur_fdm_state->set_remainder( 0 ); // allocates structures so must happen before any of the flight // model or control parameters are set diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 5ee81ab93..fe21913f8 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -730,22 +730,35 @@ void fgRenderFrame( void ) { // Update internal time dependent calculations (i.e. flight model) -void fgUpdateTimeDepCalcs(int multi_loop, int remainder) { - static fdm_state_list fdm_list; +void fgUpdateTimeDepCalcs() { fgLIGHT *l = &cur_light_params; int i; - // update the flight model - if ( multi_loop < 0 ) { - multi_loop = 1; - } + int multi_loop = 1; if ( !globals->get_freeze() && !initial_freeze ) { - // run Autopilot system - current_autopilot->run(); - - cur_fdm_state->update( multi_loop * - fgGetInt("/sim/speed-up") ); + SGTimeStamp current; + current.stamp(); + long elapsed = current - cur_fdm_state->get_time_stamp(); + cur_fdm_state->set_time_stamp( current ); + elapsed += cur_fdm_state->get_remainder(); + // cout << "elapsed = " << elapsed << endl; + // cout << "dt = " << cur_fdm_state->get_delta_t() << endl; + multi_loop = (int)(((double)elapsed * 0.000001) / + cur_fdm_state->get_delta_t() ); + cur_fdm_state->set_multi_loop( multi_loop ); + long remainder = elapsed - ( (multi_loop*1000000) * + cur_fdm_state->get_delta_t() ); + cur_fdm_state->set_remainder( remainder ); + + // cout << "multi_loop = " << multi_loop << endl; + for ( i = 0; i < multi_loop; ++i ) { + // run Autopilot system + current_autopilot->run(); + + // update autopiot + cur_fdm_state->update( 1 * fgGetInt("/sim/speed-up") ); + } FGSteam::update( multi_loop * fgGetInt("/sim/speed-up") ); } else { cur_fdm_state->update( 0 ); @@ -756,17 +769,9 @@ void fgUpdateTimeDepCalcs(int multi_loop, int remainder) { } } - fdm_list.push_back( *cur_fdm_state ); - while ( fdm_list.size() > 15 ) { - fdm_list.pop_front(); - } - if ( fgGetString("/sim/view-mode") == "pilot" ) { cur_view_fdm = *cur_fdm_state; // do nothing - } else if ( fgGetString("/sim/view-mode") == "follow" ) - { - cur_view_fdm = fdm_list.front(); } // update the view angle @@ -983,7 +988,7 @@ static void fgMainLoop( void ) { // flight model if ( global_multi_loop > 0 ) { - fgUpdateTimeDepCalcs(global_multi_loop, remainder); + fgUpdateTimeDepCalcs(); } else { FG_LOG( FG_ALL, FG_DEBUG, "Elapsed time is zero ... we're zinging" ); @@ -1629,9 +1634,9 @@ int main( int argc, char **argv ) { void fgLoadDCS(void) { - ssgEntity *ship_obj; - double bz[3]; - int j=0; + ssgEntity *ship_obj = NULL; + // double bz[3]; + // int j=0; char obj_filename[25]; for (int k=0;k<32;k++) @@ -1707,11 +1712,11 @@ void fgLoadDCS(void) { void fgUpdateDCS (void) { - double eye_lat,eye_lon,eye_alt; - static double obj_head; + // double eye_lat,eye_lon,eye_alt; + // static double obj_head; double sl_radius,obj_latgc; - float nresultmat[4][4]; - sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3; + // float nresultmat[4][4]; + // sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3; double bz[3]; // Instantaneous Geodetic Lat/Lon/Alt of moving object