]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGAircraft.cpp
JSBSim updates, including external atmosphere fix
[flightgear.git] / src / FDM / JSBSim / FGAircraft.cpp
index 5f0573b4f278f17fdd2ff721585519105c487755..5ee4979c07952e1642e4ab89ba3d2b043731f021 100644 (file)
@@ -82,6 +82,7 @@ INCLUDES
 #include "FGPosition.h"
 #include "FGAuxiliary.h"
 #include "FGOutput.h"
+#include "FGPropertyManager.h"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
@@ -101,11 +102,12 @@ CLASS IMPLEMENTATION
 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
 {
   Name = "FGAircraft";
-  alphaclmin = alphaclmax = 0;
-  HTailArea = VTailArea = HTailArm = VTailArm = 0.0;
-  lbarh = lbarv = vbarh = vbarv = 0.0;
-  WingIncidence=0;
-  impending_stall = 0;
+  HTailArea = VTailArea = 0.0;
+  HTailArm  = VTailArm  = 0.0;
+  lbarh = lbarv = 0.0;
+  vbarh = vbarv = 0.0;
+
+  bind();
 
   Debug(0);
 }
@@ -114,45 +116,12 @@ FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
 
 FGAircraft::~FGAircraft()
 {
+  unbind();
   Debug(1);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-bool FGAircraft::Load(FGConfigFile* AC_cfg)
-{
-  string token;
-
-  if (!ReadPrologue(AC_cfg)) return false;
-
-  while ((AC_cfg->GetNextConfigLine() != string("EOF")) &&
-         (token = AC_cfg->GetValue()) != string("/FDM_CONFIG")) {
-    if (token == "METRICS") {
-      if (debug_lvl > 0) cout << fgcyan << "\n  Reading Metrics" << fgdef << endl;
-      if (!ReadMetrics(AC_cfg)) return false;
-    } else if (token == "AERODYNAMICS") {
-      if (debug_lvl > 0) cout << fgcyan << "\n  Reading Aerodynamics" << fgdef << endl;
-      if (!ReadAerodynamics(AC_cfg)) return false;
-    } else if (token == "UNDERCARRIAGE") {
-      if (debug_lvl > 0) cout << fgcyan << "\n  Reading Landing Gear" << fgdef << endl;
-      if (!ReadUndercarriage(AC_cfg)) return false;
-    } else if (token == "PROPULSION") {
-      if (debug_lvl > 0) cout << fgcyan << "\n  Reading Propulsion" << fgdef << endl;
-      if (!ReadPropulsion(AC_cfg)) return false;
-    } else if (token == "FLIGHT_CONTROL") {
-      if (debug_lvl > 0) cout << fgcyan << "\n  Reading Flight Control" << fgdef << endl;
-      if (!ReadFlightControls(AC_cfg)) return false;
-    } else if (token == "OUTPUT") {
-      if (debug_lvl > 0) cout << fgcyan << "\n  Reading Output directives" << fgdef << endl;
-      if (!ReadOutput(AC_cfg)) return false;
-    }
-  }
-  
-  return true;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
 bool FGAircraft::Run(void)
 {
   if (!FGModel::Run()) {                 // if false then execute this Run()
@@ -174,14 +143,6 @@ bool FGAircraft::Run(void)
     vNwcg = State->GetTb2s() * vNcg;
     vNwcg(3) = -1*vNwcg(3) + 1;
     
-    if (alphaclmax != 0) {
-      if (Translation->Getalpha() > 0.85*alphaclmax) {
-        impending_stall = 10*(Translation->Getalpha()/alphaclmax - 0.85);
-      } else {
-        impending_stall = 0;
-      }
-    }      
-    
     return false;
   } else {                               // skip Run() execution this time
     return true;
@@ -192,38 +153,12 @@ bool FGAircraft::Run(void)
 
 float FGAircraft::GetNlf(void)
 {
-  return vNwcg(3);
+  return -1*Aerodynamics->GetvFs(3)/MassBalance->GetWeight();
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-bool FGAircraft::ReadPrologue(FGConfigFile* AC_cfg)
-{
-  string token = AC_cfg->GetValue();
-  string scratch;
-  AircraftName = AC_cfg->GetValue("NAME");
-  if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File"
-            << underoff << ": " << highint << AircraftName << normint << endl;
-  scratch = AC_cfg->GetValue("VERSION").c_str();
-
-  CFGVersion = AC_cfg->GetValue("VERSION");
-
-  if (debug_lvl > 0)
-    cout << "                            Version: " << highint << CFGVersion
-                                                             << normint << endl;
-  if (CFGVersion != needed_cfg_version) {
-    cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
-            " RESULTS WILL BE UNPREDICTABLE !!" << endl;
-    cerr << "Current version needed is: " << needed_cfg_version << endl;
-    cerr << "         You have version: " << CFGVersion << endl << fgdef << endl;
-    return false;
-  }
-  return true;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-bool FGAircraft::ReadMetrics(FGConfigFile* AC_cfg)
+bool FGAircraft::Load(FGConfigFile* AC_cfg)
 {
   string token = "";
   string parameter;
@@ -293,13 +228,9 @@ bool FGAircraft::ReadMetrics(FGConfigFile* AC_cfg)
     } else if (parameter == "AC_AERORP") {
       *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
       if (debug_lvl > 0) cout << "    Ref Pt (x, y, z): " << vXYZrp << endl;
-    } else if (parameter == "AC_ALPHALIMITS") {
-      *AC_cfg >> alphaclmin >> alphaclmax;
-      if (debug_lvl > 0) cout << "    Maximum Alpha: " << alphaclmax
-             << "    Minimum Alpha: " << alphaclmin
-             << endl;
     } else if (parameter == "AC_POINTMASS") {
       *AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
+      MassBalance->AddPointMass(pmWt, pmX, pmY, pmZ);
       if (debug_lvl > 0) cout << "    Point Mass Object: " << pmWt << " lbs. at "
                          << "X, Y, Z (in.): " << pmX << "  " << pmY << "  " << pmZ
                          << endl;
@@ -320,57 +251,87 @@ bool FGAircraft::ReadMetrics(FGConfigFile* AC_cfg)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-bool FGAircraft::ReadPropulsion(FGConfigFile* AC_cfg)
+void FGAircraft::bind(void)
 {
-  if (!Propulsion->Load(AC_cfg)) {
-    cerr << "  Propulsion not successfully loaded" << endl;
-    return false;
-  }
-  return true;
+  typedef double (FGAircraft::*PMF)(int) const;
+  PropertyManager->Tie("metrics/Sw-sqft", this,
+                       &FGAircraft::GetWingArea);
+  PropertyManager->Tie("metrics/bw-ft", this,
+                       &FGAircraft::GetWingSpan);
+  PropertyManager->Tie("metrics/cbarw-ft", this,
+                       &FGAircraft::Getcbar);
+  PropertyManager->Tie("metrics/iw-deg", this,
+                       &FGAircraft::GetWingIncidence);
+  PropertyManager->Tie("metrics/Sh-sqft", this,
+                       &FGAircraft::GetHTailArea);
+  PropertyManager->Tie("metrics/lh-ft", this,
+                       &FGAircraft::GetHTailArm);
+  PropertyManager->Tie("metrics/Sv-sqft", this,
+                       &FGAircraft::GetVTailArea);
+  PropertyManager->Tie("metrics/lv-ft", this,
+                       &FGAircraft::GetVTailArm);
+  PropertyManager->Tie("metrics/lh-norm", this,
+                       &FGAircraft::Getlbarh);
+  PropertyManager->Tie("metrics/lv-norm", this,
+                       &FGAircraft::Getlbarv);
+  PropertyManager->Tie("metrics/vbarh-norm", this,
+                       &FGAircraft::Getvbarh);
+  PropertyManager->Tie("metrics/vbarv-norm", this,
+                       &FGAircraft::Getvbarv);
+  PropertyManager->Tie("moments/l-total-lbsft", this,1,
+                       (PMF)&FGAircraft::GetMoments);
+  PropertyManager->Tie("moments/m-total-lbsft", this,2,
+                       (PMF)&FGAircraft::GetMoments);
+  PropertyManager->Tie("moments/n-total-lbsft", this,3,
+                       (PMF)&FGAircraft::GetMoments);
+  PropertyManager->Tie("forces/fbx-total-lbs", this,1,
+                       (PMF)&FGAircraft::GetForces);
+  PropertyManager->Tie("forces/fby-total-lbs", this,2,
+                       (PMF)&FGAircraft::GetForces);
+  PropertyManager->Tie("forces/fbz-total-lbs", this,3,
+                       (PMF)&FGAircraft::GetForces);
+  PropertyManager->Tie("metrics/aero-rp-x-ft", this,1,
+                       (PMF)&FGAircraft::GetXYZrp);
+  PropertyManager->Tie("metrics/aero-rp-y-ft", this,2,
+                       (PMF)&FGAircraft::GetXYZrp);
+  PropertyManager->Tie("metrics/aero-rp-z-ft", this,3,
+                       (PMF)&FGAircraft::GetXYZrp);
+  PropertyManager->Tie("metrics/eyepoint-x-ft", this,1,
+                       (PMF)&FGAircraft::GetXYZep);
+  PropertyManager->Tie("metrics/eyepoint-y-ft", this,2,
+                       (PMF)&FGAircraft::GetXYZep);
+  PropertyManager->Tie("metrics/eyepoint-z-ft", this,3,
+                       (PMF)&FGAircraft::GetXYZep);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-bool FGAircraft::ReadFlightControls(FGConfigFile* AC_cfg)
+void FGAircraft::unbind(void)
 {
-  if (!FCS->Load(AC_cfg)) {
-    cerr << "  Flight Controls not successfully loaded" << endl;
-    return false;
-  }
-  return true;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-bool FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg)
-{
-  if (!Aerodynamics->Load(AC_cfg)) {
-    cerr << "  Aerodynamics not successfully loaded" << endl;
-    return false;
-  }
-  return true;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-bool FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg)
-{
-  if (!GroundReactions->Load(AC_cfg)) {
-    cerr << "  Ground Reactions not successfully loaded" << endl;
-    return false;
-  }
-  return true;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-bool FGAircraft::ReadOutput(FGConfigFile* AC_cfg)
-{
-  if (!Output->Load(AC_cfg)) {
-    cerr << "  Output not successfully loaded" << endl;
-    return false;
-  }
-  return true;
+  PropertyManager->Untie("metrics/Sw-sqft");
+  PropertyManager->Untie("metrics/bw-ft");
+  PropertyManager->Untie("metrics/cbarw-ft");
+  PropertyManager->Untie("metrics/iw-deg");
+  PropertyManager->Untie("metrics/Sh-sqft");
+  PropertyManager->Untie("metrics/lh-ft");
+  PropertyManager->Untie("metrics/Sv-sqft");
+  PropertyManager->Untie("metrics/lv-ft");
+  PropertyManager->Untie("metrics/lh-norm");
+  PropertyManager->Untie("metrics/lv-norm");
+  PropertyManager->Untie("metrics/vbarh-norm");
+  PropertyManager->Untie("metrics/vbarv-norm");
+  PropertyManager->Untie("moments/l-total-lbsft");
+  PropertyManager->Untie("moments/m-total-lbsft");
+  PropertyManager->Untie("moments/n-total-lbsft");
+  PropertyManager->Untie("forces/fbx-total-lbs");
+  PropertyManager->Untie("forces/fby-total-lbs");
+  PropertyManager->Untie("forces/fbz-total-lbs");
+  PropertyManager->Untie("metrics/aero-rp-x-ft");
+  PropertyManager->Untie("metrics/aero-rp-y-ft");
+  PropertyManager->Untie("metrics/aero-rp-z-ft");
+  PropertyManager->Untie("metrics/eyepoint-x-ft");
+  PropertyManager->Untie("metrics/eyepoint-y-ft");
+  PropertyManager->Untie("metrics/eyepoint-z-ft");
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -410,7 +371,11 @@ void FGAircraft::Debug(int from)
   }
   if (debug_lvl & 16) { // Sanity checking
   }
-  if (debug_lvl & 32) { // Turbulence
+  if (debug_lvl & 64) {
+    if (from == 0) { // Constructor
+      cout << IdSrc << endl;
+      cout << IdHdr << endl;
+    }
   }
 }