]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGAerodynamics.cpp
Make yasim accept the launchbar and hook properties. They are not tied to anything...
[flightgear.git] / src / FDM / JSBSim / FGAerodynamics.cpp
index 9ec9edc8948ef417c69c5e3b69da192f266b7d7d..8a95e85e10250c84593a02de474794ec7c1b6add 100644 (file)
@@ -37,16 +37,21 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGAerodynamics.h"
+#include "FGPropagate.h"
+#include "FGAircraft.h"
+#include "FGState.h"
+#include "FGMassBalance.h"
 #include "FGFactorGroup.h"
-#include "FGCoefficient.h"
 #include "FGPropertyManager.h"
 
+namespace JSBSim {
+
 static const char *IdSrc = "$Id$";
 static const char *IdHdr = ID_AERODYNAMICS;
 
-const unsigned NAxes=6;                           
+const unsigned NAxes=6;
 const char* AxisNames[] = { "drag", "side-force", "lift", "rolling-moment",
-                            "pitching-moment","yawing-moment" }; 
+                            "pitching-moment","yawing-moment" };
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS IMPLEMENTATION
@@ -65,9 +70,13 @@ FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec)
   AxisIdx["YAW"]   = 5;
 
   Coeff = new CoeffArray[6];
-  
-  clsq=lod=0;
-  
+
+  impending_stall = stall_hyst = 0.0;
+  alphaclmin = alphaclmax = 0.0;
+  alphahystmin = alphahystmax = 0.0;
+  clsq = lod = 0.0;
+  alphaw = 0.0;
+  bi2vel = ci2vel = 0.0;
   bind();
 
   Debug(0);
@@ -78,16 +87,16 @@ FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec)
 FGAerodynamics::~FGAerodynamics()
 {
   unsigned int i,j;
-  
+
   unbind();
-  
+
   for (i=0; i<6; i++) {
     for (j=0; j<Coeff[i].size(); j++) {
       delete Coeff[i][j];
     }
   }
   delete[] Coeff;
-  
+
   Debug(1);
 }
 
@@ -96,51 +105,71 @@ FGAerodynamics::~FGAerodynamics()
 bool FGAerodynamics::Run(void)
 {
   unsigned int axis_ctr,ctr;
+  double alpha, twovel;
 
   if (!FGModel::Run()) {
 
+    twovel = 2*Auxiliary->GetVt();
+    if (twovel != 0) {
+      bi2vel = Aircraft->GetWingSpan() / twovel;
+      ci2vel = Aircraft->Getcbar() / twovel;
+    }
+
+    alphaw = Auxiliary->Getalpha() + Aircraft->GetWingIncidence();
+
+    alpha = Auxiliary->Getalpha();
+
+    if (alphaclmax != 0) {
+      if (alpha > 0.85*alphaclmax) {
+        impending_stall = 10*(alpha/alphaclmax - 0.85);
+      } else {
+        impending_stall = 0;
+      }
+    }
+
+    if (alphahystmax != 0.0 && alphahystmin != 0.0) {
+      if (alpha > alphahystmax) {
+         stall_hyst = 1;
+      } else if (alpha < alphahystmin) {
+         stall_hyst = 0;
+      }
+    }
+
     vLastFs = vFs;
     vFs.InitMatrix();
 
     for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
       for (ctr=0; ctr < Coeff[axis_ctr].size(); ctr++) {
-        //Coeff[axis_ctr][ctr]->Run();
         vFs(axis_ctr+1) += Coeff[axis_ctr][ctr]->TotalValue();
-        //cout << Coeff[axis_ctr][ctr]->Getname() << "= " 
-        //     << Coeff[axis_ctr][ctr]->TotalValue() << endl;
       }
     }
+
     //correct signs of drag and lift to wind axes convention
     //positive forward, right, down
-    if( Translation->Getqbar() > 0) {
-      clsq = vFs(eLift) / (Aircraft->GetWingArea()*Translation->Getqbar());
+    if ( Auxiliary->Getqbar() > 0) {
+      clsq = vFs(eLift) / (Aircraft->GetWingArea()*Auxiliary->Getqbar());
       clsq *= clsq;
     }
     if ( vFs(eDrag)  > 0) {
       lod = vFs(eLift) / vFs(eDrag);
-    }  
-        
+    }
+
     //correct signs of drag and lift to wind axes convention
     //positive forward, right, down
     vFs(eDrag)*=-1; vFs(eLift)*=-1;
-    //cout << "Aircraft::vFs: " << vFs << endl;
+
     vForces = State->GetTs2b()*vFs;
 
-    vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX) 
-                      - MassBalance->GetXYZcg(eX))*inchtoft;
-    vDXYZcg(eY) =  (Aircraft->GetXYZrp(eY) 
-                      - MassBalance->GetXYZcg(eY))*inchtoft;
-    vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ) 
-                      - MassBalance->GetXYZcg(eZ))*inchtoft;
+    vDXYZcg = MassBalance->StructuralToBody(Aircraft->GetXYZrp());
 
     vMoments = vDXYZcg*vForces; // M = r X F
 
     for (axis_ctr = 0; axis_ctr < 3; axis_ctr++) {
       for (ctr = 0; ctr < Coeff[axis_ctr+3].size(); ctr++) {
-        //Coeff[axis_ctr+3][ctr]->Run();
         vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
       }
     }
+
     return false;
   } else {
     return true;
@@ -151,37 +180,47 @@ bool FGAerodynamics::Run(void)
 
 bool FGAerodynamics::Load(FGConfigFile* AC_cfg)
 {
-  string token, axis;
+  string parameter, axis, scratch;
 
   AC_cfg->GetNextConfigLine();
 
-  while ((token = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
-    if (token == "AXIS") {
+  while ((parameter = AC_cfg->GetValue()) != string("/AERODYNAMICS")) {
+    if (parameter == "AXIS") {
       CoeffArray ca;
       axis = AC_cfg->GetValue("NAME");
       AC_cfg->GetNextConfigLine();
-      while ((token = AC_cfg->GetValue()) != string("/AXIS")) {
-        if( token == "COEFFICIENT" ) {
+      while ((parameter = AC_cfg->GetValue()) != string("/AXIS")) {
+        if ( parameter == "COEFFICIENT" ) {
           ca.push_back( new FGCoefficient(FDMExec) );
           ca.back()->Load(AC_cfg);
-        } else if ( token == "GROUP" ) {
+        } else if ( parameter == "GROUP" ) {
           ca.push_back( new FGFactorGroup(FDMExec) );
           ca.back()->Load(AC_cfg);
         }
       }
       Coeff[AxisIdx[axis]] = ca;
       AC_cfg->GetNextConfigLine();
+    } else if (parameter == "AC_ALPHALIMITS") {
+      *AC_cfg >> scratch >> alphaclmin >> alphaclmax;
+      if (debug_lvl > 0) cout << "    Maximum Alpha: " << alphaclmax
+                              << "    Minimum Alpha: " << alphaclmin
+                              << endl;
+    } else if (parameter == "AC_HYSTLIMITS") {
+      *AC_cfg >> scratch >> alphahystmin >> alphahystmax;
+      if (debug_lvl > 0) cout << "    Hysteresis Start: " << alphahystmax
+                              << "    Hysteresis End: " << alphahystmin
+                              << endl;
     }
   }
 
   bindModel();
-  
+
   return true;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGAerodynamics::GetCoefficientStrings(void)
+string FGAerodynamics::GetCoefficientStrings(string delimeter)
 {
   string CoeffStrings = "";
   bool firstime = true;
@@ -192,9 +231,9 @@ string FGAerodynamics::GetCoefficientStrings(void)
       if (firstime) {
         firstime = false;
       } else {
-        CoeffStrings += ", ";
+        CoeffStrings += delimeter;
       }
-      CoeffStrings += Coeff[axis][sd]->GetCoefficientStrings();
+      CoeffStrings += Coeff[axis][sd]->GetCoefficientName();
     }
   }
   return CoeffStrings;
@@ -202,7 +241,7 @@ string FGAerodynamics::GetCoefficientStrings(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGAerodynamics::GetCoefficientValues(void)
+string FGAerodynamics::GetCoefficientValues(string delimeter)
 {
   string SDValues = "";
   bool firstime = true;
@@ -212,9 +251,9 @@ string FGAerodynamics::GetCoefficientValues(void)
       if (firstime) {
         firstime = false;
       } else {
-        SDValues += ", ";
+        SDValues += delimeter;
       }
-      SDValues += Coeff[axis][sd]->GetCoefficientValues();
+      SDValues += Coeff[axis][sd]->GetSDstring();
     }
   }
 
@@ -223,52 +262,73 @@ string FGAerodynamics::GetCoefficientValues(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGAerodynamics::bind(void){
-  
+void FGAerodynamics::bind(void)
+{
+  typedef double (FGAerodynamics::*PMF)(int) const;
+
   PropertyManager->Tie("forces/fbx-aero-lbs", this,1,
-                       &FGAerodynamics::GetForces);
+                       (PMF)&FGAerodynamics::GetForces);
   PropertyManager->Tie("forces/fby-aero-lbs", this,2,
-                       &FGAerodynamics::GetForces);
+                       (PMF)&FGAerodynamics::GetForces);
   PropertyManager->Tie("forces/fbz-aero-lbs", this,3,
-                       &FGAerodynamics::GetForces);
+                       (PMF)&FGAerodynamics::GetForces);
   PropertyManager->Tie("moments/l-aero-lbsft", this,1,
-                       &FGAerodynamics::GetMoments);
+                       (PMF)&FGAerodynamics::GetMoments);
   PropertyManager->Tie("moments/m-aero-lbsft", this,2,
-                       &FGAerodynamics::GetMoments);
+                       (PMF)&FGAerodynamics::GetMoments);
   PropertyManager->Tie("moments/n-aero-lbsft", this,3,
-                       &FGAerodynamics::GetMoments);
+                       (PMF)&FGAerodynamics::GetMoments);
   PropertyManager->Tie("forces/fwx-aero-lbs", this,1,
-                       &FGAerodynamics::GetvFs);
+                       (PMF)&FGAerodynamics::GetvFs);
   PropertyManager->Tie("forces/fwy-aero-lbs", this,2,
-                       &FGAerodynamics::GetvFs);
+                       (PMF)&FGAerodynamics::GetvFs);
   PropertyManager->Tie("forces/fwz-aero-lbs", this,3,
-                       &FGAerodynamics::GetvFs);
+                       (PMF)&FGAerodynamics::GetvFs);
   PropertyManager->Tie("forces/lod-norm", this,
                        &FGAerodynamics::GetLoD);
   PropertyManager->Tie("aero/cl-squared-norm", this,
-                       &FGAerodynamics::GetClSquared); 
+                       &FGAerodynamics::GetClSquared);
+  PropertyManager->Tie("aero/alpha-max-deg", this,
+                       &FGAerodynamics::GetAlphaCLMax,
+                       &FGAerodynamics::SetAlphaCLMax,
+                       true);
+  PropertyManager->Tie("aero/alpha-min-deg", this,
+                       &FGAerodynamics::GetAlphaCLMin,
+                       &FGAerodynamics::SetAlphaCLMin,
+                       true);
+  PropertyManager->Tie("aero/bi2vel", this,
+                       &FGAerodynamics::GetBI2Vel);
+  PropertyManager->Tie("aero/ci2vel", this,
+                       &FGAerodynamics::GetCI2Vel);
+  PropertyManager->Tie("aero/alpha-wing-rad", this,
+                       &FGAerodynamics::GetAlphaW);
+  PropertyManager->Tie("systems/stall-warn-norm", this,
+                        &FGAerodynamics::GetStallWarn);
+  PropertyManager->Tie("aero/stall-hyst-norm", this,
+                        &FGAerodynamics::GetHysteresisParm);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGAerodynamics::bindModel(void) { 
+void FGAerodynamics::bindModel(void)
+{
   unsigned i,j;
   FGPropertyManager* node;
   string axis_node_name;
   node = PropertyManager->GetNode("aero/buildup",true);
-  for(i=0;i<NAxes;i++) {
-     node=node->GetNode( string(AxisNames[i]),true );
-     for (j=0; j < Coeff[i].size(); j++) { 
+  for (i=0;i<NAxes;i++) {
+     node = node->GetNode( string(AxisNames[i]),true );
+     for (j=0; j < Coeff[i].size(); j++) {
        Coeff[i][j]->bind(node);
-     } 
-     node=(FGPropertyManager*)node->getParent();                                         
+     }
+     node = (FGPropertyManager*)node->getParent();
   }
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGAerodynamics::unbind(void){
+void FGAerodynamics::unbind(void)
+{
   unsigned i,j;
 
   PropertyManager->Untie("forces/fbx-aero-lbs");
@@ -281,12 +341,19 @@ void FGAerodynamics::unbind(void){
   PropertyManager->Untie("forces/fwy-aero-lbs");
   PropertyManager->Untie("forces/fwz-aero-lbs");
   PropertyManager->Untie("forces/lod-norm");
-  PropertyManager->Untie("aero/cl-squared-norm");  
-  
-  for( i=0; i<NAxes; i++ ) {
+  PropertyManager->Untie("aero/cl-squared-norm");
+  PropertyManager->Untie("aero/alpha-max-deg");
+  PropertyManager->Untie("aero/alpha-min-deg");
+  PropertyManager->Untie("aero/bi2vel");
+  PropertyManager->Untie("aero/ci2vel");
+  PropertyManager->Untie("aero/alpha-wing-rad");
+  PropertyManager->Untie("aero/stall-hyst-norm");
+  PropertyManager->Untie("systems/stall-warn-norm");
+
+  for ( i=0; i<NAxes; i++ ) {
      for ( j=0; j < Coeff[i].size(); j++ ) {
        Coeff[i][j]->unbind();
-       
+
      }
   }
 }
@@ -337,3 +404,4 @@ void FGAerodynamics::Debug(int from)
   }
 }
 
+} // namespace JSBSim