1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Called by: FGFDMExec and accessed by all models.
8 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
24 Further information about the GNU General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
32 --------------------------------------------------------------------------------
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 # include <simgear/compiler.h>
43 # if defined(sgi) && !defined(__GNUC__)
50 #if defined(_MSC_VER)||defined(__BORLANDCPP__)
51 #pragma message("\n\nRedefining snprintf\n")
52 #define snprintf _snprintf
57 static const char *IdSrc = "$Id$";
58 static const char *IdHdr = ID_STATE;
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64 #define RegisterVariable(ID,DEF) coeffdef[#ID] = ID; paramdef[ID] = DEF
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
77 FGState::FGState(FGFDMExec* fdex)
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();
100 RegisterVariable(FG_TIME, " time " );
101 RegisterVariable(FG_QBAR, " qbar " );
102 RegisterVariable(FG_WINGAREA, " wing_area " );
103 RegisterVariable(FG_WINGSPAN, " wingspan " );
104 RegisterVariable(FG_CBAR, " cbar " );
105 RegisterVariable(FG_ALPHA, " alpha " );
106 RegisterVariable(FG_ALPHADOT, " alphadot " );
107 RegisterVariable(FG_BETA, " beta " );
108 RegisterVariable(FG_ABETA, " |beta| " );
109 RegisterVariable(FG_BETADOT, " betadot " );
110 RegisterVariable(FG_PHI, " roll_angle " );
111 RegisterVariable(FG_THT, " pitch_angle " );
112 RegisterVariable(FG_PSI, " heading_angle " );
113 RegisterVariable(FG_PITCHRATE, " pitch_rate " );
114 RegisterVariable(FG_ROLLRATE, " roll_rate " );
115 RegisterVariable(FG_YAWRATE, " yaw_rate " );
116 RegisterVariable(FG_AEROQ, " aero_pitch_rate " );
117 RegisterVariable(FG_AEROP, " aero_roll_rate " );
118 RegisterVariable(FG_AEROR, " aero_yaw_rate " );
119 RegisterVariable(FG_CL_SQRD, " Clift_sqrd " );
120 RegisterVariable(FG_MACH, " mach " );
121 RegisterVariable(FG_ALTITUDE, " altitude " );
122 RegisterVariable(FG_BI2VEL, " BI2Vel " );
123 RegisterVariable(FG_CI2VEL, " CI2Vel " );
124 RegisterVariable(FG_ELEVATOR_POS, " elevator_pos " );
125 RegisterVariable(FG_AELEVATOR_POS, " |elevator_pos| " );
126 RegisterVariable(FG_NELEVATOR_POS, " elevator_pos_n " );
127 RegisterVariable(FG_AILERON_POS, " aileron_pos " );
128 RegisterVariable(FG_AAILERON_POS, " |aileron_pos| " );
129 RegisterVariable(FG_NAILERON_POS, " aileron_pos_n " );
130 RegisterVariable(FG_LEFT_AILERON_POS, " left_aileron_pos " );
131 RegisterVariable(FG_ALEFT_AILERON_POS, " |left_aileron_pos| " );
132 RegisterVariable(FG_NLEFT_AILERON_POS, " left_aileron_pos_n " );
133 RegisterVariable(FG_RIGHT_AILERON_POS, " right_aileron_pos " );
134 RegisterVariable(FG_ARIGHT_AILERON_POS, " |right_aileron_pos| " );
135 RegisterVariable(FG_NRIGHT_AILERON_POS, " right_aileron_pos_n " );
136 RegisterVariable(FG_RUDDER_POS, " rudder_pos " );
137 RegisterVariable(FG_ARUDDER_POS, " |rudder_pos| " );
138 RegisterVariable(FG_NRUDDER_POS, " rudder_pos_n " );
139 RegisterVariable(FG_SPDBRAKE_POS, " speedbrake_pos " );
140 RegisterVariable(FG_NSPDBRAKE_POS, " speedbrake_pos_n " );
141 RegisterVariable(FG_SPOILERS_POS, " spoiler_pos " );
142 RegisterVariable(FG_NSPOILERS_POS, " spoiler_pos_n " );
143 RegisterVariable(FG_FLAPS_POS, " flaps_pos " );
144 RegisterVariable(FG_NFLAPS_POS, " flaps_pos_n " );
145 RegisterVariable(FG_GEAR_POS, " gear_pos " );
146 RegisterVariable(FG_ELEVATOR_CMD, " elevator_cmd " );
147 RegisterVariable(FG_AILERON_CMD, " aileron_cmd " );
148 RegisterVariable(FG_RUDDER_CMD, " rudder_cmd " );
149 RegisterVariable(FG_SPDBRAKE_CMD, " speedbrake_cmd " );
150 RegisterVariable(FG_SPOILERS_CMD, " spoiler_cmd " );
151 RegisterVariable(FG_FLAPS_CMD, " flaps_cmd " );
152 RegisterVariable(FG_THROTTLE_CMD, " throttle_cmd " );
153 RegisterVariable(FG_GEAR_CMD, " gear_cmd " );
154 RegisterVariable(FG_THROTTLE_POS, " throttle_pos " );
155 RegisterVariable(FG_MIXTURE_CMD, " mixture_cmd " );
156 RegisterVariable(FG_MIXTURE_POS, " mixture_pos " );
157 RegisterVariable(FG_MAGNETO_CMD, " magneto_cmd " );
158 RegisterVariable(FG_STARTER_CMD, " starter_cmd " );
159 RegisterVariable(FG_ACTIVE_ENGINE, " active_engine " );
160 RegisterVariable(FG_HOVERB, " height/span " );
161 RegisterVariable(FG_PITCH_TRIM_CMD, " pitch_trim_cmd " );
162 RegisterVariable(FG_YAW_TRIM_CMD, " yaw_trim_cmd " );
163 RegisterVariable(FG_ROLL_TRIM_CMD, " roll_trim_cmd " );
164 RegisterVariable(FG_LEFT_BRAKE_CMD, " left_brake_cmd " );
165 RegisterVariable(FG_RIGHT_BRAKE_CMD, " right_brake_cmd " );
166 RegisterVariable(FG_CENTER_BRAKE_CMD, " center_brake_cmd " );
167 RegisterVariable(FG_ALPHAH, " h-tail alpha " );
168 RegisterVariable(FG_ALPHAW, " wing alpha " );
169 RegisterVariable(FG_LBARH, " h-tail arm " );
170 RegisterVariable(FG_LBARV, " v-tail arm " );
171 RegisterVariable(FG_HTAILAREA, " h-tail area " );
172 RegisterVariable(FG_VTAILAREA, " v-tail area " );
173 RegisterVariable(FG_VBARH, " h-tail volume " );
174 RegisterVariable(FG_VBARV, " v-tail volume " );
175 RegisterVariable(FG_SET_LOGGING, " data_logging " );
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192 double FGState::GetParameter(eParam val_idx) {
199 return Translation->Getqbar();
201 return Aircraft->GetWingArea();
203 return Aircraft->GetWingSpan();
205 return Aircraft->Getcbar();
207 return Aircraft->Getlbarh();
209 return Aircraft->Getvbarh();
211 return Aircraft->GetHTailArea();
213 return Aircraft->GetVTailArea();
215 return Aircraft->Getvbarh();
217 return Aircraft->Getvbarv();
219 return Translation->Getalpha();
221 return Translation->Getalpha() + Aircraft->GetWingIncidence();
223 return Translation->Getadot();
225 return Translation->Getbeta();
227 return fabs(Translation->Getbeta());
229 return Translation->Getbdot();
231 return Rotation->Getphi();
233 return Rotation->Gettht();
235 return Rotation->Getpsi();
237 return Rotation->GetPQR(eQ);
239 return Rotation->GetPQR(eP);
241 return Rotation->GetPQR(eR);
243 return Rotation->GetAeroPQR(eP);
245 return Rotation->GetAeroPQR(eQ);
247 return Rotation->GetAeroPQR(eR);
249 if (Translation->Getqbar() > 0.00)
250 scratch = Aerodynamics->GetvLastFs(eLift)/(Aircraft->GetWingArea()*Translation->Getqbar());
253 return scratch*scratch;
254 case FG_ELEVATOR_POS:
255 return FCS->GetDePos();
256 case FG_AELEVATOR_POS:
257 return fabs(FCS->GetDePos());
258 case FG_NELEVATOR_POS:
259 return FCS->GetDePos(ofNorm);
261 return FCS->GetDaLPos();
262 case FG_AAILERON_POS:
263 return fabs(FCS->GetDaLPos());
264 case FG_NAILERON_POS:
265 return FCS->GetDaLPos(ofNorm);
266 case FG_LEFT_AILERON_POS:
267 return FCS->GetDaLPos();
268 case FG_ALEFT_AILERON_POS:
269 return FCS->GetDaLPos(ofMag);
270 case FG_NLEFT_AILERON_POS:
271 return FCS->GetDaLPos(ofNorm);
272 case FG_RIGHT_AILERON_POS:
273 return FCS->GetDaRPos();
274 case FG_ARIGHT_AILERON_POS:
275 return FCS->GetDaRPos(ofMag);
276 case FG_NRIGHT_AILERON_POS:
277 return FCS->GetDaRPos(ofNorm);
279 return FCS->GetDrPos();
281 return FCS->GetDrPos(ofMag);
283 return FCS->GetDrPos(ofNorm);
284 case FG_SPDBRAKE_POS:
285 return FCS->GetDsbPos();
286 case FG_NSPDBRAKE_POS:
287 return FCS->GetDsbPos(ofNorm);
288 case FG_SPOILERS_POS:
289 return FCS->GetDspPos();
290 case FG_NSPOILERS_POS:
291 return FCS->GetDspPos(ofNorm);
293 return FCS->GetDfPos();
295 return FCS->GetDfPos(ofNorm);
296 case FG_ELEVATOR_CMD:
297 return FCS->GetDeCmd();
299 return FCS->GetDaCmd();
301 return FCS->GetDrCmd();
302 case FG_SPDBRAKE_CMD:
303 return FCS->GetDsbCmd();
304 case FG_SPOILERS_CMD:
305 return FCS->GetDspCmd();
307 return FCS->GetDfCmd();
309 return Translation->GetMach();
311 return Position->Geth();
313 if(Translation->GetVt() > 0)
314 return Aircraft->GetWingSpan()/(2.0 * Translation->GetVt());
318 if(Translation->GetVt() > 0)
319 return Aircraft->Getcbar()/(2.0 * Translation->GetVt());
322 case FG_THROTTLE_CMD:
323 if (ActiveEngine < 0) return FCS->GetThrottleCmd(0);
324 else return FCS->GetThrottleCmd(ActiveEngine);
325 case FG_THROTTLE_POS:
326 if (ActiveEngine < 0) return FCS->GetThrottlePos(0);
327 else return FCS->GetThrottlePos(ActiveEngine);
329 if (ActiveEngine < 0) return Propulsion->GetEngine(0)->GetMagnetos();
330 else return Propulsion->GetEngine(ActiveEngine)->GetMagnetos();
332 if (ActiveEngine < 0) {
333 if (Propulsion->GetEngine(0)->GetStarter()) return 1.0;
336 if (Propulsion->GetEngine(ActiveEngine)->GetStarter()) return 1.0;
340 if (ActiveEngine < 0) return FCS->GetMixtureCmd(0);
341 else return FCS->GetMixtureCmd(ActiveEngine);
343 if (ActiveEngine < 0) return FCS->GetMixturePos(0);
344 else return FCS->GetMixturePos(ActiveEngine);
346 return Position->GetHOverBMAC();
347 case FG_PITCH_TRIM_CMD:
348 return FCS->GetPitchTrimCmd();
349 case FG_YAW_TRIM_CMD:
350 return FCS->GetYawTrimCmd();
351 case FG_ROLL_TRIM_CMD:
352 return FCS->GetRollTrimCmd();
354 return FCS->GetGearCmd();
356 return FCS->GetGearPos();
358 cerr << "FGState::GetParameter() - No handler for parameter " << paramdef[val_idx] << endl;
364 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
366 double FGState::GetParameter(string val_string) {
367 return GetParameter(coeffdef[val_string]);
370 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372 eParam FGState::GetParameterIndex(string val_string)
374 return coeffdef[val_string];
377 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 void FGState::SetParameter(eParam val_idx, double val)
384 case FG_ELEVATOR_POS:
385 FCS->SetDePos(ofRad,val);
387 case FG_NELEVATOR_POS:
388 FCS->SetDePos(ofNorm,val);
391 FCS->SetDaLPos(ofRad,val);
393 case FG_NAILERON_POS:
394 FCS->SetDaLPos(ofNorm,val);
396 case FG_LEFT_AILERON_POS:
397 FCS->SetDaLPos(ofRad,val);
399 case FG_NLEFT_AILERON_POS:
400 FCS->SetDaLPos(ofNorm,val);
402 case FG_RIGHT_AILERON_POS:
403 FCS->SetDaRPos(ofRad,val);
405 case FG_NRIGHT_AILERON_POS:
406 FCS->SetDaRPos(ofNorm,val);
409 FCS->SetDrPos(ofRad,val);
412 FCS->SetDrPos(ofNorm,val);
414 case FG_SPDBRAKE_POS:
415 FCS->SetDsbPos(ofRad,val);
417 case FG_NSPDBRAKE_POS:
418 FCS->SetDsbPos(ofNorm,val);
420 case FG_SPOILERS_POS:
421 FCS->SetDspPos(ofRad,val);
423 case FG_NSPOILERS_POS:
424 FCS->SetDspPos(ofNorm,val);
427 FCS->SetDfPos(ofRad,val);
430 FCS->SetDfPos(ofNorm,val);
432 case FG_THROTTLE_POS:
433 if (ActiveEngine == -1) {
434 for (i=0; i<Propulsion->GetNumEngines(); i++) {
435 FCS->SetThrottlePos(i,val);
438 FCS->SetThrottlePos(ActiveEngine,val);
442 if (ActiveEngine == -1) {
443 for (i=0; i<Propulsion->GetNumEngines(); i++) {
444 FCS->SetMixturePos(i,val);
447 FCS->SetMixturePos(ActiveEngine,val);
451 case FG_ELEVATOR_CMD:
460 case FG_SPDBRAKE_CMD:
463 case FG_SPOILERS_CMD:
469 case FG_THROTTLE_CMD:
470 if (ActiveEngine == -1) {
471 for (i=0; i<Propulsion->GetNumEngines(); i++) {
472 FCS->SetThrottleCmd(i,val);
475 FCS->SetThrottleCmd(ActiveEngine,val);
479 if (ActiveEngine == -1) {
480 for (i=0; i<Propulsion->GetNumEngines(); i++) {
481 FCS->SetMixtureCmd(i,val);
484 FCS->SetMixtureCmd(ActiveEngine,val);
488 if (ActiveEngine == -1) {
489 for (i=0; i<Propulsion->GetNumEngines(); i++) {
490 Propulsion->GetEngine(i)->SetMagnetos((int)val);
493 Propulsion->GetEngine(ActiveEngine)->SetMagnetos((int)val);
497 if (ActiveEngine == -1) {
498 for (i=0; i<Propulsion->GetNumEngines(); i++) {
500 Propulsion->GetEngine(i)->SetStarter(false);
501 else if (val >= 0.001)
502 Propulsion->GetEngine(i)->SetStarter(true);
505 Propulsion->GetEngine(ActiveEngine)->SetStarter(true);
508 case FG_ACTIVE_ENGINE:
509 ActiveEngine = (int)val;
512 case FG_LEFT_BRAKE_CMD:
515 case FG_CENTER_BRAKE_CMD:
518 case FG_RIGHT_BRAKE_CMD:
522 FCS->SetGearCmd(val);
525 FCS->SetGearPos(val);
528 if (val < -0.01) Output->Disable();
529 else if (val > 0.01) Output->Enable();
530 else Output->Toggle();
534 cerr << "Parameter '" << val_idx << "' (" << paramdef[val_idx] << ") not handled" << endl;
538 //***************************************************************************
540 // Reset: Assume all angles READ FROM FILE IN DEGREES !!
543 bool FGState::Reset(string path, string acname, string fname)
549 double phi, tht, psi;
550 double latitude, longitude, h;
551 double wdir, wmag, wnorth, weast;
554 resetDef = path + "/" + acname + "/" + fname + ".xml";
556 resetDef = path + ";" + acname + ";" + fname + ".xml";
559 FGConfigFile resetfile(resetDef);
560 if (!resetfile.IsOpen()) return false;
562 resetfile.GetNextConfigLine();
563 token = resetfile.GetValue();
564 if (token != string("initialize")) {
565 cerr << "The reset file " << resetDef
566 << " does not appear to be a reset file" << endl;
569 resetfile.GetNextConfigLine();
571 cout << "Resetting using: " << token << endl << endl;
574 while (token != string("/initialize") && token != string("EOF")) {
575 if (token == "UBODY") resetfile >> U;
576 if (token == "VBODY") resetfile >> V;
577 if (token == "WBODY") resetfile >> W;
578 if (token == "LATITUDE") resetfile >> latitude;
579 if (token == "LONGITUDE") resetfile >> longitude;
580 if (token == "PHI") resetfile >> phi;
581 if (token == "THETA") resetfile >> tht;
582 if (token == "PSI") resetfile >> psi;
583 if (token == "ALTITUDE") resetfile >> h;
584 if (token == "WINDDIR") resetfile >> wdir;
585 if (token == "VWIND") resetfile >> wmag;
591 Position->SetLatitude(latitude*degtorad);
592 Position->SetLongitude(longitude*degtorad);
595 wnorth = wmag*ktstofps*cos(wdir*degtorad);
596 weast = wmag*ktstofps*sin(wdir*degtorad);
598 Initialize(U, V, W, phi*degtorad, tht*degtorad, psi*degtorad,
599 latitude*degtorad, longitude*degtorad, h, wnorth, weast, 0.0);
604 //***************************************************************************
606 // Initialize: Assume all angles GIVEN IN RADIANS !!
609 void FGState::Initialize(double U, double V, double W,
610 double phi, double tht, double psi,
611 double Latitude, double Longitude, double H,
612 double wnorth, double weast, double wdown)
616 FGColumnVector3 vAeroUVW;
618 Position->SetLatitude(Latitude);
619 Position->SetLongitude(Longitude);
624 vLocalEuler << phi << tht << psi;
625 Rotation->SetEuler(vLocalEuler);
627 InitMatrices(phi, tht, psi);
630 Translation->SetUVW(vUVW);
632 Atmosphere->SetWindNED(wnorth, weast, wdown);
634 vAeroUVW = vUVW + mTl2b*Atmosphere->GetWindNED();
636 if (vAeroUVW(eW) != 0.0)
637 alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
640 if (vAeroUVW(eV) != 0.0)
641 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;
645 Translation->SetAB(alpha, beta);
647 Vt = sqrt(U*U + V*V + W*W);
648 Translation->SetVt(Vt);
650 Translation->SetMach(Vt/Atmosphere->GetSoundSpeed());
652 qbar = 0.5*(U*U + V*V + W*W)*Atmosphere->GetDensity();
653 Translation->Setqbar(qbar);
655 vLocalVelNED = mTb2l*vUVW;
656 Position->SetvVel(vLocalVelNED);
659 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
661 void FGState::Initialize(FGInitialCondition *FGIC) {
665 double latitude, longitude;
666 double wnorth,weast, wdown;
668 latitude = FGIC->GetLatitudeRadIC();
669 longitude = FGIC->GetLongitudeRadIC();
670 h = FGIC->GetAltitudeFtIC();
671 U = FGIC->GetUBodyFpsIC();
672 V = FGIC->GetVBodyFpsIC();
673 W = FGIC->GetWBodyFpsIC();
674 tht = FGIC->GetThetaRadIC();
675 phi = FGIC->GetPhiRadIC();
676 psi = FGIC->GetPsiRadIC();
677 wnorth = FGIC->GetWindNFpsIC();
678 weast = FGIC->GetWindEFpsIC();
679 wdown = FGIC->GetWindDFpsIC();
681 Position->SetSeaLevelRadius( FGIC->GetSeaLevelRadiusFtIC() );
682 Position->SetRunwayRadius( FGIC->GetSeaLevelRadiusFtIC() +
683 FGIC->GetTerrainAltitudeFtIC() );
685 // need to fix the wind speed args, here.
686 Initialize(U, V, W, phi, tht, psi, latitude, longitude, h, wnorth, weast, wdown);
689 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691 bool FGState::StoreData(string fname) {
692 ofstream datafile(fname.c_str());
695 datafile << Translation->GetUVW(eU);
696 datafile << Translation->GetUVW(eV);
697 datafile << Translation->GetUVW(eW);
698 datafile << Position->GetLatitude();
699 datafile << Position->GetLongitude();
700 datafile << Rotation->GetEuler(ePhi);
701 datafile << Rotation->GetEuler(eTht);
702 datafile << Rotation->GetEuler(ePsi);
703 datafile << Position->Geth();
707 cerr << "Could not open dump file " << fname << endl;
712 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
714 void FGState::InitMatrices(double phi, double tht, double psi) {
715 double thtd2, psid2, phid2;
716 double Sthtd2, Spsid2, Sphid2;
717 double Cthtd2, Cpsid2, Cphid2;
735 Cphid2Cthtd2 = Cphid2*Cthtd2;
736 Cphid2Sthtd2 = Cphid2*Sthtd2;
737 Sphid2Sthtd2 = Sphid2*Sthtd2;
738 Sphid2Cthtd2 = Sphid2*Cthtd2;
740 vQtrn(1) = Cphid2Cthtd2*Cpsid2 + Sphid2Sthtd2*Spsid2;
741 vQtrn(2) = Sphid2Cthtd2*Cpsid2 - Cphid2Sthtd2*Spsid2;
742 vQtrn(3) = Cphid2Sthtd2*Cpsid2 + Sphid2Cthtd2*Spsid2;
743 vQtrn(4) = Cphid2Cthtd2*Spsid2 - Sphid2Sthtd2*Cpsid2;
748 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750 void FGState::CalcMatrices(void) {
751 double Q0Q0, Q1Q1, Q2Q2, Q3Q3;
752 double Q0Q1, Q0Q2, Q0Q3, Q1Q2;
755 Q0Q0 = vQtrn(1)*vQtrn(1);
756 Q1Q1 = vQtrn(2)*vQtrn(2);
757 Q2Q2 = vQtrn(3)*vQtrn(3);
758 Q3Q3 = vQtrn(4)*vQtrn(4);
759 Q0Q1 = vQtrn(1)*vQtrn(2);
760 Q0Q2 = vQtrn(1)*vQtrn(3);
761 Q0Q3 = vQtrn(1)*vQtrn(4);
762 Q1Q2 = vQtrn(2)*vQtrn(3);
763 Q1Q3 = vQtrn(2)*vQtrn(4);
764 Q2Q3 = vQtrn(3)*vQtrn(4);
766 mTl2b(1,1) = Q0Q0 + Q1Q1 - Q2Q2 - Q3Q3;
767 mTl2b(1,2) = 2*(Q1Q2 + Q0Q3);
768 mTl2b(1,3) = 2*(Q1Q3 - Q0Q2);
769 mTl2b(2,1) = 2*(Q1Q2 - Q0Q3);
770 mTl2b(2,2) = Q0Q0 - Q1Q1 + Q2Q2 - Q3Q3;
771 mTl2b(2,3) = 2*(Q2Q3 + Q0Q1);
772 mTl2b(3,1) = 2*(Q1Q3 + Q0Q2);
773 mTl2b(3,2) = 2*(Q2Q3 - Q0Q1);
774 mTl2b(3,3) = Q0Q0 - Q1Q1 - Q2Q2 + Q3Q3;
780 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782 void FGState::IntegrateQuat(FGColumnVector3 vPQR, int rate) {
783 vQdot(1) = -0.5*(vQtrn(2)*vPQR(eP) + vQtrn(3)*vPQR(eQ) + vQtrn(4)*vPQR(eR));
784 vQdot(2) = 0.5*(vQtrn(1)*vPQR(eP) + vQtrn(3)*vPQR(eR) - vQtrn(4)*vPQR(eQ));
785 vQdot(3) = 0.5*(vQtrn(1)*vPQR(eQ) + vQtrn(4)*vPQR(eP) - vQtrn(2)*vPQR(eR));
786 vQdot(4) = 0.5*(vQtrn(1)*vPQR(eR) + vQtrn(2)*vPQR(eQ) - vQtrn(3)*vPQR(eP));
787 vQtrn += 0.5*dt*rate*(vlastQdot + vQdot);
794 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
796 FGColumnVector3& FGState::CalcEuler(void) {
797 if (mTl2b(3,3) == 0.0) mTl2b(3,3) = 0.0000001;
798 if (mTl2b(1,1) == 0.0) mTl2b(1,1) = 0.0000001;
800 vEuler(ePhi) = atan2(mTl2b(2,3), mTl2b(3,3));
801 vEuler(eTht) = asin(-mTl2b(1,3));
802 vEuler(ePsi) = atan2(mTl2b(1,2), mTl2b(1,1));
804 if (vEuler(ePsi) < 0.0) vEuler(ePsi) += 2*M_PI;
809 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
811 FGMatrix33& FGState::GetTs2b(void)
813 double ca, cb, sa, sb;
815 double alpha = Translation->Getalpha();
816 double beta = Translation->Getbeta();
836 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838 FGMatrix33& FGState::GetTb2s(void)
841 float ca, cb, sa, sb;
843 alpha = Translation->Getalpha();
844 beta = Translation->Getbeta();
864 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
866 void FGState::ReportState(void)
868 #if !defined(__BORLANDCPP__)
869 char out[80], flap[10], gear[12];
871 cout << endl << " JSBSim State" << endl;
872 snprintf(out,80," Weight: %7.0f lbs. CG: %5.1f, %5.1f, %5.1f inches\n",
873 FDMExec->GetMassBalance()->GetWeight(),
874 FDMExec->GetMassBalance()->GetXYZcg(1),
875 FDMExec->GetMassBalance()->GetXYZcg(2),
876 FDMExec->GetMassBalance()->GetXYZcg(3));
878 if( FCS->GetDfPos() <= 0.01)
879 snprintf(flap,10,"Up");
881 snprintf(flap,10,"%2.0f",FCS->GetDfPos());
882 if(FCS->GetGearPos() < 0.01)
883 snprintf(gear,12,"Up");
884 else if(FCS->GetGearPos() > 0.99)
885 snprintf(gear,12,"Down");
887 snprintf(gear,12,"In Transit");
888 snprintf(out,80, " Flaps: %3s Gear: %12s\n",flap,gear);
890 snprintf(out,80, " Speed: %4.0f KCAS Mach: %5.2f\n",
891 FDMExec->GetAuxiliary()->GetVcalibratedKTS(),
892 GetParameter(FG_MACH) );
894 snprintf(out,80, " Altitude: %7.0f ft. AGL Altitude: %7.0f ft.\n",
896 Position->GetDistanceAGL() );
898 snprintf(out,80, " Angle of Attack: %6.2f deg Pitch Angle: %6.2f deg\n",
899 GetParameter(FG_ALPHA)*radtodeg,
900 Rotation->Gettht()*radtodeg );
902 snprintf(out,80, " Flight Path Angle: %6.2f deg Climb Rate: %5.0f ft/min\n",
903 Position->GetGamma()*radtodeg,
904 Position->Gethdot()*60 );
906 snprintf(out,80, " Normal Load Factor: %4.2f g's Pitch Rate: %5.2f deg/s\n",
908 GetParameter(FG_PITCHRATE)*radtodeg );
910 snprintf(out,80, " Heading: %3.0f deg true Sideslip: %5.2f deg Yaw Rate: %5.2f deg/s\n",
911 Rotation->Getpsi()*radtodeg,
912 GetParameter(FG_BETA)*radtodeg,
913 Rotation->GetPQR(3)*radtodeg );
915 snprintf(out,80, " Bank Angle: %5.2f deg Roll Rate: %5.2f deg/s\n",
916 Rotation->Getphi()*radtodeg,
917 Rotation->GetPQR(1)*radtodeg );
919 snprintf(out,80, " Elevator: %5.2f deg Left Aileron: %5.2f deg Rudder: %5.2f deg\n",
920 GetParameter(FG_ELEVATOR_POS)*radtodeg,
921 GetParameter(FG_AILERON_POS)*radtodeg,
922 GetParameter(FG_RUDDER_POS)*radtodeg );
924 snprintf(out,80, " Throttle: %5.2f%c\n",
925 FCS->GetThrottlePos(0)*100,'%' );
928 snprintf(out,80, " Wind Components: %5.2f kts head wind, %5.2f kts cross wind\n",
929 FDMExec->GetAuxiliary()->GetHeadWind()*fpstokts,
930 FDMExec->GetAuxiliary()->GetCrossWind()*fpstokts );
933 snprintf(out,80, " Ground Speed: %4.0f knots , Ground Track: %3.0f deg true\n",
934 Position->GetVground()*fpstokts,
935 Position->GetGroundTrack()*radtodeg );
940 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
942 void FGState::InitPropertyMaps(void) {
943 ParamToProp[ FG_TIME ]="sim-time-sec";
944 ParamToProp[ FG_QBAR ]="aero/qbar-psf";
945 ParamToProp[ FG_WINGAREA ]="metrics/Sw-sqft";
946 ParamToProp[ FG_WINGSPAN ]="metrics/bw-ft";
947 ParamToProp[ FG_CBAR ]="metrics/cbarw-ft";
948 ParamToProp[ FG_ALPHA ]="aero/alpha-rad";
949 ParamToProp[ FG_ALPHADOT ]="aero/alphadot-rad_sec";
950 ParamToProp[ FG_BETA ]="aero/beta-rad";
951 ParamToProp[ FG_ABETA ]="aero/mag-beta-rad";
952 ParamToProp[ FG_BETADOT ]="aero/betadot-rad_sec";
953 ParamToProp[ FG_PHI ]="attitude/phi-rad";
954 ParamToProp[ FG_THT ]="attitude/theta-rad";
955 ParamToProp[ FG_PSI ]="attitude/psi-true-rad";
956 ParamToProp[ FG_PITCHRATE ]="velocities/q-rad_sec";
957 ParamToProp[ FG_ROLLRATE ]="velocities/p-rad_sec";
958 ParamToProp[ FG_YAWRATE ]="velocities/r-rad_sec";
959 ParamToProp[ FG_AEROP ]="velocities/p-aero-rad_sec";
960 ParamToProp[ FG_AEROQ ]="velocities/q-aero-rad_sec";
961 ParamToProp[ FG_AEROR ]="velocities/r-aero-rad_sec";
962 ParamToProp[ FG_CL_SQRD ]="aero/cl-squared-norm";
963 ParamToProp[ FG_MACH ]="velocities/mach-norm";
964 ParamToProp[ FG_ALTITUDE ]="position/h-sl-ft";
965 ParamToProp[ FG_BI2VEL ]="aero/bi2vel";
966 ParamToProp[ FG_CI2VEL ]="aero/ci2vel";
967 ParamToProp[ FG_ELEVATOR_POS ]="fcs/elevator-pos-rad";
968 ParamToProp[ FG_AELEVATOR_POS ]="fcs/mag-elevator-pos-rad";
969 ParamToProp[ FG_NELEVATOR_POS ]="fcs/elevator-pos-norm";
970 ParamToProp[ FG_AILERON_POS ]="fcs/left-aileron-pos-rad";
971 ParamToProp[ FG_AAILERON_POS ]="fcs/mag-aileron-pos-rad";
972 ParamToProp[ FG_NAILERON_POS ]="fcs/left-aileron-pos-norm";
973 ParamToProp[ FG_LEFT_AILERON_POS ]="fcs/left-aileron-pos-rad";
974 ParamToProp[ FG_ALEFT_AILERON_POS ]="fcs/mag-left-aileron-pos-rad";
975 ParamToProp[ FG_NLEFT_AILERON_POS ]="fcs/left-aileron-pos-norm";
976 ParamToProp[ FG_RIGHT_AILERON_POS ]="fcs/right-aileron-pos-rad";
977 ParamToProp[ FG_ARIGHT_AILERON_POS ]="fcs/mag-aileron-pos-rad";
978 ParamToProp[ FG_NRIGHT_AILERON_POS ]="fcs/right-aileron-pos-norm";
979 ParamToProp[ FG_RUDDER_POS ]="fcs/rudder-pos-rad";
980 ParamToProp[ FG_ARUDDER_POS ]="fcs/mag-rudder-pos-rad";
981 ParamToProp[ FG_NRUDDER_POS ]="fcs/rudder-pos-norm";
982 ParamToProp[ FG_SPDBRAKE_POS ]="fcs/speedbrake-pos-rad";
983 ParamToProp[ FG_NSPDBRAKE_POS ]="fcs/speedbrake-pos-norm";
984 ParamToProp[ FG_SPOILERS_POS ]="fcs/spoiler-pos-rad";
985 ParamToProp[ FG_NSPOILERS_POS ]="fcs/spoiler-pos-norm";
986 ParamToProp[ FG_FLAPS_POS ]="fcs/flap-pos-deg";
987 ParamToProp[ FG_NFLAPS_POS ]="fcs/flap-pos-norm";
988 ParamToProp[ FG_ELEVATOR_CMD ]="fcs/elevator-cmd-norm";
989 ParamToProp[ FG_AILERON_CMD ]="fcs/aileron-cmd-norm";
990 ParamToProp[ FG_RUDDER_CMD ]="fcs/rudder-cmd-norm";
991 ParamToProp[ FG_SPDBRAKE_CMD ]="fcs/speedbrake-cmd-norm";
992 ParamToProp[ FG_SPOILERS_CMD ]="fcs/spoiler-cmd-norm";
993 ParamToProp[ FG_FLAPS_CMD ]="fcs/flap-cmd-norm";
994 ParamToProp[ FG_THROTTLE_CMD ]="zero";
995 ParamToProp[ FG_THROTTLE_POS ]="zero";
996 ParamToProp[ FG_MIXTURE_CMD ]="zero";
997 ParamToProp[ FG_MIXTURE_POS ]="zero";
998 ParamToProp[ FG_MAGNETO_CMD ]="zero";
999 ParamToProp[ FG_STARTER_CMD ]="zero";
1000 ParamToProp[ FG_ACTIVE_ENGINE ]="zero";
1001 ParamToProp[ FG_HOVERB ]="position/h_b-mac-ft";
1002 ParamToProp[ FG_PITCH_TRIM_CMD ]="fcs/pitch-trim-cmd-norm";
1003 ParamToProp[ FG_YAW_TRIM_CMD ]="fcs/yaw-trim-cmd-norm";
1004 ParamToProp[ FG_ROLL_TRIM_CMD ]="fcs/roll-trim-cmd-norm";
1005 ParamToProp[ FG_LEFT_BRAKE_CMD ]="zero";
1006 ParamToProp[ FG_CENTER_BRAKE_CMD ]="zero";
1007 ParamToProp[ FG_RIGHT_BRAKE_CMD ]="zero";
1008 ParamToProp[ FG_SET_LOGGING ]="zero";
1009 ParamToProp[ FG_ALPHAH ]="aero/alpha-rad";
1010 ParamToProp[ FG_ALPHAW ]="aero/alpha-wing-rad";
1011 ParamToProp[ FG_LBARH ]="metrics/lh-norm";
1012 ParamToProp[ FG_LBARV ]="metrics/lv-norm";
1013 ParamToProp[ FG_HTAILAREA ]="metrics/Sh-sqft";
1014 ParamToProp[ FG_VTAILAREA ]="metrics/Sv-sqft";
1015 ParamToProp[ FG_VBARH ]="metrics/vbarh-norm";
1016 ParamToProp[ FG_VBARV ]="metrics/vbarv-norm";
1017 ParamToProp[ FG_GEAR_CMD ]="gear/gear-cmd-norm";
1018 ParamToProp[ FG_GEAR_POS ]="gear/gear-pos-norm";
1020 PropToParam[ "sim-time-sec" ] = FG_TIME;
1021 PropToParam[ "aero/qbar-psf" ] = FG_QBAR;
1022 PropToParam[ "metrics/Sw-sqft" ] = FG_WINGAREA;
1023 PropToParam[ "metrics/bw-ft" ] = FG_WINGSPAN;
1024 PropToParam[ "metrics/cbarw-ft" ] = FG_CBAR;
1025 PropToParam[ "aero/alpha-rad" ] = FG_ALPHA;
1026 PropToParam[ "aero/alphadot-rad_sec" ] = FG_ALPHADOT;
1027 PropToParam[ "aero/beta-rad" ] = FG_BETA;
1028 PropToParam[ "aero/mag-beta-rad" ] = FG_ABETA;
1029 PropToParam[ "aero/betadot-rad_sec" ] = FG_BETADOT;
1030 PropToParam[ "attitude/phi-rad" ] = FG_PHI;
1031 PropToParam[ "attitude/theta-rad" ] = FG_THT;
1032 PropToParam[ "attitude/psi-true-rad" ] = FG_PSI;
1033 PropToParam[ "velocities/q-rad_sec" ] = FG_PITCHRATE;
1034 PropToParam[ "velocities/p-rad_sec" ] = FG_ROLLRATE;
1035 PropToParam[ "velocities/r-rad_sec" ] = FG_YAWRATE;
1036 PropToParam[ "velocities/p-aero-rad_sec" ] = FG_AEROP;
1037 PropToParam[ "velocities/q-aero-rad_sec" ] = FG_AEROQ;
1038 PropToParam[ "velocities/r-aero-rad_sec" ] = FG_AEROR;
1039 PropToParam[ "aero/cl-squared-norm" ] = FG_CL_SQRD;
1040 PropToParam[ "velocities/mach-norm" ] = FG_MACH;
1041 PropToParam[ "position/h-sl-ft" ] = FG_ALTITUDE;
1042 PropToParam[ "aero/bi2vel" ] = FG_BI2VEL;
1043 PropToParam[ "aero/ci2vel" ] = FG_CI2VEL;
1044 PropToParam[ "fcs/elevator-pos-rad" ] = FG_ELEVATOR_POS;
1045 PropToParam[ "fcs/mag-elevator-pos-rad" ] = FG_AELEVATOR_POS;
1046 PropToParam[ "fcs/elevator-pos-norm" ] = FG_NELEVATOR_POS;
1047 PropToParam[ "fcs/left-aileron-pos-rad" ] = FG_AILERON_POS;
1048 PropToParam[ "fcs/mag-aileron-pos-rad" ] = FG_AAILERON_POS;
1049 PropToParam[ "fcs/left-aileron-pos-norm" ] = FG_NAILERON_POS;
1050 PropToParam[ "fcs/left-aileron-pos-rad" ] = FG_LEFT_AILERON_POS;
1051 PropToParam[ "fcs/mag-left-aileron-pos-rad" ] = FG_ALEFT_AILERON_POS;
1052 PropToParam[ "fcs/left-aileron-pos-norm" ] = FG_NLEFT_AILERON_POS;
1053 PropToParam[ "fcs/right-aileron-pos-rad" ] = FG_RIGHT_AILERON_POS;
1054 PropToParam[ "fcs/mag-aileron-pos-rad" ] = FG_ARIGHT_AILERON_POS;
1055 PropToParam[ "fcs/right-aileron-pos-norm" ] = FG_NRIGHT_AILERON_POS;
1056 PropToParam[ "fcs/rudder-pos-rad" ] = FG_RUDDER_POS;
1057 PropToParam[ "fcs/mag-rudder-pos-rad" ] = FG_ARUDDER_POS;
1058 PropToParam[ "fcs/rudder-pos-norm" ] = FG_NRUDDER_POS;
1059 PropToParam[ "fcs/speedbrake-pos-rad" ] = FG_SPDBRAKE_POS;
1060 PropToParam[ "fcs/speedbrake-pos-norm" ] = FG_NSPDBRAKE_POS;
1061 PropToParam[ "fcs/spoiler-pos-rad" ] = FG_SPOILERS_POS;
1062 PropToParam[ "fcs/spoiler-pos-norm" ] = FG_NSPOILERS_POS;
1063 PropToParam[ "fcs/flap-pos-deg" ] = FG_FLAPS_POS;
1064 PropToParam[ "fcs/flap-pos-norm" ] = FG_NFLAPS_POS;
1065 PropToParam[ "fcs/elevator-cmd-norm" ] = FG_ELEVATOR_CMD;
1066 PropToParam[ "fcs/aileron-cmd-norm" ] = FG_AILERON_CMD;
1067 PropToParam[ "fcs/rudder-cmd-norm" ] = FG_RUDDER_CMD;
1068 PropToParam[ "fcs/speedbrake-cmd-norm" ] = FG_SPDBRAKE_CMD;
1069 PropToParam[ "fcs/spoiler-cmd-norm" ] = FG_SPOILERS_CMD;
1070 PropToParam[ "fcs/flap-cmd-norm" ] = FG_FLAPS_CMD;
1071 PropToParam[ "position/h_b-mac-ft" ] = FG_HOVERB;
1072 PropToParam[ "fcs/pitch-trim-cmd-norm" ] = FG_PITCH_TRIM_CMD;
1073 PropToParam[ "fcs/yaw-trim-cmd-norm" ] = FG_YAW_TRIM_CMD;
1074 PropToParam[ "fcs/roll-trim-cmd-norm" ] = FG_ROLL_TRIM_CMD;
1075 PropToParam[ "aero/alpha-rad" ] = FG_ALPHAH;
1076 PropToParam[ "aero/alpha-wing-rad" ] = FG_ALPHAW;
1077 PropToParam[ "metrics/lh-norm" ] = FG_LBARH;
1078 PropToParam[ "metrics/lv-norm" ] = FG_LBARV;
1079 PropToParam[ "metrics/Sh-sqft" ] = FG_HTAILAREA;
1080 PropToParam[ "metrics/Sv-sqft" ] = FG_VTAILAREA;
1081 PropToParam[ "metrics/vbarh-norm" ] = FG_VBARH;
1082 PropToParam[ "metrics/vbarv-norm" ] = FG_VBARV;
1083 PropToParam[ "gear/gear-cmd-norm" ] = FG_GEAR_CMD;
1084 PropToParam[ "gear/gear-pos-norm" ] = FG_GEAR_POS;
1088 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1090 void FGState::bind(void) {
1091 PropertyManager->Tie("sim-time-sec",this,
1092 &FGState::Getsim_time);
1095 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1097 void FGState::unbind(void) {
1098 PropertyManager->Untie("sim-time-sec");
1103 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1104 // The bitmasked value choices are as follows:
1105 // unset: In this case (the default) JSBSim would only print
1106 // out the normally expected messages, essentially echoing
1107 // the config files as they are read. If the environment
1108 // variable is not set, debug_lvl is set to 1 internally
1109 // 0: This requests JSBSim not to output any messages
1111 // 1: This value explicity requests the normal JSBSim
1113 // 2: This value asks for a message to be printed out when
1114 // a class is instantiated
1115 // 4: When this value is set, a message is displayed when a
1116 // FGModel object executes its Run() method
1117 // 8: When this value is set, various runtime state variables
1118 // are printed out periodically
1119 // 16: When set various parameters are sanity checked and
1120 // a message is printed out when they go out of bounds
1122 void FGState::Debug(int from)
1124 if (debug_lvl <= 0) return;
1126 if (debug_lvl & 1) { // Standard console startup message output
1127 if (from == 0) { // Constructor
1131 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1132 if (from == 0) cout << "Instantiated: FGState" << endl;
1133 if (from == 1) cout << "Destroyed: FGState" << endl;
1135 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1137 if (debug_lvl & 8 ) { // Runtime state variables
1139 if (debug_lvl & 16) { // Sanity checking
1141 if (debug_lvl & 64) {
1142 if (from == 0) { // Constructor
1143 cout << IdSrc << endl;
1144 cout << IdHdr << endl;