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