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__)
51 #define snprintf _snprintf
56 static const char *IdSrc = "$Id$";
57 static const char *IdHdr = ID_STATE;
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 #define RegisterVariable(ID,DEF) coeffdef[#ID] = ID; paramdef[ID] = DEF
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 // For every term registered here there must be a corresponding handler in
72 // GetParameter() below that retrieves that parameter. Also, there must be an
73 // entry in the enum eParam definition in FGJSBBase.h. The ID is what must be used
74 // in any config file entry which references that item.
76 FGState::FGState(FGFDMExec* fdex) : mTb2l(3,3),
95 Aircraft = FDMExec->GetAircraft();
96 Translation = FDMExec->GetTranslation();
97 Rotation = FDMExec->GetRotation();
98 Position = FDMExec->GetPosition();
99 FCS = FDMExec->GetFCS();
100 Output = FDMExec->GetOutput();
101 Atmosphere = FDMExec->GetAtmosphere();
102 Aerodynamics = FDMExec->GetAerodynamics();
103 GroundReactions = FDMExec->GetGroundReactions();
104 Propulsion = FDMExec->GetPropulsion();
106 RegisterVariable(FG_TIME, " time " );
107 RegisterVariable(FG_QBAR, " qbar " );
108 RegisterVariable(FG_WINGAREA, " wing_area " );
109 RegisterVariable(FG_WINGSPAN, " wingspan " );
110 RegisterVariable(FG_CBAR, " cbar " );
111 RegisterVariable(FG_ALPHA, " alpha " );
112 RegisterVariable(FG_ALPHADOT, " alphadot " );
113 RegisterVariable(FG_BETA, " beta " );
114 RegisterVariable(FG_ABETA, " |beta| " );
115 RegisterVariable(FG_BETADOT, " betadot " );
116 RegisterVariable(FG_PHI, " roll_angle " );
117 RegisterVariable(FG_THT, " pitch_angle " );
118 RegisterVariable(FG_PSI, " heading_angle " );
119 RegisterVariable(FG_PITCHRATE, " pitch_rate " );
120 RegisterVariable(FG_ROLLRATE, " roll_rate " );
121 RegisterVariable(FG_YAWRATE, " yaw_rate " );
122 RegisterVariable(FG_AEROQ, " aero_pitch_rate ");
123 RegisterVariable(FG_AEROP, " aero_roll_rate " );
124 RegisterVariable(FG_AEROR, " aero_yaw_rate " );
125 RegisterVariable(FG_CL_SQRD, " Clift_sqrd " );
126 RegisterVariable(FG_MACH, " mach " );
127 RegisterVariable(FG_ALTITUDE, " altitude " );
128 RegisterVariable(FG_BI2VEL, " BI2Vel " );
129 RegisterVariable(FG_CI2VEL, " CI2Vel " );
130 RegisterVariable(FG_ELEVATOR_POS, " elevator_pos " );
131 RegisterVariable(FG_AILERON_POS, " aileron_pos " );
132 RegisterVariable(FG_RUDDER_POS, " rudder_pos " );
133 RegisterVariable(FG_SPDBRAKE_POS, " speedbrake_pos " );
134 RegisterVariable(FG_SPOILERS_POS, " spoiler_pos " );
135 RegisterVariable(FG_FLAPS_POS, " flaps_pos " );
136 RegisterVariable(FG_ELEVATOR_CMD, " elevator_cmd " );
137 RegisterVariable(FG_AILERON_CMD, " aileron_cmd " );
138 RegisterVariable(FG_RUDDER_CMD, " rudder_cmd " );
139 RegisterVariable(FG_SPDBRAKE_CMD, " speedbrake_cmd " );
140 RegisterVariable(FG_SPOILERS_CMD, " spoiler_cmd " );
141 RegisterVariable(FG_FLAPS_CMD, " flaps_cmd " );
142 RegisterVariable(FG_THROTTLE_CMD, " throttle_cmd " );
143 RegisterVariable(FG_THROTTLE_POS, " throttle_pos " );
144 RegisterVariable(FG_MIXTURE_CMD, " mixture_cmd " );
145 RegisterVariable(FG_MIXTURE_POS, " mixture_pos " );
146 RegisterVariable(FG_MAGNETO_CMD, " magneto_cmd " );
147 RegisterVariable(FG_STARTER_CMD, " starter_cmd " );
148 RegisterVariable(FG_ACTIVE_ENGINE, " active_engine " );
149 RegisterVariable(FG_HOVERB, " height/span " );
150 RegisterVariable(FG_PITCH_TRIM_CMD, " pitch_trim_cmd " );
151 RegisterVariable(FG_LEFT_BRAKE_CMD, " left_brake_cmd " );
152 RegisterVariable(FG_RIGHT_BRAKE_CMD," right_brake_cmd ");
153 RegisterVariable(FG_CENTER_BRAKE_CMD," center_brake_cmd ");
154 RegisterVariable(FG_ALPHAH, " h-tail alpha " );
155 RegisterVariable(FG_ALPHAW, " wing alpha " );
156 RegisterVariable(FG_LBARH, " h-tail arm " );
157 RegisterVariable(FG_LBARV, " v-tail arm " );
158 RegisterVariable(FG_HTAILAREA, " h-tail area " );
159 RegisterVariable(FG_VTAILAREA, " v-tail area " );
160 RegisterVariable(FG_VBARH, " h-tail volume " );
161 RegisterVariable(FG_VBARV, " v-tail volume " );
162 RegisterVariable(FG_SET_LOGGING, " data_logging " );
164 if (debug_lvl & 2) cout << "Instantiated: FGState" << endl;
167 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 if (debug_lvl & 2) cout << "Destroyed: FGState" << endl;
174 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 double FGState::GetParameter(eParam val_idx) {
183 return Translation->Getqbar();
185 return Aircraft->GetWingArea();
187 return Aircraft->GetWingSpan();
189 return Aircraft->Getcbar();
191 return Aircraft->Getlbarh();
193 return Aircraft->Getvbarh();
195 return Aircraft->GetHTailArea();
197 return Aircraft->GetVTailArea();
199 return Aircraft->Getvbarh();
201 return Aircraft->Getvbarv();
203 return Translation->Getalpha();
205 return Translation->Getalpha() + Aircraft->GetWingIncidence();
207 return Translation->Getadot();
209 return Translation->Getbeta();
211 return fabs(Translation->Getbeta());
213 return Translation->Getbdot();
215 return Rotation->Getphi();
217 return Rotation->Gettht();
219 return Rotation->Getpsi();
221 return Rotation->GetPQR(eQ);
223 return Rotation->GetPQR(eP);
225 return Rotation->GetPQR(eR);
227 return Rotation->GetPQR(eQ) + Atmosphere->GetTurbPQR(eQ); // add aero turbulence effects
229 return Rotation->GetPQR(eP) + Atmosphere->GetTurbPQR(eP); // add aero turbulence effects
231 return Rotation->GetPQR(eR) + Atmosphere->GetTurbPQR(eR); // add aero turbulence effects
233 if (Translation->Getqbar() > 0.00)
234 scratch = Aerodynamics->GetvLastFs(eLift)/(Aircraft->GetWingArea()*Translation->Getqbar());
237 return scratch*scratch;
238 case FG_ELEVATOR_POS:
239 return FCS->GetDePos();
241 return FCS->GetDaPos();
243 return FCS->GetDrPos();
244 case FG_SPDBRAKE_POS:
245 return FCS->GetDsbPos();
246 case FG_SPOILERS_POS:
247 return FCS->GetDspPos();
249 return FCS->GetDfPos();
250 case FG_ELEVATOR_CMD:
251 return FCS->GetDeCmd();
253 return FCS->GetDaCmd();
255 return FCS->GetDrCmd();
256 case FG_SPDBRAKE_CMD:
257 return FCS->GetDsbCmd();
258 case FG_SPOILERS_CMD:
259 return FCS->GetDspCmd();
261 return FCS->GetDfCmd();
263 return Translation->GetMach();
265 return Position->Geth();
267 if(Translation->GetVt() > 0)
268 return Aircraft->GetWingSpan()/(2.0 * Translation->GetVt());
272 if(Translation->GetVt() > 0)
273 return Aircraft->Getcbar()/(2.0 * Translation->GetVt());
276 case FG_THROTTLE_CMD:
277 if (ActiveEngine < 0) return FCS->GetThrottleCmd(0);
278 else return FCS->GetThrottleCmd(ActiveEngine);
279 case FG_THROTTLE_POS:
280 if (ActiveEngine < 0) return FCS->GetThrottlePos(0);
281 else return FCS->GetThrottlePos(ActiveEngine);
283 if (ActiveEngine < 0) return Propulsion->GetEngine(0)->GetMagnetos();
284 else return Propulsion->GetEngine(ActiveEngine)->GetMagnetos();
286 if (ActiveEngine < 0) {
287 if (Propulsion->GetEngine(0)->GetStarter()) return 1.0;
290 if (Propulsion->GetEngine(ActiveEngine)->GetStarter()) return 1.0;
294 if (ActiveEngine < 0) return FCS->GetMixtureCmd(0);
295 else return FCS->GetMixtureCmd(ActiveEngine);
297 if (ActiveEngine < 0) return FCS->GetMixturePos(0);
298 else return FCS->GetMixturePos(ActiveEngine);
300 return Position->GetHOverB();
301 case FG_PITCH_TRIM_CMD:
302 return FCS->GetPitchTrimCmd();
304 cerr << "FGState::GetParameter() - No handler for parameter " << paramdef[val_idx] << endl;
310 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 double FGState::GetParameter(string val_string) {
313 return GetParameter(coeffdef[val_string]);
316 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318 eParam FGState::GetParameterIndex(string val_string) {
319 return coeffdef[val_string];
322 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
324 void FGState::SetParameter(eParam val_idx, double val) {
326 case FG_ELEVATOR_POS:
335 case FG_SPDBRAKE_POS:
338 case FG_SPOILERS_POS:
344 case FG_THROTTLE_POS:
345 FCS->SetThrottlePos(ActiveEngine,val);
348 FCS->SetMixturePos(ActiveEngine,val);
351 case FG_ELEVATOR_CMD:
360 case FG_SPDBRAKE_CMD:
363 case FG_SPOILERS_CMD:
369 case FG_THROTTLE_CMD:
370 FCS->SetThrottleCmd(ActiveEngine,val);
373 FCS->SetMixtureCmd(ActiveEngine,val);
376 Propulsion->GetEngine(ActiveEngine)->SetMagnetos(val); // need to account for -1
380 Propulsion->GetEngine(ActiveEngine)->SetStarter(false); // need to account for -1
381 else if (val >= 0.001)
382 Propulsion->GetEngine(ActiveEngine)->SetStarter(true); // need to account for -1
384 case FG_ACTIVE_ENGINE:
385 ActiveEngine = (int)val;
388 case FG_LEFT_BRAKE_CMD:
391 case FG_CENTER_BRAKE_CMD:
394 case FG_RIGHT_BRAKE_CMD:
399 if (val < -0.01) Output->Disable();
400 else if (val > 0.01) Output->Enable();
401 else Output->Toggle();
405 cerr << "Parameter '" << val_idx << "' (" << paramdef[val_idx] << ") not handled" << endl;
409 //***************************************************************************
411 // Reset: Assume all angles READ FROM FILE IN DEGREES !!
414 bool FGState::Reset(string path, string acname, string fname)
420 double phi, tht, psi;
421 double latitude, longitude, h;
422 double wdir, wmag, wnorth, weast;
425 resetDef = path + "/" + acname + "/" + fname + ".xml";
427 resetDef = path + ";" + acname + ";" + fname + ".xml";
430 FGConfigFile resetfile(resetDef);
431 if (!resetfile.IsOpen()) return false;
433 resetfile.GetNextConfigLine();
434 token = resetfile.GetValue();
435 if (token != "initialize") {
436 cerr << "The reset file " << resetDef
437 << " does not appear to be a reset file" << endl;
441 resetfile.GetNextConfigLine();
443 while (token != "/initialize" && token != "EOF") {
444 if (token == "UBODY") resetfile >> U;
445 if (token == "VBODY") resetfile >> V;
446 if (token == "WBODY") resetfile >> W;
447 if (token == "LATITUDE") resetfile >> latitude;
448 if (token == "LONGITUDE") resetfile >> longitude;
449 if (token == "PHI") resetfile >> phi;
450 if (token == "THETA") resetfile >> tht;
451 if (token == "PSI") resetfile >> psi;
452 if (token == "ALTITUDE") resetfile >> h;
453 if (token == "WINDDIR") resetfile >> wdir;
454 if (token == "VWIND") resetfile >> wmag;
460 Position->SetLatitude(latitude*degtorad);
461 Position->SetLongitude(longitude*degtorad);
464 wnorth = wmag*ktstofps*cos(wdir*degtorad);
465 weast = wmag*ktstofps*sin(wdir*degtorad);
467 Initialize(U, V, W, phi*degtorad, tht*degtorad, psi*degtorad,
468 latitude*degtorad, longitude*degtorad, h, wnorth, weast, 0.0);
473 //***************************************************************************
475 // Initialize: Assume all angles GIVEN IN RADIANS !!
478 void FGState::Initialize(double U, double V, double W,
479 double phi, double tht, double psi,
480 double Latitude, double Longitude, double H,
481 double wnorth, double weast, double wdown)
485 FGColumnVector3 vAero;
487 Position->SetLatitude(Latitude);
488 Position->SetLongitude(Longitude);
493 vLocalEuler << phi << tht << psi;
494 Rotation->SetEuler(vLocalEuler);
496 InitMatrices(phi, tht, psi);
499 Translation->SetUVW(vUVW);
501 Atmosphere->SetWindNED(wnorth, weast, wdown);
503 vAero = vUVW + mTl2b*Atmosphere->GetWindNED();
505 if (vAero(eW) != 0.0)
506 alpha = vAero(eU)*vAero(eU) > 0.0 ? atan2(vAero(eW), vAero(eU)) : 0.0;
509 if (vAero(eV) != 0.0)
510 beta = vAero(eU)*vAero(eU)+vAero(eW)*vAero(eW) > 0.0 ? atan2(vAero(eV), (fabs(vAero(eU))/vAero(eU))*sqrt(vAero(eU)*vAero(eU) + vAero(eW)*vAero(eW))) : 0.0;
514 Translation->SetAB(alpha, beta);
516 Vt = sqrt(U*U + V*V + W*W);
517 Translation->SetVt(Vt);
519 Translation->SetMach(Vt/Atmosphere->GetSoundSpeed());
521 qbar = 0.5*(U*U + V*V + W*W)*Atmosphere->GetDensity();
522 Translation->Setqbar(qbar);
524 vLocalVelNED = mTb2l*vUVW;
525 Position->SetvVel(vLocalVelNED);
528 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
530 void FGState::Initialize(FGInitialCondition *FGIC) {
534 double latitude, longitude;
535 double wnorth,weast, wdown;
537 latitude = FGIC->GetLatitudeRadIC();
538 longitude = FGIC->GetLongitudeRadIC();
539 h = FGIC->GetAltitudeFtIC();
540 U = FGIC->GetUBodyFpsIC();
541 V = FGIC->GetVBodyFpsIC();
542 W = FGIC->GetWBodyFpsIC();
543 tht = FGIC->GetThetaRadIC();
544 phi = FGIC->GetPhiRadIC();
545 psi = FGIC->GetPsiRadIC();
546 wnorth = FGIC->GetWindNFpsIC();
547 weast = FGIC->GetWindEFpsIC();
548 wdown = FGIC->GetWindDFpsIC();
550 Position->SetSeaLevelRadius( FGIC->GetSeaLevelRadiusFtIC() );
551 Position->SetRunwayRadius( FGIC->GetSeaLevelRadiusFtIC() +
552 FGIC->GetTerrainAltitudeFtIC() );
554 // need to fix the wind speed args, here.
555 Initialize(U, V, W, phi, tht, psi, latitude, longitude, h, wnorth, weast, wdown);
558 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
560 bool FGState::StoreData(string fname) {
561 ofstream datafile(fname.c_str());
564 datafile << Translation->GetUVW(eU);
565 datafile << Translation->GetUVW(eV);
566 datafile << Translation->GetUVW(eW);
567 datafile << Position->GetLatitude();
568 datafile << Position->GetLongitude();
569 datafile << Rotation->GetEuler(ePhi);
570 datafile << Rotation->GetEuler(eTht);
571 datafile << Rotation->GetEuler(ePsi);
572 datafile << Position->Geth();
576 cerr << "Could not open dump file " << fname << endl;
581 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
583 void FGState::InitMatrices(double phi, double tht, double psi) {
584 double thtd2, psid2, phid2;
585 double Sthtd2, Spsid2, Sphid2;
586 double Cthtd2, Cpsid2, Cphid2;
604 Cphid2Cthtd2 = Cphid2*Cthtd2;
605 Cphid2Sthtd2 = Cphid2*Sthtd2;
606 Sphid2Sthtd2 = Sphid2*Sthtd2;
607 Sphid2Cthtd2 = Sphid2*Cthtd2;
609 vQtrn(1) = Cphid2Cthtd2*Cpsid2 + Sphid2Sthtd2*Spsid2;
610 vQtrn(2) = Sphid2Cthtd2*Cpsid2 - Cphid2Sthtd2*Spsid2;
611 vQtrn(3) = Cphid2Sthtd2*Cpsid2 + Sphid2Cthtd2*Spsid2;
612 vQtrn(4) = Cphid2Cthtd2*Spsid2 - Sphid2Sthtd2*Cpsid2;
617 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619 void FGState::CalcMatrices(void) {
620 double Q0Q0, Q1Q1, Q2Q2, Q3Q3;
621 double Q0Q1, Q0Q2, Q0Q3, Q1Q2;
624 Q0Q0 = vQtrn(1)*vQtrn(1);
625 Q1Q1 = vQtrn(2)*vQtrn(2);
626 Q2Q2 = vQtrn(3)*vQtrn(3);
627 Q3Q3 = vQtrn(4)*vQtrn(4);
628 Q0Q1 = vQtrn(1)*vQtrn(2);
629 Q0Q2 = vQtrn(1)*vQtrn(3);
630 Q0Q3 = vQtrn(1)*vQtrn(4);
631 Q1Q2 = vQtrn(2)*vQtrn(3);
632 Q1Q3 = vQtrn(2)*vQtrn(4);
633 Q2Q3 = vQtrn(3)*vQtrn(4);
635 mTl2b(1,1) = Q0Q0 + Q1Q1 - Q2Q2 - Q3Q3;
636 mTl2b(1,2) = 2*(Q1Q2 + Q0Q3);
637 mTl2b(1,3) = 2*(Q1Q3 - Q0Q2);
638 mTl2b(2,1) = 2*(Q1Q2 - Q0Q3);
639 mTl2b(2,2) = Q0Q0 - Q1Q1 + Q2Q2 - Q3Q3;
640 mTl2b(2,3) = 2*(Q2Q3 + Q0Q1);
641 mTl2b(3,1) = 2*(Q1Q3 + Q0Q2);
642 mTl2b(3,2) = 2*(Q2Q3 - Q0Q1);
643 mTl2b(3,3) = Q0Q0 - Q1Q1 - Q2Q2 + Q3Q3;
649 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
651 void FGState::IntegrateQuat(FGColumnVector3 vPQR, int rate) {
652 vQdot(1) = -0.5*(vQtrn(2)*vPQR(eP) + vQtrn(3)*vPQR(eQ) + vQtrn(4)*vPQR(eR));
653 vQdot(2) = 0.5*(vQtrn(1)*vPQR(eP) + vQtrn(3)*vPQR(eR) - vQtrn(4)*vPQR(eQ));
654 vQdot(3) = 0.5*(vQtrn(1)*vPQR(eQ) + vQtrn(4)*vPQR(eP) - vQtrn(2)*vPQR(eR));
655 vQdot(4) = 0.5*(vQtrn(1)*vPQR(eR) + vQtrn(2)*vPQR(eQ) - vQtrn(3)*vPQR(eP));
656 vQtrn += 0.5*dt*rate*(vlastQdot + vQdot);
663 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
665 FGColumnVector3& FGState::CalcEuler(void) {
666 if (mTl2b(3,3) == 0.0) mTl2b(3,3) = 0.0000001;
667 if (mTl2b(1,1) == 0.0) mTl2b(1,1) = 0.0000001;
669 vEuler(ePhi) = atan2(mTl2b(2,3), mTl2b(3,3));
670 vEuler(eTht) = asin(-mTl2b(1,3));
671 vEuler(ePsi) = atan2(mTl2b(1,2), mTl2b(1,1));
673 if (vEuler(ePsi) < 0.0) vEuler(ePsi) += 2*M_PI;
678 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
680 FGMatrix33& FGState::GetTs2b(void)
682 double ca, cb, sa, sb;
684 double alpha = Translation->Getalpha();
685 double beta = Translation->Getbeta();
706 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
708 void FGState::ReportState(void) {
709 char out[80], flap[10], gear[10];
711 cout << endl << " JSBSim State" << endl;
712 snprintf(out,80," Weight: %7.0f lbs. CG: %5.1f, %5.1f, %5.1f inches\n",
713 FDMExec->GetMassBalance()->GetWeight(),
714 FDMExec->GetMassBalance()->GetXYZcg(1),
715 FDMExec->GetMassBalance()->GetXYZcg(2),
716 FDMExec->GetMassBalance()->GetXYZcg(3));
718 if( FCS->GetDfPos() <= 0.01)
719 snprintf(flap,10,"Up");
721 snprintf(flap,10,"%2.0f",FCS->GetDfPos());
722 if(GroundReactions->GetGearUp() == true)
723 snprintf(gear,10,"Up");
725 snprintf(gear,10,"Down");
726 snprintf(out,80, " Flaps: %3s Gear: %4s\n",flap,gear);
728 snprintf(out,80, " Speed: %4.0f KCAS Mach: %5.2f\n",
729 FDMExec->GetAuxiliary()->GetVcalibratedKTS(),
730 GetParameter(FG_MACH) );
732 snprintf(out,80, " Altitude: %7.0f ft. AGL Altitude: %7.0f ft.\n",
734 Position->GetDistanceAGL() );
736 snprintf(out,80, " Angle of Attack: %6.2f deg Pitch Angle: %6.2f deg\n",
737 GetParameter(FG_ALPHA)*radtodeg,
738 Rotation->Gettht()*radtodeg );
740 snprintf(out,80, " Flight Path Angle: %6.2f deg Climb Rate: %5.0f ft/min\n",
741 Position->GetGamma()*radtodeg,
742 Position->Gethdot()*60 );
744 snprintf(out,80, " Normal Load Factor: %4.2f g's Pitch Rate: %5.2f deg/s\n",
745 Aerodynamics->GetNlf(),
746 GetParameter(FG_PITCHRATE)*radtodeg );
748 snprintf(out,80, " Heading: %3.0f deg true Sideslip: %5.2f deg\n",
749 Rotation->Getpsi()*radtodeg,
750 GetParameter(FG_BETA)*radtodeg );
752 snprintf(out,80, " Bank Angle: %5.2f deg\n",
753 Rotation->Getphi()*radtodeg );
755 snprintf(out,80, " Elevator: %5.2f deg Left Aileron: %5.2f deg Rudder: %5.2f deg\n",
756 GetParameter(FG_ELEVATOR_POS)*radtodeg,
757 GetParameter(FG_AILERON_POS)*radtodeg,
758 GetParameter(FG_RUDDER_POS)*radtodeg );
760 snprintf(out,80, " Throttle: %5.2f%c\n",
761 FCS->GetThrottlePos(0)*100,'%' );
764 snprintf(out,80, " Wind Components: %5.2f kts head wind, %5.2f kts cross wind\n",
765 FDMExec->GetAuxiliary()->GetHeadWind()*fpstokts,
766 FDMExec->GetAuxiliary()->GetCrossWind()*fpstokts );
769 snprintf(out,80, " Ground Speed: %4.0f knots , Ground Track: %3.0f deg true\n",
770 Position->GetVground()*fpstokts,
771 Position->GetGroundTrack()*radtodeg );
775 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
777 void FGState::Debug(void)
779 //TODO: Add your source code here