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