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