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__)
52 static const char *IdSrc = "$Id$";
53 static const char *IdHdr = ID_STATE;
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 #define RegisterVariable(ID,DEF) coeffdef[#ID] = ID; paramdef[ID] = DEF
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 // For every term registered here there must be a corresponding handler in
68 // GetParameter() below that retrieves that parameter. Also, there must be an
69 // entry in the enum eParam definition in FGJSBBase.h. The ID is what must be used
70 // in any config file entry which references that item.
72 FGState::FGState(FGFDMExec* fdex) : mTb2l(3,3),
91 Aircraft = FDMExec->GetAircraft();
92 Translation = FDMExec->GetTranslation();
93 Rotation = FDMExec->GetRotation();
94 Position = FDMExec->GetPosition();
95 FCS = FDMExec->GetFCS();
96 Output = FDMExec->GetOutput();
97 Atmosphere = FDMExec->GetAtmosphere();
98 Aerodynamics = FDMExec->GetAerodynamics();
99 GroundReactions = FDMExec->GetGroundReactions();
100 Propulsion = FDMExec->GetPropulsion();
102 RegisterVariable(FG_TIME, " time " );
103 RegisterVariable(FG_QBAR, " qbar " );
104 RegisterVariable(FG_WINGAREA, " wing_area " );
105 RegisterVariable(FG_WINGSPAN, " wingspan " );
106 RegisterVariable(FG_CBAR, " cbar " );
107 RegisterVariable(FG_ALPHA, " alpha " );
108 RegisterVariable(FG_ALPHADOT, " alphadot " );
109 RegisterVariable(FG_BETA, " beta " );
110 RegisterVariable(FG_ABETA, " |beta| " );
111 RegisterVariable(FG_BETADOT, " betadot " );
112 RegisterVariable(FG_PHI, " roll_angle " );
113 RegisterVariable(FG_THT, " pitch_angle " );
114 RegisterVariable(FG_PSI, " heading_angle " );
115 RegisterVariable(FG_PITCHRATE, " pitch_rate " );
116 RegisterVariable(FG_ROLLRATE, " roll_rate " );
117 RegisterVariable(FG_YAWRATE, " yaw_rate " );
118 RegisterVariable(FG_CL_SQRD, " Clift_sqrd " );
119 RegisterVariable(FG_MACH, " mach " );
120 RegisterVariable(FG_ALTITUDE, " altitude " );
121 RegisterVariable(FG_BI2VEL, " BI2Vel " );
122 RegisterVariable(FG_CI2VEL, " CI2Vel " );
123 RegisterVariable(FG_ELEVATOR_POS, " elevator_pos " );
124 RegisterVariable(FG_AILERON_POS, " aileron_pos " );
125 RegisterVariable(FG_RUDDER_POS, " rudder_pos " );
126 RegisterVariable(FG_SPDBRAKE_POS, " speedbrake_pos " );
127 RegisterVariable(FG_SPOILERS_POS, " spoiler_pos " );
128 RegisterVariable(FG_FLAPS_POS, " flaps_pos " );
129 RegisterVariable(FG_ELEVATOR_CMD, " elevator_cmd " );
130 RegisterVariable(FG_AILERON_CMD, " aileron_cmd " );
131 RegisterVariable(FG_RUDDER_CMD, " rudder_cmd " );
132 RegisterVariable(FG_SPDBRAKE_CMD, " speedbrake_cmd " );
133 RegisterVariable(FG_SPOILERS_CMD, " spoiler_cmd " );
134 RegisterVariable(FG_FLAPS_CMD, " flaps_cmd " );
135 RegisterVariable(FG_THROTTLE_CMD, " throttle_cmd " );
136 RegisterVariable(FG_THROTTLE_POS, " throttle_pos " );
137 RegisterVariable(FG_MIXTURE_CMD, " mixture_cmd " );
138 RegisterVariable(FG_MIXTURE_POS, " mixture_pos " );
139 RegisterVariable(FG_MAGNETO_CMD, " magneto_cmd " );
140 RegisterVariable(FG_STARTER_CMD, " starter_cmd " );
141 RegisterVariable(FG_ACTIVE_ENGINE, " active_engine " );
142 RegisterVariable(FG_HOVERB, " height/span " );
143 RegisterVariable(FG_PITCH_TRIM_CMD, " pitch_trim_cmd " );
144 RegisterVariable(FG_LEFT_BRAKE_CMD, " left_brake_cmd " );
145 RegisterVariable(FG_RIGHT_BRAKE_CMD," right_brake_cmd ");
146 RegisterVariable(FG_CENTER_BRAKE_CMD," center_brake_cmd ");
147 RegisterVariable(FG_ALPHAH, " h-tail alpha " );
148 RegisterVariable(FG_ALPHAW, " wing alpha " );
149 RegisterVariable(FG_LBARH, " h-tail arm " );
150 RegisterVariable(FG_LBARV, " v-tail arm " );
151 RegisterVariable(FG_HTAILAREA, " h-tail area " );
152 RegisterVariable(FG_VTAILAREA, " v-tail area " );
153 RegisterVariable(FG_VBARH, " h-tail volume " );
154 RegisterVariable(FG_VBARV, " v-tail volume " );
155 RegisterVariable(FG_SET_LOGGING, " data_logging " );
157 if (debug_lvl & 2) cout << "Instantiated: FGState" << endl;
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164 if (debug_lvl & 2) cout << "Destroyed: FGState" << endl;
167 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 double FGState::GetParameter(eParam val_idx) {
176 return Translation->Getqbar();
178 return Aircraft->GetWingArea();
180 return Aircraft->GetWingSpan();
182 return Aircraft->Getcbar();
184 return Aircraft->Getlbarh();
186 return Aircraft->Getvbarh();
188 return Aircraft->GetHTailArea();
190 return Aircraft->GetVTailArea();
192 return Aircraft->Getvbarh();
194 return Aircraft->Getvbarv();
196 return Translation->Getalpha();
198 return Translation->Getalpha() + Aircraft->GetWingIncidence();
200 return Translation->Getadot();
202 return Translation->Getbeta();
204 return fabs(Translation->Getbeta());
206 return Translation->Getbdot();
208 return Rotation->Getphi();
210 return Rotation->Gettht();
212 return Rotation->Getpsi();
214 return Rotation->GetPQR(eQ);
216 return Rotation->GetPQR(eP);
218 return Rotation->GetPQR(eR);
220 if (Translation->Getqbar() > 0.00)
221 scratch = Aerodynamics->GetvLastFs(eLift)/(Aircraft->GetWingArea()*Translation->Getqbar());
224 return scratch*scratch;
225 case FG_ELEVATOR_POS:
226 return FCS->GetDePos();
228 return FCS->GetDaPos();
230 return FCS->GetDrPos();
231 case FG_SPDBRAKE_POS:
232 return FCS->GetDsbPos();
233 case FG_SPOILERS_POS:
234 return FCS->GetDspPos();
236 return FCS->GetDfPos();
237 case FG_ELEVATOR_CMD:
238 return FCS->GetDeCmd();
240 return FCS->GetDaCmd();
242 return FCS->GetDrCmd();
243 case FG_SPDBRAKE_CMD:
244 return FCS->GetDsbCmd();
245 case FG_SPOILERS_CMD:
246 return FCS->GetDspCmd();
248 return FCS->GetDfCmd();
250 return Translation->GetMach();
252 return Position->Geth();
254 if(Translation->GetVt() > 0)
255 return Aircraft->GetWingSpan()/(2.0 * Translation->GetVt());
259 if(Translation->GetVt() > 0)
260 return Aircraft->Getcbar()/(2.0 * Translation->GetVt());
263 case FG_THROTTLE_CMD:
264 if (ActiveEngine < 0) return FCS->GetThrottleCmd(0);
265 else return FCS->GetThrottleCmd(ActiveEngine);
266 case FG_THROTTLE_POS:
267 if (ActiveEngine < 0) return FCS->GetThrottlePos(0);
268 else return FCS->GetThrottlePos(ActiveEngine);
270 if (ActiveEngine < 0) return Propulsion->GetEngine(0)->GetMagnetos();
271 else return Propulsion->GetEngine(ActiveEngine)->GetMagnetos();
273 if (ActiveEngine < 0) {
274 if (Propulsion->GetEngine(0)->GetStarter()) return 1.0;
277 if (Propulsion->GetEngine(ActiveEngine)->GetStarter()) return 1.0;
281 if (ActiveEngine < 0) return FCS->GetMixtureCmd(0);
282 else return FCS->GetMixtureCmd(ActiveEngine);
284 if (ActiveEngine < 0) return FCS->GetMixturePos(0);
285 else return FCS->GetMixturePos(ActiveEngine);
287 return Position->GetHOverB();
288 case FG_PITCH_TRIM_CMD:
289 return FCS->GetPitchTrimCmd();
291 cerr << "FGState::GetParameter() - No handler for parameter " << paramdef[val_idx] << endl;
297 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 double FGState::GetParameter(string val_string) {
300 return GetParameter(coeffdef[val_string]);
303 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305 eParam FGState::GetParameterIndex(string val_string) {
306 return coeffdef[val_string];
309 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 void FGState::SetParameter(eParam val_idx, double val) {
313 case FG_ELEVATOR_POS:
322 case FG_SPDBRAKE_POS:
325 case FG_SPOILERS_POS:
331 case FG_THROTTLE_POS:
332 FCS->SetThrottlePos(ActiveEngine,val);
335 FCS->SetMixturePos(ActiveEngine,val);
338 case FG_ELEVATOR_CMD:
347 case FG_SPDBRAKE_CMD:
350 case FG_SPOILERS_CMD:
356 case FG_THROTTLE_CMD:
357 FCS->SetThrottleCmd(ActiveEngine,val);
360 FCS->SetMixtureCmd(ActiveEngine,val);
363 Propulsion->GetEngine(ActiveEngine)->SetMagnetos(val); // need to account for -1
367 Propulsion->GetEngine(ActiveEngine)->SetStarter(false); // need to account for -1
368 else if (val >= 0.001)
369 Propulsion->GetEngine(ActiveEngine)->SetStarter(true); // need to account for -1
371 case FG_ACTIVE_ENGINE:
372 ActiveEngine = (int)val;
375 case FG_LEFT_BRAKE_CMD:
378 case FG_CENTER_BRAKE_CMD:
381 case FG_RIGHT_BRAKE_CMD:
386 if (val < -0.01) Output->Disable();
387 else if (val > 0.01) Output->Enable();
388 else Output->Toggle();
392 cerr << "Parameter '" << val_idx << "' (" << paramdef[val_idx] << ") not handled" << endl;
396 //***************************************************************************
398 // Reset: Assume all angles READ FROM FILE IN DEGREES !!
401 bool FGState::Reset(string path, string acname, string fname)
407 double phi, tht, psi;
408 double latitude, longitude, h;
409 double wdir, wmag, wnorth, weast;
412 resetDef = path + "/" + acname + "/" + fname + ".xml";
414 resetDef = path + ";" + acname + ";" + fname + ".xml";
417 FGConfigFile resetfile(resetDef);
418 if (!resetfile.IsOpen()) return false;
420 resetfile.GetNextConfigLine();
421 token = resetfile.GetValue();
422 if (token != "initialize") {
423 cerr << "The reset file " << resetDef
424 << " does not appear to be a reset file" << endl;
428 resetfile.GetNextConfigLine();
430 while (token != "/initialize" && token != "EOF") {
431 if (token == "UBODY") resetfile >> U;
432 if (token == "VBODY") resetfile >> V;
433 if (token == "WBODY") resetfile >> W;
434 if (token == "LATITUDE") resetfile >> latitude;
435 if (token == "LONGITUDE") resetfile >> longitude;
436 if (token == "PHI") resetfile >> phi;
437 if (token == "THETA") resetfile >> tht;
438 if (token == "PSI") resetfile >> psi;
439 if (token == "ALTITUDE") resetfile >> h;
440 if (token == "WINDDIR") resetfile >> wdir;
441 if (token == "VWIND") resetfile >> wmag;
447 Position->SetLatitude(latitude*degtorad);
448 Position->SetLongitude(longitude*degtorad);
451 wnorth = wmag*ktstofps*cos(wdir*degtorad);
452 weast = wmag*ktstofps*sin(wdir*degtorad);
454 Initialize(U, V, W, phi*degtorad, tht*degtorad, psi*degtorad,
455 latitude*degtorad, longitude*degtorad, h, wnorth, weast, 0.0);
460 //***************************************************************************
462 // Initialize: Assume all angles GIVEN IN RADIANS !!
465 void FGState::Initialize(double U, double V, double W,
466 double phi, double tht, double psi,
467 double Latitude, double Longitude, double H,
468 double wnorth, double weast, double wdown)
472 FGColumnVector3 vAero;
474 Position->SetLatitude(Latitude);
475 Position->SetLongitude(Longitude);
480 vLocalEuler << phi << tht << psi;
481 Rotation->SetEuler(vLocalEuler);
483 InitMatrices(phi, tht, psi);
486 Translation->SetUVW(vUVW);
488 Atmosphere->SetWindNED(wnorth, weast, wdown);
490 vAero = vUVW + mTl2b*Atmosphere->GetWindNED();
492 if (vAero(eW) != 0.0)
493 alpha = vAero(eU)*vAero(eU) > 0.0 ? atan2(vAero(eW), vAero(eU)) : 0.0;
496 if (vAero(eV) != 0.0)
497 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;
501 Translation->SetAB(alpha, beta);
503 Vt = sqrt(U*U + V*V + W*W);
504 Translation->SetVt(Vt);
506 Translation->SetMach(Vt/Atmosphere->GetSoundSpeed());
508 qbar = 0.5*(U*U + V*V + W*W)*Atmosphere->GetDensity();
509 Translation->Setqbar(qbar);
511 vLocalVelNED = mTb2l*vUVW;
512 Position->SetvVel(vLocalVelNED);
515 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
517 void FGState::Initialize(FGInitialCondition *FGIC) {
521 double latitude, longitude;
522 double wnorth,weast, wdown;
524 latitude = FGIC->GetLatitudeRadIC();
525 longitude = FGIC->GetLongitudeRadIC();
526 h = FGIC->GetAltitudeFtIC();
527 U = FGIC->GetUBodyFpsIC();
528 V = FGIC->GetVBodyFpsIC();
529 W = FGIC->GetWBodyFpsIC();
530 tht = FGIC->GetThetaRadIC();
531 phi = FGIC->GetPhiRadIC();
532 psi = FGIC->GetPsiRadIC();
533 wnorth = FGIC->GetWindNFpsIC();
534 weast = FGIC->GetWindEFpsIC();
535 wdown = FGIC->GetWindDFpsIC();
537 Position->SetSeaLevelRadius( FGIC->GetSeaLevelRadiusFtIC() );
538 Position->SetRunwayRadius( FGIC->GetSeaLevelRadiusFtIC() +
539 FGIC->GetTerrainAltitudeFtIC() );
541 // need to fix the wind speed args, here.
542 Initialize(U, V, W, phi, tht, psi, latitude, longitude, h, wnorth, weast, wdown);
545 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
547 bool FGState::StoreData(string fname) {
548 ofstream datafile(fname.c_str());
551 datafile << Translation->GetUVW(eU);
552 datafile << Translation->GetUVW(eV);
553 datafile << Translation->GetUVW(eW);
554 datafile << Position->GetLatitude();
555 datafile << Position->GetLongitude();
556 datafile << Rotation->GetEuler(ePhi);
557 datafile << Rotation->GetEuler(eTht);
558 datafile << Rotation->GetEuler(ePsi);
559 datafile << Position->Geth();
563 cerr << "Could not open dump file " << fname << endl;
568 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
570 void FGState::InitMatrices(double phi, double tht, double psi) {
571 double thtd2, psid2, phid2;
572 double Sthtd2, Spsid2, Sphid2;
573 double Cthtd2, Cpsid2, Cphid2;
591 Cphid2Cthtd2 = Cphid2*Cthtd2;
592 Cphid2Sthtd2 = Cphid2*Sthtd2;
593 Sphid2Sthtd2 = Sphid2*Sthtd2;
594 Sphid2Cthtd2 = Sphid2*Cthtd2;
596 vQtrn(1) = Cphid2Cthtd2*Cpsid2 + Sphid2Sthtd2*Spsid2;
597 vQtrn(2) = Sphid2Cthtd2*Cpsid2 - Cphid2Sthtd2*Spsid2;
598 vQtrn(3) = Cphid2Sthtd2*Cpsid2 + Sphid2Cthtd2*Spsid2;
599 vQtrn(4) = Cphid2Cthtd2*Spsid2 - Sphid2Sthtd2*Cpsid2;
604 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
606 void FGState::CalcMatrices(void) {
607 double Q0Q0, Q1Q1, Q2Q2, Q3Q3;
608 double Q0Q1, Q0Q2, Q0Q3, Q1Q2;
611 Q0Q0 = vQtrn(1)*vQtrn(1);
612 Q1Q1 = vQtrn(2)*vQtrn(2);
613 Q2Q2 = vQtrn(3)*vQtrn(3);
614 Q3Q3 = vQtrn(4)*vQtrn(4);
615 Q0Q1 = vQtrn(1)*vQtrn(2);
616 Q0Q2 = vQtrn(1)*vQtrn(3);
617 Q0Q3 = vQtrn(1)*vQtrn(4);
618 Q1Q2 = vQtrn(2)*vQtrn(3);
619 Q1Q3 = vQtrn(2)*vQtrn(4);
620 Q2Q3 = vQtrn(3)*vQtrn(4);
622 mTl2b(1,1) = Q0Q0 + Q1Q1 - Q2Q2 - Q3Q3;
623 mTl2b(1,2) = 2*(Q1Q2 + Q0Q3);
624 mTl2b(1,3) = 2*(Q1Q3 - Q0Q2);
625 mTl2b(2,1) = 2*(Q1Q2 - Q0Q3);
626 mTl2b(2,2) = Q0Q0 - Q1Q1 + Q2Q2 - Q3Q3;
627 mTl2b(2,3) = 2*(Q2Q3 + Q0Q1);
628 mTl2b(3,1) = 2*(Q1Q3 + Q0Q2);
629 mTl2b(3,2) = 2*(Q2Q3 - Q0Q1);
630 mTl2b(3,3) = Q0Q0 - Q1Q1 - Q2Q2 + Q3Q3;
636 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
638 void FGState::IntegrateQuat(FGColumnVector3 vPQR, int rate) {
639 vQdot(1) = -0.5*(vQtrn(2)*vPQR(eP) + vQtrn(3)*vPQR(eQ) + vQtrn(4)*vPQR(eR));
640 vQdot(2) = 0.5*(vQtrn(1)*vPQR(eP) + vQtrn(3)*vPQR(eR) - vQtrn(4)*vPQR(eQ));
641 vQdot(3) = 0.5*(vQtrn(1)*vPQR(eQ) + vQtrn(4)*vPQR(eP) - vQtrn(2)*vPQR(eR));
642 vQdot(4) = 0.5*(vQtrn(1)*vPQR(eR) + vQtrn(2)*vPQR(eQ) - vQtrn(3)*vPQR(eP));
643 vQtrn += 0.5*dt*rate*(vlastQdot + vQdot);
650 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652 FGColumnVector3& FGState::CalcEuler(void) {
653 if (mTl2b(3,3) == 0.0) mTl2b(3,3) = 0.0000001;
654 if (mTl2b(1,1) == 0.0) mTl2b(1,1) = 0.0000001;
656 vEuler(ePhi) = atan2(mTl2b(2,3), mTl2b(3,3));
657 vEuler(eTht) = asin(-mTl2b(1,3));
658 vEuler(ePsi) = atan2(mTl2b(1,2), mTl2b(1,1));
660 if (vEuler(ePsi) < 0.0) vEuler(ePsi) += 2*M_PI;
665 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
667 FGMatrix33& FGState::GetTs2b(void)
669 double ca, cb, sa, sb;
671 double alpha = Translation->Getalpha();
672 double beta = Translation->Getbeta();
693 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
695 void FGState::ReportState(void) {
696 char out[80], flap[10], gear[10];
698 cout << endl << " JSBSim State" << endl;
699 snprintf(out,80," Weight: %7.0f lbs. CG: %5.1f, %5.1f, %5.1f inches\n",
700 FDMExec->GetMassBalance()->GetWeight(),
701 FDMExec->GetMassBalance()->GetXYZcg(1),
702 FDMExec->GetMassBalance()->GetXYZcg(2),
703 FDMExec->GetMassBalance()->GetXYZcg(3));
705 if( FCS->GetDfPos() <= 0.01)
706 snprintf(flap,10,"Up");
708 snprintf(flap,10,"%2.0f",FCS->GetDfPos());
709 if(GroundReactions->GetGearUp() == true)
710 snprintf(gear,10,"Up");
712 snprintf(gear,10,"Down");
713 snprintf(out,80, " Flaps: %3s Gear: %4s\n",flap,gear);
715 snprintf(out,80, " Speed: %4.0f KCAS Mach: %5.2f\n",
716 FDMExec->GetAuxiliary()->GetVcalibratedKTS(),
717 GetParameter(FG_MACH) );
719 snprintf(out,80, " Altitude: %7.0f ft. AGL Altitude: %7.0f ft.\n",
721 Position->GetDistanceAGL() );
723 snprintf(out,80, " Angle of Attack: %6.2f deg Pitch Angle: %6.2f deg\n",
724 GetParameter(FG_ALPHA)*radtodeg,
725 Rotation->Gettht()*radtodeg );
727 snprintf(out,80, " Flight Path Angle: %6.2f deg Climb Rate: %5.0f ft/min\n",
728 Position->GetGamma()*radtodeg,
729 Position->Gethdot()*60 );
731 snprintf(out,80, " Normal Load Factor: %4.2f g's Pitch Rate: %5.2f deg/s\n",
732 Aerodynamics->GetNlf(),
733 GetParameter(FG_PITCHRATE)*radtodeg );
735 snprintf(out,80, " Heading: %3.0f deg true Sideslip: %5.2f deg\n",
736 Rotation->Getpsi()*radtodeg,
737 GetParameter(FG_BETA)*radtodeg );
739 snprintf(out,80, " Bank Angle: %5.2f deg\n",
740 Rotation->Getphi()*radtodeg );
742 snprintf(out,80, " Elevator: %5.2f deg Left Aileron: %5.2f deg Rudder: %5.2f deg\n",
743 GetParameter(FG_ELEVATOR_POS)*radtodeg,
744 GetParameter(FG_AILERON_POS)*radtodeg,
745 GetParameter(FG_RUDDER_POS)*radtodeg );
747 snprintf(out,80, " Throttle: %5.2f%c\n",
748 FCS->GetThrottlePos(0)*100,'%' );
751 snprintf(out,80, " Wind Components: %5.2f kts head wind, %5.2f kts cross wind\n",
752 FDMExec->GetAuxiliary()->GetHeadWind()*fpstokts,
753 FDMExec->GetAuxiliary()->GetCrossWind()*fpstokts );
756 snprintf(out,80, " Ground Speed: %4.0f knots , Ground Track: %3.0f deg true\n",
757 Position->GetVground()*fpstokts,
758 Position->GetGroundTrack()*radtodeg );
762 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
764 void FGState::Debug(void)
766 //TODO: Add your source code here