]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGFCS.cpp
Latest JSBSim changes.
[flightgear.git] / src / FDM / JSBSim / FGFCS.cpp
index f97ecadffc291b02c14a499d9a457a62f8378297..0a3b63cd3cfecb555e2c97781b724fcb2930316d 100644 (file)
@@ -54,12 +54,10 @@ 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";
-
-extern short debug_lvl;
+static const char *IdHdr = ID_FCS;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS IMPLEMENTATION
@@ -71,9 +69,10 @@ FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
 
   DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = PTrimCmd = 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 +81,15 @@ FGFCS::~FGFCS()
 {
   ThrottleCmd.clear();
   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;
+  for (i=0;i<Components.size();i++) delete Components[i];
+  Debug(1);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -97,6 +100,8 @@ 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 {
   }
@@ -106,43 +111,153 @@ bool FGFCS::Run(void)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGFCS::SetThrottleCmd(int engineNum, float setting)
+void FGFCS::SetThrottleCmd(int engineNum, double setting)
 {
   unsigned int ctr;
 
-  if (engineNum < 0) {
-    for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
+  if (engineNum < (int)ThrottlePos.size()) {
+    if (engineNum < 0) {
+      for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
+    } else {
+      ThrottleCmd[engineNum] = setting;
+    }
   } else {
-    ThrottleCmd[engineNum] = setting;
+    cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
+         << " engines exist, but attempted throttle command is for engine "
+         << engineNum << endl;
   }
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGFCS::SetThrottlePos(int engineNum, float setting)
+void FGFCS::SetThrottlePos(int engineNum, double setting)
 {
   unsigned int ctr;
 
-  if (engineNum < 0) {
-    for (ctr=0;ctr<=ThrottleCmd.size();ctr++) ThrottlePos[ctr] = ThrottleCmd[ctr];
+  if (engineNum < (int)ThrottlePos.size()) {
+    if (engineNum < 0) {
+      for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
+    } else {
+      ThrottlePos[engineNum] = setting;
+    }
+  } else {
+    cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
+         << " engines exist, but attempted throttle position setting is for engine "
+         << engineNum << endl;
+  }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGFCS::GetThrottleCmd(int engineNum)
+{
+  if (engineNum < (int)ThrottlePos.size()) {
+    if (engineNum < 0) {
+       cerr << "Cannot get throttle value for ALL engines" << endl;
+    } else {
+      return ThrottleCmd[engineNum];
+    }
   } else {
-    ThrottlePos[engineNum] = setting;
+    cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
+         << " engines exist, but throttle setting for engine " << engineNum
+         << " is selected" << endl;
   }
+  return 0.0;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-bool FGFCS::LoadFCS(FGConfigFile* AC_cfg)
+double FGFCS::GetThrottlePos(int engineNum)
+{
+  if (engineNum < (int)ThrottlePos.size()) {
+    if (engineNum < 0) {
+       cerr << "Cannot get throttle value for ALL engines" << endl;
+    } else {
+      return ThrottlePos[engineNum];
+    }
+  } else {
+    cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
+         << " engines exist, but attempted throttle position setting is for engine "
+         << engineNum << endl;
+  }
+  return 0.0; 
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGFCS::SetMixtureCmd(int engineNum, double setting)
+{
+  unsigned int ctr;
+
+  if (engineNum < (int)ThrottlePos.size()) {
+    if (engineNum < 0) {
+      for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
+    } else {
+      MixtureCmd[engineNum] = setting;
+    }
+  }
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGFCS::SetMixturePos(int engineNum, double setting)
+{
+  unsigned int ctr;
+
+  if (engineNum < (int)ThrottlePos.size()) {
+    if (engineNum < 0) {
+      for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
+    } else {
+      MixturePos[engineNum] = 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;
 
-  FCSName = AC_cfg->GetValue("NAME");
-  cout << "    Control System Name: " << FCSName << endl;
+  Name = Name + ":" + AC_cfg->GetValue("NAME");
+  if (debug_lvl > 0) cout << "    Control System Name: " << Name << endl;
   AC_cfg->GetNextConfigLine();
-  while ((token = AC_cfg->GetValue()) != "/FLIGHT_CONTROL") {
+  while ((token = AC_cfg->GetValue()) != string("/FLIGHT_CONTROL")) {
     if (token == "COMPONENT") {
       token = AC_cfg->GetValue("TYPE");
-      cout << "    Loading Component \"" << AC_cfg->GetValue("NAME") << "\" of type: " << token << endl;
+      if (debug_lvl > 0) cout << "    Loading Component \""
+                              << AC_cfg->GetValue("NAME")
+                              << "\" of type: " << token << endl;
       if ((token == "LAG_FILTER") ||
           (token == "LEAD_LAG_FILTER") ||
           (token == "SECOND_ORDER_FILTER") ||
@@ -163,8 +278,8 @@ bool FGFCS::LoadFCS(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;
@@ -177,7 +292,7 @@ bool FGFCS::LoadFCS(FGConfigFile* AC_cfg)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-float FGFCS::GetComponentOutput(eParam idx) {
+double FGFCS::GetComponentOutput(eParam idx) {
   return Components[idx]->GetOutput();
 }
 
@@ -189,7 +304,8 @@ string FGFCS::GetComponentName(int idx) {
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-float FGFCS::GetBrake(FGLGear::BrakeGroup bg) {
+double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
+{
   switch (bg) {
   case FGLGear::bgLeft:
     return LeftBrake;
@@ -208,7 +324,6 @@ float FGFCS::GetBrake(FGLGear::BrakeGroup bg) {
 string FGFCS::GetComponentStrings(void)
 {
   unsigned int comp;
-
   string CompStrings = "";
   bool firstime = true;
 
@@ -227,7 +342,6 @@ string FGFCS::GetComponentStrings(void)
 string FGFCS::GetComponentValues(void)
 {
   unsigned int comp;
-
   string CompValues = "";
   char buffer[10];
   bool firstime = true;
@@ -249,12 +363,48 @@ 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
+  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
+  }
+}