X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2Fmodels%2FFGFCS.cpp;h=3f659831f5c03944085cc9eb75ae589ed4e657db;hb=642735ab18421db87a07d6841dd720fd4615bfff;hp=ac015f9b010301ef6c6e50a331f1a047a018ccb6;hpb=70be1629e61d9b751a2f73df30b83bb1be6ca4fe;p=flightgear.git diff --git a/src/FDM/JSBSim/models/FGFCS.cpp b/src/FDM/JSBSim/models/FGFCS.cpp index ac015f9b0..3f659831f 100644 --- a/src/FDM/JSBSim/models/FGFCS.cpp +++ b/src/FDM/JSBSim/models/FGFCS.cpp @@ -6,7 +6,7 @@ Purpose: Model the flight controls Called by: FDMExec - ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- + ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) ------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -37,27 +37,34 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#include "FGFCS.h" -#include -#include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "FGFCS.h" +#include "FGFDMExec.h" +#include "FGGroundReactions.h" +#include "input_output/FGPropertyManager.h" + +#include "models/flight_control/FGFilter.h" +#include "models/flight_control/FGDeadBand.h" +#include "models/flight_control/FGGain.h" +#include "models/flight_control/FGPID.h" +#include "models/flight_control/FGSwitch.h" +#include "models/flight_control/FGSummer.h" +#include "models/flight_control/FGKinemat.h" +#include "models/flight_control/FGFCSFunction.h" +#include "models/flight_control/FGSensor.h" +#include "models/flight_control/FGActuator.h" +#include "models/flight_control/FGAccelerometer.h" +#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.77 2011/09/25 14:05:40 bcoconni Exp $"; static const char *IdHdr = ID_FCS; /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -72,7 +79,7 @@ FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex) DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0; PTrimCmd = YTrimCmd = RTrimCmd = 0.0; GearCmd = GearPos = 1; // default to gear down - LeftBrake = RightBrake = CenterBrake = 0.0; + BrakePos.resize(FGLGear::bgNumBrakeGroups); TailhookPos = WingFoldPos = 0.0; bind(); @@ -100,8 +107,6 @@ FGFCS::~FGFCS() unsigned int i; - for (i=0;iHolding()) return false; + if (FGModel::Run(Holding)) return true; // fast exit if nothing to do + if (Holding) return false; + + RunPreFunctions(); for (i=0; iGetGearUnit(i); + FGLGear* gear = FDMExec->GetGroundReactions()->GetGearUnit(i); SteerPosDeg[i] = gear->GetDefaultSteerAngle( GetDsCmd() ); } - // Cycle through the sensor, systems, autopilot, and flight control components - // Execute Sensors - for (i=0; iRun(); - // Execute Systems in order for (i=0; iRun(); @@ -220,6 +219,8 @@ bool FGFCS::Run(void) // Execute Flight Control System for (i=0; iRun(); + RunPostFunctions(); + return false; } @@ -453,7 +454,7 @@ void FGFCS::SetMixturePos(int engineNum, double setting) if (engineNum < (int)ThrottlePos.size()) { if (engineNum < 0) { - for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr]; + for (ctr=0;ctr *Components; - Element *component_element, *property_element, *sensor_element; + Element *component_element; Element *channel_element; 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; @@ -574,32 +573,15 @@ bool FGFCS::Load(Element* el, SystemType systype) if (document->GetName() == "flight_control") bindModel(); - // Interface properties from any autopilot, flight control, or other system are - // all stored in the interface properties array. - - property_element = document->FindElement("property"); - if (property_element) cout << endl << " Declared properties" << endl << endl; - while (property_element) { - interface_property_string = property_element->GetDataLine(); - if (PropertyManager->HasNode(interface_property_string)) { - cout << " Property " << interface_property_string << " is already defined." << endl; - } else { - double value=0.0; - if ( ! property_element->GetAttributeValue("value").empty()) - value = property_element->GetAttributeValueAsNumber("value"); - interface_properties.push_back(new double(value)); - interface_property_string = property_element->GetDataLine(); - PropertyManager->Tie(interface_property_string, interface_properties.back()); - cout << " " << interface_property_string << " (initial value: " << value << ")" << endl; - } - property_element = document->FindNextElement("property"); - } + FGModel::Load(document); // Load interface properties from document // After reading interface properties in a file, read properties in the local // flight_control, autopilot, or system element. This allows general-purpose // systems to be defined in a file, with overrides or initial loaded constants // supplied in the relevant element of the aircraft configuration file. + Element* property_element = 0; + if (!fname.empty()) { property_element = el->FindElement("property"); if (property_element && debug_lvl > 0) cout << endl << " Overriding properties" << endl << endl; @@ -611,8 +593,9 @@ bool FGFCS::Load(Element* el, SystemType systype) interface_property_string = property_element->GetDataLine(); if (PropertyManager->HasNode(interface_property_string)) { FGPropertyManager* node = PropertyManager->GetNode(interface_property_string); - cout << " " << "Overriding value for property " << interface_property_string - << " (old value: " << node->getDoubleValue() << " new value: " << value << ")" << endl; + if (debug_lvl > 0) + cout << " " << "Overriding value for property " << interface_property_string + << " (old value: " << node->getDoubleValue() << " new value: " << value << ")" << endl; node->setDoubleValue(value); } else { interface_properties.push_back(new double(value)); @@ -625,22 +608,6 @@ bool FGFCS::Load(Element* el, SystemType systype) } } - // Any sensor elements that are outside of a channel (in either the autopilot - // or the flight_control, or even any possible "system") are placed into the global - // "sensors" array, and are executed prior to any autopilot, flight control, or - // system. - - sensor_element = document->FindElement("sensor"); - while (sensor_element) { - try { - sensors.push_back(new FGSensor(this, sensor_element)); - } catch (string s) { - cerr << highint << fgred << endl << " " << s << endl; - return false; - } - sensor_element = document->FindNextElement("sensor"); - } - channel_element = document->FindElement("channel"); while (channel_element) { @@ -679,6 +646,12 @@ bool FGFCS::Load(Element* el, SystemType systype) Components->push_back(new FGActuator(this, component_element)); } else if (component_element->GetName() == string("sensor")) { Components->push_back(new FGSensor(this, component_element)); + } else if (component_element->GetName() == string("accelerometer")) { + Components->push_back(new FGAccelerometer(this, component_element)); + } else if (component_element->GetName() == string("magnetometer")) { + Components->push_back(new FGMagnetometer(this, component_element)); + } else if (component_element->GetName() == string("gyro")) { + Components->push_back(new FGGyro(this, component_element)); } else { cerr << "Unknown FCS component: " << component_element->GetName() << endl; } @@ -692,6 +665,8 @@ bool FGFCS::Load(Element* el, SystemType systype) channel_element = document->FindNextElement("channel"); } + PostLoad(document, PropertyManager); + ResetParser(); return true; @@ -701,64 +676,60 @@ bool FGFCS::Load(Element* el, SystemType systype) 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; + return BrakePos[bg]; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -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; @@ -769,7 +740,7 @@ ifstream* FGFCS::FindSystemFile(string system_filename) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGFCS::GetComponentStrings(string delimeter) +string FGFCS::GetComponentStrings(const string& delimiter) const { unsigned int comp; string CompStrings = ""; @@ -778,7 +749,7 @@ string FGFCS::GetComponentStrings(string delimeter) for (unsigned int i=0; iGetName(); total_count++; @@ -787,7 +758,7 @@ string FGFCS::GetComponentStrings(string delimeter) for (comp = 0; comp < APComponents.size(); comp++) { if (firstime) firstime = false; - else CompStrings += delimeter; + else CompStrings += delimiter; CompStrings += APComponents[comp]->GetName(); total_count++; @@ -795,7 +766,7 @@ string FGFCS::GetComponentStrings(string delimeter) for (comp = 0; comp < FCSComponents.size(); comp++) { if (firstime) firstime = false; - else CompStrings += delimeter; + else CompStrings += delimiter; CompStrings += FCSComponents[comp]->GetName(); total_count++; @@ -806,7 +777,7 @@ string FGFCS::GetComponentStrings(string delimeter) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -string FGFCS::GetComponentValues(string delimeter) +string FGFCS::GetComponentValues(const string& delimiter) const { std::ostringstream buf; @@ -816,7 +787,7 @@ string FGFCS::GetComponentValues(string delimeter) for (unsigned int i=0; iGetOutput(); total_count++; @@ -824,7 +795,7 @@ string FGFCS::GetComponentValues(string delimeter) 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++; @@ -832,7 +803,7 @@ string FGFCS::GetComponentValues(string delimeter) 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++; @@ -860,9 +831,10 @@ void FGFCS::AddThrottle(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGFCS::AddGear(void) +void FGFCS::AddGear(unsigned int NumGear) { - SteerPosDeg.push_back(0.0); + SteerPosDeg.clear(); + for (unsigned int i=0; iGetGearUnit(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); }