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>
45 #include <models/flight_control/FGFilter.h>
46 #include <models/flight_control/FGDeadBand.h>
47 #include <models/flight_control/FGGain.h>
48 #include <models/flight_control/FGPID.h>
49 #include <models/flight_control/FGSwitch.h>
50 #include <models/flight_control/FGSummer.h>
51 #include <models/flight_control/FGKinemat.h>
52 #include <models/flight_control/FGFCSFunction.h>
53 #include <models/flight_control/FGSensor.h>
54 #include <models/flight_control/FGActuator.h>
58 static const char *IdSrc = "$Id$";
59 static const char *IdHdr = ID_FCS;
61 #if defined(WIN32) && !defined(__CYGWIN__)
62 #define snprintf _snprintf
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
74 DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;
75 PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
76 GearCmd = GearPos = 1; // default to gear down
77 LeftBrake = RightBrake = CenterBrake = 0.0;
78 TailhookPos = WingFoldPos = 0.0;
81 for (i=0;i<NForms;i++) {
82 DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
83 DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
89 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 PropAdvanceCmd.clear();
100 PropFeatherCmd.clear();
105 for (i=0;i<sensors.size();i++) delete sensors[i];
107 for (i=0;i<APComponents.size();i++) delete APComponents[i];
108 APComponents.clear();
109 for (i=0;i<FCSComponents.size();i++) delete FCSComponents[i];
110 FCSComponents.clear();
111 for (i=0;i<Systems.size();i++) delete Systems[i];
114 for (unsigned int i=0; i<interface_properties.size(); i++) delete interface_properties[i];
115 interface_properties.clear();
120 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 bool FGFCS::InitModel(void)
126 if (!FGModel::InitModel()) return false;
128 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = 0.0;
129 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = 0.0;
130 for (i=0; i<ThrottleCmd.size(); i++) ThrottleCmd[i] = 0.0;
131 for (i=0; i<MixtureCmd.size(); i++) MixtureCmd[i] = 0.0;
132 for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = 0.0;
133 for (i=0; i<PropFeather.size(); i++) PropFeather[i] = 0.0;
135 DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;
136 PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
137 TailhookPos = WingFoldPos = 0.0;
139 for (i=0;i<NForms;i++) {
140 DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
141 DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
147 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 // Notes: In this logic the default engine commands are set. This is simply a
149 // sort of safe-mode method in case the user has not defined control laws for
150 // throttle, mixture, and prop-advance. The throttle, mixture, and prop advance
151 // positions are set equal to the respective commands. Any control logic that is
152 // actually present in the flight_control or autopilot section will override
153 // these simple assignments.
155 bool FGFCS::Run(void)
159 if (FGModel::Run()) return true; // fast exit if nothing to do
160 if (FDMExec->Holding()) return false;
162 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
163 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
164 for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[i];
165 for (i=0; i<PropFeather.size(); i++) PropFeather[i] = PropFeatherCmd[i];
167 // Set the default steering angle
168 for (i=0; i<SteerPosDeg.size(); i++) {
169 FGLGear* gear = GroundReactions->GetGearUnit(i);
170 SteerPosDeg[i] = gear->GetDefaultSteerAngle( GetDsCmd() );
173 // Cycle through the sensor, systems, autopilot, and flight control components
175 for (i=0; i<sensors.size(); i++) sensors[i]->Run();
177 // Execute Systems in order
178 for (i=0; i<Systems.size(); i++) Systems[i]->Run();
181 for (i=0; i<APComponents.size(); i++) APComponents[i]->Run();
183 // Execute Flight Control System
184 for (i=0; i<FCSComponents.size(); i++) FCSComponents[i]->Run();
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191 void FGFCS::SetDaLPos( int form , double pos )
196 DaLPos[ofDeg] = pos*radtodeg;
199 DaLPos[ofRad] = pos*degtorad;
203 DaLPos[ofNorm] = pos;
205 DaLPos[ofMag] = fabs(DaLPos[ofRad]);
208 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 void FGFCS::SetDaRPos( int form , double pos )
215 DaRPos[ofDeg] = pos*radtodeg;
218 DaRPos[ofRad] = pos*degtorad;
222 DaRPos[ofNorm] = pos;
224 DaRPos[ofMag] = fabs(DaRPos[ofRad]);
227 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 void FGFCS::SetDePos( int form , double pos )
234 DePos[ofDeg] = pos*radtodeg;
237 DePos[ofRad] = pos*degtorad;
243 DePos[ofMag] = fabs(DePos[ofRad]);
246 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 void FGFCS::SetDrPos( int form , double pos )
253 DrPos[ofDeg] = pos*radtodeg;
256 DrPos[ofRad] = pos*degtorad;
262 DrPos[ofMag] = fabs(DrPos[ofRad]);
265 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267 void FGFCS::SetDfPos( int form , double pos )
272 DfPos[ofDeg] = pos*radtodeg;
275 DfPos[ofRad] = pos*degtorad;
281 DfPos[ofMag] = fabs(DfPos[ofRad]);
284 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286 void FGFCS::SetDsbPos( int form , double pos )
291 DsbPos[ofDeg] = pos*radtodeg;
294 DsbPos[ofRad] = pos*degtorad;
298 DsbPos[ofNorm] = pos;
300 DsbPos[ofMag] = fabs(DsbPos[ofRad]);
303 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 void FGFCS::SetDspPos( int form , double pos )
310 DspPos[ofDeg] = pos*radtodeg;
313 DspPos[ofRad] = pos*degtorad;
317 DspPos[ofNorm] = pos;
319 DspPos[ofMag] = fabs(DspPos[ofRad]);
322 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
324 void FGFCS::SetThrottleCmd(int engineNum, double setting)
328 if (engineNum < (int)ThrottlePos.size()) {
330 for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
332 ThrottleCmd[engineNum] = setting;
335 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
336 << " engines exist, but attempted throttle command is for engine "
337 << engineNum << endl;
341 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 void FGFCS::SetThrottlePos(int engineNum, double setting)
347 if (engineNum < (int)ThrottlePos.size()) {
349 for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
351 ThrottlePos[engineNum] = setting;
354 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
355 << " engines exist, but attempted throttle position setting is for engine "
356 << engineNum << endl;
360 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
362 double FGFCS::GetThrottleCmd(int engineNum) const
364 if (engineNum < (int)ThrottlePos.size()) {
366 cerr << "Cannot get throttle value for ALL engines" << endl;
368 return ThrottleCmd[engineNum];
371 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
372 << " engines exist, but throttle setting for engine " << engineNum
373 << " is selected" << endl;
378 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380 double FGFCS::GetThrottlePos(int engineNum) const
382 if (engineNum < (int)ThrottlePos.size()) {
384 cerr << "Cannot get throttle value for ALL engines" << endl;
386 return ThrottlePos[engineNum];
389 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
390 << " engines exist, but attempted throttle position setting is for engine "
391 << engineNum << endl;
396 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398 void FGFCS::SetMixtureCmd(int engineNum, double setting)
402 if (engineNum < (int)ThrottlePos.size()) {
404 for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
406 MixtureCmd[engineNum] = setting;
411 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413 void FGFCS::SetMixturePos(int engineNum, double setting)
417 if (engineNum < (int)ThrottlePos.size()) {
419 for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
421 MixturePos[engineNum] = setting;
426 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 void FGFCS::SetPropAdvanceCmd(int engineNum, double setting)
432 if (engineNum < (int)ThrottlePos.size()) {
434 for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
436 PropAdvanceCmd[engineNum] = setting;
441 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
443 void FGFCS::SetPropAdvance(int engineNum, double setting)
447 if (engineNum < (int)ThrottlePos.size()) {
449 for (ctr=0;ctr<=PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
451 PropAdvance[engineNum] = setting;
456 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
458 void FGFCS::SetFeatherCmd(int engineNum, bool setting)
462 if (engineNum < (int)ThrottlePos.size()) {
464 for (ctr=0;ctr<PropFeatherCmd.size();ctr++) PropFeatherCmd[ctr] = setting;
466 PropFeatherCmd[engineNum] = setting;
471 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
473 void FGFCS::SetPropFeather(int engineNum, bool setting)
477 if (engineNum < (int)ThrottlePos.size()) {
479 for (ctr=0;ctr<=PropFeatherCmd.size();ctr++) PropFeather[ctr] = PropFeatherCmd[ctr];
481 PropFeather[engineNum] = setting;
486 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
488 bool FGFCS::Load(Element* el, SystemType systype)
490 string name, file, fname="", interface_property_string, parent_name;
491 vector <FGFCSComponent*> *Components;
492 Element *component_element, *property_element, *sensor_element;
493 Element *channel_element;
497 string separator = "/";
499 // ToDo: The handling of name and file attributes could be improved, here,
500 // considering that a name can be in the external file, as well.
502 name = el->GetAttributeValue("name");
505 fname = el->GetAttributeValue("file");
506 if (systype == stSystem) {
507 file = FindSystemFullPathname(fname);
509 file = FDMExec->GetFullAircraftPath() + separator + fname + ".xml";
512 cerr << "FCS, Autopilot, or system does not appear to be defined inline nor in a file" << endl;
515 document = LoadXMLDocument(file);
517 cerr << "Error loading file " << file << endl;
520 name = document->GetAttributeValue("name");
526 if (document->GetName() == "autopilot") {
527 Components = &APComponents;
528 Name = "Autopilot: " + document->GetAttributeValue("name");
529 } else if (document->GetName() == "flight_control") {
530 Components = &FCSComponents;
531 Name = "FCS: " + document->GetAttributeValue("name");
532 } else if (document->GetName() == "system") {
533 Components = &Systems;
534 Name = "System: " + document->GetAttributeValue("name");
538 if (document->GetName() == "flight_control") bindModel();
540 // Interface properties from any autopilot, flight control, or other system are
541 // all stored in the interface properties array.
543 property_element = document->FindElement("property");
544 if (property_element) cout << endl << " Declared properties" << endl << endl;
545 while (property_element) {
547 if ( ! property_element->GetAttributeValue("value").empty())
548 value = property_element->GetAttributeValueAsNumber("value");
549 interface_properties.push_back(new double(value));
550 interface_property_string = property_element->GetDataLine();
551 PropertyManager->Tie(interface_property_string, interface_properties.back());
552 cout << " " << interface_property_string << " (initial value: " << value << ")" << endl;
553 property_element = document->FindNextElement("property");
556 // After reading interface properties in a file, read properties in the local
557 // flight_control, autopilot, or system element. This allows general-purpose
558 // systems to be defined in a file, with overrides or initial loaded constants
559 // supplied in the relevant element of the aircraft configuration file.
561 if (!fname.empty()) {
562 property_element = el->FindElement("property");
563 if (property_element && debug_lvl > 0) cout << endl << " Declared properties" << endl << endl;
564 while (property_element) {
566 if ( ! property_element->GetAttributeValue("value").empty())
567 value = property_element->GetAttributeValueAsNumber("value");
569 interface_property_string = property_element->GetDataLine();
571 FGPropertyManager* node = PropertyManager->GetNode(interface_property_string);
573 cout << " " << "Overriding value for property " << interface_property_string
574 << " (old value: " << node->getDoubleValue() << " new value: " << value << ")" << endl;
575 node->setDoubleValue(value);
577 interface_properties.push_back(new double(value));
578 PropertyManager->Tie(interface_property_string, interface_properties.back());
580 cout << " " << interface_property_string << " (initial value: " << value << ")" << endl;
584 property_element = el->FindNextElement("property");
588 // Any sensor elements that are outside of a channel (in either the autopilot
589 // or the flight_control, or even any possible "system") are placed into the global
590 // "sensors" array, and are executed prior to any autopilot, flight control, or
593 sensor_element = document->FindElement("sensor");
594 while (sensor_element) {
596 sensors.push_back(new FGSensor(this, sensor_element));
598 cerr << highint << fgred << endl << " " << s << endl;
601 sensor_element = document->FindNextElement("sensor");
604 channel_element = document->FindElement("channel");
605 while (channel_element) {
608 cout << endl << highint << fgblue << " Channel "
609 << normint << channel_element->GetAttributeValue("name") << reset << endl;
611 component_element = channel_element->GetElement();
612 while (component_element) {
614 if ((component_element->GetName() == string("lag_filter")) ||
615 (component_element->GetName() == string("lead_lag_filter")) ||
616 (component_element->GetName() == string("washout_filter")) ||
617 (component_element->GetName() == string("second_order_filter")) ||
618 (component_element->GetName() == string("integrator")) )
620 Components->push_back(new FGFilter(this, component_element));
621 } else if ((component_element->GetName() == string("pure_gain")) ||
622 (component_element->GetName() == string("scheduled_gain")) ||
623 (component_element->GetName() == string("aerosurface_scale")))
625 Components->push_back(new FGGain(this, component_element));
626 } else if (component_element->GetName() == string("summer")) {
627 Components->push_back(new FGSummer(this, component_element));
628 } else if (component_element->GetName() == string("deadband")) {
629 Components->push_back(new FGDeadBand(this, component_element));
630 } else if (component_element->GetName() == string("switch")) {
631 Components->push_back(new FGSwitch(this, component_element));
632 } else if (component_element->GetName() == string("kinematic")) {
633 Components->push_back(new FGKinemat(this, component_element));
634 } else if (component_element->GetName() == string("fcs_function")) {
635 Components->push_back(new FGFCSFunction(this, component_element));
636 } else if (component_element->GetName() == string("pid")) {
637 Components->push_back(new FGPID(this, component_element));
638 } else if (component_element->GetName() == string("actuator")) {
639 Components->push_back(new FGActuator(this, component_element));
640 } else if (component_element->GetName() == string("sensor")) {
641 Components->push_back(new FGSensor(this, component_element));
643 cerr << "Unknown FCS component: " << component_element->GetName() << endl;
646 cerr << highint << fgred << endl << " " << s << endl;
647 cerr << reset << endl;
650 component_element = channel_element->GetNextElement();
652 channel_element = document->FindNextElement("channel");
660 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
662 double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
665 case FGLGear::bgLeft:
667 case FGLGear::bgRight:
669 case FGLGear::bgCenter:
672 cerr << "GetBrake asked to return a bogus brake value" << endl;
677 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
679 string FGFCS::FindSystemFullPathname(string system_filename)
681 string fullpath, localpath;
682 string systemPath = FDMExec->GetSystemsPath();
683 string aircraftPath = FDMExec->GetFullAircraftPath();
684 ifstream system_file;
686 string separator = "/";
688 fullpath = systemPath + separator;
689 localpath = aircraftPath + separator + "Systems" + separator;
691 system_file.open(string(fullpath + system_filename + ".xml").c_str());
692 if ( !system_file.is_open()) {
693 system_file.open(string(localpath + system_filename + ".xml").c_str());
694 if ( !system_file.is_open()) {
695 cerr << " Could not open system file: " << system_filename << " in path "
696 << fullpath << " or " << localpath << endl;
699 return string(localpath + system_filename + ".xml");
702 return string(fullpath + system_filename + ".xml");
705 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
707 ifstream* FGFCS::FindSystemFile(string system_filename)
709 string fullpath, localpath;
710 string systemPath = FDMExec->GetSystemsPath();
711 string aircraftPath = FDMExec->GetFullAircraftPath();
712 ifstream* system_file = new ifstream();
714 string separator = "/";
716 fullpath = systemPath + separator;
717 localpath = aircraftPath + separator + "Systems" + separator;
719 system_file->open(string(fullpath + system_filename + ".xml").c_str());
720 if ( !system_file->is_open()) {
721 system_file->open(string(localpath + system_filename + ".xml").c_str());
722 if ( !system_file->is_open()) {
723 cerr << " Could not open system file: " << system_filename << " in path "
724 << fullpath << " or " << localpath << endl;
730 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
732 string FGFCS::GetComponentStrings(string delimeter)
735 string CompStrings = "";
736 bool firstime = true;
739 for (unsigned int i=0; i<Systems.size(); i++) {
740 if (firstime) firstime = false;
741 else CompStrings += delimeter;
743 CompStrings += Systems[i]->GetName();
747 for (comp = 0; comp < APComponents.size(); comp++)
749 if (firstime) firstime = false;
750 else CompStrings += delimeter;
752 CompStrings += APComponents[comp]->GetName();
756 for (comp = 0; comp < FCSComponents.size(); comp++) {
757 if (firstime) firstime = false;
758 else CompStrings += delimeter;
760 CompStrings += FCSComponents[comp]->GetName();
767 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
769 string FGFCS::GetComponentValues(string delimeter)
772 string CompValues = "";
774 bool firstime = true;
777 for (unsigned int i=0; i<Systems.size(); i++) {
778 if (firstime) firstime = false;
779 else CompValues += delimeter;
781 snprintf(buffer, 100, "%9.6f", Systems[i]->GetOutput());
782 CompValues += string(buffer);
786 for (comp = 0; comp < APComponents.size(); comp++) {
787 if (firstime) firstime = false;
788 else CompValues += delimeter;
790 sprintf(buffer, "%9.6f", APComponents[comp]->GetOutput());
791 CompValues += string(buffer);
795 for (comp = 0; comp < FCSComponents.size(); comp++) {
796 if (firstime) firstime = false;
797 else CompValues += delimeter;
799 sprintf(buffer, "%9.6f", FCSComponents[comp]->GetOutput());
800 CompValues += string(buffer);
808 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
810 void FGFCS::AddThrottle(void)
812 ThrottleCmd.push_back(0.0);
813 ThrottlePos.push_back(0.0);
814 MixtureCmd.push_back(0.0); // assume throttle and mixture are coupled
815 MixturePos.push_back(0.0);
816 PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled
817 PropAdvance.push_back(0.0);
818 PropFeatherCmd.push_back(false);
819 PropFeather.push_back(false);
821 unsigned int num = (unsigned int)ThrottleCmd.size()-1;
825 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
827 void FGFCS::AddGear(void)
829 SteerPosDeg.push_back(0.0);
832 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
834 double FGFCS::GetDt(void)
836 return FDMExec->GetDeltaT()*rate;
839 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
841 void FGFCS::bind(void)
843 PropertyManager->Tie("fcs/aileron-cmd-norm", this, &FGFCS::GetDaCmd, &FGFCS::SetDaCmd);
844 PropertyManager->Tie("fcs/elevator-cmd-norm", this, &FGFCS::GetDeCmd, &FGFCS::SetDeCmd);
845 PropertyManager->Tie("fcs/rudder-cmd-norm", this, &FGFCS::GetDrCmd, &FGFCS::SetDrCmd);
846 PropertyManager->Tie("fcs/flap-cmd-norm", this, &FGFCS::GetDfCmd, &FGFCS::SetDfCmd);
847 PropertyManager->Tie("fcs/speedbrake-cmd-norm", this, &FGFCS::GetDsbCmd, &FGFCS::SetDsbCmd);
848 PropertyManager->Tie("fcs/spoiler-cmd-norm", this, &FGFCS::GetDspCmd, &FGFCS::SetDspCmd);
849 PropertyManager->Tie("fcs/pitch-trim-cmd-norm", this, &FGFCS::GetPitchTrimCmd, &FGFCS::SetPitchTrimCmd);
850 PropertyManager->Tie("fcs/roll-trim-cmd-norm", this, &FGFCS::GetRollTrimCmd, &FGFCS::SetRollTrimCmd);
851 PropertyManager->Tie("fcs/yaw-trim-cmd-norm", this, &FGFCS::GetYawTrimCmd, &FGFCS::SetYawTrimCmd);
853 PropertyManager->Tie("fcs/left-aileron-pos-rad", this, ofRad, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
854 PropertyManager->Tie("fcs/left-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
855 PropertyManager->Tie("fcs/left-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
856 PropertyManager->Tie("fcs/mag-left-aileron-pos-rad", this, ofMag, &FGFCS::GetDaLPos);
858 PropertyManager->Tie("fcs/right-aileron-pos-rad", this, ofRad, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
859 PropertyManager->Tie("fcs/right-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
860 PropertyManager->Tie("fcs/right-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
861 PropertyManager->Tie("fcs/mag-right-aileron-pos-rad", this, ofMag, &FGFCS::GetDaRPos);
863 PropertyManager->Tie("fcs/elevator-pos-rad", this, ofRad, &FGFCS::GetDePos, &FGFCS::SetDePos);
864 PropertyManager->Tie("fcs/elevator-pos-deg", this, ofDeg, &FGFCS::GetDePos, &FGFCS::SetDePos);
865 PropertyManager->Tie("fcs/elevator-pos-norm", this, ofNorm, &FGFCS::GetDePos, &FGFCS::SetDePos);
866 PropertyManager->Tie("fcs/mag-elevator-pos-rad", this, ofMag, &FGFCS::GetDePos);
868 PropertyManager->Tie("fcs/rudder-pos-rad", this,ofRad, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
869 PropertyManager->Tie("fcs/rudder-pos-deg", this,ofDeg, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
870 PropertyManager->Tie("fcs/rudder-pos-norm", this,ofNorm, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
871 PropertyManager->Tie("fcs/mag-rudder-pos-rad", this,ofMag, &FGFCS::GetDrPos);
873 PropertyManager->Tie("fcs/flap-pos-rad", this,ofRad, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
874 PropertyManager->Tie("fcs/flap-pos-deg", this,ofDeg, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
875 PropertyManager->Tie("fcs/flap-pos-norm", this,ofNorm, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
877 PropertyManager->Tie("fcs/speedbrake-pos-rad", this,ofRad, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
878 PropertyManager->Tie("fcs/speedbrake-pos-deg", this,ofDeg, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
879 PropertyManager->Tie("fcs/speedbrake-pos-norm", this,ofNorm, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
880 PropertyManager->Tie("fcs/mag-speedbrake-pos-rad", this,ofMag, &FGFCS::GetDsbPos);
882 PropertyManager->Tie("fcs/spoiler-pos-rad", this, ofRad, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
883 PropertyManager->Tie("fcs/spoiler-pos-deg", this, ofDeg, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
884 PropertyManager->Tie("fcs/spoiler-pos-norm", this, ofNorm, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
885 PropertyManager->Tie("fcs/mag-spoiler-pos-rad", this, ofMag, &FGFCS::GetDspPos);
887 PropertyManager->Tie("gear/gear-pos-norm", this, &FGFCS::GetGearPos, &FGFCS::SetGearPos);
888 PropertyManager->Tie("gear/gear-cmd-norm", this, &FGFCS::GetGearCmd, &FGFCS::SetGearCmd);
889 PropertyManager->Tie("fcs/left-brake-cmd-norm", this, &FGFCS::GetLBrake, &FGFCS::SetLBrake);
890 PropertyManager->Tie("fcs/right-brake-cmd-norm", this, &FGFCS::GetRBrake, &FGFCS::SetRBrake);
891 PropertyManager->Tie("fcs/center-brake-cmd-norm", this, &FGFCS::GetCBrake, &FGFCS::SetCBrake);
892 PropertyManager->Tie("fcs/steer-cmd-norm", this, &FGFCS::GetDsCmd, &FGFCS::SetDsCmd);
894 PropertyManager->Tie("gear/tailhook-pos-norm", this, &FGFCS::GetTailhookPos, &FGFCS::SetTailhookPos);
895 PropertyManager->Tie("fcs/wing-fold-pos-norm", this, &FGFCS::GetWingFoldPos, &FGFCS::SetWingFoldPos);
898 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
899 // Technically, this function should probably bind propulsion type specific controls
900 // rather than mixture and prop-advance.
903 void FGFCS::bindThrottle(unsigned int num)
907 snprintf(tmp, 80, "fcs/throttle-cmd-norm[%u]",num);
908 PropertyManager->Tie( tmp, this, num, &FGFCS::GetThrottleCmd,
909 &FGFCS::SetThrottleCmd);
910 snprintf(tmp, 80, "fcs/throttle-pos-norm[%u]",num);
911 PropertyManager->Tie( tmp, this, num, &FGFCS::GetThrottlePos,
912 &FGFCS::SetThrottlePos);
913 snprintf(tmp, 80, "fcs/mixture-cmd-norm[%u]",num);
914 PropertyManager->Tie( tmp, this, num, &FGFCS::GetMixtureCmd,
915 &FGFCS::SetMixtureCmd);
916 snprintf(tmp, 80, "fcs/mixture-pos-norm[%u]",num);
917 PropertyManager->Tie( tmp, this, num, &FGFCS::GetMixturePos,
918 &FGFCS::SetMixturePos);
919 snprintf(tmp, 80, "fcs/advance-cmd-norm[%u]",num);
920 PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropAdvanceCmd,
921 &FGFCS::SetPropAdvanceCmd);
922 snprintf(tmp, 80, "fcs/advance-pos-norm[%u]", num);
923 PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropAdvance,
924 &FGFCS::SetPropAdvance);
925 snprintf(tmp, 80, "fcs/feather-cmd-norm[%u]", num);
926 PropertyManager->Tie( tmp, this, num, &FGFCS::GetFeatherCmd,
927 &FGFCS::SetFeatherCmd);
928 snprintf(tmp, 80, "fcs/feather-pos-norm[%u]", num);
929 PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropFeather,
930 &FGFCS::SetPropFeather);
933 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
935 void FGFCS::bindModel(void)
940 for (i=0; i<SteerPosDeg.size(); i++) {
941 if (GroundReactions->GetGearUnit(i)->GetSteerable()) {
942 snprintf(tmp,80,"fcs/steer-pos-deg[%u]",i);
943 PropertyManager->Tie( tmp, this, i, &FGFCS::GetSteerPosDeg, &FGFCS::SetSteerPosDeg);
948 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
949 // The bitmasked value choices are as follows:
950 // unset: In this case (the default) JSBSim would only print
951 // out the normally expected messages, essentially echoing
952 // the config files as they are read. If the environment
953 // variable is not set, debug_lvl is set to 1 internally
954 // 0: This requests JSBSim not to output any messages
956 // 1: This value explicity requests the normal JSBSim
958 // 2: This value asks for a message to be printed out when
959 // a class is instantiated
960 // 4: When this value is set, a message is displayed when a
961 // FGModel object executes its Run() method
962 // 8: When this value is set, various runtime state variables
963 // are printed out periodically
964 // 16: When set various parameters are sanity checked and
965 // a message is printed out when they go out of bounds
967 void FGFCS::Debug(int from)
969 if (debug_lvl <= 0) return;
971 if (debug_lvl & 1) { // Standard console startup message output
972 if (from == 2) { // Loader
973 cout << endl << " " << Name << endl;
976 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
977 if (from == 0) cout << "Instantiated: FGFCS" << endl;
978 if (from == 1) cout << "Destroyed: FGFCS" << endl;
980 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
982 if (debug_lvl & 8 ) { // Runtime state variables
984 if (debug_lvl & 16) { // Sanity checking
986 if (debug_lvl & 64) {
987 if (from == 0) { // Constructor
988 cout << IdSrc << endl;
989 cout << IdHdr << endl;