]> git.mxchange.org Git - flightgear.git/commitdiff
More "delta-t" and fdm interface timing tweaks.
authorcurt <curt>
Wed, 17 Jan 2001 02:37:12 +0000 (02:37 +0000)
committercurt <curt>
Wed, 17 Jan 2001 02:37:12 +0000 (02:37 +0000)
src/FDM/ADA.cxx
src/FDM/External.cxx
src/FDM/LaRCsim.cxx
src/FDM/MagicCarpet.cxx
src/FDM/flight.cxx
src/FDM/flight.hxx
src/Main/fg_init.cxx
src/Main/main.cxx

index 61385090edc9a1d7a6e0b82d2e5a96ebba74fdfb..b2dc15c2652da45231f47f349e8170d7c1d1ff3e 100644 (file)
@@ -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" );
index f196afa48d011419af2f73872f4cefe42ac51238..b0406dc38bd47bd645a9a5520bc1ea2502a3d819 100644 (file)
@@ -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();
 }
 
 
index 3de7f911fc0071a6ce61b3e1f49fdfa0bf7c74d1..0dceba1e27d8499ac35cce3dbb0fc4060987778f 100644 (file)
@@ -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();
 }
 
 
index 67aeea398d27093855ff135d165c595ec09462bf..0e8f8b308fe75c1d580d0955b3914b1aa48e2ddd 100644 (file)
@@ -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();
 }
 
 
index 5e3dac21d84b7bb832f2f8ce6bc28e3c28c9479a..c015ee032c35cfbe731881e443504306e791be04 100644 (file)
@@ -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,
index 205e442aa53bead039fa994a222ba27284ba972a..cd8a2c705956df2664f9ed38c506ee16175263b1 100644 (file)
@@ -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 );
index 43bd1d3265492294d60b818cb35b4e661c649879..0783faec9f22df2618aee54703d2ad4a0dab81fc 100644 (file)
@@ -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
index 5ee81ab933f316e42a0ed78f50113f0c07fb4cd3..fe21913f8ad133966b943c48deb3b23b2edb93b6 100644 (file)
@@ -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