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;
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;
138 for (i=0;i<NForms;i++) {
139 DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
140 DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
146 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 // Notes: In this logic the default engine commands are set. This is simply a
148 // sort of safe-mode method in case the user has not defined control laws for
149 // throttle, mixture, and prop-advance. The throttle, mixture, and prop advance
150 // positions are set equal to the respective commands. Any control logic that is
151 // actually present in the flight_control or autopilot section will override
152 // these simple assignments.
154 bool FGFCS::Run(void)
158 if (FGModel::Run()) return true; // fast exit if nothing to do
159 if (FDMExec->Holding()) return false;
161 for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
162 for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
163 for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[i];
164 for (i=0; i<PropFeather.size(); i++) PropFeather[i] = PropFeatherCmd[i];
166 // Set the default steering angle
167 for (i=0; i<SteerPosDeg.size(); i++) {
168 FGLGear* gear = GroundReactions->GetGearUnit(i);
169 SteerPosDeg[i] = gear->GetDefaultSteerAngle( GetDsCmd() );
172 // Cycle through the sensor, systems, autopilot, and flight control components
174 for (i=0; i<sensors.size(); i++) sensors[i]->Run();
176 // Execute Systems in order
177 for (i=0; i<Systems.size(); i++) Systems[i]->Run();
180 for (i=0; i<APComponents.size(); i++) APComponents[i]->Run();
182 // Execute Flight Control System
183 for (i=0; i<FCSComponents.size(); i++) FCSComponents[i]->Run();
188 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 void FGFCS::SetDaLPos( int form , double pos )
195 DaLPos[ofDeg] = pos*radtodeg;
198 DaLPos[ofRad] = pos*degtorad;
202 DaLPos[ofNorm] = pos;
204 DaLPos[ofMag] = fabs(DaLPos[ofRad]);
207 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 void FGFCS::SetDaRPos( int form , double pos )
214 DaRPos[ofDeg] = pos*radtodeg;
217 DaRPos[ofRad] = pos*degtorad;
221 DaRPos[ofNorm] = pos;
223 DaRPos[ofMag] = fabs(DaRPos[ofRad]);
226 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 void FGFCS::SetDePos( int form , double pos )
233 DePos[ofDeg] = pos*radtodeg;
236 DePos[ofRad] = pos*degtorad;
242 DePos[ofMag] = fabs(DePos[ofRad]);
245 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 void FGFCS::SetDrPos( int form , double pos )
252 DrPos[ofDeg] = pos*radtodeg;
255 DrPos[ofRad] = pos*degtorad;
261 DrPos[ofMag] = fabs(DrPos[ofRad]);
264 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266 void FGFCS::SetDfPos( int form , double pos )
271 DfPos[ofDeg] = pos*radtodeg;
274 DfPos[ofRad] = pos*degtorad;
280 DfPos[ofMag] = fabs(DfPos[ofRad]);
283 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 void FGFCS::SetDsbPos( int form , double pos )
290 DsbPos[ofDeg] = pos*radtodeg;
293 DsbPos[ofRad] = pos*degtorad;
297 DsbPos[ofNorm] = pos;
299 DsbPos[ofMag] = fabs(DsbPos[ofRad]);
302 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 void FGFCS::SetDspPos( int form , double pos )
309 DspPos[ofDeg] = pos*radtodeg;
312 DspPos[ofRad] = pos*degtorad;
316 DspPos[ofNorm] = pos;
318 DspPos[ofMag] = fabs(DspPos[ofRad]);
321 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 void FGFCS::SetThrottleCmd(int engineNum, double setting)
327 if (engineNum < (int)ThrottlePos.size()) {
329 for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
331 ThrottleCmd[engineNum] = setting;
334 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
335 << " engines exist, but attempted throttle command is for engine "
336 << engineNum << endl;
340 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342 void FGFCS::SetThrottlePos(int engineNum, double setting)
346 if (engineNum < (int)ThrottlePos.size()) {
348 for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
350 ThrottlePos[engineNum] = setting;
353 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
354 << " engines exist, but attempted throttle position setting is for engine "
355 << engineNum << endl;
359 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361 double FGFCS::GetThrottleCmd(int engineNum) const
363 if (engineNum < (int)ThrottlePos.size()) {
365 cerr << "Cannot get throttle value for ALL engines" << endl;
367 return ThrottleCmd[engineNum];
370 cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
371 << " engines exist, but throttle setting for engine " << engineNum
372 << " is selected" << endl;
377 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 double FGFCS::GetThrottlePos(int engineNum) const
381 if (engineNum < (int)ThrottlePos.size()) {
383 cerr << "Cannot get throttle value for ALL engines" << endl;
385 return ThrottlePos[engineNum];
388 cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
389 << " engines exist, but attempted throttle position setting is for engine "
390 << engineNum << endl;
395 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
397 void FGFCS::SetMixtureCmd(int engineNum, double setting)
401 if (engineNum < (int)ThrottlePos.size()) {
403 for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
405 MixtureCmd[engineNum] = setting;
410 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
412 void FGFCS::SetMixturePos(int engineNum, double setting)
416 if (engineNum < (int)ThrottlePos.size()) {
418 for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
420 MixturePos[engineNum] = setting;
425 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427 void FGFCS::SetPropAdvanceCmd(int engineNum, double setting)
431 if (engineNum < (int)ThrottlePos.size()) {
433 for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
435 PropAdvanceCmd[engineNum] = setting;
440 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
442 void FGFCS::SetPropAdvance(int engineNum, double setting)
446 if (engineNum < (int)ThrottlePos.size()) {
448 for (ctr=0;ctr<=PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
450 PropAdvance[engineNum] = setting;
455 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
457 void FGFCS::SetFeatherCmd(int engineNum, bool setting)
461 if (engineNum < (int)ThrottlePos.size()) {
463 for (ctr=0;ctr<PropFeatherCmd.size();ctr++) PropFeatherCmd[ctr] = setting;
465 PropFeatherCmd[engineNum] = setting;
470 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
472 void FGFCS::SetPropFeather(int engineNum, bool setting)
476 if (engineNum < (int)ThrottlePos.size()) {
478 for (ctr=0;ctr<=PropFeatherCmd.size();ctr++) PropFeather[ctr] = PropFeatherCmd[ctr];
480 PropFeather[engineNum] = setting;
485 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
487 bool FGFCS::Load(Element* el, SystemType systype)
489 string name, file, fname, interface_property_string, parent_name;
490 vector <FGFCSComponent*> *Components;
491 Element *component_element, *property_element, *sensor_element;
492 Element *channel_element;
496 string separator = "/";
501 // ToDo: The handling of name and file attributes could be improved, here,
502 // considering that a name can be in the external file, as well.
504 name = el->GetAttributeValue("name");
507 fname = el->GetAttributeValue("file");
508 if (systype == stSystem) {
509 file = FindSystemFullPathname(fname);
511 file = FDMExec->GetFullAircraftPath() + separator + fname + ".xml";
514 cerr << "FCS, Autopilot, or system does not appear to be defined inline nor in a file" << endl;
517 document = LoadXMLDocument(file);
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 // ToDo: How do these get untied?
537 // ToDo: Consider having INPUT and OUTPUT interface properties. Would then
538 // have to duplicate this block of code after channel read code.
539 // Input properties could be write only (nah), and output could be read
542 if (document->GetName() == "flight_control") bindModel();
544 // Interface properties from any autopilot, flight control, or other system are
545 // all stored in the interface properties array.
547 property_element = document->FindElement("property");
548 while (property_element) {
550 if ( ! property_element->GetAttributeValue("value").empty())
551 value = property_element->GetAttributeValueAsNumber("value");
552 interface_properties.push_back(new double(value));
553 interface_property_string = property_element->GetDataLine();
554 PropertyManager->Tie(interface_property_string, interface_properties.back());
555 property_element = document->FindNextElement("property");
558 // Any sensor elements that are outside of a channel (in either the autopilot
559 // or the flight_control, or even any possible "system") are placed into the global
560 // "sensors" array, and are executed prior to any autopilot, flight control, or
563 sensor_element = document->FindElement("sensor");
564 while (sensor_element) {
566 sensors.push_back(new FGSensor(this, sensor_element));
568 cerr << highint << fgred << endl << " " << s << endl;
571 sensor_element = document->FindNextElement("sensor");
574 channel_element = document->FindElement("channel");
575 while (channel_element) {
576 component_element = channel_element->GetElement();
577 while (component_element) {
579 if ((component_element->GetName() == string("lag_filter")) ||
580 (component_element->GetName() == string("lead_lag_filter")) ||
581 (component_element->GetName() == string("washout_filter")) ||
582 (component_element->GetName() == string("second_order_filter")) ||
583 (component_element->GetName() == string("integrator")) )
585 Components->push_back(new FGFilter(this, component_element));
586 } else if ((component_element->GetName() == string("pure_gain")) ||
587 (component_element->GetName() == string("scheduled_gain")) ||
588 (component_element->GetName() == string("aerosurface_scale")))
590 Components->push_back(new FGGain(this, component_element));
591 } else if (component_element->GetName() == string("summer")) {
592 Components->push_back(new FGSummer(this, component_element));
593 } else if (component_element->GetName() == string("deadband")) {
594 Components->push_back(new FGDeadBand(this, component_element));
595 } else if (component_element->GetName() == string("switch")) {
596 Components->push_back(new FGSwitch(this, component_element));
597 } else if (component_element->GetName() == string("kinematic")) {
598 Components->push_back(new FGKinemat(this, component_element));
599 } else if (component_element->GetName() == string("fcs_function")) {
600 Components->push_back(new FGFCSFunction(this, component_element));
601 } else if (component_element->GetName() == string("pid")) {
602 Components->push_back(new FGPID(this, component_element));
603 } else if (component_element->GetName() == string("actuator")) {
604 Components->push_back(new FGActuator(this, component_element));
605 } else if (component_element->GetName() == string("sensor")) {
606 Components->push_back(new FGSensor(this, component_element));
608 cerr << "Unknown FCS component: " << component_element->GetName() << endl;
611 cerr << highint << fgred << endl << " " << s << endl;
612 cerr << reset << endl;
615 component_element = channel_element->GetNextElement();
617 channel_element = document->FindNextElement("channel");
625 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
627 double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
630 case FGLGear::bgLeft:
632 case FGLGear::bgRight:
634 case FGLGear::bgCenter:
637 cerr << "GetBrake asked to return a bogus brake value" << endl;
642 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
644 string FGFCS::FindSystemFullPathname(string system_filename)
646 string fullpath, localpath;
647 string systemPath = FDMExec->GetSystemsPath();
648 string aircraftPath = FDMExec->GetFullAircraftPath();
649 ifstream system_file;
651 string separator = "/";
656 fullpath = systemPath + separator;
657 localpath = aircraftPath + separator + "Systems" + separator;
659 system_file.open(string(fullpath + system_filename + ".xml").c_str());
660 if ( !system_file.is_open()) {
661 system_file.open(string(localpath + system_filename + ".xml").c_str());
662 if ( !system_file.is_open()) {
663 cerr << " Could not open system file: " << system_filename << " in path "
664 << fullpath << " or " << localpath << endl;
667 return string(localpath + system_filename + ".xml");
670 return string(fullpath + system_filename + ".xml");
673 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
675 ifstream* FGFCS::FindSystemFile(string system_filename)
677 string fullpath, localpath;
678 string systemPath = FDMExec->GetSystemsPath();
679 string aircraftPath = FDMExec->GetFullAircraftPath();
680 ifstream* system_file = new ifstream();
682 string separator = "/";
687 fullpath = systemPath + separator;
688 localpath = aircraftPath + separator + "Systems" + separator;
690 system_file->open(string(fullpath + system_filename + ".xml").c_str());
691 if ( !system_file->is_open()) {
692 system_file->open(string(localpath + system_filename + ".xml").c_str());
693 if ( !system_file->is_open()) {
694 cerr << " Could not open system file: " << system_filename << " in path "
695 << fullpath << " or " << localpath << endl;
701 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
703 string FGFCS::GetComponentStrings(string delimeter)
706 string CompStrings = "";
707 bool firstime = true;
710 for (unsigned int i=0; i<Systems.size(); i++) {
711 if (firstime) firstime = false;
712 else CompStrings += delimeter;
714 CompStrings += Systems[i]->GetName();
718 for (comp = 0; comp < APComponents.size(); comp++)
720 if (firstime) firstime = false;
721 else CompStrings += delimeter;
723 CompStrings += APComponents[comp]->GetName();
727 for (comp = 0; comp < FCSComponents.size(); comp++) {
728 if (firstime) firstime = false;
729 else CompStrings += delimeter;
731 CompStrings += FCSComponents[comp]->GetName();
738 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
740 string FGFCS::GetComponentValues(string delimeter)
743 string CompValues = "";
745 bool firstime = true;
748 for (unsigned int i=0; i<Systems.size(); i++) {
749 if (firstime) firstime = false;
750 else CompValues += delimeter;
752 sprintf(buffer, "%9.6f", Systems[i]->GetOutput());
753 CompValues += string(buffer);
757 for (comp = 0; comp < APComponents.size(); comp++) {
758 if (firstime) firstime = false;
759 else CompValues += delimeter;
761 sprintf(buffer, "%9.6f", APComponents[comp]->GetOutput());
762 CompValues += string(buffer);
766 for (comp = 0; comp < FCSComponents.size(); comp++) {
767 if (firstime) firstime = false;
768 else CompValues += delimeter;
770 sprintf(buffer, "%9.6f", FCSComponents[comp]->GetOutput());
771 CompValues += string(buffer);
779 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
781 void FGFCS::AddThrottle(void)
783 ThrottleCmd.push_back(0.0);
784 ThrottlePos.push_back(0.0);
785 MixtureCmd.push_back(0.0); // assume throttle and mixture are coupled
786 MixturePos.push_back(0.0);
787 PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled
788 PropAdvance.push_back(0.0);
789 PropFeatherCmd.push_back(false);
790 PropFeather.push_back(false);
792 unsigned int num = (unsigned int)ThrottleCmd.size()-1;
796 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
798 void FGFCS::AddGear(void)
800 SteerPosDeg.push_back(0.0);
803 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
805 double FGFCS::GetDt(void)
807 return FDMExec->GetDeltaT()*rate;
810 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812 void FGFCS::bind(void)
814 PropertyManager->Tie("fcs/aileron-cmd-norm", this, &FGFCS::GetDaCmd, &FGFCS::SetDaCmd);
815 PropertyManager->Tie("fcs/elevator-cmd-norm", this, &FGFCS::GetDeCmd, &FGFCS::SetDeCmd);
816 PropertyManager->Tie("fcs/rudder-cmd-norm", this, &FGFCS::GetDrCmd, &FGFCS::SetDrCmd);
817 PropertyManager->Tie("fcs/flap-cmd-norm", this, &FGFCS::GetDfCmd, &FGFCS::SetDfCmd);
818 PropertyManager->Tie("fcs/speedbrake-cmd-norm", this, &FGFCS::GetDsbCmd, &FGFCS::SetDsbCmd);
819 PropertyManager->Tie("fcs/spoiler-cmd-norm", this, &FGFCS::GetDspCmd, &FGFCS::SetDspCmd);
820 PropertyManager->Tie("fcs/pitch-trim-cmd-norm", this, &FGFCS::GetPitchTrimCmd, &FGFCS::SetPitchTrimCmd);
821 PropertyManager->Tie("fcs/roll-trim-cmd-norm", this, &FGFCS::GetRollTrimCmd, &FGFCS::SetRollTrimCmd);
822 PropertyManager->Tie("fcs/yaw-trim-cmd-norm", this, &FGFCS::GetYawTrimCmd, &FGFCS::SetYawTrimCmd);
824 PropertyManager->Tie("fcs/left-aileron-pos-rad", this, ofRad, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
825 PropertyManager->Tie("fcs/left-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
826 PropertyManager->Tie("fcs/left-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaLPos, &FGFCS::SetDaLPos);
827 PropertyManager->Tie("fcs/mag-left-aileron-pos-rad", this, ofMag, &FGFCS::GetDaLPos);
829 PropertyManager->Tie("fcs/right-aileron-pos-rad", this, ofRad, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
830 PropertyManager->Tie("fcs/right-aileron-pos-deg", this, ofDeg, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
831 PropertyManager->Tie("fcs/right-aileron-pos-norm", this, ofNorm, &FGFCS::GetDaRPos, &FGFCS::SetDaRPos);
832 PropertyManager->Tie("fcs/mag-right-aileron-pos-rad", this, ofMag, &FGFCS::GetDaRPos);
834 PropertyManager->Tie("fcs/elevator-pos-rad", this, ofRad, &FGFCS::GetDePos, &FGFCS::SetDePos);
835 PropertyManager->Tie("fcs/elevator-pos-deg", this, ofDeg, &FGFCS::GetDePos, &FGFCS::SetDePos);
836 PropertyManager->Tie("fcs/elevator-pos-norm", this, ofNorm, &FGFCS::GetDePos, &FGFCS::SetDePos);
837 PropertyManager->Tie("fcs/mag-elevator-pos-rad", this, ofMag, &FGFCS::GetDePos);
839 PropertyManager->Tie("fcs/rudder-pos-rad", this,ofRad, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
840 PropertyManager->Tie("fcs/rudder-pos-deg", this,ofDeg, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
841 PropertyManager->Tie("fcs/rudder-pos-norm", this,ofNorm, &FGFCS::GetDrPos, &FGFCS::SetDrPos);
842 PropertyManager->Tie("fcs/mag-rudder-pos-rad", this,ofMag, &FGFCS::GetDrPos);
844 PropertyManager->Tie("fcs/flap-pos-rad", this,ofRad, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
845 PropertyManager->Tie("fcs/flap-pos-deg", this,ofDeg, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
846 PropertyManager->Tie("fcs/flap-pos-norm", this,ofNorm, &FGFCS::GetDfPos, &FGFCS::SetDfPos);
848 PropertyManager->Tie("fcs/speedbrake-pos-rad", this,ofRad, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
849 PropertyManager->Tie("fcs/speedbrake-pos-deg", this,ofDeg, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
850 PropertyManager->Tie("fcs/speedbrake-pos-norm", this,ofNorm, &FGFCS::GetDsbPos, &FGFCS::SetDsbPos);
851 PropertyManager->Tie("fcs/mag-speedbrake-pos-rad", this,ofMag, &FGFCS::GetDsbPos);
853 PropertyManager->Tie("fcs/spoiler-pos-rad", this, ofRad, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
854 PropertyManager->Tie("fcs/spoiler-pos-deg", this, ofDeg, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
855 PropertyManager->Tie("fcs/spoiler-pos-norm", this, ofNorm, &FGFCS::GetDspPos, &FGFCS::SetDspPos);
856 PropertyManager->Tie("fcs/mag-spoiler-pos-rad", this, ofMag, &FGFCS::GetDspPos);
858 PropertyManager->Tie("gear/gear-pos-norm", this, &FGFCS::GetGearPos, &FGFCS::SetGearPos);
859 PropertyManager->Tie("gear/gear-cmd-norm", this, &FGFCS::GetGearCmd, &FGFCS::SetGearCmd);
860 PropertyManager->Tie("fcs/left-brake-cmd-norm", this, &FGFCS::GetLBrake, &FGFCS::SetLBrake);
861 PropertyManager->Tie("fcs/right-brake-cmd-norm", this, &FGFCS::GetRBrake, &FGFCS::SetRBrake);
862 PropertyManager->Tie("fcs/center-brake-cmd-norm", this, &FGFCS::GetCBrake, &FGFCS::SetCBrake);
863 PropertyManager->Tie("fcs/steer-cmd-norm", this, &FGFCS::GetDsCmd, &FGFCS::SetDsCmd);
866 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
867 // Technically, this function should probably bind propulsion type specific controls
868 // rather than mixture and prop-advance.
871 void FGFCS::bindThrottle(unsigned int num)
875 snprintf(tmp, 80, "fcs/throttle-cmd-norm[%u]",num);
876 PropertyManager->Tie( tmp, this, num, &FGFCS::GetThrottleCmd,
877 &FGFCS::SetThrottleCmd);
878 snprintf(tmp, 80, "fcs/throttle-pos-norm[%u]",num);
879 PropertyManager->Tie( tmp, this, num, &FGFCS::GetThrottlePos,
880 &FGFCS::SetThrottlePos);
881 snprintf(tmp, 80, "fcs/mixture-cmd-norm[%u]",num);
882 PropertyManager->Tie( tmp, this, num, &FGFCS::GetMixtureCmd,
883 &FGFCS::SetMixtureCmd);
884 snprintf(tmp, 80, "fcs/mixture-pos-norm[%u]",num);
885 PropertyManager->Tie( tmp, this, num, &FGFCS::GetMixturePos,
886 &FGFCS::SetMixturePos);
887 snprintf(tmp, 80, "fcs/advance-cmd-norm[%u]",num);
888 PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropAdvanceCmd,
889 &FGFCS::SetPropAdvanceCmd);
890 snprintf(tmp, 80, "fcs/advance-pos-norm[%u]", num);
891 PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropAdvance,
892 &FGFCS::SetPropAdvance);
893 snprintf(tmp, 80, "fcs/feather-cmd-norm[%u]", num);
894 PropertyManager->Tie( tmp, this, num, &FGFCS::GetFeatherCmd,
895 &FGFCS::SetFeatherCmd);
896 snprintf(tmp, 80, "fcs/feather-pos-norm[%u]", num);
897 PropertyManager->Tie( tmp, this, num, &FGFCS::GetPropFeather,
898 &FGFCS::SetPropFeather);
901 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
903 void FGFCS::bindModel(void)
908 for (i=0; i<SteerPosDeg.size(); i++) {
909 if (GroundReactions->GetGearUnit(i)->GetSteerable()) {
910 snprintf(tmp,80,"fcs/steer-pos-deg[%u]",i);
911 PropertyManager->Tie( tmp, this, i, &FGFCS::GetSteerPosDeg, &FGFCS::SetSteerPosDeg);
916 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
917 // The bitmasked value choices are as follows:
918 // unset: In this case (the default) JSBSim would only print
919 // out the normally expected messages, essentially echoing
920 // the config files as they are read. If the environment
921 // variable is not set, debug_lvl is set to 1 internally
922 // 0: This requests JSBSim not to output any messages
924 // 1: This value explicity requests the normal JSBSim
926 // 2: This value asks for a message to be printed out when
927 // a class is instantiated
928 // 4: When this value is set, a message is displayed when a
929 // FGModel object executes its Run() method
930 // 8: When this value is set, various runtime state variables
931 // are printed out periodically
932 // 16: When set various parameters are sanity checked and
933 // a message is printed out when they go out of bounds
935 void FGFCS::Debug(int from)
937 if (debug_lvl <= 0) return;
939 if (debug_lvl & 1) { // Standard console startup message output
940 if (from == 2) { // Loader
941 cout << endl << " Flight Control (" << Name << ")" << endl;
944 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
945 if (from == 0) cout << "Instantiated: FGFCS" << endl;
946 if (from == 1) cout << "Destroyed: FGFCS" << endl;
948 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
950 if (debug_lvl & 8 ) { // Runtime state variables
952 if (debug_lvl & 16) { // Sanity checking
954 if (debug_lvl & 64) {
955 if (from == 0) { // Constructor
956 cout << IdSrc << endl;
957 cout << IdHdr << endl;