]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGFCS.cpp
- fixed fuel-need calculations
[flightgear.git] / src / FDM / JSBSim / FGFCS.cpp
index a1434dcb972fbf304dbae6c7641ee5ac3afc6de9..d95e3d8c0fffbe9f0deeafb2e8e6903921d98a1b 100644 (file)
@@ -54,7 +54,7 @@ INCLUDES
 #include "filtersjb/FGGradient.h"
 #include "filtersjb/FGSwitch.h"
 #include "filtersjb/FGSummer.h"
-#include "filtersjb/FGFlaps.h"
+#include "filtersjb/FGKinemat.h"
 
 static const char *IdSrc = "$Id$";
 static const char *IdHdr = ID_FCS;
@@ -67,11 +67,13 @@ FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
 {
   Name = "FGFCS";
 
-  DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = PTrimCmd = 0.0;
+  DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = 0.0;
+  PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
   DaPos = DePos = DrPos = DfPos = DsbPos = DspPos = 0.0;
+  GearCmd = GearPos = 1; // default to gear down
   LeftBrake = RightBrake = CenterBrake = 0.0;
 
-  if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
+  Debug(0);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -82,11 +84,13 @@ FGFCS::~FGFCS()
   ThrottlePos.clear();
   MixtureCmd.clear();
   MixturePos.clear();
+  PropAdvanceCmd.clear();
+  PropAdvance.clear();
 
   unsigned int i;
 
   for (i=0;i<Components.size();i++) delete Components[i];
-  if (debug_lvl & 2) cout << "Destroyed:    FGFCS" << endl;
+  Debug(1);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -98,6 +102,7 @@ bool FGFCS::Run(void)
   if (!FGModel::Run()) {
     for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
     for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
+    for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[i];
     for (i=0; i<Components.size(); i++)  Components[i]->Run();
   } else {
   }
@@ -156,8 +161,9 @@ double FGFCS::GetThrottleCmd(int engineNum)
   } else {
     cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
          << " engines exist, but throttle setting for engine " << engineNum
-              << " is selected" << endl;
+         << " is selected" << endl;
   }
+  return 0.0;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -175,6 +181,7 @@ double FGFCS::GetThrottlePos(int engineNum)
          << " engines exist, but attempted throttle position setting is for engine "
          << engineNum << endl;
   }
+  return 0.0; 
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -209,6 +216,36 @@ void FGFCS::SetMixturePos(int engineNum, double setting)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+void FGFCS::SetPropAdvanceCmd(int engineNum, double setting)
+{
+  unsigned int ctr;
+
+  if (engineNum < (int)ThrottlePos.size()) {
+    if (engineNum < 0) {
+      for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
+    } else {
+      PropAdvanceCmd[engineNum] = setting;
+    }
+  }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGFCS::SetPropAdvance(int engineNum, double setting)
+{
+  unsigned int ctr;
+
+  if (engineNum < (int)ThrottlePos.size()) {
+    if (engineNum < 0) {
+      for (ctr=0;ctr<=PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
+    } else {
+      PropAdvance[engineNum] = setting;
+    }
+  }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 bool FGFCS::Load(FGConfigFile* AC_cfg)
 {
   string token;
@@ -221,7 +258,7 @@ bool FGFCS::Load(FGConfigFile* AC_cfg)
       token = AC_cfg->GetValue("TYPE");
       if (debug_lvl > 0) cout << "    Loading Component \""
                               << AC_cfg->GetValue("NAME")
-                                               << "\" of type: " << token << endl;
+                              << "\" of type: " << token << endl;
       if ((token == "LAG_FILTER") ||
           (token == "LEAD_LAG_FILTER") ||
           (token == "SECOND_ORDER_FILTER") ||
@@ -242,8 +279,8 @@ bool FGFCS::Load(FGConfigFile* AC_cfg)
         Components.push_back(new FGGradient(this, AC_cfg));
       } else if (token == "SWITCH") {
         Components.push_back(new FGSwitch(this, AC_cfg));
-      } else if (token == "FLAPS") {
-        Components.push_back(new FGFlaps(this, AC_cfg));
+      } else if (token == "KINEMAT") {
+        Components.push_back(new FGKinemat(this, AC_cfg));
       } else {
         cerr << "Unknown token [" << token << "] in FCS portion of config file" << endl;
         return false;
@@ -268,7 +305,8 @@ string FGFCS::GetComponentName(int idx) {
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-double FGFCS::GetBrake(FGLGear::BrakeGroup bg) {
+double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
+{
   switch (bg) {
   case FGLGear::bgLeft:
     return LeftBrake;
@@ -287,7 +325,6 @@ double FGFCS::GetBrake(FGLGear::BrakeGroup bg) {
 string FGFCS::GetComponentStrings(void)
 {
   unsigned int comp;
-
   string CompStrings = "";
   bool firstime = true;
 
@@ -306,7 +343,6 @@ string FGFCS::GetComponentStrings(void)
 string FGFCS::GetComponentValues(void)
 {
   unsigned int comp;
-
   string CompValues = "";
   char buffer[10];
   bool firstime = true;
@@ -328,14 +364,55 @@ void FGFCS::AddThrottle(void)
 {
   ThrottleCmd.push_back(0.0);
   ThrottlePos.push_back(0.0);
-  MixtureCmd.push_back(0.0);   // assume throttle and mixture are coupled
+  MixtureCmd.push_back(0.0);     // assume throttle and mixture are coupled
   MixturePos.push_back(0.0);
+  PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled
+  PropAdvance.push_back(0.0);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-void FGFCS::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 FGFCS::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: FGFCS" << endl;
+    if (from == 1) cout << "Destroyed:    FGFCS" << 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;
+    }
+  }
 }