]> git.mxchange.org Git - flightgear.git/commitdiff
Oct. 10, 2000 sync with JSBSim master repository.
authorcurt <curt>
Tue, 10 Oct 2000 17:44:35 +0000 (17:44 +0000)
committercurt <curt>
Tue, 10 Oct 2000 17:44:35 +0000 (17:44 +0000)
15 files changed:
src/FDM/JSBSim.cxx
src/FDM/JSBSim/FGAircraft.cpp
src/FDM/JSBSim/FGAircraft.h
src/FDM/JSBSim/FGControls.cpp
src/FDM/JSBSim/FGControls.h
src/FDM/JSBSim/FGFDMExec.cpp
src/FDM/JSBSim/FGFDMExec.h
src/FDM/JSBSim/FGInitialCondition.h
src/FDM/JSBSim/FGLGear.cpp
src/FDM/JSBSim/FGOutput.cpp
src/FDM/JSBSim/FGState.cpp
src/FDM/JSBSim/FGState.h
src/FDM/JSBSim/FGTranslation.cpp
src/FDM/JSBSim/FGTranslation.h
src/FDM/JSBSim/JSBSim.cpp

index 192a5a080ea2f2bb28ad07db5e9bbfc6ac456023..a23e88bee7026c101a038cb88193db06674252af 100644 (file)
@@ -80,7 +80,7 @@ int FGJSBsim::init( double dt ) {
                                        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");
@@ -103,7 +103,7 @@ int FGJSBsim::init( double dt ) {
   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());
index 74859c38d434f7a5572dbb7f0607bfd8ed22c747..8184840f8a166d3e3bf037433ddf1f786cb5583d 100644 (file)
@@ -168,35 +168,20 @@ FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex),
 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];
-  }  
 }
 
 /******************************************************************************/
@@ -409,21 +394,15 @@ void FGAircraft::FMAero(void) {
 
 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
   }
 }
 
@@ -581,7 +560,7 @@ void FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg) {
   AC_cfg->GetNextConfigLine();
 
   while ((token = AC_cfg->GetValue()) != "/UNDERCARRIAGE") {
-    lGear.push_back(new FGLGear(AC_cfg, FDMExec));
+    lGear.push_back(FGLGear(AC_cfg, FDMExec));
   }
 }
 
@@ -737,10 +716,10 @@ string FGAircraft::GetGroundReactionStrings(void) {
 
   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;
   }
@@ -758,10 +737,10 @@ string FGAircraft::GetGroundReactionValues(void) {
 
   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;
   }
index 9c2b287cd9d32700fe562008748ac3baf51991c1..b831e92a1079e98349d28c295bc316668c6b8003 100644 (file)
@@ -125,6 +125,14 @@ INCLUDES
 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
 *******************************************************************************/
@@ -136,16 +144,31 @@ class FGAircraft : public FGModel {
   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; }
@@ -177,8 +200,6 @@ public:
   string GetGroundReactionStrings(void);
   string GetGroundReactionValues(void);
 
-  vector <FGLGear>::iterator iGear;
-
   enum { ssSimulation      = 1,
          ssAerosurfaces    = 2,
          ssRates           = 4,
@@ -235,7 +256,7 @@ private:
   bool GearUp;
 
   string Axis[6];
-  vector <FGLGear*> lGear;
+  vector <FGLGear> lGear;
 
   string AircraftPath;
   string EnginePath;
index 4e593558653b084bb9ab9eb9698324c3a46dffbe..de2ef278f6b051abb314e6a5b63de2e90ebb226e 100644 (file)
@@ -51,8 +51,8 @@ FGControls::~FGControls() {
 
 
 // $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
index 0b94d242dbf8584c606f5e878183e3beb4b893b0..57eb899fe862d369798ff40fd4c4ccb054284624 100644 (file)
@@ -177,8 +177,8 @@ extern FGControls controls;
 
 
 // $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
index e24b445a4220a1b5efafd80c2827e7f870bafd80..0eab1d6d00201ca0622a1de6d86d0912105847e5 100644 (file)
@@ -84,8 +84,21 @@ FGFDMExec::FGFDMExec(void)
   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);
@@ -107,7 +120,9 @@ FGFDMExec::FGFDMExec(void)
   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.
@@ -120,24 +135,41 @@ FGFDMExec::FGFDMExec(void)
   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;
-
+  }
 }
 
 
@@ -199,7 +231,9 @@ bool FGFDMExec::RunIC(FGInitialCondition *fgic)
 
 bool FGFDMExec::LoadModel(string APath, string EPath, string model)
 {
-       AircraftPath = APath;
+       DeAllocate();
+  Allocate();
+  AircraftPath = APath;
        EnginePath = EPath;
   return Aircraft->LoadAircraft(AircraftPath, EnginePath, model);
 }
index 307f31c05d82e68371a8aa29325d5125a197269f..3eebd503ef13716a9f620a8766719aac88862466 100644 (file)
@@ -96,6 +96,7 @@ public:
 private:
   bool frozen;
   bool terminate;
+  bool allocated;
   int Error;
 
   string AircraftPath;
@@ -112,6 +113,9 @@ private:
   FGPosition*    Position;
   FGAuxiliary*   Auxiliary;
   FGOutput*      Output;
+  
+  bool Allocate(void);
+  bool DeAllocate(void);
 
 protected:
 };
index bd8d48a10d9e56409809f2d0e3586b711e30a4be..9e15820c56f113504ab7940e9cfe49914c7e3f2d 100644 (file)
@@ -126,7 +126,7 @@ public:
   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);
index 322412fd0ddf19e048a6e4b431809f6a25a6d33e..2ad970baece799be1b83277970e4457589009e18 100644 (file)
@@ -83,6 +83,7 @@ FGLGear::FGLGear(FGConfigFile* AC_cfg, FGFDMExec* fdmex) : vXYZ(3),
 
 FGLGear::~FGLGear(void)
 {
+  cout << "Destructing Landing Gear ..." << endl;
 }
 
 /******************************************************************************/
index 7b698f520574b2f57cb8d11a92fe618af2afb470..ff0b07c90f4e49d5745878c68241756e5fe1d9ee 100644 (file)
@@ -61,6 +61,7 @@ FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
   Type = otNone;
   Filename = "JSBSim.out";
   SubSystems = 0;
+  enabled = true;
   
 #ifdef FG_WITH_JSBSIM_SOCKET
   socket = new FGfdmSocket("localhost",1138);
index 51d6deaff67cfa0ed63748365611bf683e5a1b22..b7649a405a4b69d8737b4babc2f0f291dbd9f680 100644 (file)
@@ -87,7 +87,6 @@ FGState::FGState(FGFDMExec* fdex) : mTb2l(3,3),
 {
   FDMExec = fdex;
 
-  adot = bdot = 0.0;
   a = 1000.0;
   sim_time = 0.0;
   dt = 1.0/120.0;
@@ -144,11 +143,11 @@ float FGState::GetParameter(eParam val_idx) {
   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:
index b8705e81bf65fc22de5e4267936bc9a01d3dcdf6..10896b4f50c8195cfa13841661e5329923b362ee 100644 (file)
@@ -81,9 +81,6 @@ public:
   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; }
@@ -96,8 +93,6 @@ public:
   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; }
 
@@ -125,7 +120,6 @@ public:
 
 private:
 
-  float adot, bdot;                 // alpha dot and beta dot
   float a;                          // speed of sound
   float sim_time, dt;
   float saved_dt;
index 82eff48edefefcdf0d947ab78ad399fea34a3bd3..f17e13756918b2891c195b118b915a8ecca1325d 100644 (file)
@@ -87,6 +87,7 @@ FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex),
   Vt = 0.0;
   Mach = 0.0;
   alpha = beta = 0.0;
+  adot = bdot = 0.0;
   rho = 0.002378;
 }
 
@@ -127,7 +128,25 @@ bool FGTranslation::Run(void) {
     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();
index c4a068b67ea8d55cfd30c8f70c74c62d1a971d71..db9f9732f18b96c6a801b41b7128f1d5480501c1 100644 (file)
@@ -88,7 +88,8 @@ public:
   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; }
 
@@ -97,6 +98,8 @@ public:
   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; }
 
@@ -115,6 +118,7 @@ private:
   float Vt, qbar, Mach;
   float Mass, dt;
   float alpha, beta;
+  float adot,bdot;
   float rho;
 
   void GetState(void);
index 99c9e1f6b4b556570bf1f3c1f22e09aeac3e2e4a..bbae63b137828b9910cd5e926e9334a484cd51ec 100644 (file)
@@ -144,24 +144,24 @@ int main(int argc, char** argv)
   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();
   }