1
0
Fork 0

More "delta-t" and fdm interface timing tweaks.

This commit is contained in:
curt 2001-01-17 02:37:12 +00:00
parent d346e53aee
commit 26dca37028
8 changed files with 48 additions and 50 deletions

View 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" );

View 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();
}

View 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();
}

View 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();
}

View 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,

View 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,8 +273,8 @@ 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);
@ -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 );

View 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

View 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 ) {
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();
cur_fdm_state->update( multi_loop *
fgGetInt("/sim/speed-up") );
// 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