]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGPropulsion.cpp
JSBSim updates. This update changes the file format, so an update of the base
[flightgear.git] / src / FDM / JSBSim / FGPropulsion.cpp
index 2b8767dd0a19f23e3717820d8d547411e37948eb..3ee7b2058a4fe06c846bcef67cef536c4f6455ef 100644 (file)
@@ -53,10 +53,24 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGPropulsion.h"
+#include "FGPropertyManager.h"
+
 
 static const char *IdSrc = "$Id$";
 static const char *IdHdr = ID_PROPULSION;
 
+extern short debug_lvl;
+
+#if defined (__APPLE__)
+/* Not all systems have the gcvt function */
+inline char* gcvt (double value, int ndigits, char *buf) {
+    /* note that this is not exactly what gcvt is supposed to do! */
+    snprintf (buf, ndigits+1, "%f", value);
+    return buf;
+}
+#endif
+
+
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS IMPLEMENTATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
@@ -67,7 +81,9 @@ FGPropulsion::FGPropulsion(FGFDMExec* exec) : FGModel(exec)
   numSelectedFuelTanks = numSelectedOxiTanks = 0;
   numTanks = numEngines = numThrusters = 0;
   numOxiTanks = numFuelTanks = 0;
-
+  dt = 0.0;
+  ActiveEngine = -1; // -1: ALL, 0: Engine 1, 1: Engine 2 ...
+  bind();
   Debug(0);
 }
 
@@ -77,6 +93,7 @@ FGPropulsion::~FGPropulsion()
 {
   for (unsigned int i=0; i<Engines.size(); i++) delete Engines[i];
   Engines.clear();
+  unbind();
   Debug(1);
 }
 
@@ -127,13 +144,13 @@ bool FGPropulsion::GetSteadyState(void)
         PowerAvailable = Engines[i]->Calculate(Thrusters[i]->GetPowerRequired());
         lastThrust = currentThrust;
         currentThrust = Thrusters[i]->Calculate(PowerAvailable);
-        if(fabs(lastThrust-currentThrust) < 0.0001) {
+        if (fabs(lastThrust-currentThrust) < 0.0001) {
           steady_count++;
-          if(steady_count > 120) { steady=true; }
+          if (steady_count > 120) { steady=true; }
         } else {
           steady_count=0;
         }
-        j++;    
+        j++;
       }
       vForces  += Thrusters[i]->GetBodyForces();  // sum body frame forces
       vMoments += Thrusters[i]->GetMoments();     // sum body frame moments
@@ -156,7 +173,7 @@ bool FGPropulsion::ICEngineStart(void)
 
   vForces.InitMatrix();
   vMoments.InitMatrix();
-    
+
   for (unsigned int i=0; i<numEngines; i++) {
     Engines[i]->SetTrimMode(true);
     Thrusters[i]->SetdeltaT(dt*rate);
@@ -164,7 +181,7 @@ bool FGPropulsion::ICEngineStart(void)
     while (!Engines[i]->GetRunning() && j < 2000) {
       PowerAvailable = Engines[i]->Calculate(Thrusters[i]->GetPowerRequired());
       Thrusters[i]->Calculate(PowerAvailable);
-      j++;    
+      j++;
     }
     vForces  += Thrusters[i]->GetBodyForces();  // sum body frame forces
     vMoments += Thrusters[i]->GetMoments();     // sum body frame moments
@@ -208,6 +225,7 @@ bool FGPropulsion::Load(FGConfigFile* AC_cfg)
       if (Eng_cfg.IsOpen()) {
         Eng_cfg.GetNextConfigLine();
         engType = Eng_cfg.GetValue();
+        cout << engType << endl;
 
         FCS->AddThrottle();
         ThrottleAdded = true;
@@ -216,12 +234,8 @@ bool FGPropulsion::Load(FGConfigFile* AC_cfg)
           Engines.push_back(new FGRocket(FDMExec, &Eng_cfg));
         } else if (engType == "FG_PISTON") {
           Engines.push_back(new FGPiston(FDMExec, &Eng_cfg));
-        } else if (engType == "FG_TURBOJET") {
-          Engines.push_back(new FGTurboJet(FDMExec, &Eng_cfg));
-        } else if (engType == "FG_TURBOSHAFT") {
-          Engines.push_back(new FGTurboShaft(FDMExec, &Eng_cfg));
-        } else if (engType == "FG_TURBOPROP") {
-          Engines.push_back(new FGTurboProp(FDMExec, &Eng_cfg));
+        } else if (engType == "FG_TURBINE") {
+          Engines.push_back(new FGTurbine(FDMExec, &Eng_cfg));
         } else {
           cerr << fgred << "    Unrecognized engine type: " << underon << engType
                     << underoff << " found in config file." << fgdef << endl;
@@ -295,8 +309,10 @@ bool FGPropulsion::Load(FGConfigFile* AC_cfg)
         if (thrType == "FG_PROPELLER") {
           Thrusters.push_back(new FGPropeller(FDMExec, &Thruster_cfg));
         } else if (thrType == "FG_NOZZLE") {
-          Thrusters.push_back(new FGNozzle(FDMExec, &Thruster_cfg));
-        }
+          Thrusters.push_back(new FGNozzle(FDMExec, &Thruster_cfg ));
+        } else if (thrType == "FG_DIRECT") {
+          Thrusters.push_back(new FGThruster( FDMExec, &Thruster_cfg) );
+        }  
 
         AC_cfg->GetNextConfigLine();
         while ((token = AC_cfg->GetValue()) != string("/AC_THRUSTER")) {
@@ -360,9 +376,7 @@ string FGPropulsion::GetPropulsionStrings(void)
     case FGEngine::etRocket:
       PropulsionStrings += (Engines[i]->GetName() + "_ChamberPress[" + buffer + "]");
       break;
-    case FGEngine::etTurboJet:
-    case FGEngine::etTurboProp:
-    case FGEngine::etTurboShaft:
+    case FGEngine::etTurbine:
       break;
     default:
       PropulsionStrings += "INVALID ENGINE TYPE";
@@ -391,7 +405,7 @@ string FGPropulsion::GetPropulsionStrings(void)
     default:
       PropulsionStrings += "INVALID THRUSTER TYPE";
       break;
-    }    
+    }
   }
 
   return PropulsionStrings;
@@ -416,9 +430,7 @@ string FGPropulsion::GetPropulsionValues(void)
     case FGEngine::etRocket:
       PropulsionValues += (string(gcvt(((FGRocket*)Engines[i])->GetChamberPressure(), 10, buff)));
       break;
-    case FGEngine::etTurboJet:
-    case FGEngine::etTurboProp:
-    case FGEngine::etTurboShaft:
+    case FGEngine::etTurbine:
       break;
     }
 
@@ -450,7 +462,7 @@ string FGPropulsion::GetPropulsionValues(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-FGColumnVector3& FGPropulsion::GetTanksCG(void)
+FGColumnVector3& FGPropulsion::GetTanksMoment(void)
 {
   iTank = Tanks.begin();
   vXYZtank.InitMatrix();
@@ -542,6 +554,109 @@ double FGPropulsion::GetTanksIxy(const FGColumnVector3& vXYZcg)
   return I;
 }
 
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropulsion::SetMagnetos(int setting)
+{
+  if (ActiveEngine == -1) {
+    for (unsigned i=0; i<Engines.size(); i++) {
+      Engines[i]->SetMagnetos(setting);
+    }
+  } else {
+    Engines[ActiveEngine]->SetMagnetos(setting);
+  }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropulsion::SetStarter(int setting)
+{
+  if (ActiveEngine == -1) {
+    for (unsigned i=0; i<Engines.size(); i++) {
+      Engines[i]->SetStarter(setting);
+    }
+  } else {
+    if (setting == 0)
+      Engines[ActiveEngine]->SetStarter(false);
+    else
+      Engines[ActiveEngine]->SetStarter(true);
+  }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropulsion::SetActiveEngine(int engine)
+{
+  if ( unsigned(engine) > Engines.size())
+    ActiveEngine = -1;
+  else
+    ActiveEngine = engine;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropulsion::bind(void)
+{
+  typedef double (FGPropulsion::*PMF)(int) const;
+  typedef int (FGPropulsion::*iPMF)(void) const;
+  /* PropertyManager->Tie("propulsion/num-engines", this,
+                       &FGPropulsion::GetNumEngines);
+  PropertyManager->Tie("propulsion/num-tanks", this,
+                       &FGPropulsion::GetNumTanks); */
+
+  PropertyManager->Tie("propulsion/magneto_cmd", this,
+                       (iPMF)0,
+                       &FGPropulsion::SetMagnetos,
+                       true);
+  PropertyManager->Tie("propulsion/starter_cmd", this,
+                       (iPMF)0,
+                       &FGPropulsion::SetStarter,
+                       true);
+  PropertyManager->Tie("propulsion/active_engine", this,
+                       (iPMF)0,
+                       &FGPropulsion::SetActiveEngine,
+                       true);
+
+  PropertyManager->Tie("propulsion/num-sel-fuel-tanks", this,
+                       &FGPropulsion::GetnumSelectedFuelTanks);
+  PropertyManager->Tie("propulsion/num-sel-ox-tanks", this,
+                       &FGPropulsion::GetnumSelectedOxiTanks);
+  PropertyManager->Tie("forces/fbx-prop-lbs", this,1,
+                       (PMF)&FGPropulsion::GetForces);
+  PropertyManager->Tie("forces/fby-prop-lbs", this,2,
+                       (PMF)&FGPropulsion::GetForces);
+  PropertyManager->Tie("forces/fbz-prop-lbs", this,3,
+                       (PMF)&FGPropulsion::GetForces);
+  PropertyManager->Tie("moments/l-prop-lbsft", this,1,
+                       (PMF)&FGPropulsion::GetMoments);
+  PropertyManager->Tie("moments/m-prop-lbsft", this,2,
+                       (PMF)&FGPropulsion::GetMoments);
+  PropertyManager->Tie("moments/n-prop-lbsft", this,3,
+                       (PMF)&FGPropulsion::GetMoments);
+  //PropertyManager->Tie("propulsion/tanks-weight-lbs", this,
+  //                     &FGPropulsion::GetTanksWeight);
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropulsion::unbind(void)
+{
+  /* PropertyManager->Untie("propulsion/num-engines");
+  PropertyManager->Untie("propulsion/num-tanks"); */
+  PropertyManager->Untie("propulsion/num-sel-fuel-tanks");
+  PropertyManager->Untie("propulsion/num-sel-ox-tanks");
+  PropertyManager->Untie("propulsion/magneto_cmd");
+  PropertyManager->Untie("propulsion/starter_cmd");
+  PropertyManager->Untie("propulsion/active_engine");
+  PropertyManager->Untie("forces/fbx-prop-lbs");
+  PropertyManager->Untie("forces/fby-prop-lbs");
+  PropertyManager->Untie("forces/fbz-prop-lbs");
+  PropertyManager->Untie("moments/l-prop-lbsft");
+  PropertyManager->Untie("moments/m-prop-lbsft");
+  PropertyManager->Untie("moments/n-prop-lbsft");
+  //PropertyManager->Untie("propulsion/tanks-weight-lbs");
+}
+
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 //    The bitmasked value choices are as follows:
 //    unset: In this case (the default) JSBSim would only print
@@ -580,5 +695,11 @@ void FGPropulsion::Debug(int from)
   }
   if (debug_lvl & 16) { // Sanity checking
   }
+  if (debug_lvl & 64) {
+    if (from == 0) { // Constructor
+      cout << IdSrc << endl;
+      cout << IdHdr << endl;
+    }
+  }
 }