]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFCS.cpp
sync JSBSim and FlightGear
[flightgear.git] / src / FDM / JSBSim / FGFCS.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2  
3  Module:       FGFCS.cpp
4  Author:       Jon Berndt
5  Date started: 12/12/98
6  Purpose:      Model the flight controls
7  Called by:    FDMExec
8  
9  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
10  
11  This program is free software; you can redistribute it and/or modify it under
12  the terms of the GNU General Public License as published by the Free Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  version.
15  
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 General Public License for more
19  details.
20  
21  You should have received a copy of the GNU 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.
24  
25  Further information about the GNU General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27  
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This class models the flight controls for a specific airplane
31  
32 HISTORY
33 --------------------------------------------------------------------------------
34 12/12/98   JSB   Created
35  
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40 #include "FGFCS.h"
41 #include "FGState.h"
42 #include "FGFDMExec.h"
43 #include "FGAtmosphere.h"
44 #include "FGAircraft.h"
45 #include "FGTranslation.h"
46 #include "FGRotation.h"
47 #include "FGPosition.h"
48 #include "FGAuxiliary.h"
49 #include "FGOutput.h"
50 #include "FGPropertyManager.h"
51
52 #include "filtersjb/FGFilter.h"
53 #include "filtersjb/FGDeadBand.h"
54 #include "filtersjb/FGGain.h"
55 #include "filtersjb/FGGradient.h"
56 #include "filtersjb/FGSwitch.h"
57 #include "filtersjb/FGSummer.h"
58 #include "filtersjb/FGKinemat.h"
59
60 namespace JSBSim {
61
62 static const char *IdSrc = "$Id$";
63 static const char *IdHdr = ID_FCS;
64
65 #if defined(WIN32) && !defined(__CYGWIN__)
66 #define snprintf _snprintf
67 #endif
68
69 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 CLASS IMPLEMENTATION
71 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
72
73 FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
74 {
75   int i;
76   Name = "FGFCS";
77
78   DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = 0.0;
79   AP_DaCmd = AP_DeCmd = AP_DrCmd = AP_ThrottleCmd = 0.0;
80   PTrimCmd = YTrimCmd = RTrimCmd = 0.0;
81   GearCmd = GearPos = 1; // default to gear down
82   LeftBrake = RightBrake = CenterBrake = 0.0;
83   APAttitudeSetPt = APAltitudeSetPt = APHeadingSetPt = APAirspeedSetPt = 0.0;
84   DoNormalize=true;
85   
86   eMode = mNone;
87
88   bind();
89   for (i=0;i<=NForms;i++) {
90     DePos[i] = DaLPos[i] = DaRPos[i] = DrPos[i] = 0.0;
91     DfPos[i] = DsbPos[i] = DspPos[i] = 0.0;
92   }
93     
94   for (i=0;i<NNorm;i++) { ToNormalize[i]=-1;}
95   Debug(0);
96 }
97
98 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
100 FGFCS::~FGFCS()
101 {
102   unbind( PropertyManager->GetNode("fcs") );
103   unbind( PropertyManager->GetNode("ap") );
104   PropertyManager->Untie( "gear/gear-cmd-norm" );
105   PropertyManager->Untie( "gear/gear-pos-norm" );
106
107   ThrottleCmd.clear();
108   ThrottlePos.clear();
109   MixtureCmd.clear();
110   MixturePos.clear();
111   PropAdvanceCmd.clear();
112   PropAdvance.clear();
113
114
115   unsigned int i;
116
117   for (i=0;i<APComponents.size();i++) delete APComponents[i];
118   for (i=0;i<FCSComponents.size();i++) delete FCSComponents[i];
119   
120   Debug(1);
121 }
122
123 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124
125 bool FGFCS::Run(void)
126 {
127   unsigned int i;
128
129   if (!FGModel::Run()) {
130     for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];
131     for (i=0; i<MixturePos.size(); i++) MixturePos[i] = MixtureCmd[i];
132     for (i=0; i<PropAdvance.size(); i++) PropAdvance[i] = PropAdvanceCmd[i];
133     for (i=0; i<APComponents.size(); i++)  {
134       eMode = mAP;
135       APComponents[i]->Run();
136       eMode = mNone;
137     }
138     for (i=0; i<FCSComponents.size(); i++)  {
139       eMode = mFCS;
140       FCSComponents[i]->Run();
141       eMode = mNone;
142     }
143     if (DoNormalize) Normalize();
144
145     return false;
146   } else {
147     return true;
148   }
149 }
150
151 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152
153 void FGFCS::SetThrottleCmd(int engineNum, double setting)
154 {
155   unsigned int ctr;
156
157   if (engineNum < (int)ThrottlePos.size()) {
158     if (engineNum < 0) {
159       for (ctr=0;ctr<ThrottleCmd.size();ctr++) ThrottleCmd[ctr] = setting;
160     } else {
161       ThrottleCmd[engineNum] = setting;
162     }
163   } else {
164     cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
165          << " engines exist, but attempted throttle command is for engine "
166          << engineNum << endl;
167   }
168 }
169
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171
172 void FGFCS::SetThrottlePos(int engineNum, double setting)
173 {
174   unsigned int ctr;
175
176   if (engineNum < (int)ThrottlePos.size()) {
177     if (engineNum < 0) {
178       for (ctr=0;ctr<ThrottlePos.size();ctr++) ThrottlePos[ctr] = setting;
179     } else {
180       ThrottlePos[engineNum] = setting;
181     }
182   } else {
183     cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
184          << " engines exist, but attempted throttle position setting is for engine "
185          << engineNum << endl;
186   }
187 }
188
189 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190
191 double FGFCS::GetThrottleCmd(int engineNum) const
192 {
193   if (engineNum < (int)ThrottlePos.size()) {
194     if (engineNum < 0) {
195        cerr << "Cannot get throttle value for ALL engines" << endl;
196     } else {
197       return ThrottleCmd[engineNum];
198     }
199   } else {
200     cerr << "Throttle " << engineNum << " does not exist! " << ThrottleCmd.size()
201          << " engines exist, but throttle setting for engine " << engineNum
202          << " is selected" << endl;
203   }
204   return 0.0;
205 }
206
207 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208
209 double FGFCS::GetThrottlePos(int engineNum) const
210 {
211   if (engineNum < (int)ThrottlePos.size()) {
212     if (engineNum < 0) {
213        cerr << "Cannot get throttle value for ALL engines" << endl;
214     } else {
215       return ThrottlePos[engineNum];
216     }
217   } else {
218     cerr << "Throttle " << engineNum << " does not exist! " << ThrottlePos.size()
219          << " engines exist, but attempted throttle position setting is for engine "
220          << engineNum << endl;
221   }
222   return 0.0; 
223 }
224
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226
227 void FGFCS::SetMixtureCmd(int engineNum, double setting)
228 {
229   unsigned int ctr;
230
231   if (engineNum < (int)ThrottlePos.size()) {
232     if (engineNum < 0) {
233       for (ctr=0;ctr<MixtureCmd.size();ctr++) MixtureCmd[ctr] = setting;
234     } else {
235       MixtureCmd[engineNum] = setting;
236     }
237   }
238 }
239
240 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241
242 void FGFCS::SetMixturePos(int engineNum, double setting)
243 {
244   unsigned int ctr;
245
246   if (engineNum < (int)ThrottlePos.size()) {
247     if (engineNum < 0) {
248       for (ctr=0;ctr<=MixtureCmd.size();ctr++) MixturePos[ctr] = MixtureCmd[ctr];
249     } else {
250       MixturePos[engineNum] = setting;
251     }
252   }
253 }
254
255 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256
257 void FGFCS::SetPropAdvanceCmd(int engineNum, double setting)
258 {
259   unsigned int ctr;
260
261   if (engineNum < (int)ThrottlePos.size()) {
262     if (engineNum < 0) {
263       for (ctr=0;ctr<PropAdvanceCmd.size();ctr++) PropAdvanceCmd[ctr] = setting;
264     } else {
265       PropAdvanceCmd[engineNum] = setting;
266     }
267   }
268 }
269
270 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271
272 void FGFCS::SetPropAdvance(int engineNum, double setting)
273 {
274   unsigned int ctr;
275
276   if (engineNum < (int)ThrottlePos.size()) {
277     if (engineNum < 0) {
278       for (ctr=0;ctr<=PropAdvanceCmd.size();ctr++) PropAdvance[ctr] = PropAdvanceCmd[ctr];
279     } else {
280       PropAdvance[engineNum] = setting;
281     }
282   }
283 }
284
285 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286
287 bool FGFCS::Load(FGConfigFile* AC_cfg)
288 {
289   string token, delimiter;
290   string name, file, fname;
291   unsigned i;
292   vector <FGFCSComponent*> *Components;
293   FGConfigFile *FCS_cfg;
294
295   Components=0;
296   // Determine if the FCS/Autopilot is defined inline in the aircraft configuration
297   // file or in a separate file. Set up the config file class as appropriate.
298
299   delimiter = AC_cfg->GetValue();
300   name  = AC_cfg->GetValue("NAME");
301   fname = AC_cfg->GetValue("FILE");
302
303   if ( AC_cfg->GetValue("NORMALIZE") == "FALSE") {
304     DoNormalize = false;
305     cout << "    Automatic Control Surface Normalization Disabled" << endl;
306   }
307
308 # ifndef macintosh
309   file = "control/" + fname + ".xml";
310 # else
311   file = "control;" + fname + ".xml";
312 # endif
313
314   if (name.empty()) {
315     name = fname;
316     if (file.empty()) {
317       cerr << "FCS/Autopilot does not appear to be defined inline nor in a file" << endl;
318     } else {
319       FCS_cfg = new FGConfigFile(file);
320       if (!FCS_cfg->IsOpen()) {
321         cerr << "Could not open " << delimiter << " file: " << file << endl;
322         return false;
323       } else {
324         AC_cfg = FCS_cfg; // set local config file object pointer to FCS config
325                                 // file object pointer
326       }
327     }
328   } else {
329     AC_cfg->GetNextConfigLine();
330   }
331
332   if (delimiter == "AUTOPILOT") {
333     Components = &APComponents;
334     eMode = mAP;
335     Name = "Autopilot: " + name;
336   } else if (delimiter == "FLIGHT_CONTROL") {
337     Components = &FCSComponents;
338     eMode = mFCS;
339     Name = "FCS: " + name;
340   } else {
341     cerr << endl << "Unknown FCS delimiter" << endl << endl;
342   }
343   
344   if (debug_lvl > 0) cout << "    Control System Name: " << Name << endl;
345
346   while ((token = AC_cfg->GetValue()) != string("/" + delimiter)) {
347     if (token == "COMPONENT") {
348       token = AC_cfg->GetValue("TYPE");
349       if (debug_lvl > 0) cout << endl << "    Loading Component \""
350                               << AC_cfg->GetValue("NAME")
351                               << "\" of type: " << token << endl;
352       if ((token == "LAG_FILTER") ||
353           (token == "LEAD_LAG_FILTER") ||
354           (token == "SECOND_ORDER_FILTER") ||
355           (token == "WASHOUT_FILTER") ||
356           (token == "INTEGRATOR") ) {
357         Components->push_back(new FGFilter(this, AC_cfg));
358       } else if ((token == "PURE_GAIN") ||
359                  (token == "SCHEDULED_GAIN") ||
360                  (token == "AEROSURFACE_SCALE") ) {
361
362         Components->push_back(new FGGain(this, AC_cfg));
363
364       } else if (token == "SUMMER") {
365         Components->push_back(new FGSummer(this, AC_cfg));
366       } else if (token == "DEADBAND") {
367         Components->push_back(new FGDeadBand(this, AC_cfg));
368       } else if (token == "GRADIENT") {
369         Components->push_back(new FGGradient(this, AC_cfg));
370       } else if (token == "SWITCH") {
371         Components->push_back(new FGSwitch(this, AC_cfg));
372       } else if (token == "KINEMAT") {
373         Components->push_back(new FGKinemat(this, AC_cfg));
374       } else {
375         cerr << "Unknown token [" << token << "] in FCS portion of config file" << endl;
376         return false;
377       }
378       if (AC_cfg->GetNextConfigLine() == "EOF") break;
379     }
380   }
381
382   //collect information for normalizing control surfaces
383
384   string nodeName;
385   for (i=0; i<Components->size(); i++) {
386     
387     if ( (((*Components)[i])->GetType() == "AEROSURFACE_SCALE" 
388           || ((*Components)[i])->GetType() == "KINEMAT")  
389                     && ((*Components)[i])->GetOutputNode() ) { 
390       nodeName = ((*Components)[i])->GetOutputNode()->GetName();
391       if ( nodeName == "elevator-pos-rad" ) {
392         ToNormalize[iDe]=i;
393       } else if ( nodeName  == "left-aileron-pos-rad" 
394                    || nodeName == "aileron-pos-rad" ) {
395         ToNormalize[iDaL]=i;
396       } else if ( nodeName == "right-aileron-pos-rad" ) {
397         ToNormalize[iDaR]=i;
398       } else if ( nodeName == "rudder-pos-rad" ) {
399         ToNormalize[iDr]=i;
400       } else if ( nodeName == "speedbrake-pos-rad" ) {
401         ToNormalize[iDsb]=i;
402       } else if ( nodeName == "spoiler-pos-rad" ) {
403         ToNormalize[iDsp]=i;
404       } else if ( nodeName == "flap-pos-deg" ) {
405         ToNormalize[iDf]=i;
406       }
407     }
408   }     
409   
410   if (delimiter == "FLIGHT_CONTROL") bindModel();
411
412   eMode = mNone;
413
414   return true;
415 }
416
417 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418
419 double FGFCS::GetComponentOutput(int idx)
420 {
421   switch (eMode) {
422   case mFCS:
423     return FCSComponents[idx]->GetOutput();
424   case mAP:
425     return APComponents[idx]->GetOutput();
426   case mNone:
427     cerr << "Unknown FCS mode" << endl;
428     break;
429   }
430   return 0.0;
431 }
432
433 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
434
435 string FGFCS::GetComponentName(int idx)
436 {
437   switch (eMode) {
438   case mFCS:
439     return FCSComponents[idx]->GetName();
440   case mAP:
441     return APComponents[idx]->GetName();
442   case mNone:
443     cerr << "Unknown FCS mode" << endl;
444     break;
445   }
446   return string("");
447
448
449 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450
451 double FGFCS::GetBrake(FGLGear::BrakeGroup bg)
452 {
453   switch (bg) {
454   case FGLGear::bgLeft:
455     return LeftBrake;
456   case FGLGear::bgRight:
457     return RightBrake;
458   case FGLGear::bgCenter:
459     return CenterBrake;
460   default:
461     cerr << "GetBrake asked to return a bogus brake value" << endl;
462   }
463   return 0.0;
464 }
465
466 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
467
468 string FGFCS::GetComponentStrings(void)
469 {
470   unsigned int comp;
471   string CompStrings = "";
472   bool firstime = true;
473
474   for (comp = 0; comp < FCSComponents.size(); comp++) {
475     if (firstime) firstime = false;
476     else          CompStrings += ", ";
477
478     CompStrings += FCSComponents[comp]->GetName();
479   }
480
481   for (comp = 0; comp < APComponents.size(); comp++)
482   {
483     CompStrings += ", ";
484     CompStrings += APComponents[comp]->GetName();
485   }
486
487   return CompStrings;
488 }
489
490 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
491
492 string FGFCS::GetComponentValues(void)
493 {
494   unsigned int comp;
495   string CompValues = "";
496   char buffer[10];
497   bool firstime = true;
498
499   for (comp = 0; comp < FCSComponents.size(); comp++) {
500     if (firstime) firstime = false;
501     else          CompValues += ", ";
502
503     sprintf(buffer, "%9.6f", FCSComponents[comp]->GetOutput());
504     CompValues += string(buffer);
505   }
506
507   for (comp = 0; comp < APComponents.size(); comp++) {
508     sprintf(buffer, ", %9.6f", APComponents[comp]->GetOutput());
509     CompValues += string(buffer);
510   }
511
512   return CompValues;
513 }
514
515 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
516
517 void FGFCS::AddThrottle(void)
518 {
519   ThrottleCmd.push_back(0.0);
520   ThrottlePos.push_back(0.0);
521   MixtureCmd.push_back(0.0);     // assume throttle and mixture are coupled
522   MixturePos.push_back(0.0);
523   PropAdvanceCmd.push_back(0.0); // assume throttle and prop pitch are coupled
524   PropAdvance.push_back(0.0);
525 }
526
527 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
528
529 void FGFCS::Normalize(void) {
530   
531   //not all of these are guaranteed to be defined for every model
532   //those that are have an index >=0 in the ToNormalize array
533   //ToNormalize is filled in Load()
534   
535   if ( ToNormalize[iDe] > -1 ) {
536     DePos[ofNorm] = FCSComponents[ToNormalize[iDe]]->GetOutputPct();
537   }
538   
539   if ( ToNormalize[iDaL] > -1 ) {
540     DaLPos[ofNorm] = FCSComponents[ToNormalize[iDaL]]->GetOutputPct();
541   }
542   
543   if ( ToNormalize[iDaR] > -1 ) {
544     DaRPos[ofNorm] = FCSComponents[ToNormalize[iDaR]]->GetOutputPct();
545   }
546
547   if ( ToNormalize[iDr] > -1 ) {
548     DrPos[ofNorm] = FCSComponents[ToNormalize[iDr]]->GetOutputPct();
549   }
550        
551   if ( ToNormalize[iDsb] > -1 ) { 
552     DsbPos[ofNorm] = FCSComponents[ToNormalize[iDsb]]->GetOutputPct();
553   }
554   
555   if ( ToNormalize[iDsp] > -1 ) {
556     DspPos[ofNorm] = FCSComponents[ToNormalize[iDsp]]->GetOutputPct();
557   }
558   
559   if ( ToNormalize[iDf] > -1 ) {
560     DfPos[ofNorm] = FCSComponents[ToNormalize[iDf]]->GetOutputPct();
561   }
562   
563   DePos[ofMag]  = fabs(DePos[ofRad]);
564   DaLPos[ofMag] = fabs(DaLPos[ofRad]);
565   DaRPos[ofMag] = fabs(DaRPos[ofRad]);
566   DrPos[ofMag]  = fabs(DrPos[ofRad]);
567   DsbPos[ofMag] = fabs(DsbPos[ofRad]);
568   DspPos[ofMag] = fabs(DspPos[ofRad]);
569   DfPos[ofMag]  = fabs(DfPos[ofRad]);
570    
571 }  
572     
573 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
574
575 void FGFCS::bind(void)
576 {
577   PropertyManager->Tie("fcs/aileron-cmd-norm", this,
578                        &FGFCS::GetDaCmd,
579                        &FGFCS::SetDaCmd,
580                        true);
581   PropertyManager->Tie("fcs/elevator-cmd-norm", this,
582                        &FGFCS::GetDeCmd,
583                        &FGFCS::SetDeCmd,
584                        true);
585   PropertyManager->Tie("fcs/rudder-cmd-norm", this,
586                        &FGFCS::GetDrCmd,
587                        &FGFCS::SetDrCmd,
588                        true);
589   PropertyManager->Tie("fcs/flap-cmd-norm", this,
590                        &FGFCS::GetDfCmd,
591                        &FGFCS::SetDfCmd,
592                        true);
593   PropertyManager->Tie("fcs/speedbrake-cmd-norm", this,
594                        &FGFCS::GetDsbCmd,
595                        &FGFCS::SetDsbCmd,
596                        true);
597   PropertyManager->Tie("fcs/spoiler-cmd-norm", this,
598                        &FGFCS::GetDspCmd,
599                        &FGFCS::SetDspCmd,
600                        true);
601   PropertyManager->Tie("fcs/pitch-trim-cmd-norm", this,
602                        &FGFCS::GetPitchTrimCmd,
603                        &FGFCS::SetPitchTrimCmd,
604                        true);
605   PropertyManager->Tie("fcs/roll-trim-cmd-norm", this,
606                        &FGFCS::GetRollTrimCmd,
607                        &FGFCS::SetRollTrimCmd,
608                        true);
609   PropertyManager->Tie("fcs/yaw-trim-cmd-norm", this,
610                        &FGFCS::GetYawTrimCmd,
611                        &FGFCS::SetYawTrimCmd,
612                        true);
613   PropertyManager->Tie("gear/gear-cmd-norm", this,
614                        &FGFCS::GetGearCmd,
615                        &FGFCS::SetGearCmd,
616                        true);
617   
618   PropertyManager->Tie("fcs/left-aileron-pos-rad", this,ofRad,
619                        &FGFCS::GetDaLPos,
620                        &FGFCS::SetDaLPos,
621                        true);
622   PropertyManager->Tie("fcs/left-aileron-pos-norm", this,ofNorm,
623                        &FGFCS::GetDaLPos,
624                        &FGFCS::SetDaLPos,
625                        true);
626   PropertyManager->Tie("fcs/mag-left-aileron-pos-rad", this,ofMag,
627                        &FGFCS::GetDaLPos,
628                        &FGFCS::SetDaLPos,
629                        true);
630  
631   PropertyManager->Tie("fcs/right-aileron-pos-rad", this,ofRad,
632                        &FGFCS::GetDaRPos,
633                        &FGFCS::SetDaRPos,
634                        true);
635   PropertyManager->Tie("fcs/right-aileron-pos-norm", this,ofNorm,
636                        &FGFCS::GetDaRPos,
637                        &FGFCS::SetDaRPos,
638                        true);
639   PropertyManager->Tie("fcs/mag-right-aileron-pos-rad", this,ofMag,
640                        &FGFCS::GetDaRPos,
641                        &FGFCS::SetDaRPos,
642                        true);
643   
644   PropertyManager->Tie("fcs/elevator-pos-rad", this, ofRad,
645                        &FGFCS::GetDePos,
646                        &FGFCS::SetDePos,
647                        true );
648   PropertyManager->Tie("fcs/elevator-pos-norm", this,ofNorm,
649                        &FGFCS::GetDePos,                       
650                        &FGFCS::SetDePos,
651                        true );
652   PropertyManager->Tie("fcs/mag-elevator-pos-rad", this,ofMag,
653                        &FGFCS::GetDePos,
654                        &FGFCS::SetDePos,
655                        true );
656   
657   PropertyManager->Tie("fcs/rudder-pos-rad", this,ofRad,
658                        &FGFCS::GetDrPos,
659                        &FGFCS::SetDrPos,
660                        true);
661   PropertyManager->Tie("fcs/rudder-pos-norm", this,ofNorm,
662                        &FGFCS::GetDrPos,
663                        &FGFCS::SetDrPos,
664                        true);
665   PropertyManager->Tie("fcs/mag-rudder-pos-rad", this,ofMag,
666                        &FGFCS::GetDrPos,
667                        &FGFCS::SetDrPos,
668                        true);
669                        
670   PropertyManager->Tie("fcs/flap-pos-deg", this,ofRad,
671                        &FGFCS::GetDfPos,
672                        &FGFCS::SetDfPos,
673                        true);
674   PropertyManager->Tie("fcs/flap-pos-norm", this,ofNorm,
675                        &FGFCS::GetDfPos,
676                        &FGFCS::SetDfPos,
677                        true);
678   
679   PropertyManager->Tie("fcs/speedbrake-pos-rad", this,ofRad,
680                        &FGFCS::GetDsbPos,
681                        &FGFCS::SetDsbPos,
682                        true);
683   PropertyManager->Tie("fcs/speedbrake-pos-norm", this,ofNorm,
684                        &FGFCS::GetDsbPos,
685                        &FGFCS::SetDsbPos,
686                        true);
687   PropertyManager->Tie("fcs/mag-speedbrake-pos-rad", this,ofMag,
688                        &FGFCS::GetDsbPos,
689                        &FGFCS::SetDsbPos,
690                        true);
691                        
692   PropertyManager->Tie("fcs/spoiler-pos-rad", this,ofRad,
693                        &FGFCS::GetDspPos,
694                        &FGFCS::SetDspPos,
695                        true);
696   PropertyManager->Tie("fcs/spoiler-pos-norm", this,ofNorm,
697                        &FGFCS::GetDspPos,
698                        &FGFCS::SetDspPos,
699                        true);
700   PropertyManager->Tie("fcs/mag-spoiler-pos-rad", this,ofMag,
701                        &FGFCS::GetDspPos,
702                        &FGFCS::SetDspPos,
703                        true);
704                        
705   PropertyManager->Tie("gear/gear-pos-norm", this,
706                        &FGFCS::GetGearPos,
707                        &FGFCS::SetGearPos,
708                        true);
709
710   PropertyManager->Tie("ap/elevator_cmd", this,
711                        &FGFCS::GetAPDeCmd,
712                        &FGFCS::SetAPDeCmd,
713                        true);
714
715   PropertyManager->Tie("ap/aileron_cmd", this,
716                        &FGFCS::GetAPDaCmd,
717                        &FGFCS::SetAPDaCmd,
718                        true);
719
720   PropertyManager->Tie("ap/rudder_cmd", this,
721                        &FGFCS::GetAPDrCmd,
722                        &FGFCS::SetAPDrCmd,
723                        true);
724
725   PropertyManager->Tie("ap/throttle_cmd", this,
726                        &FGFCS::GetAPThrottleCmd,
727                        &FGFCS::SetAPThrottleCmd,
728                        true);
729
730   PropertyManager->Tie("ap/attitude_setpoint", this,
731                        &FGFCS::GetAPAttitudeSetPt,
732                        &FGFCS::SetAPAttitudeSetPt,
733                        true);
734
735   PropertyManager->Tie("ap/altitude_setpoint", this,
736                        &FGFCS::GetAPAltitudeSetPt,
737                        &FGFCS::SetAPAltitudeSetPt,
738                        true);
739
740   PropertyManager->Tie("ap/heading_setpoint", this,
741                        &FGFCS::GetAPHeadingSetPt,
742                        &FGFCS::SetAPHeadingSetPt,
743                        true);
744
745   PropertyManager->Tie("ap/airspeed_setpoint", this,
746                        &FGFCS::GetAPAirspeedSetPt,
747                        &FGFCS::SetAPAirspeedSetPt,
748                        true);
749
750   PropertyManager->Tie("ap/acquire_attitude", this,
751                        &FGFCS::GetAPAcquireAttitude,
752                        &FGFCS::SetAPAcquireAttitude,
753                        true);
754
755   PropertyManager->Tie("ap/acquire_altitude", this,
756                        &FGFCS::GetAPAcquireAltitude,
757                        &FGFCS::SetAPAcquireAltitude,
758                        true);
759
760   PropertyManager->Tie("ap/acquire_heading", this,
761                        &FGFCS::GetAPAcquireHeading,
762                        &FGFCS::SetAPAcquireHeading,
763                        true);
764
765   PropertyManager->Tie("ap/acquire_airspeed", this,
766                        &FGFCS::GetAPAcquireAirspeed,
767                        &FGFCS::SetAPAcquireAirspeed,
768                        true);
769
770   PropertyManager->Tie("ap/attitude_hold", this,
771                        &FGFCS::GetAPAttitudeHold,
772                        &FGFCS::SetAPAttitudeHold,
773                        true);
774
775   PropertyManager->Tie("ap/altitude_hold", this,
776                        &FGFCS::GetAPAltitudeHold,
777                        &FGFCS::SetAPAltitudeHold,
778                        true);
779
780   PropertyManager->Tie("ap/heading_hold", this,
781                        &FGFCS::GetAPHeadingHold,
782                        &FGFCS::SetAPHeadingHold,
783                        true);
784
785   PropertyManager->Tie("ap/airspeed_hold", this,
786                        &FGFCS::GetAPAirspeedHold,
787                        &FGFCS::SetAPAirspeedHold,
788                        true);
789
790   PropertyManager->Tie("ap/wingslevel_hold", this,
791                        &FGFCS::GetAPWingsLevelHold,
792                        &FGFCS::SetAPWingsLevelHold,
793                        true);
794 }
795
796 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
797
798 void FGFCS::bindModel(void)
799 {
800   unsigned i;
801   char tmp[80];
802   
803   
804   for (i=0; i<ThrottleCmd.size(); i++) {
805     snprintf(tmp,80,"fcs/throttle-cmd-norm[%u]",i);
806     PropertyManager->Tie( tmp,this,i,
807                           &FGFCS::GetThrottleCmd,
808                           &FGFCS::SetThrottleCmd,
809                           true );
810     snprintf(tmp,80,"fcs/throttle-pos-norm[%u]",i);                      
811     PropertyManager->Tie( tmp,this,i,
812                           &FGFCS::GetThrottlePos,
813                           &FGFCS::SetThrottlePos,
814                           true );
815     if ( MixtureCmd.size() > i ) {
816       snprintf(tmp,80,"fcs/mixture-cmd-norm[%u]",i); 
817       PropertyManager->Tie( tmp,this,i,
818                             &FGFCS::GetMixtureCmd,
819                             &FGFCS::SetMixtureCmd,
820                             true );
821       snprintf(tmp,80,"fcs/mixture-pos-norm[%u]",i);                    
822       PropertyManager->Tie( tmp,this,i,
823                             &FGFCS::GetMixturePos,
824                             &FGFCS::SetMixturePos,
825                             true );
826     }
827     if ( PropAdvanceCmd.size() > i ) {
828       snprintf(tmp,80,"fcs/advance-cmd-norm[%u]",i); 
829       PropertyManager->Tie( tmp,this,i,
830                             &FGFCS::GetPropAdvanceCmd,
831                             &FGFCS::SetPropAdvanceCmd,
832                             true );
833       snprintf(tmp,80,"fcs/advance-pos-norm[%u]",i);                       
834       PropertyManager->Tie( tmp,this,i,
835                             &FGFCS::GetPropAdvance,
836                             &FGFCS::SetPropAdvance,
837                             true );
838     }
839   }
840 }                            
841                           
842 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
843
844 void FGFCS::unbind(FGPropertyManager *node)
845 {
846   int N = node->nChildren();
847   for(int i=0;i<N;i++) {
848     if(node->getChild(i)->nChildren() ) {
849       unbind( (FGPropertyManager*)node->getChild(i) );
850     } else if( node->getChild(i)->isTied() ) {
851       node->getChild(i)->untie();
852     } 
853   }        
854 }
855
856 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857 //    The bitmasked value choices are as follows:
858 //    unset: In this case (the default) JSBSim would only print
859 //       out the normally expected messages, essentially echoing
860 //       the config files as they are read. If the environment
861 //       variable is not set, debug_lvl is set to 1 internally
862 //    0: This requests JSBSim not to output any messages
863 //       whatsoever.
864 //    1: This value explicity requests the normal JSBSim
865 //       startup messages
866 //    2: This value asks for a message to be printed out when
867 //       a class is instantiated
868 //    4: When this value is set, a message is displayed when a
869 //       FGModel object executes its Run() method
870 //    8: When this value is set, various runtime state variables
871 //       are printed out periodically
872 //    16: When set various parameters are sanity checked and
873 //       a message is printed out when they go out of bounds
874
875 void FGFCS::Debug(int from)
876 {
877   if (debug_lvl <= 0) return;
878
879   if (debug_lvl & 1) { // Standard console startup message output
880     if (from == 0) { // Constructor
881
882     }
883   }
884   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
885     if (from == 0) cout << "Instantiated: FGFCS" << endl;
886     if (from == 1) cout << "Destroyed:    FGFCS" << endl;
887   }
888   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
889   }
890   if (debug_lvl & 8 ) { // Runtime state variables
891   }
892   if (debug_lvl & 16) { // Sanity checking
893   }
894   if (debug_lvl & 64) {
895     if (from == 0) { // Constructor
896       cout << IdSrc << endl;
897       cout << IdHdr << endl;
898     }
899   }
900 }
901
902 }