1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Model the flight controls
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class models the flight controls for a specific airplane
33 --------------------------------------------------------------------------------
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 #include <FGFDMExec.h>
42 #include <input_output/FGPropertyManager.h>
47 #include <models/flight_control/FGFilter.h>
48 #include <models/flight_control/FGDeadBand.h>
49 #include <models/flight_control/FGGain.h>
50 #include <models/flight_control/FGPID.h>
51 #include <models/flight_control/FGSwitch.h>
52 #include <models/flight_control/FGSummer.h>
53 #include <models/flight_control/FGKinemat.h>
54 #include <models/flight_control/FGFCSFunction.h>
55 #include <models/flight_control/FGSensor.h>
56 #include <models/flight_control/FGActuator.h>
57 #include <models/flight_control/FGAccelerometer.h>
61 static const char *IdSrc = "$Id$";
62 static const char *IdHdr = ID_FCS;
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
73 DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;
74 PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
75 GearCmd = GearPos = 1; // default to gear down
76 LeftBrake = RightBrake = CenterBrake = 0.0;
77 TailhookPos = WingFoldPos = 0.0;
80 for (i=0;i<NForms;i++) {
81 DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
82 DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
88 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 PropAdvanceCmd.clear();
99 PropFeatherCmd.clear();
104 for (i=0;i<APComponents.size();i++) delete APComponents[i];
105 APComponents.clear();
106 for (i=0;i<FCSComponents.size();i++) delete FCSComponents[i];
107 FCSComponents.clear();
108 for (i=0;i<Systems.size();i++) delete Systems[i];
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 bool FGFCS::InitModel(void)
121 if (!FGModel::InitModel()) return false;
123 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = 0.0;
124 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = 0.0;
125 for (i=0; i<ThrottleCmd.size(); i++) ThrottleCmd[i] = 0.0;
126 for (i=0; i<MixtureCmd.size(); i++) MixtureCmd[i] = 0.0;
127 for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = 0.0;
128 for (i=0; i<PropFeather.size(); i++) PropFeather[i] = 0.0;
130 DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;
131 PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
132 TailhookPos = WingFoldPos = 0.0;
134 for (i=0;i<NForms;i++) {
135 DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
136 DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
139 for (unsigned int i=0; i<Systems.size(); i++) {
140 if (Systems[i]->GetType() == "LAG" ||
141 Systems[i]->GetType() == "LEAD_LAG" ||
142 Systems[i]->GetType() == "WASHOUT" ||
143 Systems[i]->GetType() == "SECOND_ORDER_FILTER" ||
144 Systems[i]->GetType() == "INTEGRATOR")
146 ((FGFilter*)Systems[i])->ResetPastStates();
147 } else if (Systems[i]->GetType() == "PID" ) {
148 ((FGPID*)Systems[i])->ResetPastStates();
152 for (unsigned int i=0; i<FCSComponents.size(); i++) {
153 if (FCSComponents[i]->GetType() == "LAG" ||
154 FCSComponents[i]->GetType() == "LEAD_LAG" ||
155 FCSComponents[i]->GetType() == "WASHOUT" ||
156 FCSComponents[i]->GetType() == "SECOND_ORDER_FILTER" ||
157 FCSComponents[i]->GetType() == "INTEGRATOR")
159 ((FGFilter*)FCSComponents[i])->ResetPastStates();
160 } else if (FCSComponents[i]->GetType() == "PID" ) {
161 ((FGPID*)FCSComponents[i])->ResetPastStates();
165 for (unsigned int i=0; i<APComponents.size(); i++) {
166 if (APComponents[i]->GetType() == "LAG" ||
167 APComponents[i]->GetType() == "LEAD_LAG" ||
168 APComponents[i]->GetType() == "WASHOUT" ||
169 APComponents[i]->GetType() == "SECOND_ORDER_FILTER" ||
170 APComponents[i]->GetType() == "INTEGRATOR")
172 ((FGFilter*)APComponents[i])->ResetPastStates();
173 } else if (APComponents[i]->GetType() == "PID" ) {
174 ((FGPID*)APComponents[i])->ResetPastStates();
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 // Notes: In this logic the default engine commands are set. This is simply a
183 // sort of safe-mode method in case the user has not defined control laws for
184 // throttle, mixture, and prop-advance. The throttle, mixture, and prop advance
185 // positions are set equal to the respective commands. Any control logic that is
186 // actually present in the flight_control or autopilot section will override
187 // these simple assignments.
189 bool FGFCS::Run(void)
193 if (FGModel::Run()) return true; // fast exit if nothing to do
194 if (FDMExec->Holding()) return false;
196 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
197 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
198 for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[i];
199 for (i=0; i<PropFeather.size(); i++) PropFeather[i] = PropFeatherCmd[i];
201 // Set the default steering angle
202 for (i=0; i<SteerPosDeg.size(); i++) {
203 FGLGear* gear = GroundReactions->GetGearUnit(i);
204 SteerPosDeg[i] = gear->GetDefaultSteerAngle( GetDsCmd() );
207 // Execute Systems in order
208 for (i=0; i<Systems.size(); i++) Systems[i]->Run();
211 for (i=0; i<APComponents.size(); i++) APComponents[i]->Run();
213 // Execute Flight Control System
214 for (i=0; i<FCSComponents.size(); i++) FCSComponents[i]->Run();
219 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 void FGFCS::SetDaLPos( int form , double pos )
226 DaLPos[ofDeg] = pos*radtodeg;
229 DaLPos[ofRad] = pos*degtorad;
233 DaLPos[ofNorm] = pos;
235 DaLPos[ofMag] = fabs(DaLPos[ofRad]);
238 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 void FGFCS::SetDaRPos( int form , double pos )
245 DaRPos[ofDeg] = pos*radtodeg;
248 DaRPos[ofRad] = pos*degtorad;
252 DaRPos[ofNorm] = pos;
254 DaRPos[ofMag] = fabs(DaRPos[ofRad]);
257 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 void FGFCS::SetDePos( int form , double pos )
264 DePos[ofDeg] = pos*radtodeg;
267 DePos[ofRad] = pos*degtorad;
273 DePos[ofMag] = fabs(DePos[ofRad]);
276 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 void FGFCS::SetDrPos( int form , double pos )
283 DrPos[ofDeg] = pos*radtodeg;
286 DrPos[ofRad] = pos*degtorad;
292 DrPos[ofMag] = fabs(DrPos[ofRad]);
295 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 void FGFCS::SetDfPos( int form , double pos )
302 DfPos[ofDeg] = pos*radtodeg;
305 DfPos[ofRad] = pos*degtorad;
311 DfPos[ofMag] = fabs(DfPos[ofRad]);
314 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 void FGFCS::SetDsbPos( int form , double pos )
321 DsbPos[ofDeg] = pos*radtodeg;
324 DsbPos[ofRad] = pos*degtorad;
328 DsbPos[ofNorm] = pos;
330 DsbPos[ofMag] = fabs(DsbPos[ofRad]);
333 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 void FGFCS::SetDspPos( int form , double pos )
340 DspPos[ofDeg] = pos*radtodeg;
343 DspPos[ofRad] = pos*degtorad;
347 DspPos[ofNorm] = pos;
349 DspPos[ofMag] = fabs(DspPos[ofRad]);
352 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 void FGFCS::SetThrottleCmd(int engineNum, double setting)
358 if (engineNum < (int)ThrottlePos.size()) {
360 for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
362 ThrottleCmd[engineNum] = setting;
365 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
366 << " engines exist, but attempted throttle command is for engine "
367 << engineNum << endl;
371 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 void FGFCS::SetThrottlePos(int engineNum, double setting)
377 if (engineNum < (int)ThrottlePos.size()) {
379 for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
381 ThrottlePos[engineNum] = setting;
384 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
385 << " engines exist, but attempted throttle position setting is for engine "
386 << engineNum << endl;
390 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 double FGFCS::GetThrottleCmd(int engineNum) const
394 if (engineNum < (int)ThrottlePos.size()) {
396 cerr << "Cannot get throttle value for ALL engines" << endl;
398 return ThrottleCmd[engineNum];
401 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
402 << " engines exist, but throttle setting for engine " << engineNum
403 << " is selected" << endl;
408 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410 double FGFCS::GetThrottlePos(int engineNum) const
412 if (engineNum < (int)ThrottlePos.size()) {
414 cerr << "Cannot get throttle value for ALL engines" << endl;
416 return ThrottlePos[engineNum];
419 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
420 << " engines exist, but attempted throttle position setting is for engine "
421 << engineNum << endl;
426 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 void FGFCS::SetMixtureCmd(int engineNum, double setting)
432 if (engineNum < (int)ThrottlePos.size()) {
434 for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
436 MixtureCmd[engineNum] = setting;
441 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
443 void FGFCS::SetMixturePos(int engineNum, double setting)
447 if (engineNum < (int)ThrottlePos.size()) {
449 for (ctr=0;ctr<MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
451 MixturePos[engineNum] = setting;
456 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
458 void FGFCS::SetPropAdvanceCmd(int engineNum, double setting)
462 if (engineNum < (int)ThrottlePos.size()) {
464 for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
466 PropAdvanceCmd[engineNum] = setting;
471 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
473 void FGFCS::SetPropAdvance(int engineNum, double setting)
477 if (engineNum < (int)ThrottlePos.size()) {
479 for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
481 PropAdvance[engineNum] = setting;
486 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
488 void FGFCS::SetFeatherCmd(int engineNum, bool setting)
492 if (engineNum < (int)ThrottlePos.size()) {
494 for (ctr=0;ctr<PropFeatherCmd.size();ctr++) PropFeatherCmd[ctr] = setting;
496 PropFeatherCmd[engineNum] = setting;
501 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
503 void FGFCS::SetPropFeather(int engineNum, bool setting)
507 if (engineNum < (int)ThrottlePos.size()) {
509 for (ctr=0;ctr<PropFeatherCmd.size();ctr++) PropFeather[ctr] = PropFeatherCmd[ctr];
511 PropFeather[engineNum] = setting;
516 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
518 bool FGFCS::Load(Element* el, SystemType systype)
520 string name, file, fname="", interface_property_string, parent_name;
521 vector <FGFCSComponent*> *Components;
522 Element *component_element, *sensor_element;
523 Element *channel_element;
527 string separator = "/";
529 // ToDo: The handling of name and file attributes could be improved, here,
530 // considering that a name can be in the external file, as well.
532 name = el->GetAttributeValue("name");
535 fname = el->GetAttributeValue("file");
536 if (systype == stSystem) {
537 file = FindSystemFullPathname(fname);
539 file = FDMExec->GetFullAircraftPath() + separator + fname + ".xml";
542 cerr << "FCS, Autopilot, or system does not appear to be defined inline nor in a file" << endl;
545 document = LoadXMLDocument(file);
547 cerr << "Error loading file " << file << endl;
550 name = document->GetAttributeValue("name");
556 if (document->GetName() == "autopilot") {
557 Components = &APComponents;
558 Name = "Autopilot: " + document->GetAttributeValue("name");
559 } else if (document->GetName() == "flight_control") {
560 Components = &FCSComponents;
561 Name = "FCS: " + document->GetAttributeValue("name");
562 } else if (document->GetName() == "system") {
563 Components = &Systems;
564 Name = "System: " + document->GetAttributeValue("name");
568 if (document->GetName() == "flight_control") bindModel();
570 FGModel::Load(document); // Load interface properties from document
572 // After reading interface properties in a file, read properties in the local
573 // flight_control, autopilot, or system element. This allows general-purpose
574 // systems to be defined in a file, with overrides or initial loaded constants
575 // supplied in the relevant element of the aircraft configuration file.
577 Element* property_element = 0;
579 if (!fname.empty()) {
580 property_element = el->FindElement("property");
581 if (property_element && debug_lvl > 0) cout << endl << " Overriding properties" << endl << endl;
582 while (property_element) {
584 if ( ! property_element->GetAttributeValue("value").empty())
585 value = property_element->GetAttributeValueAsNumber("value");
587 interface_property_string = property_element->GetDataLine();
588 if (PropertyManager->HasNode(interface_property_string)) {
589 FGPropertyManager* node = PropertyManager->GetNode(interface_property_string);
591 cout << " " << "Overriding value for property " << interface_property_string
592 << " (old value: " << node->getDoubleValue() << " new value: " << value << ")" << endl;
593 node->setDoubleValue(value);
595 interface_properties.push_back(new double(value));
596 PropertyManager->Tie(interface_property_string, interface_properties.back());
598 cout << " " << interface_property_string << " (initial value: " << value << ")" << endl;
601 property_element = el->FindNextElement("property");
605 channel_element = document->FindElement("channel");
606 while (channel_element) {
609 cout << endl << highint << fgblue << " Channel "
610 << normint << channel_element->GetAttributeValue("name") << reset << endl;
612 component_element = channel_element->GetElement();
613 while (component_element) {
615 if ((component_element->GetName() == string("lag_filter")) ||
616 (component_element->GetName() == string("lead_lag_filter")) ||
617 (component_element->GetName() == string("washout_filter")) ||
618 (component_element->GetName() == string("second_order_filter")) ||
619 (component_element->GetName() == string("integrator")) )
621 Components->push_back(new FGFilter(this, component_element));
622 } else if ((component_element->GetName() == string("pure_gain")) ||
623 (component_element->GetName() == string("scheduled_gain")) ||
624 (component_element->GetName() == string("aerosurface_scale")))
626 Components->push_back(new FGGain(this, component_element));
627 } else if (component_element->GetName() == string("summer")) {
628 Components->push_back(new FGSummer(this, component_element));
629 } else if (component_element->GetName() == string("deadband")) {
630 Components->push_back(new FGDeadBand(this, component_element));
631 } else if (component_element->GetName() == string("switch")) {
632 Components->push_back(new FGSwitch(this, component_element));
633 } else if (component_element->GetName() == string("kinematic")) {
634 Components->push_back(new FGKinemat(this, component_element));
635 } else if (component_element->GetName() == string("fcs_function")) {
636 Components->push_back(new FGFCSFunction(this, component_element));
637 } else if (component_element->GetName() == string("pid")) {
638 Components->push_back(new FGPID(this, component_element));
639 } else if (component_element->GetName() == string("actuator")) {
640 Components->push_back(new FGActuator(this, component_element));
641 } else if (component_element->GetName() == string("sensor")) {
642 Components->push_back(new FGSensor(this, component_element));
643 } else if (component_element->GetName() == string("accelerometer")) {
644 Components->push_back(new FGAccelerometer(this, component_element));
646 cerr << "Unknown FCS component: " << component_element->GetName() << endl;
649 cerr << highint << fgred << endl << " " << s << endl;
650 cerr << reset << endl;
653 component_element = channel_element->GetNextElement();
655 channel_element = document->FindNextElement("channel");
663 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
665 double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
668 case FGLGear::bgLeft:
670 case FGLGear::bgRight:
672 case FGLGear::bgCenter:
675 cerr << "GetBrake asked to return a bogus brake value" << endl;
680 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
682 string FGFCS::FindSystemFullPathname(string system_filename)
684 string fullpath, localpath;
685 string systemPath = FDMExec->GetSystemsPath();
686 string aircraftPath = FDMExec->GetFullAircraftPath();
687 ifstream system_file;
689 string separator = "/";
691 fullpath = systemPath + separator;
692 localpath = aircraftPath + separator + "Systems" + separator;
694 system_file.open(string(fullpath + system_filename + ".xml").c_str());
695 if ( !system_file.is_open()) {
696 system_file.open(string(localpath + system_filename + ".xml").c_str());
697 if ( !system_file.is_open()) {
698 cerr << " Could not open system file: " << system_filename << " in path "
699 << fullpath << " or " << localpath << endl;
702 return string(localpath + system_filename + ".xml");
705 return string(fullpath + system_filename + ".xml");
708 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
710 ifstream* FGFCS::FindSystemFile(string system_filename)
712 string fullpath, localpath;
713 string systemPath = FDMExec->GetSystemsPath();
714 string aircraftPath = FDMExec->GetFullAircraftPath();
715 ifstream* system_file = new ifstream();
717 string separator = "/";
719 fullpath = systemPath + separator;
720 localpath = aircraftPath + separator + "Systems" + separator;
722 system_file->open(string(fullpath + system_filename + ".xml").c_str());
723 if ( !system_file->is_open()) {
724 system_file->open(string(localpath + system_filename + ".xml").c_str());
725 if ( !system_file->is_open()) {
726 cerr << " Could not open system file: " << system_filename << " in path "
727 << fullpath << " or " << localpath << endl;
733 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
735 string FGFCS::GetComponentStrings(string delimeter)
738 string CompStrings = "";
739 bool firstime = true;
742 for (unsigned int i=0; i<Systems.size(); i++) {
743 if (firstime) firstime = false;
744 else CompStrings += delimeter;
746 CompStrings += Systems[i]->GetName();
750 for (comp = 0; comp < APComponents.size(); comp++)
752 if (firstime) firstime = false;
753 else CompStrings += delimeter;
755 CompStrings += APComponents[comp]->GetName();
759 for (comp = 0; comp < FCSComponents.size(); comp++) {
760 if (firstime) firstime = false;
761 else CompStrings += delimeter;
763 CompStrings += FCSComponents[comp]->GetName();
770 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
772 string FGFCS::GetComponentValues(string delimeter)
774 std::ostringstream buf;
777 bool firstime = true;
780 for (unsigned int i=0; i<Systems.size(); i++) {
781 if (firstime) firstime = false;
782 else buf << delimeter;
784 buf << setprecision(9) << Systems[i]->GetOutput();
788 for (comp = 0; comp < APComponents.size(); comp++) {
789 if (firstime) firstime = false;
790 else buf << delimeter;
792 buf << setprecision(9) << APComponents[comp]->GetOutput();
796 for (comp = 0; comp < FCSComponents.size(); comp++) {
797 if (firstime) firstime = false;
798 else buf << delimeter;
800 buf << setprecision(9) << FCSComponents[comp]->GetOutput();
807 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
809 void FGFCS::AddThrottle(void)
811 ThrottleCmd.push_back(0.0);
812 ThrottlePos.push_back(0.0);
813 MixtureCmd.push_back(0.0); // assume throttle and mixture are coupled
814 MixturePos.push_back(0.0);
815 PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled
816 PropAdvance.push_back(0.0);
817 PropFeatherCmd.push_back(false);
818 PropFeather.push_back(false);
820 unsigned int num = (unsigned int)ThrottleCmd.size()-1;
824 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
826 void FGFCS::AddGear(void)
828 SteerPosDeg.push_back(0.0);
831 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
833 double FGFCS::GetDt(void)
835 return FDMExec->GetDeltaT()*rate;
838 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
840 void FGFCS::bind(void)
842 PropertyManager->Tie("fcs/aileron-cmd-norm", this, &FGFCS::GetDaCmd, &FGFCS::SetDaCmd);
843 PropertyManager->Tie("fcs/elevator-cmd-norm", this, &FGFCS::GetDeCmd, &FGFCS::SetDeCmd);
844 PropertyManager->Tie("fcs/rudder-cmd-norm", this, &FGFCS::GetDrCmd, &FGFCS::SetDrCmd);
845 PropertyManager->Tie("fcs/flap-cmd-norm", this, &FGFCS::GetDfCmd, &FGFCS::SetDfCmd);
846 PropertyManager->Tie("fcs/speedbrake-cmd-norm", this, &FGFCS::GetDsbCmd, &FGFCS::SetDsbCmd);
847 PropertyManager->Tie("fcs/spoiler-cmd-norm", this, &FGFCS::GetDspCmd, &FGFCS::SetDspCmd);
848 PropertyManager->Tie("fcs/pitch-trim-cmd-norm", this, &FGFCS::GetPitchTrimCmd, &FGFCS::SetPitchTrimCmd);
849 PropertyManager->Tie("fcs/roll-trim-cmd-norm", this, &FGFCS::GetRollTrimCmd, &FGFCS::SetRollTrimCmd);
850 PropertyManager->Tie("fcs/yaw-trim-cmd-norm", this, &FGFCS::GetYawTrimCmd, &FGFCS::SetYawTrimCmd);
852 PropertyManager->Tie("fcs/left-aileron-pos-rad", this, ofRad, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
853 PropertyManager->Tie("fcs/left-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
854 PropertyManager->Tie("fcs/left-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
855 PropertyManager->Tie("fcs/mag-left-aileron-pos-rad", this, ofMag, &FGFCS::GetDaLPos);
857 PropertyManager->Tie("fcs/right-aileron-pos-rad", this, ofRad, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
858 PropertyManager->Tie("fcs/right-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
859 PropertyManager->Tie("fcs/right-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
860 PropertyManager->Tie("fcs/mag-right-aileron-pos-rad", this, ofMag, &FGFCS::GetDaRPos);
862 PropertyManager->Tie("fcs/elevator-pos-rad", this, ofRad, &FGFCS::GetDePos, &FGFCS::SetDePos);
863 PropertyManager->Tie("fcs/elevator-pos-deg", this, ofDeg, &FGFCS::GetDePos, &FGFCS::SetDePos);
864 PropertyManager->Tie("fcs/elevator-pos-norm", this, ofNorm, &FGFCS::GetDePos, &FGFCS::SetDePos);
865 PropertyManager->Tie("fcs/mag-elevator-pos-rad", this, ofMag, &FGFCS::GetDePos);
867 PropertyManager->Tie("fcs/rudder-pos-rad", this,ofRad, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
868 PropertyManager->Tie("fcs/rudder-pos-deg", this,ofDeg, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
869 PropertyManager->Tie("fcs/rudder-pos-norm", this,ofNorm, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
870 PropertyManager->Tie("fcs/mag-rudder-pos-rad", this,ofMag, &FGFCS::GetDrPos);
872 PropertyManager->Tie("fcs/flap-pos-rad", this,ofRad, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
873 PropertyManager->Tie("fcs/flap-pos-deg", this,ofDeg, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
874 PropertyManager->Tie("fcs/flap-pos-norm", this,ofNorm, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
876 PropertyManager->Tie("fcs/speedbrake-pos-rad", this,ofRad, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
877 PropertyManager->Tie("fcs/speedbrake-pos-deg", this,ofDeg, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
878 PropertyManager->Tie("fcs/speedbrake-pos-norm", this,ofNorm, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
879 PropertyManager->Tie("fcs/mag-speedbrake-pos-rad", this,ofMag, &FGFCS::GetDsbPos);
881 PropertyManager->Tie("fcs/spoiler-pos-rad", this, ofRad, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
882 PropertyManager->Tie("fcs/spoiler-pos-deg", this, ofDeg, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
883 PropertyManager->Tie("fcs/spoiler-pos-norm", this, ofNorm, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
884 PropertyManager->Tie("fcs/mag-spoiler-pos-rad", this, ofMag, &FGFCS::GetDspPos);
886 PropertyManager->Tie("gear/gear-pos-norm", this, &FGFCS::GetGearPos, &FGFCS::SetGearPos);
887 PropertyManager->Tie("gear/gear-cmd-norm", this, &FGFCS::GetGearCmd, &FGFCS::SetGearCmd);
888 PropertyManager->Tie("fcs/left-brake-cmd-norm", this, &FGFCS::GetLBrake, &FGFCS::SetLBrake);
889 PropertyManager->Tie("fcs/right-brake-cmd-norm", this, &FGFCS::GetRBrake, &FGFCS::SetRBrake);
890 PropertyManager->Tie("fcs/center-brake-cmd-norm", this, &FGFCS::GetCBrake, &FGFCS::SetCBrake);
891 PropertyManager->Tie("fcs/steer-cmd-norm", this, &FGFCS::GetDsCmd, &FGFCS::SetDsCmd);
893 PropertyManager->Tie("gear/tailhook-pos-norm", this, &FGFCS::GetTailhookPos, &FGFCS::SetTailhookPos);
894 PropertyManager->Tie("fcs/wing-fold-pos-norm", this, &FGFCS::GetWingFoldPos, &FGFCS::SetWingFoldPos);
897 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
898 // Technically, this function should probably bind propulsion type specific controls
899 // rather than mixture and prop-advance.
901 void FGFCS::bindThrottle(unsigned int num)
905 tmp = CreateIndexedPropertyName("fcs/throttle-cmd-norm", num);
906 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetThrottleCmd,
907 &FGFCS::SetThrottleCmd);
908 tmp = CreateIndexedPropertyName("fcs/throttle-pos-norm", num);
909 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetThrottlePos,
910 &FGFCS::SetThrottlePos);
911 tmp = CreateIndexedPropertyName("fcs/mixture-cmd-norm", num);
912 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetMixtureCmd,
913 &FGFCS::SetMixtureCmd);
914 tmp = CreateIndexedPropertyName("fcs/mixture-pos-norm", num);
915 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetMixturePos,
916 &FGFCS::SetMixturePos);
917 tmp = CreateIndexedPropertyName("fcs/advance-cmd-norm", num);
918 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetPropAdvanceCmd,
919 &FGFCS::SetPropAdvanceCmd);
920 tmp = CreateIndexedPropertyName("fcs/advance-pos-norm", num);
921 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetPropAdvance,
922 &FGFCS::SetPropAdvance);
923 tmp = CreateIndexedPropertyName("fcs/feather-cmd-norm", num);
924 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetFeatherCmd,
925 &FGFCS::SetFeatherCmd);
926 tmp = CreateIndexedPropertyName("fcs/feather-pos-norm", num);
927 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetPropFeather,
928 &FGFCS::SetPropFeather);
931 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
933 void FGFCS::bindModel(void)
938 for (i=0; i<SteerPosDeg.size(); i++) {
939 if (GroundReactions->GetGearUnit(i)->GetSteerable()) {
940 tmp = CreateIndexedPropertyName("fcs/steer-pos-deg", i);
941 PropertyManager->Tie( tmp.c_str(), this, i, &FGFCS::GetSteerPosDeg, &FGFCS::SetSteerPosDeg);
946 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
947 // The bitmasked value choices are as follows:
948 // unset: In this case (the default) JSBSim would only print
949 // out the normally expected messages, essentially echoing
950 // the config files as they are read. If the environment
951 // variable is not set, debug_lvl is set to 1 internally
952 // 0: This requests JSBSim not to output any messages
954 // 1: This value explicity requests the normal JSBSim
956 // 2: This value asks for a message to be printed out when
957 // a class is instantiated
958 // 4: When this value is set, a message is displayed when a
959 // FGModel object executes its Run() method
960 // 8: When this value is set, various runtime state variables
961 // are printed out periodically
962 // 16: When set various parameters are sanity checked and
963 // a message is printed out when they go out of bounds
965 void FGFCS::Debug(int from)
967 if (debug_lvl <= 0) return;
969 if (debug_lvl & 1) { // Standard console startup message output
970 if (from == 2) { // Loader
971 cout << endl << " " << Name << endl;
974 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
975 if (from == 0) cout << "Instantiated: FGFCS" << endl;
976 if (from == 1) cout << "Destroyed: FGFCS" << endl;
978 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
980 if (debug_lvl & 8 ) { // Runtime state variables
982 if (debug_lvl & 16) { // Sanity checking
984 if (debug_lvl & 64) {
985 if (from == 0) { // Constructor
986 cout << IdSrc << endl;
987 cout << IdHdr << endl;