1
0
Fork 0

Fixes to jsbsim.

This commit is contained in:
curt 2000-08-04 16:08:55 +00:00
parent 120b26cc88
commit 342842537d
5 changed files with 87 additions and 96 deletions

View file

@ -319,67 +319,70 @@ char *dmshh_format(double degrees)
} }
#endif // 0 #endif // 0
/****************************************************************************/
/* Convert degrees to dd mm'ss.s'' (DMS-Format) */
/****************************************************************************/
static char *toDMS(float a)
{
int neg = 0;
float d, m, s;
static char dms[16];
if (a < 0.0f) { /************************************************************************
a = -a; Convert degrees to dd mm.mmm' (DMM-Format)
neg = 1; Description: Converts using a round-off factor tailored to the required
} precision of the minutes field (three decimal places). Round-off
d = (float) ((int) a); prevents function from returning a minutes value of 60.
a = (a - d) * 60.0f;
m = (float) ((int) a); Input arguments: Coordinate value in decimal degrees
s = (a - m) * 60.0f;
************************************************************************/
if (s > 59.5f) { static char *toDM(float dd)
s = 0.0f; {
m += 1.0f; static char dm[16];
} double tempdd;
if (m > 59.5f) { double mn;
m = 0.0f; double sign = 1;
d += 1.0f; int deg;
}
if (neg) if (dd < 0) {
d = -d; sign = -1;
}
sprintf(dms, "%.0f*%02.0f %04.1f", d, m, s); /* round for minutes expressed to three decimal places */
return dms; tempdd = fabs(dd) + (5.0E-4 / 60.0);
deg = (int)tempdd;
mn = fabs( (tempdd - (double)(deg)) * 60.0 - 4.999E-4 );
deg *= (int)sign;
sprintf(dm, "%d*%06.3f", deg, mn);
return dm;
} }
/****************************************************************************/ /************************************************************************
/* Convert degrees to dd mm.mmm' (DMM-Format) */ Convert degrees to dd mm'ss.s'' (DMS-Format)
/****************************************************************************/ Description: Converts using a round-off factor tailored to the required
static char *toDM(float a) precision of the seconds field (one decimal place). Round-off
{ prevents function from returning a seconds value of 60.
int neg = 0;
float d, m;
static char dm[16];
if (a < 0.0f) {
a = -a;
neg = 1;
}
d = (float) ( (int) a); Input arguments: Coordinate value in decimal degrees
m = (a - d) * 60.0f;
************************************************************************/
if (m > 59.5f) { static char *toDMS(float dd)
m = 0.0f; {
d += 1.0f; static char dms[16];
} double tempdd, tempmin;
if (neg) d = -d; int deg;
int mn;
sprintf(dm, "%.0f*%06.3f", d, m); double sec;
return dm; double sign = 1;
if(dd < 0) {
sign = -1;
}
/* round up for seconds expressed to one decimal place */
tempdd = fabs(dd) + (0.05 / 3600.0);
deg = (int)tempdd;
tempmin = (tempdd - (double)(deg)) * 60.0;
mn = (int)tempmin;
sec = fabs( (tempmin - (double)(mn)) * 60.0 - 0.049 );
deg *= (int)sign;
sprintf(dms, "%d*%02d %04.1f", deg, mn, sec);
return dms;
} }
// Have to set the LatLon display type // Have to set the LatLon display type
//static char *(*fgLatLonFormat)(float) = toDM; //static char *(*fgLatLonFormat)(float) = toDM;
static char *(*fgLatLonFormat)(float); static char *(*fgLatLonFormat)(float);

View file

@ -87,6 +87,13 @@ int FGJSBsim::init( double dt ) {
return 0; return 0;
} }
FDMExec.GetAtmosphere()->SetExTemperature(get_Static_temperature());
FDMExec.GetAtmosphere()->SetExPressure(get_Static_pressure());
FDMExec.GetAtmosphere()->SetExDensity(get_Density());
FDMExec.GetAtmosphere()->SetWindNED(get_V_north_airmass(),
get_V_east_airmass(),
get_V_down_airmass());
FDMExec.GetAtmosphere()->UseInternal(); FDMExec.GetAtmosphere()->UseInternal();
FG_LOG( FG_FLIGHT, FG_INFO, " Initializing JSBSim with:" ); FG_LOG( FG_FLIGHT, FG_INFO, " Initializing JSBSim with:" );
@ -160,8 +167,7 @@ int FGJSBsim::init( double dt ) {
FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing JSBSim" ); FG_LOG( FG_FLIGHT, FG_INFO, "Finished initializing JSBSim" );
copy_from_JSBsim(); copy_from_JSBsim();
return 1; return 1;
} }
@ -257,11 +263,6 @@ int FGJSBsim::copy_from_JSBsim() {
FDMExec.GetAircraft()->GetXYZcg()(2), FDMExec.GetAircraft()->GetXYZcg()(2),
FDMExec.GetAircraft()->GetXYZcg()(3) ); FDMExec.GetAircraft()->GetXYZcg()(3) );
set_Accels_Local( FDMExec.GetPosition()->GetVelDot()(1),
FDMExec.GetPosition()->GetVelDot()(2),
FDMExec.GetPosition()->GetVelDot()(3) );
set_Accels_Body ( FDMExec.GetTranslation()->GetUVWdot()(1), set_Accels_Body ( FDMExec.GetTranslation()->GetUVWdot()(1),
FDMExec.GetTranslation()->GetUVWdot()(2), FDMExec.GetTranslation()->GetUVWdot()(2),
FDMExec.GetTranslation()->GetUVWdot()(3) ); FDMExec.GetTranslation()->GetUVWdot()(3) );
@ -274,7 +275,6 @@ int FGJSBsim::copy_from_JSBsim() {
// FDMExec.GetTranslation()->GetNcg()(2), // FDMExec.GetTranslation()->GetNcg()(2),
// FDMExec.GetTranslation()->GetNcg()(3) ); // FDMExec.GetTranslation()->GetNcg()(3) );
// //
set_Accels_Pilot_Body( FDMExec.GetAuxiliary()->GetPilotAccel()(1), set_Accels_Pilot_Body( FDMExec.GetAuxiliary()->GetPilotAccel()(1),
FDMExec.GetAuxiliary()->GetPilotAccel()(2), FDMExec.GetAuxiliary()->GetPilotAccel()(2),
FDMExec.GetAuxiliary()->GetPilotAccel()(3) ); FDMExec.GetAuxiliary()->GetPilotAccel()(3) );
@ -311,13 +311,11 @@ int FGJSBsim::copy_from_JSBsim() {
FDMExec.GetState()->GetParameter(FG_PITCHRATE), FDMExec.GetState()->GetParameter(FG_PITCHRATE),
FDMExec.GetState()->GetParameter(FG_YAWRATE) ); FDMExec.GetState()->GetParameter(FG_YAWRATE) );
set_Euler_Rates( FDMExec.GetRotation()->GetEulerRates()(1), /* HUH!?! */ set_Euler_Rates( FDMExec.GetRotation()->Getphi(),
FDMExec.GetRotation()->GetEulerRates()(2), FDMExec.GetRotation()->Gettht(),
FDMExec.GetRotation()->GetEulerRates()(3) ); FDMExec.GetRotation()->Getpsi() );
set_Geocentric_Rates( FDMExec.GetPosition()->GetLatitudeDot(), // ***FIXME*** set_Geocentric_Rates( Latitude_dot, Longitude_dot, Radius_dot );
FDMExec.GetPosition()->GetLongitudeDot(),
FDMExec.GetPosition()->Gethdot() );
set_Mach_number( FDMExec.GetTranslation()->GetMach()); set_Mach_number( FDMExec.GetTranslation()->GetMach());
@ -345,35 +343,13 @@ int FGJSBsim::copy_from_JSBsim() {
set_Euler_Angles( FDMExec.GetRotation()->Getphi(), set_Euler_Angles( FDMExec.GetRotation()->Getphi(),
FDMExec.GetRotation()->Gettht(), FDMExec.GetRotation()->Gettht(),
FDMExec.GetRotation()->Getpsi() ); FDMExec.GetRotation()->Getpsi() );
for(int i=0; i<3; i++ ) {
for (int j=0; j<3; j++ ) {
set_T_Local_to_Body(i,j,FDMExec.GetState()->GetTl2b()(i,j));
}
}
set_Alpha( FDMExec.GetTranslation()->Getalpha() ); set_Alpha( FDMExec.GetTranslation()->Getalpha() );
set_Beta( FDMExec.GetTranslation()->Getbeta() ); set_Beta( FDMExec.GetTranslation()->Getbeta() );
set_Cos_phi( FDMExec.GetRotation()->GetCosphi() );
//set_Sin_phi ( FDMExec.GetRotation()->GetSinpphi() );
set_Cos_theta( FDMExec.GetRotation()->GetCostht() );
//set_Sin_theta ( FDMExec.GetRotation()->GetSintht() );
//set_Cos_psi( FDMExec.GetRotation()->GetCospsi() );
//set_Sin_psi ( FDMExec.GetRotation()->GetSinpsi() );
set_Gamma_vert_rad( FDMExec.GetPosition()->GetGamma() ); set_Gamma_vert_rad( FDMExec.GetPosition()->GetGamma() );
// set_Gamma_horiz_rad( Gamma_horiz_rad ); // set_Gamma_horiz_rad( Gamma_horiz_rad );
set_Density( FDMExec.GetAtmosphere()->GetDensity() );
set_Static_pressure( FDMExec.GetAtmosphere()->GetPressure() );
set_Static_temperature ( FDMExec.GetAtmosphere()->GetTemperature() );
set_Earth_position_angle( FDMExec.GetAuxiliary()->GetEarthPositionAngle() );
/* **FIXME*** */ set_Sea_level_radius( sl_radius2 * METER_TO_FEET ); /* **FIXME*** */ set_Sea_level_radius( sl_radius2 * METER_TO_FEET );
/* **FIXME*** */ set_Earth_position_angle( 0.0 ); /* **FIXME*** */ set_Earth_position_angle( 0.0 );

View file

@ -344,22 +344,24 @@ FGMatrix FGMatrix::operator/(const double scalar)
} }
} }
} } else
return Quot; cerr << "Attempt to divide by zero in method FGMatrix::operator/(const double scalar), object at " << this << endl;
return Quot;
} }
/******************************************************************************/ /******************************************************************************/
void FGMatrix::operator/=(const double scalar) void FGMatrix::operator/=(const double scalar)
{ {
if(scalar != 0) { if(scalar != 0) {
for (unsigned int i=1; i<=Rows(); i++) { for (unsigned int i=1; i<=Rows(); i++) {
for (unsigned int j=1; j<=Cols(); j++) { for (unsigned int j=1; j<=Cols(); j++) {
data[i][j]/=scalar; data[i][j]/=scalar;
} }
} }
} } else
cerr << "Attempt to divide by zero in method FGMatrix::operator/=(const double scalar), object " << this << endl;
} }
/******************************************************************************/ /******************************************************************************/
@ -519,9 +521,15 @@ FGColumnVector FGColumnVector::operator/(const double scalar)
{ {
FGColumnVector Quotient(Rows()); FGColumnVector Quotient(Rows());
if(scalar != 0) { if(scalar != 0) {
for (unsigned int i=1; i<=Rows(); i++) Quotient(i) = data[i][1] / scalar; for (unsigned int i=1; i<=Rows(); i++) Quotient(i) = data[i][1] / scalar;
}
} else
cerr << "Attempt to divide by zero in method FGColumnVector::operator/(const double scalar), object " << this << endl;
return Quotient; return Quotient;
} }
/******************************************************************************/ /******************************************************************************/

View file

@ -406,7 +406,9 @@ bool FGTrimLong::DoTrim(void) {
if(checkLimits(udotf,dth,0,1) == false) { if(checkLimits(udotf,dth,0,1) == false) {
cout << " Sorry, udot doesn't appear to be trimmable" << endl; cout << " Sorry, udot doesn't appear to be trimmable" << endl;
cout << " Resetting throttles to zero" << endl; cout << " Resetting throttles to zero" << endl;
setThrottlesPct(0);
fdmex->GetFCS()->SetThrottleCmd(-1,0); fdmex->GetFCS()->SetThrottleCmd(-1,0);
fdmex->RunIC(fgic);
total_its=k; total_its=k;
k=Ncycles; //force the trim to fail k=Ncycles; //force the trim to fail
} }

View file

@ -30,6 +30,8 @@
# include <windows.h> # include <windows.h>
#endif #endif
#include <math.h>
#include <string> #include <string>
#include <simgear/misc/props.hxx> #include <simgear/misc/props.hxx>