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/FGGradient.h>
50 #include <models/flight_control/FGSwitch.h>
51 #include <models/flight_control/FGSummer.h>
52 #include <models/flight_control/FGKinemat.h>
53 #include <models/flight_control/FGFCSFunction.h>
54 #include <models/flight_control/FGSensor.h>
55 #include <models/flight_control/FGActuator.h>
59 static const char *IdSrc = "$Id$";
60 static const char *IdHdr = ID_FCS;
62 #if defined(WIN32) && !defined(__CYGWIN__)
63 #define snprintf _snprintf
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
75 DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;
76 PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
77 GearCmd = GearPos = 1; // default to gear down
78 LeftBrake = RightBrake = CenterBrake = 0.0;
79 TailhookPos = WingFoldPos = 0.0;
82 for (i=0;i<NForms;i++) {
83 DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
84 DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
90 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 PropAdvanceCmd.clear();
101 PropFeatherCmd.clear();
106 for (i=0;i<sensors.size();i++) delete sensors[i];
108 for (i=0;i<APComponents.size();i++) delete APComponents[i];
109 APComponents.clear();
110 for (i=0;i<FCSComponents.size();i++) delete FCSComponents[i];
111 FCSComponents.clear();
112 for (i=0;i<Systems.size();i++) delete Systems[i];
115 for (unsigned int i=0; i<interface_properties.size(); i++) delete interface_properties[i];
116 interface_properties.clear();
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 bool FGFCS::InitModel(void)
127 if (!FGModel::InitModel()) return false;
129 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = 0.0;
130 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = 0.0;
131 for (i=0; i<ThrottleCmd.size(); i++) ThrottleCmd[i] = 0.0;
132 for (i=0; i<MixtureCmd.size(); i++) MixtureCmd[i] = 0.0;
133 for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = 0.0;
134 for (i=0; i<PropFeather.size(); i++) PropFeather[i] = 0.0;
136 DaCmd = DeCmd = DrCmd = DsCmd = DfCmd = DsbCmd = DspCmd = 0;
137 PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
138 TailhookPos = WingFoldPos = 0.0;
140 for (i=0;i<NForms;i++) {
141 DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
142 DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
148 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 // Notes: In this logic the default engine commands are set. This is simply a
150 // sort of safe-mode method in case the user has not defined control laws for
151 // throttle, mixture, and prop-advance. The throttle, mixture, and prop advance
152 // positions are set equal to the respective commands. Any control logic that is
153 // actually present in the flight_control or autopilot section will override
154 // these simple assignments.
156 bool FGFCS::Run(void)
160 if (FGModel::Run()) return true; // fast exit if nothing to do
161 if (FDMExec->Holding()) return false;
163 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
164 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
165 for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[i];
166 for (i=0; i<PropFeather.size(); i++) PropFeather[i] = PropFeatherCmd[i];
168 // Set the default steering angle
169 for (i=0; i<SteerPosDeg.size(); i++) {
170 FGLGear* gear = GroundReactions->GetGearUnit(i);
171 SteerPosDeg[i] = gear->GetDefaultSteerAngle( GetDsCmd() );
174 // Cycle through the sensor, systems, autopilot, and flight control components
176 for (i=0; i<sensors.size(); i++) sensors[i]->Run();
178 // Execute Systems in order
179 for (i=0; i<Systems.size(); i++) Systems[i]->Run();
182 for (i=0; i<APComponents.size(); i++) APComponents[i]->Run();
184 // Execute Flight Control System
185 for (i=0; i<FCSComponents.size(); i++) FCSComponents[i]->Run();
190 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 void FGFCS::SetDaLPos( int form , double pos )
197 DaLPos[ofDeg] = pos*radtodeg;
200 DaLPos[ofRad] = pos*degtorad;
204 DaLPos[ofNorm] = pos;
206 DaLPos[ofMag] = fabs(DaLPos[ofRad]);
209 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 void FGFCS::SetDaRPos( int form , double pos )
216 DaRPos[ofDeg] = pos*radtodeg;
219 DaRPos[ofRad] = pos*degtorad;
223 DaRPos[ofNorm] = pos;
225 DaRPos[ofMag] = fabs(DaRPos[ofRad]);
228 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 void FGFCS::SetDePos( int form , double pos )
235 DePos[ofDeg] = pos*radtodeg;
238 DePos[ofRad] = pos*degtorad;
244 DePos[ofMag] = fabs(DePos[ofRad]);
247 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249 void FGFCS::SetDrPos( int form , double pos )
254 DrPos[ofDeg] = pos*radtodeg;
257 DrPos[ofRad] = pos*degtorad;
263 DrPos[ofMag] = fabs(DrPos[ofRad]);
266 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268 void FGFCS::SetDfPos( int form , double pos )
273 DfPos[ofDeg] = pos*radtodeg;
276 DfPos[ofRad] = pos*degtorad;
282 DfPos[ofMag] = fabs(DfPos[ofRad]);
285 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 void FGFCS::SetDsbPos( int form , double pos )
292 DsbPos[ofDeg] = pos*radtodeg;
295 DsbPos[ofRad] = pos*degtorad;
299 DsbPos[ofNorm] = pos;
301 DsbPos[ofMag] = fabs(DsbPos[ofRad]);
304 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 void FGFCS::SetDspPos( int form , double pos )
311 DspPos[ofDeg] = pos*radtodeg;
314 DspPos[ofRad] = pos*degtorad;
318 DspPos[ofNorm] = pos;
320 DspPos[ofMag] = fabs(DspPos[ofRad]);
323 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 void FGFCS::SetThrottleCmd(int engineNum, double setting)
329 if (engineNum < (int)ThrottlePos.size()) {
331 for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
333 ThrottleCmd[engineNum] = setting;
336 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
337 << " engines exist, but attempted throttle command is for engine "
338 << engineNum << endl;
342 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 void FGFCS::SetThrottlePos(int engineNum, double setting)
348 if (engineNum < (int)ThrottlePos.size()) {
350 for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
352 ThrottlePos[engineNum] = setting;
355 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
356 << " engines exist, but attempted throttle position setting is for engine "
357 << engineNum << endl;
361 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363 double FGFCS::GetThrottleCmd(int engineNum) const
365 if (engineNum < (int)ThrottlePos.size()) {
367 cerr << "Cannot get throttle value for ALL engines" << endl;
369 return ThrottleCmd[engineNum];
372 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
373 << " engines exist, but throttle setting for engine " << engineNum
374 << " is selected" << endl;
379 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381 double FGFCS::GetThrottlePos(int engineNum) const
383 if (engineNum < (int)ThrottlePos.size()) {
385 cerr << "Cannot get throttle value for ALL engines" << endl;
387 return ThrottlePos[engineNum];
390 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
391 << " engines exist, but attempted throttle position setting is for engine "
392 << engineNum << endl;
397 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
399 void FGFCS::SetMixtureCmd(int engineNum, double setting)
403 if (engineNum < (int)ThrottlePos.size()) {
405 for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
407 MixtureCmd[engineNum] = setting;
412 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414 void FGFCS::SetMixturePos(int engineNum, double setting)
418 if (engineNum < (int)ThrottlePos.size()) {
420 for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
422 MixturePos[engineNum] = setting;
427 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 void FGFCS::SetPropAdvanceCmd(int engineNum, double setting)
433 if (engineNum < (int)ThrottlePos.size()) {
435 for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
437 PropAdvanceCmd[engineNum] = setting;
442 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
444 void FGFCS::SetPropAdvance(int engineNum, double setting)
448 if (engineNum < (int)ThrottlePos.size()) {
450 for (ctr=0;ctr<=PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
452 PropAdvance[engineNum] = setting;
457 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
459 void FGFCS::SetFeatherCmd(int engineNum, bool setting)
463 if (engineNum < (int)ThrottlePos.size()) {
465 for (ctr=0;ctr<PropFeatherCmd.size();ctr++) PropFeatherCmd[ctr] = setting;
467 PropFeatherCmd[engineNum] = setting;
472 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
474 void FGFCS::SetPropFeather(int engineNum, bool setting)
478 if (engineNum < (int)ThrottlePos.size()) {
480 for (ctr=0;ctr<=PropFeatherCmd.size();ctr++) PropFeather[ctr] = PropFeatherCmd[ctr];
482 PropFeather[engineNum] = setting;
487 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
489 bool FGFCS::Load(Element* el, SystemType systype)
491 string name, file, fname="", interface_property_string, parent_name;
492 vector <FGFCSComponent*> *Components;
493 Element *component_element, *property_element, *sensor_element;
494 Element *channel_element;
498 string separator = "/";
500 // ToDo: The handling of name and file attributes could be improved, here,
501 // considering that a name can be in the external file, as well.
503 name = el->GetAttributeValue("name");
506 fname = el->GetAttributeValue("file");
507 if (systype == stSystem) {
508 file = FindSystemFullPathname(fname);
510 file = FDMExec->GetFullAircraftPath() + separator + fname + ".xml";
513 cerr << "FCS, Autopilot, or system does not appear to be defined inline nor in a file" << endl;
516 document = LoadXMLDocument(file);
517 name = document->GetAttributeValue("name");
523 if (document->GetName() == "autopilot") {
524 Components = &APComponents;
525 Name = "Autopilot: " + document->GetAttributeValue("name");
526 } else if (document->GetName() == "flight_control") {
527 Components = &FCSComponents;
528 Name = "FCS: " + document->GetAttributeValue("name");
529 } else if (document->GetName() == "system") {
530 Components = &Systems;
531 Name = "System: " + document->GetAttributeValue("name");
535 if (document->GetName() == "flight_control") bindModel();
537 // Interface properties from any autopilot, flight control, or other system are
538 // all stored in the interface properties array.
540 property_element = document->FindElement("property");
541 if (property_element) cout << endl << " Declared properties" << endl << endl;
542 while (property_element) {
544 if ( ! property_element->GetAttributeValue("value").empty())
545 value = property_element->GetAttributeValueAsNumber("value");
546 interface_properties.push_back(new double(value));
547 interface_property_string = property_element->GetDataLine();
548 PropertyManager->Tie(interface_property_string, interface_properties.back());
549 cout << " " << interface_property_string << " (initial value: " << value << ")" << endl;
550 property_element = document->FindNextElement("property");
553 // After reading interface properties in a file, read properties in the local
554 // flight_control, autopiot, or system element. This allows general-purpose
555 // systems to be defined in a file, with overrides or initial loaded constants
556 // supplied in the relevant element of the aircraft configuration file.
558 if (!fname.empty()) {
559 property_element = el->FindElement("property");
560 if (property_element) cout << endl << " Declared properties" << endl << endl;
561 while (property_element) {
563 if ( ! property_element->GetAttributeValue("value").empty())
564 value = property_element->GetAttributeValueAsNumber("value");
566 interface_property_string = property_element->GetDataLine();
568 FGPropertyManager* node = PropertyManager->GetNode(interface_property_string);
570 cout << " " << "Overriding value for property " << interface_property_string
571 << " (old value: " << node->getDoubleValue() << " new value: " << value << ")" << endl;
572 node->setDoubleValue(value);
574 interface_properties.push_back(new double(value));
575 PropertyManager->Tie(interface_property_string, interface_properties.back());
576 cout << " " << interface_property_string << " (initial value: " << value << ")" << endl;
580 property_element = el->FindNextElement("property");
584 // Any sensor elements that are outside of a channel (in either the autopilot
585 // or the flight_control, or even any possible "system") are placed into the global
586 // "sensors" array, and are executed prior to any autopilot, flight control, or
589 sensor_element = document->FindElement("sensor");
590 while (sensor_element) {
592 sensors.push_back(new FGSensor(this, sensor_element));
594 cerr << highint << fgred << endl << " " << s << endl;
597 sensor_element = document->FindNextElement("sensor");
600 channel_element = document->FindElement("channel");
601 while (channel_element) {
603 cout << endl << highint << fgblue << " Channel "
604 << normint << channel_element->GetAttributeValue("name") << reset << endl;
606 component_element = channel_element->GetElement();
607 while (component_element) {
609 if ((component_element->GetName() == string("lag_filter")) ||
610 (component_element->GetName() == string("lead_lag_filter")) ||
611 (component_element->GetName() == string("washout_filter")) ||
612 (component_element->GetName() == string("second_order_filter")) ||
613 (component_element->GetName() == string("integrator")) )
615 Components->push_back(new FGFilter(this, component_element));
616 } else if ((component_element->GetName() == string("pure_gain")) ||
617 (component_element->GetName() == string("scheduled_gain")) ||
618 (component_element->GetName() == string("aerosurface_scale")))
620 Components->push_back(new FGGain(this, component_element));
621 } else if (component_element->GetName() == string("summer")) {
622 Components->push_back(new FGSummer(this, component_element));
623 } else if (component_element->GetName() == string("deadband")) {
624 Components->push_back(new FGDeadBand(this, component_element));
625 } else if (component_element->GetName() == string("switch")) {
626 Components->push_back(new FGSwitch(this, component_element));
627 } else if (component_element->GetName() == string("kinematic")) {
628 Components->push_back(new FGKinemat(this, component_element));
629 } else if (component_element->GetName() == string("fcs_function")) {
630 Components->push_back(new FGFCSFunction(this, component_element));
631 } else if (component_element->GetName() == string("pid")) {
632 Components->push_back(new FGPID(this, component_element));
633 } else if (component_element->GetName() == string("actuator")) {
634 Components->push_back(new FGActuator(this, component_element));
635 } else if (component_element->GetName() == string("sensor")) {
636 Components->push_back(new FGSensor(this, component_element));
638 cerr << "Unknown FCS component: " << component_element->GetName() << endl;
641 cerr << highint << fgred << endl << " " << s << endl;
642 cerr << reset << endl;
645 component_element = channel_element->GetNextElement();
647 channel_element = document->FindNextElement("channel");
655 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
657 double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
660 case FGLGear::bgLeft:
662 case FGLGear::bgRight:
664 case FGLGear::bgCenter:
667 cerr << "GetBrake asked to return a bogus brake value" << endl;
672 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
674 string FGFCS::FindSystemFullPathname(string system_filename)
676 string fullpath, localpath;
677 string systemPath = FDMExec->GetSystemsPath();
678 string aircraftPath = FDMExec->GetFullAircraftPath();
679 ifstream system_file;
681 string separator = "/";
683 fullpath = systemPath + separator;
684 localpath = aircraftPath + separator + "Systems" + separator;
686 system_file.open(string(fullpath + system_filename + ".xml").c_str());
687 if ( !system_file.is_open()) {
688 system_file.open(string(localpath + system_filename + ".xml").c_str());
689 if ( !system_file.is_open()) {
690 cerr << " Could not open system file: " << system_filename << " in path "
691 << fullpath << " or " << localpath << endl;
694 return string(localpath + system_filename + ".xml");
697 return string(fullpath + system_filename + ".xml");
700 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
702 ifstream* FGFCS::FindSystemFile(string system_filename)
704 string fullpath, localpath;
705 string systemPath = FDMExec->GetSystemsPath();
706 string aircraftPath = FDMExec->GetFullAircraftPath();
707 ifstream* system_file = new ifstream();
709 string separator = "/";
711 fullpath = systemPath + separator;
712 localpath = aircraftPath + separator + "Systems" + separator;
714 system_file->open(string(fullpath + system_filename + ".xml").c_str());
715 if ( !system_file->is_open()) {
716 system_file->open(string(localpath + system_filename + ".xml").c_str());
717 if ( !system_file->is_open()) {
718 cerr << " Could not open system file: " << system_filename << " in path "
719 << fullpath << " or " << localpath << endl;
725 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
727 string FGFCS::GetComponentStrings(string delimeter)
730 string CompStrings = "";
731 bool firstime = true;
734 for (unsigned int i=0; i<Systems.size(); i++) {
735 if (firstime) firstime = false;
736 else CompStrings += delimeter;
738 CompStrings += Systems[i]->GetName();
742 for (comp = 0; comp < APComponents.size(); comp++)
744 if (firstime) firstime = false;
745 else CompStrings += delimeter;
747 CompStrings += APComponents[comp]->GetName();
751 for (comp = 0; comp < FCSComponents.size(); comp++) {
752 if (firstime) firstime = false;
753 else CompStrings += delimeter;
755 CompStrings += FCSComponents[comp]->GetName();
762 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
764 string FGFCS::GetComponentValues(string delimeter)
767 string CompValues = "";
769 bool firstime = true;
772 for (unsigned int i=0; i<Systems.size(); i++) {
773 if (firstime) firstime = false;
774 else CompValues += delimeter;
776 snprintf(buffer, 100, "%9.6f", Systems[i]->GetOutput());
777 CompValues += string(buffer);
781 for (comp = 0; comp < APComponents.size(); comp++) {
782 if (firstime) firstime = false;
783 else CompValues += delimeter;
785 sprintf(buffer, "%9.6f", APComponents[comp]->GetOutput());
786 CompValues += string(buffer);
790 for (comp = 0; comp < FCSComponents.size(); comp++) {
791 if (firstime) firstime = false;
792 else CompValues += delimeter;
794 sprintf(buffer, "%9.6f", FCSComponents[comp]->GetOutput());
795 CompValues += string(buffer);
803 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
805 void FGFCS::AddThrottle(void)
807 ThrottleCmd.push_back(0.0);
808 ThrottlePos.push_back(0.0);
809 MixtureCmd.push_back(0.0); // assume throttle and mixture are coupled
810 MixturePos.push_back(0.0);
811 PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled
812 PropAdvance.push_back(0.0);
813 PropFeatherCmd.push_back(false);
814 PropFeather.push_back(false);
816 unsigned int num = (unsigned int)ThrottleCmd.size()-1;
820 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
822 void FGFCS::AddGear(void)
824 SteerPosDeg.push_back(0.0);
827 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
829 double FGFCS::GetDt(void)
831 return FDMExec->GetDeltaT()*rate;
834 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
836 void FGFCS::bind(void)
838 PropertyManager->Tie("fcs/aileron-cmd-norm", this, &FGFCS::GetDaCmd, &FGFCS::SetDaCmd);
839 PropertyManager->Tie("fcs/elevator-cmd-norm", this, &FGFCS::GetDeCmd, &FGFCS::SetDeCmd);
840 PropertyManager->Tie("fcs/rudder-cmd-norm", this, &FGFCS::GetDrCmd, &FGFCS::SetDrCmd);
841 PropertyManager->Tie("fcs/flap-cmd-norm", this, &FGFCS::GetDfCmd, &FGFCS::SetDfCmd);
842 PropertyManager->Tie("fcs/speedbrake-cmd-norm", this, &FGFCS::GetDsbCmd, &FGFCS::SetDsbCmd);
843 PropertyManager->Tie("fcs/spoiler-cmd-norm", this, &FGFCS::GetDspCmd, &FGFCS::SetDspCmd);
844 PropertyManager->Tie("fcs/pitch-trim-cmd-norm", this, &FGFCS::GetPitchTrimCmd, &FGFCS::SetPitchTrimCmd);
845 PropertyManager->Tie("fcs/roll-trim-cmd-norm", this, &FGFCS::GetRollTrimCmd, &FGFCS::SetRollTrimCmd);
846 PropertyManager->Tie("fcs/yaw-trim-cmd-norm", this, &FGFCS::GetYawTrimCmd, &FGFCS::SetYawTrimCmd);
848 PropertyManager->Tie("fcs/left-aileron-pos-rad", this, ofRad, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
849 PropertyManager->Tie("fcs/left-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
850 PropertyManager->Tie("fcs/left-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
851 PropertyManager->Tie("fcs/mag-left-aileron-pos-rad", this, ofMag, &FGFCS::GetDaLPos);
853 PropertyManager->Tie("fcs/right-aileron-pos-rad", this, ofRad, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
854 PropertyManager->Tie("fcs/right-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
855 PropertyManager->Tie("fcs/right-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
856 PropertyManager->Tie("fcs/mag-right-aileron-pos-rad", this, ofMag, &FGFCS::GetDaRPos);
858 PropertyManager->Tie("fcs/elevator-pos-rad", this, ofRad, &FGFCS::GetDePos, &FGFCS::SetDePos);
859 PropertyManager->Tie("fcs/elevator-pos-deg", this, ofDeg, &FGFCS::GetDePos, &FGFCS::SetDePos);
860 PropertyManager->Tie("fcs/elevator-pos-norm", this, ofNorm, &FGFCS::GetDePos, &FGFCS::SetDePos);
861 PropertyManager->Tie("fcs/mag-elevator-pos-rad", this, ofMag, &FGFCS::GetDePos);
863 PropertyManager->Tie("fcs/rudder-pos-rad", this,ofRad, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
864 PropertyManager->Tie("fcs/rudder-pos-deg", this,ofDeg, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
865 PropertyManager->Tie("fcs/rudder-pos-norm", this,ofNorm, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
866 PropertyManager->Tie("fcs/mag-rudder-pos-rad", this,ofMag, &FGFCS::GetDrPos);
868 PropertyManager->Tie("fcs/flap-pos-rad", this,ofRad, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
869 PropertyManager->Tie("fcs/flap-pos-deg", this,ofDeg, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
870 PropertyManager->Tie("fcs/flap-pos-norm", this,ofNorm, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
872 PropertyManager->Tie("fcs/speedbrake-pos-rad", this,ofRad, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
873 PropertyManager->Tie("fcs/speedbrake-pos-deg", this,ofDeg, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
874 PropertyManager->Tie("fcs/speedbrake-pos-norm", this,ofNorm, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
875 PropertyManager->Tie("fcs/mag-speedbrake-pos-rad", this,ofMag, &FGFCS::GetDsbPos);
877 PropertyManager->Tie("fcs/spoiler-pos-rad", this, ofRad, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
878 PropertyManager->Tie("fcs/spoiler-pos-deg", this, ofDeg, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
879 PropertyManager->Tie("fcs/spoiler-pos-norm", this, ofNorm, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
880 PropertyManager->Tie("fcs/mag-spoiler-pos-rad", this, ofMag, &FGFCS::GetDspPos);
882 PropertyManager->Tie("gear/gear-pos-norm", this, &FGFCS::GetGearPos, &FGFCS::SetGearPos);
883 PropertyManager->Tie("gear/gear-cmd-norm", this, &FGFCS::GetGearCmd, &FGFCS::SetGearCmd);
884 PropertyManager->Tie("fcs/left-brake-cmd-norm", this, &FGFCS::GetLBrake, &FGFCS::SetLBrake);
885 PropertyManager->Tie("fcs/right-brake-cmd-norm", this, &FGFCS::GetRBrake, &FGFCS::SetRBrake);
886 PropertyManager->Tie("fcs/center-brake-cmd-norm", this, &FGFCS::GetCBrake, &FGFCS::SetCBrake);
887 PropertyManager->Tie("fcs/steer-cmd-norm", this, &FGFCS::GetDsCmd, &FGFCS::SetDsCmd);
889 PropertyManager->Tie("gear/tailhook-pos-norm", this, &FGFCS::GetTailhookPos, &FGFCS::SetTailhookPos);
890 PropertyManager->Tie("fcs/wing-fold-pos-norm", this, &FGFCS::GetWingFoldPos, &FGFCS::SetWingFoldPos);
893 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
894 // Technically, this function should probably bind propulsion type specific controls
895 // rather than mixture and prop-advance.
898 void FGFCS::bindThrottle(unsigned int num)
902 snprintf(tmp, 80, "fcs/throttle-cmd-norm[%u]",num);
903 PropertyManager->Tie( tmp, this, num, &FGFCS::GetThrottleCmd,
904 &FGFCS::SetThrottleCmd);
905 snprintf(tmp, 80, "fcs/throttle-pos-norm[%u]",num);
906 PropertyManager->Tie( tmp, this, num, &FGFCS::GetThrottlePos,
907 &FGFCS::SetThrottlePos);
908 snprintf(tmp, 80, "fcs/mixture-cmd-norm[%u]",num);
909 PropertyManager->Tie( tmp, this, num, &FGFCS::GetMixtureCmd,
910 &FGFCS::SetMixtureCmd);
911 snprintf(tmp, 80, "fcs/mixture-pos-norm[%u]",num);
912 PropertyManager->Tie( tmp, this, num, &FGFCS::GetMixturePos,
913 &FGFCS::SetMixturePos);
914 snprintf(tmp, 80, "fcs/advance-cmd-norm[%u]",num);
915 PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropAdvanceCmd,
916 &FGFCS::SetPropAdvanceCmd);
917 snprintf(tmp, 80, "fcs/advance-pos-norm[%u]", num);
918 PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropAdvance,
919 &FGFCS::SetPropAdvance);
920 snprintf(tmp, 80, "fcs/feather-cmd-norm[%u]", num);
921 PropertyManager->Tie( tmp, this, num, &FGFCS::GetFeatherCmd,
922 &FGFCS::SetFeatherCmd);
923 snprintf(tmp, 80, "fcs/feather-pos-norm[%u]", num);
924 PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropFeather,
925 &FGFCS::SetPropFeather);
928 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
930 void FGFCS::bindModel(void)
935 for (i=0; i<SteerPosDeg.size(); i++) {
936 if (GroundReactions->GetGearUnit(i)->GetSteerable()) {
937 snprintf(tmp,80,"fcs/steer-pos-deg[%u]",i);
938 PropertyManager->Tie( tmp, this, i, &FGFCS::GetSteerPosDeg, &FGFCS::SetSteerPosDeg);
943 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
944 // The bitmasked value choices are as follows:
945 // unset: In this case (the default) JSBSim would only print
946 // out the normally expected messages, essentially echoing
947 // the config files as they are read. If the environment
948 // variable is not set, debug_lvl is set to 1 internally
949 // 0: This requests JSBSim not to output any messages
951 // 1: This value explicity requests the normal JSBSim
953 // 2: This value asks for a message to be printed out when
954 // a class is instantiated
955 // 4: When this value is set, a message is displayed when a
956 // FGModel object executes its Run() method
957 // 8: When this value is set, various runtime state variables
958 // are printed out periodically
959 // 16: When set various parameters are sanity checked and
960 // a message is printed out when they go out of bounds
962 void FGFCS::Debug(int from)
964 if (debug_lvl <= 0) return;
966 if (debug_lvl & 1) { // Standard console startup message output
967 if (from == 2) { // Loader
968 cout << endl << " Flight Control (" << Name << ")" << endl;
971 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
972 if (from == 0) cout << "Instantiated: FGFCS" << endl;
973 if (from == 1) cout << "Destroyed: FGFCS" << endl;
975 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
977 if (debug_lvl & 8 ) { // Runtime state variables
979 if (debug_lvl & 16) { // Sanity checking
981 if (debug_lvl & 64) {
982 if (from == 0) { // Constructor
983 cout << IdSrc << endl;
984 cout << IdHdr << endl;