]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGAerodynamics.cpp
Updated to match changes in radiostack.[ch]xx
[flightgear.git] / src / FDM / JSBSim / FGAerodynamics.cpp
index 778dd95380f263e68d9e66c52ab8d9832a311a93..bbcf0eb9c12941b925c6dc197d2d28951992652b 100644 (file)
@@ -37,23 +37,23 @@ INCLUDES
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGAerodynamics.h"
+#include "FGFactorGroup.h"
+#include "FGCoefficient.h"
+#include "FGPropertyManager.h"
 
 static const char *IdSrc = "$Id$";
 static const char *IdHdr = ID_AERODYNAMICS;
 
-extern short debug_lvl;
+const unsigned NAxes=6;                           
+const char* AxisNames[] = { "drag", "side-force", "lift", "rolling-moment",
+                            "pitching-moment","yawing-moment" }; 
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS IMPLEMENTATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 
-FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec),
-    vMoments(3),
-    vForces(3),
-    vFs(3),
-    vLastFs(3),
-    vDXYZcg(3)
+FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec)
 {
   Name = "FGAerodynamics";
 
@@ -65,8 +65,15 @@ FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec),
   AxisIdx["YAW"]   = 5;
 
   Coeff = new CoeffArray[6];
-
-  if (debug_lvl & 2) cout << "Instantiated: FGAerodynamics" << endl;
+  
+  impending_stall = stall_hyst = 0.0;
+  alphaclmin = alphaclmax = 0.0;
+  alphahystmin = alphahystmax = 0.0;
+  clsq = lod = 0.0;
+  alphaw = 0.0;  
+  bind();
+
+  Debug(0);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -74,28 +81,54 @@ 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;
-
-  if (debug_lvl & 2) cout << "Destroyed:    FGAerodynamics" << endl;
+  
+  Debug(1);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 bool FGAerodynamics::Run(void)
 {
-  float alpha, beta;
   unsigned int axis_ctr,ctr;
+  double alpha, twovel;
 
   if (!FGModel::Run()) {
 
+    twovel = 2*Translation->GetVt();
+    if (twovel > 0) {
+      bi2vel = Aircraft->GetWingSpan() / twovel;
+      ci2vel = Aircraft->Getcbar() / twovel;
+    }  
+    
+    alphaw = Translation->Getalpha() + Aircraft->GetWingIncidence();
+    
     alpha = Translation->Getalpha();
-    beta = Translation->Getbeta();
-
+    
+    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();
 
@@ -105,24 +138,37 @@ bool FGAerodynamics::Run(void)
       }
     }
 
-    vForces = State->GetTs2b(alpha, beta)*vFs;
+    //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());
+      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;
 
-    // see http://home.earthlink.net/~apeden/jsbsim_moments_due_to_forces.txt
-    // for details on this
+    vForces = State->GetTs2b()*vFs;
 
-    vDXYZcg(eX) = -(Aircraft->GetXYZrp(eX) - MassBalance->GetXYZcg(eX))/12.0;
-    vDXYZcg(eY) =  (Aircraft->GetXYZrp(eY) - MassBalance->GetXYZcg(eY))/12.0;
-    vDXYZcg(eZ) = -(Aircraft->GetXYZrp(eZ) - MassBalance->GetXYZcg(eZ))/12.0;
+    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;
 
-    vMoments(eL) = vForces(eZ)*vDXYZcg(eY) - vForces(eY)*vDXYZcg(eZ);
-    vMoments(eM) = vForces(eX)*vDXYZcg(eZ) - vForces(eZ)*vDXYZcg(eX);
-    vMoments(eN) = vForces(eY)*vDXYZcg(eX) - vForces(eX)*vDXYZcg(eY);
+    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++) {
         vMoments(axis_ctr+1) += Coeff[axis_ctr+3][ctr]->TotalValue();
       }
     }
+
     return false;
   } else {
     return true;
@@ -131,44 +177,48 @@ bool FGAerodynamics::Run(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-bool FGAerodynamics::LoadAerodynamics(FGConfigFile* AC_cfg)
+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")) {
-        ca.push_back(new FGCoefficient(FDMExec, AC_cfg));
-        if (debug_lvl > 0) DisplayCoeffFactors(ca.back()->Getmultipliers());
+      while ((parameter = AC_cfg->GetValue()) != string("/AXIS")) {
+        if ( parameter == "COEFFICIENT" ) {
+          ca.push_back( new FGCoefficient(FDMExec) );
+          ca.back()->Load(AC_cfg);
+        } 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;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGAerodynamics::DisplayCoeffFactors(vector <eParam> multipliers)
-{
-  unsigned int i;
-
-  cout << "   Non-Dimensionalized by: ";
-
-  for (i=0; i<multipliers.size();i++) cout << State->paramdef[multipliers[i]];
-
-  cout << endl;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
 string FGAerodynamics::GetCoefficientStrings(void)
 {
   string CoeffStrings = "";
@@ -182,10 +232,9 @@ string FGAerodynamics::GetCoefficientStrings(void)
       } else {
         CoeffStrings += ", ";
       }
-      CoeffStrings += Coeff[axis][sd]->Getname();
+      CoeffStrings += Coeff[axis][sd]->GetCoefficientName();
     }
   }
-
   return CoeffStrings;
 }
 
@@ -194,7 +243,6 @@ string FGAerodynamics::GetCoefficientStrings(void)
 string FGAerodynamics::GetCoefficientValues(void)
 {
   string SDValues = "";
-  char buffer[10];
   bool firstime = true;
 
   for (unsigned int axis = 0; axis < 6; axis++) {
@@ -204,8 +252,7 @@ string FGAerodynamics::GetCoefficientValues(void)
       } else {
         SDValues += ", ";
       }
-      sprintf(buffer, "%9.6f", Coeff[axis][sd]->GetSD());
-      SDValues += string(buffer);
+      SDValues += Coeff[axis][sd]->GetSDstring();
     }
   }
 
@@ -214,29 +261,144 @@ string FGAerodynamics::GetCoefficientValues(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-float FGAerodynamics::GetNlf(void)
+void FGAerodynamics::bind(void)
 {
-  if (fabs(Position->GetGamma()) < 1.57) {
-    return (vFs(eZ)/(MassBalance->GetWeight()*cos(Position->GetGamma())));
-  } else {
-    return 0.0;
+  typedef double (FGAerodynamics::*PMF)(int) const;
+
+  PropertyManager->Tie("forces/fbx-aero-lbs", this,1,
+                       (PMF)&FGAerodynamics::GetForces);
+  PropertyManager->Tie("forces/fby-aero-lbs", this,2,
+                       (PMF)&FGAerodynamics::GetForces);
+  PropertyManager->Tie("forces/fbz-aero-lbs", this,3,
+                       (PMF)&FGAerodynamics::GetForces);
+  PropertyManager->Tie("moments/l-aero-lbsft", this,1,
+                       (PMF)&FGAerodynamics::GetMoments);
+  PropertyManager->Tie("moments/m-aero-lbsft", this,2,
+                       (PMF)&FGAerodynamics::GetMoments);
+  PropertyManager->Tie("moments/n-aero-lbsft", this,3,
+                       (PMF)&FGAerodynamics::GetMoments);
+  PropertyManager->Tie("forces/fwx-aero-lbs", this,1,
+                       (PMF)&FGAerodynamics::GetvFs);
+  PropertyManager->Tie("forces/fwy-aero-lbs", this,2,
+                       (PMF)&FGAerodynamics::GetvFs);
+  PropertyManager->Tie("forces/fwz-aero-lbs", this,3,
+                       (PMF)&FGAerodynamics::GetvFs);
+  PropertyManager->Tie("forces/lod-norm", this,
+                       &FGAerodynamics::GetLoD);
+  PropertyManager->Tie("aero/cl-squared-norm", this,
+                       &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)
+{ 
+  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++) {
+       Coeff[i][j]->bind(node);
+     } 
+     node = (FGPropertyManager*)node->getParent();                                         
   }
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-float FGAerodynamics::GetLoD(void)
+void FGAerodynamics::unbind(void)
 {
-  float LoD;
-
-  if (vFs(1) != 0.00) return vFs(3)/vFs(1);
-  else                return 0.00;
+  unsigned i,j;
+
+  PropertyManager->Untie("forces/fbx-aero-lbs");
+  PropertyManager->Untie("forces/fby-aero-lbs");
+  PropertyManager->Untie("forces/fbz-aero-lbs");
+  PropertyManager->Untie("moments/l-aero-lbsft");
+  PropertyManager->Untie("moments/m-aero-lbsft");
+  PropertyManager->Untie("moments/n-aero-lbsft");
+  PropertyManager->Untie("forces/fwx-aero-lbs");
+  PropertyManager->Untie("forces/fwy-aero-lbs");
+  PropertyManager->Untie("forces/fwz-aero-lbs");
+  PropertyManager->Untie("forces/lod-norm");
+  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("systems/stall-warn-norm");
+
+  for ( i=0; i<NAxes; i++ ) {
+     for ( j=0; j < Coeff[i].size(); j++ ) {
+       Coeff[i][j]->unbind();
+       
+     }
+  }
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-void FGAerodynamics::Debug(void)
+//    The bitmasked value choices are as follows:
+//    unset: In this case (the default) JSBSim would only print
+//       out the normally expected messages, essentially echoing
+//       the config files as they are read. If the environment
+//       variable is not set, debug_lvl is set to 1 internally
+//    0: This requests JSBSim not to output any messages
+//       whatsoever.
+//    1: This value explicity requests the normal JSBSim
+//       startup messages
+//    2: This value asks for a message to be printed out when
+//       a class is instantiated
+//    4: When this value is set, a message is displayed when a
+//       FGModel object executes its Run() method
+//    8: When this value is set, various runtime state variables
+//       are printed out periodically
+//    16: When set various parameters are sanity checked and
+//       a message is printed out when they go out of bounds
+
+void FGAerodynamics::Debug(int from)
 {
-    //TODO: Add your source code here
+  if (debug_lvl <= 0) return;
+
+  if (debug_lvl & 1) { // Standard console startup message output
+    if (from == 0) { // Constructor
+
+    }
+  }
+  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
+    if (from == 0) cout << "Instantiated: FGAerodynamics" << endl;
+    if (from == 1) cout << "Destroyed:    FGAerodynamics" << endl;
+  }
+  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
+  }
+  if (debug_lvl & 8 ) { // Runtime state variables
+  }
+  if (debug_lvl & 16) { // Sanity checking
+  }
+  if (debug_lvl & 64) {
+    if (from == 0) { // Constructor
+      cout << IdSrc << endl;
+      cout << IdHdr << endl;
+    }
+  }
 }