More "delta-t" and fdm interface timing tweaks.
This commit is contained in:
parent
d346e53aee
commit
26dca37028
8 changed files with 48 additions and 50 deletions
|
@ -158,9 +158,6 @@ void FGADA::init() {
|
||||||
|
|
||||||
char Buffer[numberofbytes];
|
char Buffer[numberofbytes];
|
||||||
|
|
||||||
// set valid time for this record
|
|
||||||
stamp_time();
|
|
||||||
|
|
||||||
printf("\nInitialising UDP sockets\n");
|
printf("\nInitialising UDP sockets\n");
|
||||||
// initialise a "udp" socket
|
// initialise a "udp" socket
|
||||||
fdmsock = new SGSocket( "reddy_pc", "5001", "udp" );
|
fdmsock = new SGSocket( "reddy_pc", "5001", "udp" );
|
||||||
|
|
|
@ -37,9 +37,6 @@ FGExternal::~FGExternal() {
|
||||||
// for each subsequent iteration through the EOM
|
// for each subsequent iteration through the EOM
|
||||||
void FGExternal::init() {
|
void FGExternal::init() {
|
||||||
// cout << "FGExternal::init()" << endl;
|
// cout << "FGExternal::init()" << endl;
|
||||||
|
|
||||||
// set valid time for this record
|
|
||||||
stamp_time();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
FGLaRCsim::FGLaRCsim( double dt ) {
|
FGLaRCsim::FGLaRCsim( double dt ) {
|
||||||
set_delta_t( dt );
|
set_delta_t( dt );
|
||||||
|
cout << "dt = " << get_delta_t() << endl;
|
||||||
|
|
||||||
ls_toplevel_init( 0.0,
|
ls_toplevel_init( 0.0,
|
||||||
(char *)fgGetString("/sim/aircraft").c_str() );
|
(char *)fgGetString("/sim/aircraft").c_str() );
|
||||||
|
@ -101,9 +102,6 @@ void FGLaRCsim::init() {
|
||||||
if ( save_alt < -9000.0 ) {
|
if ( save_alt < -9000.0 ) {
|
||||||
set_Altitude( save_alt );
|
set_Altitude( save_alt );
|
||||||
}
|
}
|
||||||
|
|
||||||
// set valid time for this record
|
|
||||||
stamp_time();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,6 @@ FGMagicCarpet::~FGMagicCarpet() {
|
||||||
// Initialize the Magic Carpet flight model, dt is the time increment
|
// Initialize the Magic Carpet flight model, dt is the time increment
|
||||||
// for each subsequent iteration through the EOM
|
// for each subsequent iteration through the EOM
|
||||||
void FGMagicCarpet::init() {
|
void FGMagicCarpet::init() {
|
||||||
// set valid time for this record
|
|
||||||
stamp_time();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -164,20 +164,16 @@ FGInterface::bind ()
|
||||||
{
|
{
|
||||||
// Time management
|
// Time management
|
||||||
fgTie("/fdm/time/delta_t", this,
|
fgTie("/fdm/time/delta_t", this,
|
||||||
&(FGInterface::get_delta_t),
|
&(FGInterface::get_delta_t));
|
||||||
&(FGInterface::set_delta_t));
|
|
||||||
|
|
||||||
// The following two can't be uncommented until we have support for
|
// The following two can't be uncommented until we have support for
|
||||||
// the "long" data type in the property manager
|
// the "long" data type in the property manager
|
||||||
/* fgTie("/fdm/time/elapsed", this,
|
/* fgTie("/fdm/time/elapsed", this,
|
||||||
&(FGInterface::get_elapsed),
|
&(FGInterface::get_elapsed));
|
||||||
&(FGInterface::set_elapsed));
|
|
||||||
fgTie("/fdm/time/remainder", this,
|
fgTie("/fdm/time/remainder", this,
|
||||||
&(FGInterface::get_remainder),
|
&(FGInterface::get_remainder); */
|
||||||
&(FGInterface::set_remainder)); */
|
|
||||||
fgTie("/fdm/time/multi_loop", this,
|
fgTie("/fdm/time/multi_loop", this,
|
||||||
&(FGInterface::get_multi_loop),
|
&(FGInterface::get_multi_loop));
|
||||||
&(FGInterface::set_multi_loop));
|
|
||||||
|
|
||||||
// Aircraft position
|
// Aircraft position
|
||||||
fgTie("/position/latitude", this,
|
fgTie("/position/latitude", this,
|
||||||
|
|
|
@ -178,6 +178,7 @@ private:
|
||||||
// jitter ( < dt ) but in practice seems to work well.
|
// jitter ( < dt ) but in practice seems to work well.
|
||||||
|
|
||||||
double delta_t; // delta "t"
|
double delta_t; // delta "t"
|
||||||
|
SGTimeStamp time_stamp; // time stamp of last run
|
||||||
long elapsed; // time elapsed since last run
|
long elapsed; // time elapsed since last run
|
||||||
long remainder; // remainder time from last run
|
long remainder; // remainder time from last run
|
||||||
int multi_loop; // number of iterations of "delta_t" to run
|
int multi_loop; // number of iterations of "delta_t" to run
|
||||||
|
@ -272,11 +273,11 @@ private:
|
||||||
// Engine list
|
// Engine list
|
||||||
engine_list engines;
|
engine_list engines;
|
||||||
|
|
||||||
SGTimeStamp valid_stamp; // time this record is valid
|
// SGTimeStamp valid_stamp; // time this record is valid
|
||||||
SGTimeStamp next_stamp; // time this record is valid
|
// SGTimeStamp next_stamp; // time this record is valid
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _busdump(void);
|
void _busdump(void);
|
||||||
void _updatePosition( double lat_geoc, double lon, double alt );
|
void _updatePosition( double lat_geoc, double lon, double alt );
|
||||||
void _updateWeather( void );
|
void _updateWeather( void );
|
||||||
|
|
||||||
|
@ -474,6 +475,9 @@ public:
|
||||||
// time and update management values
|
// time and update management values
|
||||||
inline double get_delta_t() const { return delta_t; }
|
inline double get_delta_t() const { return delta_t; }
|
||||||
inline void set_delta_t( double dt ) { delta_t = dt; }
|
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 long get_elapsed() const { return elapsed; }
|
||||||
inline void set_elapsed( long e ) { elapsed = e; }
|
inline void set_elapsed( long e ) { elapsed = e; }
|
||||||
inline long get_remainder() const { return remainder; }
|
inline long get_remainder() const { return remainder; }
|
||||||
|
@ -1047,8 +1051,8 @@ public:
|
||||||
|
|
||||||
inline double get_Climb_Rate() const { return climb_rate; }
|
inline double get_Climb_Rate() const { return climb_rate; }
|
||||||
|
|
||||||
inline SGTimeStamp get_time_stamp() const { return valid_stamp; }
|
// inline SGTimeStamp get_time_stamp() const { return valid_stamp; }
|
||||||
inline void stamp_time() { valid_stamp = next_stamp; next_stamp.stamp(); }
|
// inline void stamp_time() { valid_stamp = next_stamp; next_stamp.stamp(); }
|
||||||
|
|
||||||
// Extrapolate FDM based on time_offset (in usec)
|
// Extrapolate FDM based on time_offset (in usec)
|
||||||
void extrapolate( int time_offset );
|
void extrapolate( int time_offset );
|
||||||
|
|
|
@ -489,6 +489,7 @@ bool fgInitSubsystems( void ) {
|
||||||
scenery.cur_elev );
|
scenery.cur_elev );
|
||||||
|
|
||||||
double dt = 1.0 / fgGetInt("/sim/model-hz");
|
double dt = 1.0 / fgGetInt("/sim/model-hz");
|
||||||
|
// cout << "dt = " << dt << endl;
|
||||||
|
|
||||||
const string &model = fgGetString("/sim/flight-model");
|
const string &model = fgGetString("/sim/flight-model");
|
||||||
if (model == "larcsim") {
|
if (model == "larcsim") {
|
||||||
|
@ -509,6 +510,8 @@ bool fgInitSubsystems( void ) {
|
||||||
<< ", can't init aircraft");
|
<< ", can't init aircraft");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
cur_fdm_state->stamp();
|
||||||
|
cur_fdm_state->set_remainder( 0 );
|
||||||
|
|
||||||
// allocates structures so must happen before any of the flight
|
// allocates structures so must happen before any of the flight
|
||||||
// model or control parameters are set
|
// model or control parameters are set
|
||||||
|
|
|
@ -730,22 +730,35 @@ void fgRenderFrame( void ) {
|
||||||
|
|
||||||
|
|
||||||
// Update internal time dependent calculations (i.e. flight model)
|
// Update internal time dependent calculations (i.e. flight model)
|
||||||
void fgUpdateTimeDepCalcs(int multi_loop, int remainder) {
|
void fgUpdateTimeDepCalcs() {
|
||||||
static fdm_state_list fdm_list;
|
|
||||||
fgLIGHT *l = &cur_light_params;
|
fgLIGHT *l = &cur_light_params;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// update the flight model
|
int multi_loop = 1;
|
||||||
if ( multi_loop < 0 ) {
|
|
||||||
multi_loop = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !globals->get_freeze() && !initial_freeze ) {
|
if ( !globals->get_freeze() && !initial_freeze ) {
|
||||||
// run Autopilot system
|
SGTimeStamp current;
|
||||||
current_autopilot->run();
|
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 );
|
||||||
|
|
||||||
cur_fdm_state->update( multi_loop *
|
// cout << "multi_loop = " << multi_loop << endl;
|
||||||
fgGetInt("/sim/speed-up") );
|
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") );
|
FGSteam::update( multi_loop * fgGetInt("/sim/speed-up") );
|
||||||
} else {
|
} else {
|
||||||
cur_fdm_state->update( 0 );
|
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" ) {
|
if ( fgGetString("/sim/view-mode") == "pilot" ) {
|
||||||
cur_view_fdm = *cur_fdm_state;
|
cur_view_fdm = *cur_fdm_state;
|
||||||
// do nothing
|
// do nothing
|
||||||
} else if ( fgGetString("/sim/view-mode") == "follow" )
|
|
||||||
{
|
|
||||||
cur_view_fdm = fdm_list.front();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the view angle
|
// update the view angle
|
||||||
|
@ -983,7 +988,7 @@ static void fgMainLoop( void ) {
|
||||||
|
|
||||||
// flight model
|
// flight model
|
||||||
if ( global_multi_loop > 0 ) {
|
if ( global_multi_loop > 0 ) {
|
||||||
fgUpdateTimeDepCalcs(global_multi_loop, remainder);
|
fgUpdateTimeDepCalcs();
|
||||||
} else {
|
} else {
|
||||||
FG_LOG( FG_ALL, FG_DEBUG,
|
FG_LOG( FG_ALL, FG_DEBUG,
|
||||||
"Elapsed time is zero ... we're zinging" );
|
"Elapsed time is zero ... we're zinging" );
|
||||||
|
@ -1629,9 +1634,9 @@ int main( int argc, char **argv ) {
|
||||||
|
|
||||||
void fgLoadDCS(void) {
|
void fgLoadDCS(void) {
|
||||||
|
|
||||||
ssgEntity *ship_obj;
|
ssgEntity *ship_obj = NULL;
|
||||||
double bz[3];
|
// double bz[3];
|
||||||
int j=0;
|
// int j=0;
|
||||||
char obj_filename[25];
|
char obj_filename[25];
|
||||||
|
|
||||||
for (int k=0;k<32;k++)
|
for (int k=0;k<32;k++)
|
||||||
|
@ -1707,11 +1712,11 @@ void fgLoadDCS(void) {
|
||||||
|
|
||||||
void fgUpdateDCS (void) {
|
void fgUpdateDCS (void) {
|
||||||
|
|
||||||
double eye_lat,eye_lon,eye_alt;
|
// double eye_lat,eye_lon,eye_alt;
|
||||||
static double obj_head;
|
// static double obj_head;
|
||||||
double sl_radius,obj_latgc;
|
double sl_radius,obj_latgc;
|
||||||
float nresultmat[4][4];
|
// float nresultmat[4][4];
|
||||||
sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
|
// sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
|
||||||
double bz[3];
|
double bz[3];
|
||||||
|
|
||||||
// Instantaneous Geodetic Lat/Lon/Alt of moving object
|
// Instantaneous Geodetic Lat/Lon/Alt of moving object
|
||||||
|
|
Loading…
Add table
Reference in a new issue