current_options.get_aircraft() );
if (result) {
- FG_LOG( FG_FLIGHT, FG_INFO, " loaded aircraft" << current_options.get_aircraft() );
+ FG_LOG( FG_FLIGHT, FG_INFO, " loaded aircraft " << current_options.get_aircraft() );
} else {
FG_LOG( FG_FLIGHT, FG_INFO, " aircraft" << current_options.get_aircraft()
<< " does not exist");
FG_LOG( FG_FLIGHT, FG_INFO, " Initializing JSBSim with:" );
FGInitialCondition *fgic = new FGInitialCondition(&FDMExec);
- fgic->SetAltitudeAGLFtIC(get_Altitude());
+ fgic->SetAltitudeFtIC(get_Altitude());
if((current_options.get_mach() < 0) && (current_options.get_vc() < 0 )) {
fgic->SetUBodyFpsIC(current_options.get_uBody());
fgic->SetVBodyFpsIC(current_options.get_vBody());
FGAircraft::~FGAircraft(void) {
unsigned int i,j;
- cout << " ~FGAircraft" << endl;
if (Engine != NULL) {
for (i=0; i<numEngines; i++)
delete Engine[i];
}
- cout << " Engine" << endl;
-
if (Tank != NULL) {
for (i=0; i<numTanks; i++)
delete Tank[i];
}
- cout << " Tank" << endl;
-
- cout << " NumAxes: " << 6 << endl;
for (i=0; i<6; i++) {
- cout << " NumCoeffs: " << Coeff[i].size() << " " << &Coeff[i] << endl;
for (j=0; j<Coeff[i].size(); j++) {
-
- cout << " Coeff[" << i << "][" << j << "]: " << Coeff[i][j] << endl;
delete Coeff[i][j];
}
}
-
delete[] Coeff;
- cout << " Coeffs" << endl;
-
- for (i=0; i<lGear.size(); i++) {
- delete lGear[i];
- }
}
/******************************************************************************/
void FGAircraft::FMGear(void) {
- if (GearUp) {
- // crash routine
- } else {
-
-// iGear = lGear.begin();
-// while (iGear != lGear.end()) {
-// vForces += iGear->Force();
-// vMoments += iGear->Moment();
-// iGear++;
-// }
-
- for (unsigned int i=0;i<lGear.size();i++) {
- vForces += lGear[i]->Force();
- vMoments += lGear[i]->Moment();
+ if ( !GearUp ) {
+ vector <FGLGear>::iterator iGear = lGear.begin();
+ while (iGear != lGear.end()) {
+ vForces += iGear->Force();
+ vMoments += iGear->Moment();
+ iGear++;
}
+ } else {
+ // Crash Routine
}
}
AC_cfg->GetNextConfigLine();
while ((token = AC_cfg->GetValue()) != "/UNDERCARRIAGE") {
- lGear.push_back(new FGLGear(AC_cfg, FDMExec));
+ lGear.push_back(FGLGear(AC_cfg, FDMExec));
}
}
for (unsigned int i=0;i<lGear.size();i++) {
if (!firstime) GroundReactionStrings += ", ";
- GroundReactionStrings += (lGear[i]->GetName() + "_WOW, ");
- GroundReactionStrings += (lGear[i]->GetName() + "_compressLength, ");
- GroundReactionStrings += (lGear[i]->GetName() + "_compressSpeed, ");
- GroundReactionStrings += (lGear[i]->GetName() + "_Force");
+ GroundReactionStrings += (lGear[i].GetName() + "_WOW, ");
+ GroundReactionStrings += (lGear[i].GetName() + "_compressLength, ");
+ GroundReactionStrings += (lGear[i].GetName() + "_compressSpeed, ");
+ GroundReactionStrings += (lGear[i].GetName() + "_Force");
firstime = false;
}
for (unsigned int i=0;i<lGear.size();i++) {
if (!firstime) GroundReactionValues += ", ";
- GroundReactionValues += string( lGear[i]->GetWOW()?"1":"0" ) + ", ";
- GroundReactionValues += (string(gcvt(lGear[i]->GetCompLen(), 5, buff)) + ", ");
- GroundReactionValues += (string(gcvt(lGear[i]->GetCompVel(), 6, buff)) + ", ");
- GroundReactionValues += (string(gcvt(lGear[i]->GetCompForce(), 10, buff)));
+ GroundReactionValues += string( lGear[i].GetWOW()?"1":"0" ) + ", ";
+ GroundReactionValues += (string(gcvt(lGear[i].GetCompLen(), 5, buff)) + ", ");
+ GroundReactionValues += (string(gcvt(lGear[i].GetCompVel(), 6, buff)) + ", ");
+ GroundReactionValues += (string(gcvt(lGear[i].GetCompForce(), 10, buff)));
firstime = false;
}
DEFINITIONS
*******************************************************************************/
+/** Encapsulates an Aircraft and its systems.
+ Owns all the parts (other classes) which make
+ up this aircraft. This includes the Engines, Tanks, Propellers, Nozzles,
+ aerodynamic and mass properties, landing gear, etc.
+ @author Jon S. Berndt
+ @version $Id$
+ */
+
/*******************************************************************************
CLASS DECLARATION
*******************************************************************************/
enum {ePhi=1, eTht, ePsi};
public:
- FGAircraft(FGFDMExec*);
+ /** Constructor
+ @param Executive a pointer to the parent executive object
+ */
+ FGAircraft(FGFDMExec *Executive);
+ /// Destructor
~FGAircraft(void);
+ /** Runs the model; called by the Executive
+ @see JSBSim.cpp documentation
+ @return bool returns false if no error
+ */
bool Run(void);
- bool LoadAircraft(string, string, string);
+ /** Loads the aircraft.
+ The executive calls this method to load the aircraft into JSBSim.
+ @param apath path to the aircraft files (e.g. "aircraft/X15/")
+ @param epath path to engine files (e.g. "engine/")
+ @param acname name of aircraft (e.g. "X15")
+ @return true if succesful
+ */
+ bool LoadAircraft(string apath, string epath, string acname);
inline string GetAircraftName(void) { return AircraftName; }
inline void SetGearUp(bool tt) { GearUp = tt; }
inline bool GetGearUp(void) { return GearUp; }
inline int GetNumGearUnits(void) { return lGear.size(); }
- inline FGLGear* GetGearUnit(int ii) { return lGear[ii]; }
+ inline FGLGear* GetGearUnit(int ii) { return &(lGear[ii]); }
inline float GetWingArea(void) { return WingArea; }
inline float GetWingSpan(void) { return WingSpan; }
inline float Getcbar(void) { return cbar; }
string GetGroundReactionStrings(void);
string GetGroundReactionValues(void);
- vector <FGLGear>::iterator iGear;
-
enum { ssSimulation = 1,
ssAerosurfaces = 2,
ssRates = 4,
bool GearUp;
string Axis[6];
- vector <FGLGear*> lGear;
+ vector <FGLGear> lGear;
string AircraftPath;
string EnginePath;
// $Log$
-// Revision 1.16 2000/10/09 19:16:22 curt
-// Oct. 9, 2000 - synced with latest JSBsim code.
+// Revision 1.17 2000/10/10 15:44:35 curt
+// Oct. 10, 2000 sync with JSBSim master repository.
//
// Revision 1.3 2000/04/26 10:55:57 jsb
// Made changes as required by Curt to install JSBSim into FGFS
// $Log$
-// Revision 1.15 2000/10/09 19:16:22 curt
-// Oct. 9, 2000 - synced with latest JSBsim code.
+// Revision 1.16 2000/10/10 15:44:35 curt
+// Oct. 10, 2000 sync with JSBSim master repository.
//
// Revision 1.6 2000/06/03 13:59:52 jsb
// Changes for compatibility with MSVC
Auxiliary = 0;
Output = 0;
- // Instantiate this FDM Executive's Models
+ allocated = false;
+ terminate = false;
+ frozen = false;
+}
+
+FGFDMExec::~FGFDMExec(void){
+
+ DeAllocate();
+}
+
+bool FGFDMExec::Allocate(void) {
+
+ bool result=true;
+
Atmosphere = new FGAtmosphere(this);
FCS = new FGFCS(this);
Aircraft = new FGAircraft(this);
if (!Position->InitModel()) {cerr << "Position model init failed"; Error+=32;}
if (!Auxiliary->InitModel()) {cerr << "Auxiliary model init failed"; Error+=64;}
if (!Output->InitModel()) {cerr << "Output model init failed"; Error+=128;}
-
+
+ if(Error > 0) result=false;
+
// Schedule a model. The second arg (the integer) is the pass number. For
// instance, the atmosphere model gets executed every fifth pass it is called
// by the executive. Everything else here gets executed each pass.
Schedule(Position, 1);
Schedule(Auxiliary, 1);
Schedule(Output, 1);
+
+ allocated = true;
+
+ return result;
- terminate = false;
- frozen = false;
}
-
-FGFDMExec::~FGFDMExec(void){
+bool FGFDMExec::DeAllocate(void) {
+ if(allocated) {
+ if ( Atmosphere != 0 ) delete Atmosphere;
+ if ( FCS != 0 ) delete FCS;
+ if ( Aircraft != 0 ) delete Aircraft;
+ if ( Translation != 0 ) delete Translation;
+ if ( Rotation != 0 ) delete Rotation;
+ if ( Position != 0 ) delete Position;
+ if ( Auxiliary != 0 ) delete Auxiliary;
+ if ( Output != 0 ) delete Output;
+ if ( State != 0 ) delete State;
+
+ FirstModel = 0L;
+ Error = 0;
+
+ State = 0;
+ Atmosphere = 0;
+ FCS = 0;
+ Aircraft = 0;
+ Translation = 0;
+ Rotation = 0;
+ Position = 0;
+ Auxiliary = 0;
+ Output = 0;
+
+ allocated = false;
- if ( Atmosphere != NULL ) delete Atmosphere;
- if ( FCS != NULL ) delete FCS;
- if ( Aircraft != NULL ) delete Aircraft;
- if ( Translation != NULL ) delete Translation;
- if ( Rotation != NULL ) delete Rotation;
- if ( Position != NULL ) delete Position;
- if ( Auxiliary != NULL ) delete Auxiliary;
- if ( Output != NULL ) delete Output;
- if ( State != NULL ) delete State;
-
+ }
}
bool FGFDMExec::LoadModel(string APath, string EPath, string model)
{
- AircraftPath = APath;
+ DeAllocate();
+ Allocate();
+ AircraftPath = APath;
EnginePath = EPath;
return Aircraft->LoadAircraft(AircraftPath, EnginePath, model);
}
private:
bool frozen;
bool terminate;
+ bool allocated;
int Error;
string AircraftPath;
FGPosition* Position;
FGAuxiliary* Auxiliary;
FGOutput* Output;
+
+ bool Allocate(void);
+ bool DeAllocate(void);
protected:
};
void SetAltitudeAGLFtIC(float tt);
//"vertical" flight path, recalculate theta
- inline void SetFlightPathAngleDegIC(float tt) { SetFlightPathAngleRadIC(gamma=tt*DEGTORAD); }
+ inline void SetFlightPathAngleDegIC(float tt) { SetFlightPathAngleRadIC(tt*DEGTORAD); }
void SetFlightPathAngleRadIC(float tt);
//set speed first
void SetClimbRateFpmIC(float tt);
FGLGear::~FGLGear(void)
{
+ cout << "Destructing Landing Gear ..." << endl;
}
/******************************************************************************/
Type = otNone;
Filename = "JSBSim.out";
SubSystems = 0;
+ enabled = true;
#ifdef FG_WITH_JSBSIM_SOCKET
socket = new FGfdmSocket("localhost",1138);
{
FDMExec = fdex;
- adot = bdot = 0.0;
a = 1000.0;
sim_time = 0.0;
dt = 1.0/120.0;
case FG_ALPHA:
return FDMExec->GetTranslation()->Getalpha();
case FG_ALPHADOT:
- return Getadot();
+ return FDMExec->GetTranslation()->Getadot();
case FG_BETA:
return FDMExec->GetTranslation()->Getbeta();
case FG_BETADOT:
- return Getbdot();
+ return FDMExec->GetTranslation()->Getbdot();
case FG_PITCHRATE:
return (FDMExec->GetRotation()->GetPQR())(2);
case FG_ROLLRATE:
void Initialize(FGInitialCondition *FGIC);
bool StoreData(string);
- inline float Getadot(void) { return adot; }
- inline float Getbdot(void) { return bdot; }
-
inline float Geta(void) { return a; }
inline float Getsim_time(void) { return sim_time; }
float GetParameter(string val_string);
eParam GetParameterIndex(string val_string);
- inline void Setadot(float tt) { adot = tt; }
- inline void Setbdot(float tt) { bdot = tt; }
inline void Seta(float tt) { a = tt; }
private:
- float adot, bdot; // alpha dot and beta dot
float a; // speed of sound
float sim_time, dt;
float saved_dt;
Vt = 0.0;
Mach = 0.0;
alpha = beta = 0.0;
+ adot = bdot = 0.0;
rho = 0.002378;
}
if (vUVW(eV) != 0.0)
beta = vUVW(eU)*vUVW(eU)+vUVW(eW)*vUVW(eW) > 0.0 ? atan2(vUVW(eV),
sqrt(vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW))) : 0.0;
-
+
+
+
+ // stolen, quite shamelessly, from LaRCsim
+ float mUW = (vUVW(eU)*vUVW(eU) + vUVW(eW)*vUVW(eW));
+ float signU=1;
+ if (vUVW(eU) != 0.0)
+ signU = vUVW(eU)/fabs(vUVW(eU));
+
+ if( (mUW == 0.0) || (Vt == 0.0) ) {
+ adot = 0.0;
+ bdot = 0.0;
+ } else {
+ adot = (vUVW(eU)*vUVWdot(eW) - vUVW(eW)*vUVWdot(eU))/mUW;
+ bdot = (signU*mUW*vUVWdot(eV) - vUVW(eV)*(vUVW(eU)*vUVWdot(eU)
+ + vUVW(eW)*vUVWdot(eW)))/(Vt*Vt*sqrt(mUW));
+ }
+ //
+
qbar = 0.5*rho*Vt*Vt;
Mach = Vt / State->Geta();
inline float Getqbar (void) { return qbar; }
inline float GetVt (void) { return Vt; }
inline float GetMach (void) { return Mach; }
-
+ inline float Getadot (void) { return adot; }
+ inline float Getbdot (void) { return bdot; }
void SetUVW(FGColumnVector tt) { vUVW = tt; }
inline void Setqbar (float tt) { qbar = tt; }
inline void SetVt (float tt) { Vt = tt; }
inline void SetMach (float tt) { Mach=tt; }
+ inline void Setadot (float tt) { adot = tt; }
+ inline void Setbdot (float tt) { bdot = tt; }
inline void SetAB(float t1, float t2) { alpha=t1; beta=t2; }
float Vt, qbar, Mach;
float Mass, dt;
float alpha, beta;
+ float adot,bdot;
float rho;
void GetState(void);
while (FDMExec->GetState()->Getsim_time() <= 10.0)
{
// Fake an elevator ramp here after 1 second, hold for one second, ramp down
- /*
+
if (FDMExec->GetState()->Getsim_time() >= 1.00 &&
FDMExec->GetState()->Getsim_time() < 2.0)
{
- cmd = FDMExec->GetState()->Getsim_time() - 1.00;
+ cmd = -(FDMExec->GetState()->Getsim_time() - 1.00)/2.0;
} else if (FDMExec->GetState()->Getsim_time() >= 2.00 &&
- FDMExec->GetState()->Getsim_time() < 3.0)
+ FDMExec->GetState()->Getsim_time() < 6.0)
{
- cmd = 1.00;
- } else if (FDMExec->GetState()->Getsim_time() >= 3.00 &&
- FDMExec->GetState()->Getsim_time() < 4.0)
+ cmd = -1.00/2.0;
+ } else if (FDMExec->GetState()->Getsim_time() >= 6.00 &&
+ FDMExec->GetState()->Getsim_time() < 7.0)
{
- cmd = 4.0 - FDMExec->GetState()->Getsim_time();
+ cmd = -(7.0 - FDMExec->GetState()->Getsim_time())/2.0;
} else {
cmd = 0.00;
}
FDMExec->GetFCS()->SetDeCmd(cmd); // input between -1 and 1
- */
+
FDMExec->Run();
}