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