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>
60 static const char *IdSrc = "$Id$";
61 static const char *IdHdr = ID_FCS;
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
72 DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;
73 PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
74 GearCmd = GearPos = 1; // default to gear down
75 LeftBrake = RightBrake = CenterBrake = 0.0;
76 TailhookPos = WingFoldPos = 0.0;
79 for (i=0;i<NForms;i++) {
80 DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
81 DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 PropAdvanceCmd.clear();
98 PropFeatherCmd.clear();
103 for (i=0;i<sensors.size();i++) delete sensors[i];
105 for (i=0;i<APComponents.size();i++) delete APComponents[i];
106 APComponents.clear();
107 for (i=0;i<FCSComponents.size();i++) delete FCSComponents[i];
108 FCSComponents.clear();
109 for (i=0;i<Systems.size();i++) delete Systems[i];
112 for (unsigned int i=0; i<interface_properties.size(); i++) delete interface_properties[i];
113 interface_properties.clear();
118 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 bool FGFCS::InitModel(void)
124 if (!FGModel::InitModel()) return false;
126 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = 0.0;
127 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = 0.0;
128 for (i=0; i<ThrottleCmd.size(); i++) ThrottleCmd[i] = 0.0;
129 for (i=0; i<MixtureCmd.size(); i++) MixtureCmd[i] = 0.0;
130 for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = 0.0;
131 for (i=0; i<PropFeather.size(); i++) PropFeather[i] = 0.0;
133 DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;
134 PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
135 TailhookPos = WingFoldPos = 0.0;
137 for (i=0;i<NForms;i++) {
138 DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
139 DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
145 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 // Notes: In this logic the default engine commands are set. This is simply a
147 // sort of safe-mode method in case the user has not defined control laws for
148 // throttle, mixture, and prop-advance. The throttle, mixture, and prop advance
149 // positions are set equal to the respective commands. Any control logic that is
150 // actually present in the flight_control or autopilot section will override
151 // these simple assignments.
153 bool FGFCS::Run(void)
157 if (FGModel::Run()) return true; // fast exit if nothing to do
158 if (FDMExec->Holding()) return false;
160 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
161 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
162 for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[i];
163 for (i=0; i<PropFeather.size(); i++) PropFeather[i] = PropFeatherCmd[i];
165 // Set the default steering angle
166 for (i=0; i<SteerPosDeg.size(); i++) {
167 FGLGear* gear = GroundReactions->GetGearUnit(i);
168 SteerPosDeg[i] = gear->GetDefaultSteerAngle( GetDsCmd() );
171 // Cycle through the sensor, systems, autopilot, and flight control components
173 for (i=0; i<sensors.size(); i++) sensors[i]->Run();
175 // Execute Systems in order
176 for (i=0; i<Systems.size(); i++) Systems[i]->Run();
179 for (i=0; i<APComponents.size(); i++) APComponents[i]->Run();
181 // Execute Flight Control System
182 for (i=0; i<FCSComponents.size(); i++) FCSComponents[i]->Run();
187 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 void FGFCS::SetDaLPos( int form , double pos )
194 DaLPos[ofDeg] = pos*radtodeg;
197 DaLPos[ofRad] = pos*degtorad;
201 DaLPos[ofNorm] = pos;
203 DaLPos[ofMag] = fabs(DaLPos[ofRad]);
206 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 void FGFCS::SetDaRPos( int form , double pos )
213 DaRPos[ofDeg] = pos*radtodeg;
216 DaRPos[ofRad] = pos*degtorad;
220 DaRPos[ofNorm] = pos;
222 DaRPos[ofMag] = fabs(DaRPos[ofRad]);
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 void FGFCS::SetDePos( int form , double pos )
232 DePos[ofDeg] = pos*radtodeg;
235 DePos[ofRad] = pos*degtorad;
241 DePos[ofMag] = fabs(DePos[ofRad]);
244 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 void FGFCS::SetDrPos( int form , double pos )
251 DrPos[ofDeg] = pos*radtodeg;
254 DrPos[ofRad] = pos*degtorad;
260 DrPos[ofMag] = fabs(DrPos[ofRad]);
263 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 void FGFCS::SetDfPos( int form , double pos )
270 DfPos[ofDeg] = pos*radtodeg;
273 DfPos[ofRad] = pos*degtorad;
279 DfPos[ofMag] = fabs(DfPos[ofRad]);
282 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 void FGFCS::SetDsbPos( int form , double pos )
289 DsbPos[ofDeg] = pos*radtodeg;
292 DsbPos[ofRad] = pos*degtorad;
296 DsbPos[ofNorm] = pos;
298 DsbPos[ofMag] = fabs(DsbPos[ofRad]);
301 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 void FGFCS::SetDspPos( int form , double pos )
308 DspPos[ofDeg] = pos*radtodeg;
311 DspPos[ofRad] = pos*degtorad;
315 DspPos[ofNorm] = pos;
317 DspPos[ofMag] = fabs(DspPos[ofRad]);
320 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322 void FGFCS::SetThrottleCmd(int engineNum, double setting)
326 if (engineNum < (int)ThrottlePos.size()) {
328 for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
330 ThrottleCmd[engineNum] = setting;
333 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
334 << " engines exist, but attempted throttle command is for engine "
335 << engineNum << endl;
339 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 void FGFCS::SetThrottlePos(int engineNum, double setting)
345 if (engineNum < (int)ThrottlePos.size()) {
347 for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
349 ThrottlePos[engineNum] = setting;
352 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
353 << " engines exist, but attempted throttle position setting is for engine "
354 << engineNum << endl;
358 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
360 double FGFCS::GetThrottleCmd(int engineNum) const
362 if (engineNum < (int)ThrottlePos.size()) {
364 cerr << "Cannot get throttle value for ALL engines" << endl;
366 return ThrottleCmd[engineNum];
369 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
370 << " engines exist, but throttle setting for engine " << engineNum
371 << " is selected" << endl;
376 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
378 double FGFCS::GetThrottlePos(int engineNum) const
380 if (engineNum < (int)ThrottlePos.size()) {
382 cerr << "Cannot get throttle value for ALL engines" << endl;
384 return ThrottlePos[engineNum];
387 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
388 << " engines exist, but attempted throttle position setting is for engine "
389 << engineNum << endl;
394 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396 void FGFCS::SetMixtureCmd(int engineNum, double setting)
400 if (engineNum < (int)ThrottlePos.size()) {
402 for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
404 MixtureCmd[engineNum] = setting;
409 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 void FGFCS::SetMixturePos(int engineNum, double setting)
415 if (engineNum < (int)ThrottlePos.size()) {
417 for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
419 MixturePos[engineNum] = setting;
424 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426 void FGFCS::SetPropAdvanceCmd(int engineNum, double setting)
430 if (engineNum < (int)ThrottlePos.size()) {
432 for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
434 PropAdvanceCmd[engineNum] = setting;
439 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441 void FGFCS::SetPropAdvance(int engineNum, double setting)
445 if (engineNum < (int)ThrottlePos.size()) {
447 for (ctr=0;ctr<=PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
449 PropAdvance[engineNum] = setting;
454 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456 void FGFCS::SetFeatherCmd(int engineNum, bool setting)
460 if (engineNum < (int)ThrottlePos.size()) {
462 for (ctr=0;ctr<PropFeatherCmd.size();ctr++) PropFeatherCmd[ctr] = setting;
464 PropFeatherCmd[engineNum] = setting;
469 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
471 void FGFCS::SetPropFeather(int engineNum, bool setting)
475 if (engineNum < (int)ThrottlePos.size()) {
477 for (ctr=0;ctr<=PropFeatherCmd.size();ctr++) PropFeather[ctr] = PropFeatherCmd[ctr];
479 PropFeather[engineNum] = setting;
484 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
486 bool FGFCS::Load(Element* el, SystemType systype)
488 string name, file, fname="", interface_property_string, parent_name;
489 vector <FGFCSComponent*> *Components;
490 Element *component_element, *property_element, *sensor_element;
491 Element *channel_element;
495 string separator = "/";
497 // ToDo: The handling of name and file attributes could be improved, here,
498 // considering that a name can be in the external file, as well.
500 name = el->GetAttributeValue("name");
503 fname = el->GetAttributeValue("file");
504 if (systype == stSystem) {
505 file = FindSystemFullPathname(fname);
507 file = FDMExec->GetFullAircraftPath() + separator + fname + ".xml";
510 cerr << "FCS, Autopilot, or system does not appear to be defined inline nor in a file" << endl;
513 document = LoadXMLDocument(file);
515 cerr << "Error loading file " << file << endl;
518 name = document->GetAttributeValue("name");
524 if (document->GetName() == "autopilot") {
525 Components = &APComponents;
526 Name = "Autopilot: " + document->GetAttributeValue("name");
527 } else if (document->GetName() == "flight_control") {
528 Components = &FCSComponents;
529 Name = "FCS: " + document->GetAttributeValue("name");
530 } else if (document->GetName() == "system") {
531 Components = &Systems;
532 Name = "System: " + document->GetAttributeValue("name");
536 if (document->GetName() == "flight_control") bindModel();
538 // Interface properties from any autopilot, flight control, or other system are
539 // all stored in the interface properties array.
541 property_element = document->FindElement("property");
542 if (property_element) cout << endl << " Declared properties" << endl << endl;
543 while (property_element) {
545 if ( ! property_element->GetAttributeValue("value").empty())
546 value = property_element->GetAttributeValueAsNumber("value");
547 interface_properties.push_back(new double(value));
548 interface_property_string = property_element->GetDataLine();
549 PropertyManager->Tie(interface_property_string, interface_properties.back());
550 cout << " " << interface_property_string << " (initial value: " << value << ")" << endl;
551 property_element = document->FindNextElement("property");
554 // After reading interface properties in a file, read properties in the local
555 // flight_control, autopilot, or system element. This allows general-purpose
556 // systems to be defined in a file, with overrides or initial loaded constants
557 // supplied in the relevant element of the aircraft configuration file.
559 if (!fname.empty()) {
560 property_element = el->FindElement("property");
561 if (property_element && debug_lvl > 0) cout << endl << " Declared properties" << endl << endl;
562 while (property_element) {
564 if ( ! property_element->GetAttributeValue("value").empty())
565 value = property_element->GetAttributeValueAsNumber("value");
567 interface_property_string = property_element->GetDataLine();
569 FGPropertyManager* node = PropertyManager->GetNode(interface_property_string);
571 cout << " " << "Overriding value for property " << interface_property_string
572 << " (old value: " << node->getDoubleValue() << " new value: " << value << ")" << endl;
573 node->setDoubleValue(value);
575 interface_properties.push_back(new double(value));
576 PropertyManager->Tie(interface_property_string, interface_properties.back());
578 cout << " " << interface_property_string << " (initial value: " << value << ")" << endl;
582 property_element = el->FindNextElement("property");
586 // Any sensor elements that are outside of a channel (in either the autopilot
587 // or the flight_control, or even any possible "system") are placed into the global
588 // "sensors" array, and are executed prior to any autopilot, flight control, or
591 sensor_element = document->FindElement("sensor");
592 while (sensor_element) {
594 sensors.push_back(new FGSensor(this, sensor_element));
596 cerr << highint << fgred << endl << " " << s << endl;
599 sensor_element = document->FindNextElement("sensor");
602 channel_element = document->FindElement("channel");
603 while (channel_element) {
606 cout << endl << highint << fgblue << " Channel "
607 << normint << channel_element->GetAttributeValue("name") << reset << endl;
609 component_element = channel_element->GetElement();
610 while (component_element) {
612 if ((component_element->GetName() == string("lag_filter")) ||
613 (component_element->GetName() == string("lead_lag_filter")) ||
614 (component_element->GetName() == string("washout_filter")) ||
615 (component_element->GetName() == string("second_order_filter")) ||
616 (component_element->GetName() == string("integrator")) )
618 Components->push_back(new FGFilter(this, component_element));
619 } else if ((component_element->GetName() == string("pure_gain")) ||
620 (component_element->GetName() == string("scheduled_gain")) ||
621 (component_element->GetName() == string("aerosurface_scale")))
623 Components->push_back(new FGGain(this, component_element));
624 } else if (component_element->GetName() == string("summer")) {
625 Components->push_back(new FGSummer(this, component_element));
626 } else if (component_element->GetName() == string("deadband")) {
627 Components->push_back(new FGDeadBand(this, component_element));
628 } else if (component_element->GetName() == string("switch")) {
629 Components->push_back(new FGSwitch(this, component_element));
630 } else if (component_element->GetName() == string("kinematic")) {
631 Components->push_back(new FGKinemat(this, component_element));
632 } else if (component_element->GetName() == string("fcs_function")) {
633 Components->push_back(new FGFCSFunction(this, component_element));
634 } else if (component_element->GetName() == string("pid")) {
635 Components->push_back(new FGPID(this, component_element));
636 } else if (component_element->GetName() == string("actuator")) {
637 Components->push_back(new FGActuator(this, component_element));
638 } else if (component_element->GetName() == string("sensor")) {
639 Components->push_back(new FGSensor(this, component_element));
641 cerr << "Unknown FCS component: " << component_element->GetName() << endl;
644 cerr << highint << fgred << endl << " " << s << endl;
645 cerr << reset << endl;
648 component_element = channel_element->GetNextElement();
650 channel_element = document->FindNextElement("channel");
658 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
660 double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
663 case FGLGear::bgLeft:
665 case FGLGear::bgRight:
667 case FGLGear::bgCenter:
670 cerr << "GetBrake asked to return a bogus brake value" << endl;
675 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
677 string FGFCS::FindSystemFullPathname(string system_filename)
679 string fullpath, localpath;
680 string systemPath = FDMExec->GetSystemsPath();
681 string aircraftPath = FDMExec->GetFullAircraftPath();
682 ifstream system_file;
684 string separator = "/";
686 fullpath = systemPath + separator;
687 localpath = aircraftPath + separator + "Systems" + separator;
689 system_file.open(string(fullpath + system_filename + ".xml").c_str());
690 if ( !system_file.is_open()) {
691 system_file.open(string(localpath + system_filename + ".xml").c_str());
692 if ( !system_file.is_open()) {
693 cerr << " Could not open system file: " << system_filename << " in path "
694 << fullpath << " or " << localpath << endl;
697 return string(localpath + system_filename + ".xml");
700 return string(fullpath + system_filename + ".xml");
703 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
705 ifstream* FGFCS::FindSystemFile(string system_filename)
707 string fullpath, localpath;
708 string systemPath = FDMExec->GetSystemsPath();
709 string aircraftPath = FDMExec->GetFullAircraftPath();
710 ifstream* system_file = new ifstream();
712 string separator = "/";
714 fullpath = systemPath + separator;
715 localpath = aircraftPath + separator + "Systems" + separator;
717 system_file->open(string(fullpath + system_filename + ".xml").c_str());
718 if ( !system_file->is_open()) {
719 system_file->open(string(localpath + system_filename + ".xml").c_str());
720 if ( !system_file->is_open()) {
721 cerr << " Could not open system file: " << system_filename << " in path "
722 << fullpath << " or " << localpath << endl;
728 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
730 string FGFCS::GetComponentStrings(string delimeter)
733 string CompStrings = "";
734 bool firstime = true;
737 for (unsigned int i=0; i<Systems.size(); i++) {
738 if (firstime) firstime = false;
739 else CompStrings += delimeter;
741 CompStrings += Systems[i]->GetName();
745 for (comp = 0; comp < APComponents.size(); comp++)
747 if (firstime) firstime = false;
748 else CompStrings += delimeter;
750 CompStrings += APComponents[comp]->GetName();
754 for (comp = 0; comp < FCSComponents.size(); comp++) {
755 if (firstime) firstime = false;
756 else CompStrings += delimeter;
758 CompStrings += FCSComponents[comp]->GetName();
765 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
767 string FGFCS::GetComponentValues(string delimeter)
769 std::ostringstream buf;
772 bool firstime = true;
775 for (unsigned int i=0; i<Systems.size(); i++) {
776 if (firstime) firstime = false;
777 else buf << delimeter;
779 buf << setprecision(9) << Systems[i]->GetOutput();
783 for (comp = 0; comp < APComponents.size(); comp++) {
784 if (firstime) firstime = false;
785 else buf << delimeter;
787 buf << setprecision(9) << APComponents[comp]->GetOutput();
791 for (comp = 0; comp < FCSComponents.size(); comp++) {
792 if (firstime) firstime = false;
793 else buf << delimeter;
795 buf << setprecision(9) << FCSComponents[comp]->GetOutput();
802 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
804 void FGFCS::AddThrottle(void)
806 ThrottleCmd.push_back(0.0);
807 ThrottlePos.push_back(0.0);
808 MixtureCmd.push_back(0.0); // assume throttle and mixture are coupled
809 MixturePos.push_back(0.0);
810 PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled
811 PropAdvance.push_back(0.0);
812 PropFeatherCmd.push_back(false);
813 PropFeather.push_back(false);
815 unsigned int num = (unsigned int)ThrottleCmd.size()-1;
819 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821 void FGFCS::AddGear(void)
823 SteerPosDeg.push_back(0.0);
826 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
828 double FGFCS::GetDt(void)
830 return FDMExec->GetDeltaT()*rate;
833 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
835 void FGFCS::bind(void)
837 PropertyManager->Tie("fcs/aileron-cmd-norm", this, &FGFCS::GetDaCmd, &FGFCS::SetDaCmd);
838 PropertyManager->Tie("fcs/elevator-cmd-norm", this, &FGFCS::GetDeCmd, &FGFCS::SetDeCmd);
839 PropertyManager->Tie("fcs/rudder-cmd-norm", this, &FGFCS::GetDrCmd, &FGFCS::SetDrCmd);
840 PropertyManager->Tie("fcs/flap-cmd-norm", this, &FGFCS::GetDfCmd, &FGFCS::SetDfCmd);
841 PropertyManager->Tie("fcs/speedbrake-cmd-norm", this, &FGFCS::GetDsbCmd, &FGFCS::SetDsbCmd);
842 PropertyManager->Tie("fcs/spoiler-cmd-norm", this, &FGFCS::GetDspCmd, &FGFCS::SetDspCmd);
843 PropertyManager->Tie("fcs/pitch-trim-cmd-norm", this, &FGFCS::GetPitchTrimCmd, &FGFCS::SetPitchTrimCmd);
844 PropertyManager->Tie("fcs/roll-trim-cmd-norm", this, &FGFCS::GetRollTrimCmd, &FGFCS::SetRollTrimCmd);
845 PropertyManager->Tie("fcs/yaw-trim-cmd-norm", this, &FGFCS::GetYawTrimCmd, &FGFCS::SetYawTrimCmd);
847 PropertyManager->Tie("fcs/left-aileron-pos-rad", this, ofRad, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
848 PropertyManager->Tie("fcs/left-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
849 PropertyManager->Tie("fcs/left-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
850 PropertyManager->Tie("fcs/mag-left-aileron-pos-rad", this, ofMag, &FGFCS::GetDaLPos);
852 PropertyManager->Tie("fcs/right-aileron-pos-rad", this, ofRad, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
853 PropertyManager->Tie("fcs/right-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
854 PropertyManager->Tie("fcs/right-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
855 PropertyManager->Tie("fcs/mag-right-aileron-pos-rad", this, ofMag, &FGFCS::GetDaRPos);
857 PropertyManager->Tie("fcs/elevator-pos-rad", this, ofRad, &FGFCS::GetDePos, &FGFCS::SetDePos);
858 PropertyManager->Tie("fcs/elevator-pos-deg", this, ofDeg, &FGFCS::GetDePos, &FGFCS::SetDePos);
859 PropertyManager->Tie("fcs/elevator-pos-norm", this, ofNorm, &FGFCS::GetDePos, &FGFCS::SetDePos);
860 PropertyManager->Tie("fcs/mag-elevator-pos-rad", this, ofMag, &FGFCS::GetDePos);
862 PropertyManager->Tie("fcs/rudder-pos-rad", this,ofRad, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
863 PropertyManager->Tie("fcs/rudder-pos-deg", this,ofDeg, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
864 PropertyManager->Tie("fcs/rudder-pos-norm", this,ofNorm, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
865 PropertyManager->Tie("fcs/mag-rudder-pos-rad", this,ofMag, &FGFCS::GetDrPos);
867 PropertyManager->Tie("fcs/flap-pos-rad", this,ofRad, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
868 PropertyManager->Tie("fcs/flap-pos-deg", this,ofDeg, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
869 PropertyManager->Tie("fcs/flap-pos-norm", this,ofNorm, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
871 PropertyManager->Tie("fcs/speedbrake-pos-rad", this,ofRad, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
872 PropertyManager->Tie("fcs/speedbrake-pos-deg", this,ofDeg, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
873 PropertyManager->Tie("fcs/speedbrake-pos-norm", this,ofNorm, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
874 PropertyManager->Tie("fcs/mag-speedbrake-pos-rad", this,ofMag, &FGFCS::GetDsbPos);
876 PropertyManager->Tie("fcs/spoiler-pos-rad", this, ofRad, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
877 PropertyManager->Tie("fcs/spoiler-pos-deg", this, ofDeg, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
878 PropertyManager->Tie("fcs/spoiler-pos-norm", this, ofNorm, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
879 PropertyManager->Tie("fcs/mag-spoiler-pos-rad", this, ofMag, &FGFCS::GetDspPos);
881 PropertyManager->Tie("gear/gear-pos-norm", this, &FGFCS::GetGearPos, &FGFCS::SetGearPos);
882 PropertyManager->Tie("gear/gear-cmd-norm", this, &FGFCS::GetGearCmd, &FGFCS::SetGearCmd);
883 PropertyManager->Tie("fcs/left-brake-cmd-norm", this, &FGFCS::GetLBrake, &FGFCS::SetLBrake);
884 PropertyManager->Tie("fcs/right-brake-cmd-norm", this, &FGFCS::GetRBrake, &FGFCS::SetRBrake);
885 PropertyManager->Tie("fcs/center-brake-cmd-norm", this, &FGFCS::GetCBrake, &FGFCS::SetCBrake);
886 PropertyManager->Tie("fcs/steer-cmd-norm", this, &FGFCS::GetDsCmd, &FGFCS::SetDsCmd);
888 PropertyManager->Tie("gear/tailhook-pos-norm", this, &FGFCS::GetTailhookPos, &FGFCS::SetTailhookPos);
889 PropertyManager->Tie("fcs/wing-fold-pos-norm", this, &FGFCS::GetWingFoldPos, &FGFCS::SetWingFoldPos);
892 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
893 // Technically, this function should probably bind propulsion type specific controls
894 // rather than mixture and prop-advance.
896 void FGFCS::bindThrottle(unsigned int num)
900 tmp = CreateIndexedPropertyName("fcs/throttle-cmd-norm", num);
901 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetThrottleCmd,
902 &FGFCS::SetThrottleCmd);
903 tmp = CreateIndexedPropertyName("fcs/throttle-pos-norm", num);
904 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetThrottlePos,
905 &FGFCS::SetThrottlePos);
906 tmp = CreateIndexedPropertyName("fcs/mixture-cmd-norm", num);
907 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetMixtureCmd,
908 &FGFCS::SetMixtureCmd);
909 tmp = CreateIndexedPropertyName("fcs/mixture-pos-norm", num);
910 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetMixturePos,
911 &FGFCS::SetMixturePos);
912 tmp = CreateIndexedPropertyName("fcs/advance-cmd-norm", num);
913 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetPropAdvanceCmd,
914 &FGFCS::SetPropAdvanceCmd);
915 tmp = CreateIndexedPropertyName("fcs/advance-pos-norm", num);
916 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetPropAdvance,
917 &FGFCS::SetPropAdvance);
918 tmp = CreateIndexedPropertyName("fcs/feather-cmd-norm", num);
919 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetFeatherCmd,
920 &FGFCS::SetFeatherCmd);
921 tmp = CreateIndexedPropertyName("fcs/feather-pos-norm", num);
922 PropertyManager->Tie( tmp.c_str(), this, num, &FGFCS::GetPropFeather,
923 &FGFCS::SetPropFeather);
926 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
928 void FGFCS::bindModel(void)
933 for (i=0; i<SteerPosDeg.size(); i++) {
934 if (GroundReactions->GetGearUnit(i)->GetSteerable()) {
935 tmp = CreateIndexedPropertyName("fcs/steer-pos-deg", i);
936 PropertyManager->Tie( tmp.c_str(), this, i, &FGFCS::GetSteerPosDeg, &FGFCS::SetSteerPosDeg);
941 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
942 // The bitmasked value choices are as follows:
943 // unset: In this case (the default) JSBSim would only print
944 // out the normally expected messages, essentially echoing
945 // the config files as they are read. If the environment
946 // variable is not set, debug_lvl is set to 1 internally
947 // 0: This requests JSBSim not to output any messages
949 // 1: This value explicity requests the normal JSBSim
951 // 2: This value asks for a message to be printed out when
952 // a class is instantiated
953 // 4: When this value is set, a message is displayed when a
954 // FGModel object executes its Run() method
955 // 8: When this value is set, various runtime state variables
956 // are printed out periodically
957 // 16: When set various parameters are sanity checked and
958 // a message is printed out when they go out of bounds
960 void FGFCS::Debug(int from)
962 if (debug_lvl <= 0) return;
964 if (debug_lvl & 1) { // Standard console startup message output
965 if (from == 2) { // Loader
966 cout << endl << " " << Name << endl;
969 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
970 if (from == 0) cout << "Instantiated: FGFCS" << endl;
971 if (from == 1) cout << "Destroyed: FGFCS" << endl;
973 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
975 if (debug_lvl & 8 ) { // Runtime state variables
977 if (debug_lvl & 16) { // Sanity checking
979 if (debug_lvl & 64) {
980 if (from == 0) { // Constructor
981 cout << IdSrc << endl;
982 cout << IdHdr << endl;