-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Module: FGFCS.cpp
Author: Jon Berndt
--------------------------------------------------------------------------------
12/12/98 JSB Created
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include "FGFCS.h"
#include "FGState.h"
#include "filtersjb/FGGradient.h"
#include "filtersjb/FGSwitch.h"
#include "filtersjb/FGSummer.h"
-#include "filtersjb/FGFlaps.h"
+#include "filtersjb/FGKinemat.h"
-/*******************************************************************************
-************************************ CODE **************************************
-*******************************************************************************/
+static const char *IdSrc = "$Id$";
+static const char *IdHdr = ID_FCS;
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS IMPLEMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex) {
+FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
+{
Name = "FGFCS";
- for (int i=0; i < MAX_ENGINES; i++) {
- ThrottleCmd[i] = 0.0;
- ThrottlePos[i] = 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;
+
+ Debug(0);
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-FGFCS::~FGFCS(void) {}
+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];
+ Debug(1);
+}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+bool FGFCS::Run(void)
+{
+ unsigned int i;
-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 {
+ }
- for (unsigned int i=0; i<Aircraft->GetNumEngines(); i++) ThrottlePos[i]=ThrottleCmd[i];
+ return false;
+}
- for (unsigned int i=0; i<Components.size(); i++) Components[i]->Run();
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- } else {}
+void FGFCS::SetThrottleCmd(int engineNum, double setting)
+{
+ unsigned int ctr;
+ if (engineNum < (int)ThrottlePos.size()) {
+ if (engineNum < 0) {
+ for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
+ } else {
+ ThrottleCmd[engineNum] = setting;
+ }
+ } else {
+ cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
+ << " engines exist, but attempted throttle command is for engine "
+ << engineNum << endl;
+ }
+}
- return false;
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGFCS::SetThrottlePos(int engineNum, double setting)
+{
+ unsigned int 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;
+ }
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGFCS::SetThrottleCmd(int engineNum, float setting) {
- if (engineNum < 0) {
- for (unsigned int ctr=0;ctr<Aircraft->GetNumEngines();ctr++) ThrottleCmd[ctr] = setting;
+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 {
- ThrottleCmd[engineNum] = setting;
+ cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
+ << " engines exist, but throttle setting for engine " << engineNum
+ << " is selected" << endl;
}
+ return 0.0;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-void FGFCS::SetThrottlePos(int engineNum, float setting) {
- if (engineNum < 0) {
- for (unsigned int ctr=0;ctr<=Aircraft->GetNumEngines();ctr++) ThrottlePos[ctr] = ThrottleCmd[ctr];
+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 {
- ThrottlePos[engineNum] = setting;
+ 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;
+ }
}
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-bool FGFCS::LoadFCS(FGConfigFile* AC_cfg) {
+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 << endl << " Loading Component \""
+ << AC_cfg->GetValue("NAME")
+ << "\" of type: " << token << endl;
if ((token == "LAG_FILTER") ||
- (token == "RECT_LAG_FILTER") ||
(token == "LEAD_LAG_FILTER") ||
(token == "SECOND_ORDER_FILTER") ||
(token == "WASHOUT_FILTER") ||
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;
}
AC_cfg->GetNextConfigLine();
}
return true;
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-float FGFCS::GetComponentOutput(int idx) {
+double FGFCS::GetComponentOutput(eParam idx) {
return Components[idx]->GetOutput();
}
-/******************************************************************************/
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
string FGFCS::GetComponentName(int idx) {
return Components[idx]->GetName();
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
+{
+ switch (bg) {
+ case FGLGear::bgLeft:
+ return LeftBrake;
+ case FGLGear::bgRight:
+ return RightBrake;
+ case FGLGear::bgCenter:
+ return CenterBrake;
+ default:
+ cerr << "GetBrake asked to return a bogus brake value" << endl;
+ }
+ return 0.0;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+string FGFCS::GetComponentStrings(void)
+{
+ unsigned int comp;
+ string CompStrings = "";
+ bool firstime = true;
+
+ for (comp = 0; comp < Components.size(); comp++) {
+ if (firstime) firstime = false;
+ else CompStrings += ", ";
+
+ CompStrings += Components[comp]->GetName();
+ }
+
+ return CompStrings;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+string FGFCS::GetComponentValues(void)
+{
+ unsigned int comp;
+ string CompValues = "";
+ char buffer[10];
+ bool firstime = true;
+
+ for (comp = 0; comp < Components.size(); comp++) {
+ if (firstime) firstime = false;
+ else CompValues += ", ";
+
+ sprintf(buffer, "%9.6f", Components[comp]->GetOutput());
+ CompValues += string(buffer);
+ }
+
+ return CompValues;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+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);
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+// 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)
+{
+ 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;
+ }
+ }
+}
+