#include "FGFCS.h"
#include "FGFDMExec.h"
+#include "FGGroundReactions.h"
#include "input_output/FGPropertyManager.h"
#include <fstream>
#include <sstream>
#include "models/flight_control/FGMagnetometer.h"
#include "models/flight_control/FGGyro.h"
+using namespace std;
+
namespace JSBSim {
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGFCS.cpp,v 1.72 2010/11/18 12:38:06 jberndt Exp $";
static const char *IdHdr = ID_FCS;
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return true;
}
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGFCS::LateBind(void)
+{
+ unsigned int i;
+
+ for (i=0; i<Systems.size(); i++) Systems[i]->LateBind();
+ for (i=0; i<APComponents.size(); i++) APComponents[i]->LateBind();
+ for (i=0; i<FCSComponents.size(); i++) FCSComponents[i]->LateBind();
+}
+
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Notes: In this logic the default engine commands are set. This is simply a
// sort of safe-mode method in case the user has not defined control laws for
if (FGModel::Run()) return true; // fast exit if nothing to do
if (FDMExec->Holding()) return false;
+ RunPreFunctions();
+
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];
// Set the default steering angle
for (i=0; i<SteerPosDeg.size(); i++) {
- FGLGear* gear = GroundReactions->GetGearUnit(i);
+ FGLGear* gear = FDMExec->GetGroundReactions()->GetGearUnit(i);
SteerPosDeg[i] = gear->GetDefaultSteerAngle( GetDsCmd() );
}
// Execute Flight Control System
for (i=0; i<FCSComponents.size(); i++) FCSComponents[i]->Run();
+ RunPostFunctions();
+
return false;
}
Components=0;
- string separator = "/";
-
// ToDo: The handling of name and file attributes could be improved, here,
// considering that a name can be in the external file, as well.
name = el->GetAttributeValue("name");
- if (name.empty()) {
+ if (name.empty() || !el->GetAttributeValue("file").empty()) {
fname = el->GetAttributeValue("file");
if (systype == stSystem) {
file = FindSystemFullPathname(fname);
} else {
- file = FDMExec->GetFullAircraftPath() + separator + fname + ".xml";
+ file = FDMExec->GetFullAircraftPath() + "/" + fname + ".xml";
}
if (fname.empty()) {
cerr << "FCS, Autopilot, or system does not appear to be defined inline nor in a file" << endl;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-string FGFCS::FindSystemFullPathname(string system_filename)
+string FGFCS::FindSystemFullPathname(const string& sysfilename)
{
string fullpath, localpath;
+ string system_filename = sysfilename;
string systemPath = FDMExec->GetSystemsPath();
string aircraftPath = FDMExec->GetFullAircraftPath();
ifstream system_file;
- string separator = "/";
+ fullpath = systemPath + "/";
+ localpath = aircraftPath + "/Systems/";
- fullpath = systemPath + separator;
- localpath = aircraftPath + separator + "Systems" + separator;
+ if (system_filename.length() <=4 || system_filename.substr(system_filename.length()-4, 4) != ".xml") {
+ system_filename.append(".xml");
+ }
- system_file.open(string(fullpath + system_filename + ".xml").c_str());
+ system_file.open(string(localpath + system_filename).c_str());
if ( !system_file.is_open()) {
- system_file.open(string(localpath + system_filename + ".xml").c_str());
+ system_file.open(string(fullpath + system_filename).c_str());
if ( !system_file.is_open()) {
cerr << " Could not open system file: " << system_filename << " in path "
<< fullpath << " or " << localpath << endl;
return string("");
} else {
- return string(localpath + system_filename + ".xml");
+ return string(fullpath + system_filename);
}
}
- return string(fullpath + system_filename + ".xml");
+ return string(localpath + system_filename);
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-ifstream* FGFCS::FindSystemFile(string system_filename)
+ifstream* FGFCS::FindSystemFile(const string& sysfilename)
{
string fullpath, localpath;
+ string system_filename = sysfilename;
string systemPath = FDMExec->GetSystemsPath();
string aircraftPath = FDMExec->GetFullAircraftPath();
ifstream* system_file = new ifstream();
- string separator = "/";
+ fullpath = systemPath + "/";
+ localpath = aircraftPath + "/Systems/";
- fullpath = systemPath + separator;
- localpath = aircraftPath + separator + "Systems" + separator;
+ if (system_filename.substr(system_filename.length()-4, 4) != ".xml") {
+ system_filename.append(".xml");
+ }
- system_file->open(string(fullpath + system_filename + ".xml").c_str());
+ system_file->open(string(localpath + system_filename).c_str());
if ( !system_file->is_open()) {
- system_file->open(string(localpath + system_filename + ".xml").c_str());
+ system_file->open(string(fullpath + system_filename).c_str());
if ( !system_file->is_open()) {
cerr << " Could not open system file: " << system_filename << " in path "
<< fullpath << " or " << localpath << endl;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-string FGFCS::GetComponentStrings(string delimeter)
+string FGFCS::GetComponentStrings(const string& delimiter) const
{
unsigned int comp;
string CompStrings = "";
for (unsigned int i=0; i<Systems.size(); i++) {
if (firstime) firstime = false;
- else CompStrings += delimeter;
+ else CompStrings += delimiter;
CompStrings += Systems[i]->GetName();
total_count++;
for (comp = 0; comp < APComponents.size(); comp++)
{
if (firstime) firstime = false;
- else CompStrings += delimeter;
+ else CompStrings += delimiter;
CompStrings += APComponents[comp]->GetName();
total_count++;
for (comp = 0; comp < FCSComponents.size(); comp++) {
if (firstime) firstime = false;
- else CompStrings += delimeter;
+ else CompStrings += delimiter;
CompStrings += FCSComponents[comp]->GetName();
total_count++;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-string FGFCS::GetComponentValues(string delimeter)
+string FGFCS::GetComponentValues(const string& delimiter) const
{
std::ostringstream buf;
for (unsigned int i=0; i<Systems.size(); i++) {
if (firstime) firstime = false;
- else buf << delimeter;
+ else buf << delimiter;
buf << setprecision(9) << Systems[i]->GetOutput();
total_count++;
for (comp = 0; comp < APComponents.size(); comp++) {
if (firstime) firstime = false;
- else buf << delimeter;
+ else buf << delimiter;
buf << setprecision(9) << APComponents[comp]->GetOutput();
total_count++;
for (comp = 0; comp < FCSComponents.size(); comp++) {
if (firstime) firstime = false;
- else buf << delimeter;
+ else buf << delimiter;
buf << setprecision(9) << FCSComponents[comp]->GetOutput();
total_count++;
string tmp;
for (i=0; i<SteerPosDeg.size(); i++) {
- if (GroundReactions->GetGearUnit(i)->GetSteerable()) {
+ if (FDMExec->GetGroundReactions()->GetGearUnit(i)->GetSteerable()) {
tmp = CreateIndexedPropertyName("fcs/steer-pos-deg", i);
PropertyManager->Tie( tmp.c_str(), this, i, &FGFCS::GetSteerPosDeg, &FGFCS::SetSteerPosDeg);
}