]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGState.cpp
Added flap_deflection so that remote fdm can pass back actual flap deflection
[flightgear.git] / src / FDM / JSBSim / FGState.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2                                                                        
3  Module:       FGState.cpp
4  Author:       Jon Berndt
5  Date started: 11/17/98
6  Called by:    FGFDMExec and accessed by all models.
7  
8  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
9  
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14  
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19  
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23  
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26  
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29 See header file.
30  
31 HISTORY
32 --------------------------------------------------------------------------------
33 11/17/98   JSB   Created
34  
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 INCLUDES
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39 #ifdef FGFS
40 #  include <simgear/compiler.h>
41 #  include <math.h>
42 #else
43 #  if defined(sgi) && !defined(__GNUC__)
44 #    include <math.h>
45 #  else
46 #    include <cmath>
47 #  endif
48 #endif
49
50 #ifdef _WIN32
51 #define snprintf _snprintf
52 #endif
53
54 #include "FGState.h"
55
56 static const char *IdSrc = "$Id$";
57 static const char *IdHdr = ID_STATE;
58
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 MACROS
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62
63 //#define RegisterVariable(ID,DEF) coeffdef[#ID] = ID; paramdef[ID] = DEF
64 #define RegisterVariable(ID,DEF) coeffdef[#ID] = ID;
65
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 CLASS IMPLEMENTATION
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69
70 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 //
72 // For every term registered here there must be a corresponding handler in
73 // GetParameter() below that retrieves that parameter. Also, there must be an
74 // entry in the enum eParam definition in FGJSBBase.h. The ID is what must be used
75 // in any config file entry which references that item.
76
77 FGState::FGState(FGFDMExec* fdex)
78 {
79   FDMExec = fdex;
80
81   a = 1000.0;
82   sim_time = 0.0;
83   dt = 1.0/120.0;
84   ActiveEngine = -1;
85
86   Aircraft     = FDMExec->GetAircraft();
87   Translation  = FDMExec->GetTranslation();
88   Rotation     = FDMExec->GetRotation();
89   Position     = FDMExec->GetPosition();
90   FCS          = FDMExec->GetFCS();
91   Output       = FDMExec->GetOutput();
92   Atmosphere   = FDMExec->GetAtmosphere();
93   Aerodynamics = FDMExec->GetAerodynamics();
94   GroundReactions = FDMExec->GetGroundReactions();
95   Propulsion      = FDMExec->GetPropulsion();
96   PropertyManager = FDMExec->GetPropertyManager();
97
98   InitPropertyMaps();
99
100   bind();
101   
102   Debug(0);
103 }
104
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106
107 FGState::~FGState()
108 {
109   unbind();
110   Debug(1);
111 }
112
113 //***************************************************************************
114 //
115 // Reset: Assume all angles READ FROM FILE IN DEGREES !!
116 //
117
118 bool FGState::Reset(string path, string acname, string fname)
119 {
120   string resetDef;
121   string token="";
122
123   double U, V, W;
124   double phi, tht, psi;
125   double latitude, longitude, h;
126   double wdir, wmag, wnorth, weast;
127
128 # ifndef macintosh
129   resetDef = path + "/" + acname + "/" + fname + ".xml";
130 # else
131   resetDef = path + ";" + acname + ";" + fname + ".xml";
132 # endif
133
134   FGConfigFile resetfile(resetDef);
135   if (!resetfile.IsOpen()) return false;
136
137   resetfile.GetNextConfigLine();
138   token = resetfile.GetValue();
139   if (token != string("initialize")) {
140     cerr << "The reset file " << resetDef
141          << " does not appear to be a reset file" << endl;
142     return false;
143   } else {
144     resetfile.GetNextConfigLine();
145     resetfile >> token;
146     cout << "Resetting using: " << token << endl << endl;
147   }
148   
149   while (token != string("/initialize") && token != string("EOF")) {
150     if (token == "UBODY") resetfile >> U;
151     if (token == "VBODY") resetfile >> V;
152     if (token == "WBODY") resetfile >> W;
153     if (token == "LATITUDE") resetfile >> latitude;
154     if (token == "LONGITUDE") resetfile >> longitude;
155     if (token == "PHI") resetfile >> phi;
156     if (token == "THETA") resetfile >> tht;
157     if (token == "PSI") resetfile >> psi;
158     if (token == "ALTITUDE") resetfile >> h;
159     if (token == "WINDDIR") resetfile >> wdir;
160     if (token == "VWIND") resetfile >> wmag;
161
162     resetfile >> token;
163   }
164   
165   
166   Position->SetLatitude(latitude*degtorad);
167   Position->SetLongitude(longitude*degtorad);
168   Position->Seth(h);
169
170   wnorth = wmag*ktstofps*cos(wdir*degtorad);
171   weast = wmag*ktstofps*sin(wdir*degtorad);
172   
173   Initialize(U, V, W, phi*degtorad, tht*degtorad, psi*degtorad,
174                latitude*degtorad, longitude*degtorad, h, wnorth, weast, 0.0);
175
176   return true;
177 }
178
179 //***************************************************************************
180 //
181 // Initialize: Assume all angles GIVEN IN RADIANS !!
182 //
183
184 void FGState::Initialize(double U, double V, double W,
185                          double phi, double tht, double psi,
186                          double Latitude, double Longitude, double H,
187                          double wnorth, double weast, double wdown)
188 {
189   double alpha, beta;
190   double qbar, Vt;
191   FGColumnVector3 vAeroUVW;
192
193   Position->SetLatitude(Latitude);
194   Position->SetLongitude(Longitude);
195   Position->Seth(H);
196
197   Atmosphere->Run();
198   
199   vLocalEuler << phi << tht << psi;
200   Rotation->SetEuler(vLocalEuler);
201
202   InitMatrices(phi, tht, psi);
203   
204   vUVW << U << V << W;
205   Translation->SetUVW(vUVW);
206   
207   Atmosphere->SetWindNED(wnorth, weast, wdown);
208   
209   vAeroUVW = vUVW + mTl2b*Atmosphere->GetWindNED();
210   
211   if (vAeroUVW(eW) != 0.0)
212     alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
213   else
214     alpha = 0.0;
215   if (vAeroUVW(eV) != 0.0)
216     beta = vAeroUVW(eU)*vAeroUVW(eU)+vAeroUVW(eW)*vAeroUVW(eW) > 0.0 ? atan2(vAeroUVW(eV), (fabs(vAeroUVW(eU))/vAeroUVW(eU))*sqrt(vAeroUVW(eU)*vAeroUVW(eU) + vAeroUVW(eW)*vAeroUVW(eW))) : 0.0;
217   else
218     beta = 0.0;
219
220   Translation->SetAB(alpha, beta);
221
222   Vt = sqrt(U*U + V*V + W*W);
223   Translation->SetVt(Vt);
224
225   Translation->SetMach(Vt/Atmosphere->GetSoundSpeed());
226
227   qbar = 0.5*(U*U + V*V + W*W)*Atmosphere->GetDensity();
228   Translation->Setqbar(qbar);
229
230   vLocalVelNED = mTb2l*vUVW;
231   Position->SetvVel(vLocalVelNED);
232 }
233
234 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
235
236 void FGState::Initialize(FGInitialCondition *FGIC)
237 {
238   double tht,psi,phi;
239   double U, V, W, h;
240   double latitude, longitude;
241   double wnorth,weast, wdown;
242   
243   latitude = FGIC->GetLatitudeRadIC();
244   longitude = FGIC->GetLongitudeRadIC();
245   h = FGIC->GetAltitudeFtIC();
246   U = FGIC->GetUBodyFpsIC();
247   V = FGIC->GetVBodyFpsIC();
248   W = FGIC->GetWBodyFpsIC();
249   tht = FGIC->GetThetaRadIC();
250   phi = FGIC->GetPhiRadIC();
251   psi = FGIC->GetPsiRadIC();
252   wnorth = FGIC->GetWindNFpsIC();
253   weast = FGIC->GetWindEFpsIC();
254   wdown = FGIC->GetWindDFpsIC();
255   
256   Position->SetSeaLevelRadius( FGIC->GetSeaLevelRadiusFtIC() );
257   Position->SetRunwayRadius( FGIC->GetSeaLevelRadiusFtIC() + 
258                                              FGIC->GetTerrainAltitudeFtIC() );
259
260   // need to fix the wind speed args, here.  
261   Initialize(U, V, W, phi, tht, psi, latitude, longitude, h, wnorth, weast, wdown);
262 }
263
264 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265
266 void FGState::InitMatrices(double phi, double tht, double psi)
267 {
268   double thtd2, psid2, phid2;
269   double Sthtd2, Spsid2, Sphid2;
270   double Cthtd2, Cpsid2, Cphid2;
271   double Cphid2Cthtd2;
272   double Cphid2Sthtd2;
273   double Sphid2Sthtd2;
274   double Sphid2Cthtd2;
275
276   thtd2 = tht/2.0;
277   psid2 = psi/2.0;
278   phid2 = phi/2.0;
279
280   Sthtd2 = sin(thtd2);
281   Spsid2 = sin(psid2);
282   Sphid2 = sin(phid2);
283
284   Cthtd2 = cos(thtd2);
285   Cpsid2 = cos(psid2);
286   Cphid2 = cos(phid2);
287
288   Cphid2Cthtd2 = Cphid2*Cthtd2;
289   Cphid2Sthtd2 = Cphid2*Sthtd2;
290   Sphid2Sthtd2 = Sphid2*Sthtd2;
291   Sphid2Cthtd2 = Sphid2*Cthtd2;
292
293   vQtrn(1) = Cphid2Cthtd2*Cpsid2 + Sphid2Sthtd2*Spsid2;
294   vQtrn(2) = Sphid2Cthtd2*Cpsid2 - Cphid2Sthtd2*Spsid2;
295   vQtrn(3) = Cphid2Sthtd2*Cpsid2 + Sphid2Cthtd2*Spsid2;
296   vQtrn(4) = Cphid2Cthtd2*Spsid2 - Sphid2Sthtd2*Cpsid2;
297
298   CalcMatrices();
299 }
300
301 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302
303 void FGState::CalcMatrices(void)
304 {
305   double Q0Q0, Q1Q1, Q2Q2, Q3Q3;
306   double Q0Q1, Q0Q2, Q0Q3, Q1Q2;
307   double Q1Q3, Q2Q3;
308
309   Q0Q0 = vQtrn(1)*vQtrn(1);
310   Q1Q1 = vQtrn(2)*vQtrn(2);
311   Q2Q2 = vQtrn(3)*vQtrn(3);
312   Q3Q3 = vQtrn(4)*vQtrn(4);
313   Q0Q1 = vQtrn(1)*vQtrn(2);
314   Q0Q2 = vQtrn(1)*vQtrn(3);
315   Q0Q3 = vQtrn(1)*vQtrn(4);
316   Q1Q2 = vQtrn(2)*vQtrn(3);
317   Q1Q3 = vQtrn(2)*vQtrn(4);
318   Q2Q3 = vQtrn(3)*vQtrn(4);
319
320   mTl2b(1,1) = Q0Q0 + Q1Q1 - Q2Q2 - Q3Q3;
321   mTl2b(1,2) = 2*(Q1Q2 + Q0Q3);
322   mTl2b(1,3) = 2*(Q1Q3 - Q0Q2);
323   mTl2b(2,1) = 2*(Q1Q2 - Q0Q3);
324   mTl2b(2,2) = Q0Q0 - Q1Q1 + Q2Q2 - Q3Q3;
325   mTl2b(2,3) = 2*(Q2Q3 + Q0Q1);
326   mTl2b(3,1) = 2*(Q1Q3 + Q0Q2);
327   mTl2b(3,2) = 2*(Q2Q3 - Q0Q1);
328   mTl2b(3,3) = Q0Q0 - Q1Q1 - Q2Q2 + Q3Q3;
329
330   mTb2l = mTl2b;
331   mTb2l.T();
332 }
333
334 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335
336 void FGState::IntegrateQuat(FGColumnVector3 vPQR, int rate)
337 {
338   vQdot(1) = -0.5*(vQtrn(2)*vPQR(eP) + vQtrn(3)*vPQR(eQ) + vQtrn(4)*vPQR(eR));
339   vQdot(2) =  0.5*(vQtrn(1)*vPQR(eP) + vQtrn(3)*vPQR(eR) - vQtrn(4)*vPQR(eQ));
340   vQdot(3) =  0.5*(vQtrn(1)*vPQR(eQ) + vQtrn(4)*vPQR(eP) - vQtrn(2)*vPQR(eR));
341   vQdot(4) =  0.5*(vQtrn(1)*vPQR(eR) + vQtrn(2)*vPQR(eQ) - vQtrn(3)*vPQR(eP));
342   vQtrn += 0.5*dt*rate*(vlastQdot + vQdot);
343
344   vQtrn.Normalize();
345
346   vlastQdot = vQdot;
347 }
348
349 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
350
351 FGColumnVector3& FGState::CalcEuler(void)
352 {
353   if (mTl2b(3,3) == 0.0) mTl2b(3,3) = 0.0000001;
354   if (mTl2b(1,1) == 0.0) mTl2b(1,1) = 0.0000001;
355
356   vEuler(ePhi) = atan2(mTl2b(2,3), mTl2b(3,3));
357   vEuler(eTht) = asin(-mTl2b(1,3));
358   vEuler(ePsi) = atan2(mTl2b(1,2), mTl2b(1,1));
359
360   if (vEuler(ePsi) < 0.0) vEuler(ePsi) += 2*M_PI;
361
362   return vEuler;
363 }
364
365 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
366
367 FGMatrix33& FGState::GetTs2b(void)
368 {
369   double ca, cb, sa, sb;
370
371   double alpha = Translation->Getalpha();
372   double beta  = Translation->Getbeta();
373
374   ca = cos(alpha);
375   sa = sin(alpha);
376   cb = cos(beta);
377   sb = sin(beta);
378
379   mTs2b(1,1) = ca*cb;
380   mTs2b(1,2) = -ca*sb;
381   mTs2b(1,3) = -sa;
382   mTs2b(2,1) = sb;
383   mTs2b(2,2) = cb;
384   mTs2b(2,3) = 0.0;
385   mTs2b(3,1) = sa*cb;
386   mTs2b(3,2) = -sa*sb;
387   mTs2b(3,3) = ca;
388
389   return mTs2b;
390 }
391
392 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
393
394 FGMatrix33& FGState::GetTb2s(void)
395 {
396   float alpha,beta;
397   float ca, cb, sa, sb;
398   
399   alpha = Translation->Getalpha();
400   beta  = Translation->Getbeta();
401   
402   ca = cos(alpha);
403   sa = sin(alpha);
404   cb = cos(beta);
405   sb = sin(beta);
406
407   mTb2s(1,1) = ca*cb;
408   mTb2s(1,2) = sb;
409   mTb2s(1,3) = sa*cb;
410   mTb2s(2,1) = -ca*sb;
411   mTb2s(2,2) = cb;
412   mTb2s(2,3) = -sa*sb;
413   mTb2s(3,1) = -sa;
414   mTb2s(3,2) = 0.0;
415   mTb2s(3,3) = ca;
416
417   return mTb2s;
418 }
419
420 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421
422 void FGState::ReportState(void)
423 {
424 #if !defined(__BORLANDCPP__)
425   char out[80], flap[10], gear[12];
426   
427   cout << endl << "  JSBSim State" << endl;
428   snprintf(out,80,"    Weight: %7.0f lbs.  CG: %5.1f, %5.1f, %5.1f inches\n",
429                    FDMExec->GetMassBalance()->GetWeight(),
430                    FDMExec->GetMassBalance()->GetXYZcg(1),
431                    FDMExec->GetMassBalance()->GetXYZcg(2),
432                    FDMExec->GetMassBalance()->GetXYZcg(3));
433   cout << out;             
434   if ( FCS->GetDfPos() <= 0.01)
435     snprintf(flap,10,"Up");
436   else
437     snprintf(flap,10,"%2.0f",FCS->GetDfPos());
438
439   if (FCS->GetGearPos() < 0.01)
440     snprintf(gear,12,"Up");
441   else if (FCS->GetGearPos() > 0.99)
442     snprintf(gear,12,"Down");
443   else
444     snprintf(gear,12,"In Transit");
445
446   snprintf(out,80, "    Flaps: %3s  Gear: %12s\n",flap,gear);
447   cout << out;
448   snprintf(out,80, "    Speed: %4.0f KCAS  Mach: %5.2f\n",
449                     FDMExec->GetAuxiliary()->GetVcalibratedKTS(),
450                     Translation->GetMach() );
451   cout << out;
452   snprintf(out,80, "    Altitude: %7.0f ft.  AGL Altitude: %7.0f ft.\n",
453                     Position->Geth(),
454                     Position->GetDistanceAGL() );
455   cout << out;
456   snprintf(out,80, "    Angle of Attack: %6.2f deg  Pitch Angle: %6.2f deg\n",
457                     Translation->Getalpha()*radtodeg,
458                     Rotation->Gettht()*radtodeg );
459   cout << out;
460   snprintf(out,80, "    Flight Path Angle: %6.2f deg  Climb Rate: %5.0f ft/min\n",
461                     Position->GetGamma()*radtodeg,
462                     Position->Gethdot()*60 );
463   cout << out;                  
464   snprintf(out,80, "    Normal Load Factor: %4.2f g's  Pitch Rate: %5.2f deg/s\n",
465                     Aircraft->GetNlf(),
466                     Rotation->GetPQR(2)*radtodeg );
467   cout << out;
468   snprintf(out,80, "    Heading: %3.0f deg true  Sideslip: %5.2f deg  Yaw Rate: %5.2f deg/s\n",
469                     Rotation->Getpsi()*radtodeg,
470                     Translation->Getbeta()*radtodeg,
471                     Rotation->GetPQR(3)*radtodeg  );                  
472   cout << out;
473   snprintf(out,80, "    Bank Angle: %5.2f deg  Roll Rate: %5.2f deg/s\n",
474                     Rotation->Getphi()*radtodeg, 
475                     Rotation->GetPQR(1)*radtodeg );
476   cout << out;
477   snprintf(out,80, "    Elevator: %5.2f deg  Left Aileron: %5.2f deg  Rudder: %5.2f deg\n",
478                     FCS->GetDePos(ofRad)*radtodeg,
479                     FCS->GetDaLPos(ofRad)*radtodeg,
480                     FCS->GetDrPos(ofRad)*radtodeg );
481   cout << out;                  
482   snprintf(out,80, "    Throttle: %5.2f%c\n",
483                     FCS->GetThrottlePos(0)*100,'%' );
484   cout << out;
485   
486   snprintf(out,80, "    Wind Components: %5.2f kts head wind, %5.2f kts cross wind\n",
487                     FDMExec->GetAuxiliary()->GetHeadWind()*fpstokts,
488                     FDMExec->GetAuxiliary()->GetCrossWind()*fpstokts );
489   cout << out; 
490   
491   snprintf(out,80, "    Ground Speed: %4.0f knots , Ground Track: %3.0f deg true\n",
492                     Position->GetVground()*fpstokts,
493                     Position->GetGroundTrack()*radtodeg );
494   cout << out;                                   
495 #endif
496
497
498 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
499
500 void FGState::InitPropertyMaps(void)
501 {
502   ParamNameToProp[  "FG_TIME" ]="sim-time-sec";
503   ParamNameToProp[  "FG_QBAR" ]="aero/qbar-psf";
504   ParamNameToProp[  "FG_WINGAREA" ]="metrics/Sw-sqft";
505   ParamNameToProp[  "FG_WINGSPAN" ]="metrics/bw-ft";
506   ParamNameToProp[  "FG_CBAR" ]="metrics/cbarw-ft";
507   ParamNameToProp[  "FG_ALPHA" ]="aero/alpha-rad";
508   ParamNameToProp[  "FG_ALPHADOT" ]="aero/alphadot-rad_sec";
509   ParamNameToProp[  "FG_BETA" ]="aero/beta-rad";
510   ParamNameToProp[  "FG_ABETA" ]="aero/mag-beta-rad";
511   ParamNameToProp[  "FG_BETADOT" ]="aero/betadot-rad_sec";
512   ParamNameToProp[  "FG_PHI" ]="attitude/phi-rad";
513   ParamNameToProp[  "FG_THT" ]="attitude/theta-rad";
514   ParamNameToProp[  "FG_PSI" ]="attitude/psi-true-rad";
515   ParamNameToProp[  "FG_PITCHRATE" ]="velocities/q-rad_sec";
516   ParamNameToProp[  "FG_ROLLRATE" ]="velocities/p-rad_sec";
517   ParamNameToProp[  "FG_YAWRATE" ]="velocities/r-rad_sec";
518   ParamNameToProp[  "FG_AEROP" ]="velocities/p-aero-rad_sec";
519   ParamNameToProp[  "FG_AEROQ" ]="velocities/q-aero-rad_sec";
520   ParamNameToProp[  "FG_AEROR" ]="velocities/r-aero-rad_sec";
521   ParamNameToProp[  "FG_CL_SQRD" ]="aero/cl-squared-norm";
522   ParamNameToProp[  "FG_MACH" ]="velocities/mach-norm";
523   ParamNameToProp[  "FG_ALTITUDE" ]="position/h-sl-ft";
524   ParamNameToProp[  "FG_BI2VEL" ]="aero/bi2vel";
525   ParamNameToProp[  "FG_CI2VEL" ]="aero/ci2vel";
526   ParamNameToProp[  "FG_ELEVATOR_POS" ]="fcs/elevator-pos-rad";
527   ParamNameToProp[  "FG_AELEVATOR_POS" ]="fcs/mag-elevator-pos-rad";
528   ParamNameToProp[  "FG_NELEVATOR_POS" ]="fcs/elevator-pos-norm";
529   ParamNameToProp[  "FG_AILERON_POS" ]="fcs/left-aileron-pos-rad";
530   ParamNameToProp[  "FG_AAILERON_POS" ]="fcs/mag-aileron-pos-rad";
531   ParamNameToProp[  "FG_NAILERON_POS" ]="fcs/left-aileron-pos-norm";
532   ParamNameToProp[  "FG_LEFT_AILERON_POS" ]="fcs/left-aileron-pos-rad";
533   ParamNameToProp[  "FG_ALEFT_AILERON_POS" ]="fcs/mag-left-aileron-pos-rad";
534   ParamNameToProp[  "FG_NLEFT_AILERON_POS" ]="fcs/left-aileron-pos-norm";
535   ParamNameToProp[  "FG_RIGHT_AILERON_POS" ]="fcs/right-aileron-pos-rad";
536   ParamNameToProp[  "FG_ARIGHT_AILERON_POS" ]="fcs/mag-aileron-pos-rad";
537   ParamNameToProp[  "FG_NRIGHT_AILERON_POS" ]="fcs/right-aileron-pos-norm";
538   ParamNameToProp[  "FG_RUDDER_POS" ]="fcs/rudder-pos-rad";
539   ParamNameToProp[  "FG_ARUDDER_POS" ]="fcs/mag-rudder-pos-rad";
540   ParamNameToProp[  "FG_NRUDDER_POS" ]="fcs/rudder-pos-norm";
541   ParamNameToProp[  "FG_SPDBRAKE_POS" ]="fcs/speedbrake-pos-rad";
542   ParamNameToProp[  "FG_NSPDBRAKE_POS" ]="fcs/speedbrake-pos-norm";
543   ParamNameToProp[  "FG_SPOILERS_POS" ]="fcs/spoiler-pos-rad";
544   ParamNameToProp[  "FG_NSPOILERS_POS" ]="fcs/spoiler-pos-norm";
545   ParamNameToProp[  "FG_FLAPS_POS" ]="fcs/flap-pos-deg";
546   ParamNameToProp[  "FG_NFLAPS_POS" ]="fcs/flap-pos-norm";
547   ParamNameToProp[  "FG_ELEVATOR_CMD" ]="fcs/elevator-cmd-norm";
548   ParamNameToProp[  "FG_AILERON_CMD" ]="fcs/aileron-cmd-norm";
549   ParamNameToProp[  "FG_RUDDER_CMD" ]="fcs/rudder-cmd-norm";
550   ParamNameToProp[  "FG_SPDBRAKE_CMD" ]="fcs/speedbrake-cmd-norm";
551   ParamNameToProp[  "FG_SPOILERS_CMD" ]="fcs/spoiler-cmd-norm";
552   ParamNameToProp[  "FG_FLAPS_CMD" ]="fcs/flap-cmd-norm";
553   ParamNameToProp[  "FG_THROTTLE_CMD" ]="fcs/throttle-cmd-norm";
554   ParamNameToProp[  "FG_THROTTLE_POS" ]="fcs/throttle-pos-norm";
555   ParamNameToProp[  "FG_MIXTURE_CMD" ]="fcs/mixture-cmd-norm";
556   ParamNameToProp[  "FG_MIXTURE_POS" ]="fcs/mixture-pos-norm";
557   ParamNameToProp[  "FG_MAGNETO_CMD" ]="zero";
558   ParamNameToProp[  "FG_STARTER_CMD" ]="zero";
559   ParamNameToProp[  "FG_ACTIVE_ENGINE" ]="zero";
560   ParamNameToProp[  "FG_HOVERB" ]="aero/h_b-mac-ft";
561   ParamNameToProp[  "FG_PITCH_TRIM_CMD" ]="fcs/pitch-trim-cmd-norm";
562   ParamNameToProp[  "FG_YAW_TRIM_CMD" ]="fcs/yaw-trim-cmd-norm";
563   ParamNameToProp[  "FG_ROLL_TRIM_CMD" ]="fcs/roll-trim-cmd-norm";
564   ParamNameToProp[  "FG_LEFT_BRAKE_CMD" ]="zero";
565   ParamNameToProp[  "FG_CENTER_BRAKE_CMD" ]="zero";
566   ParamNameToProp[  "FG_RIGHT_BRAKE_CMD" ]="zero";
567   ParamNameToProp[  "FG_SET_LOGGING" ]="zero";
568   ParamNameToProp[  "FG_ALPHAH" ]="aero/alpha-rad";
569   ParamNameToProp[  "FG_ALPHAW" ]="aero/alpha-wing-rad";
570   ParamNameToProp[  "FG_LBARH" ]="metrics/lh-norm";     
571   ParamNameToProp[  "FG_LBARV" ]="metrics/lv-norm";     
572   ParamNameToProp[  "FG_HTAILAREA" ]="metrics/Sh-sqft";
573   ParamNameToProp[  "FG_VTAILAREA" ]="metrics/Sv-sqft";
574   ParamNameToProp[  "FG_VBARH" ]="metrics/vbarh-norm";    
575   ParamNameToProp[  "FG_VBARV" ]="metrics/vbarv-norm";     
576   ParamNameToProp[  "FG_GEAR_CMD" ]="gear/gear-cmd-norm";
577   ParamNameToProp[  "FG_GEAR_POS" ]="gear/gear-pos-norm";
578   ParamNameToProp[  "FG_HYSTPARM" ]="aero/stall-hyst-norm";
579 }
580
581 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582
583 void FGState::bind(void)
584 {
585   PropertyManager->Tie("sim-time-sec",this,
586                         &FGState::Getsim_time);
587 }
588
589 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
590                         
591 void FGState::unbind(void)
592 {
593   PropertyManager->Untie("sim-time-sec");
594 }
595
596 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
597 //    The bitmasked value choices are as follows:
598 //    unset: In this case (the default) JSBSim would only print
599 //       out the normally expected messages, essentially echoing
600 //       the config files as they are read. If the environment
601 //       variable is not set, debug_lvl is set to 1 internally
602 //    0: This requests JSBSim not to output any messages
603 //       whatsoever.
604 //    1: This value explicity requests the normal JSBSim
605 //       startup messages
606 //    2: This value asks for a message to be printed out when
607 //       a class is instantiated
608 //    4: When this value is set, a message is displayed when a
609 //       FGModel object executes its Run() method
610 //    8: When this value is set, various runtime state variables
611 //       are printed out periodically
612 //    16: When set various parameters are sanity checked and
613 //       a message is printed out when they go out of bounds
614
615 void FGState::Debug(int from)
616 {
617   if (debug_lvl <= 0) return;
618
619   if (debug_lvl & 1) { // Standard console startup message output
620     if (from == 0) { // Constructor
621
622     }
623   }
624   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
625     if (from == 0) cout << "Instantiated: FGState" << endl;
626     if (from == 1) cout << "Destroyed:    FGState" << endl;
627   }
628   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
629   }
630   if (debug_lvl & 8 ) { // Runtime state variables
631   }
632   if (debug_lvl & 16) { // Sanity checking
633   }
634   if (debug_lvl & 64) {
635     if (from == 0) { // Constructor
636       cout << IdSrc << endl;
637       cout << IdHdr << endl;
638     }
639   }
640 }
641