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 FGDefs.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_BETADOT, " betadot " );
111 RegisterVariable(FG_PHI, " roll_angle " );
112 RegisterVariable(FG_THT, " pitch_angle " );
113 RegisterVariable(FG_PSI, " heading_angle " );
114 RegisterVariable(FG_PITCHRATE, " pitch_rate " );
115 RegisterVariable(FG_ROLLRATE, " roll_rate " );
116 RegisterVariable(FG_YAWRATE, " yaw_rate " );
117 RegisterVariable(FG_CL_SQRD, " Clift_sqrd " );
118 RegisterVariable(FG_MACH, " mach " );
119 RegisterVariable(FG_ALTITUDE, " altitude " );
120 RegisterVariable(FG_BI2VEL, " BI2Vel " );
121 RegisterVariable(FG_CI2VEL, " CI2Vel " );
122 RegisterVariable(FG_ELEVATOR_POS, " elevator_pos " );
123 RegisterVariable(FG_AILERON_POS, " aileron_pos " );
124 RegisterVariable(FG_RUDDER_POS, " rudder_pos " );
125 RegisterVariable(FG_SPDBRAKE_POS, " speedbrake_pos " );
126 RegisterVariable(FG_SPOILERS_POS, " spoiler_pos " );
127 RegisterVariable(FG_FLAPS_POS, " flaps_pos " );
128 RegisterVariable(FG_ELEVATOR_CMD, " elevator_cmd " );
129 RegisterVariable(FG_AILERON_CMD, " aileron_cmd " );
130 RegisterVariable(FG_RUDDER_CMD, " rudder_cmd " );
131 RegisterVariable(FG_SPDBRAKE_CMD, " speedbrake_cmd " );
132 RegisterVariable(FG_SPOILERS_CMD, " spoiler_cmd " );
133 RegisterVariable(FG_FLAPS_CMD, " flaps_cmd " );
134 RegisterVariable(FG_THROTTLE_CMD, " throttle_cmd " );
135 RegisterVariable(FG_THROTTLE_POS, " throttle_pos " );
136 RegisterVariable(FG_MIXTURE_CMD, " mixture_cmd " );
137 RegisterVariable(FG_MIXTURE_POS, " mixture_pos " );
138 RegisterVariable(FG_MAGNETO_CMD, " magneto_cmd " );
139 RegisterVariable(FG_STARTER_CMD, " starter_cmd " );
140 RegisterVariable(FG_ACTIVE_ENGINE, " active_engine " );
141 RegisterVariable(FG_HOVERB, " height/span " );
142 RegisterVariable(FG_PITCH_TRIM_CMD, " pitch_trim_cmd " );
143 RegisterVariable(FG_LEFT_BRAKE_CMD, " left_brake_cmd " );
144 RegisterVariable(FG_RIGHT_BRAKE_CMD," right_brake_cmd ");
145 RegisterVariable(FG_CENTER_BRAKE_CMD," center_brake_cmd ");
146 RegisterVariable(FG_ALPHAH, " h-tail alpha " );
147 RegisterVariable(FG_ALPHAW, " wing alpha " );
148 RegisterVariable(FG_LBARH, " h-tail arm " );
149 RegisterVariable(FG_LBARV, " v-tail arm " );
150 RegisterVariable(FG_HTAILAREA, " h-tail area " );
151 RegisterVariable(FG_VTAILAREA, " v-tail area " );
152 RegisterVariable(FG_VBARH, " h-tail volume " );
153 RegisterVariable(FG_VBARV, " v-tail volume " );
154 RegisterVariable(FG_SET_LOGGING, " data_logging " );
156 if (debug_lvl & 2) cout << "Instantiated: FGState" << endl;
159 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 if (debug_lvl & 2) cout << "Destroyed: FGState" << endl;
166 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 float FGState::GetParameter(eParam val_idx) {
175 return Translation->Getqbar();
177 return Aircraft->GetWingArea();
179 return Aircraft->GetWingSpan();
181 return Aircraft->Getcbar();
183 return Aircraft->Getlbarh();
185 return Aircraft->Getvbarh();
187 return Aircraft->GetHTailArea();
189 return Aircraft->GetVTailArea();
191 return Aircraft->Getvbarh();
193 return Aircraft->Getvbarv();
195 return Translation->Getalpha();
197 return Translation->Getalpha() + Aircraft->GetWingIncidence();
199 return Translation->Getadot();
201 return Translation->Getbeta();
203 return Translation->Getbdot();
205 return Rotation->Getphi();
207 return Rotation->Gettht();
209 return Rotation->Getpsi();
211 return Rotation->GetPQR(eQ);
213 return Rotation->GetPQR(eP);
215 return Rotation->GetPQR(eR);
217 if (Translation->Getqbar() > 0.00)
218 scratch = Aerodynamics->GetvLastFs(eLift)/(Aircraft->GetWingArea()*Translation->Getqbar());
221 return scratch*scratch;
222 case FG_ELEVATOR_POS:
223 return FCS->GetDePos();
225 return FCS->GetDaPos();
227 return FCS->GetDrPos();
228 case FG_SPDBRAKE_POS:
229 return FCS->GetDsbPos();
230 case FG_SPOILERS_POS:
231 return FCS->GetDspPos();
233 return FCS->GetDfPos();
234 case FG_ELEVATOR_CMD:
235 return FCS->GetDeCmd();
237 return FCS->GetDaCmd();
239 return FCS->GetDrCmd();
240 case FG_SPDBRAKE_CMD:
241 return FCS->GetDsbCmd();
242 case FG_SPOILERS_CMD:
243 return FCS->GetDspCmd();
245 return FCS->GetDfCmd();
247 return Translation->GetMach();
249 return Position->Geth();
251 if(Translation->GetVt() > 0)
252 return Aircraft->GetWingSpan()/(2.0 * Translation->GetVt());
256 if(Translation->GetVt() > 0)
257 return Aircraft->Getcbar()/(2.0 * Translation->GetVt());
260 case FG_THROTTLE_CMD:
261 if (ActiveEngine < 0) return FCS->GetThrottleCmd(0);
262 else return FCS->GetThrottleCmd(ActiveEngine);
263 case FG_THROTTLE_POS:
264 if (ActiveEngine < 0) return FCS->GetThrottlePos(0);
265 else return FCS->GetThrottlePos(ActiveEngine);
267 if (ActiveEngine < 0) return Propulsion->GetEngine(0)->GetMagnetos();
268 else return Propulsion->GetEngine(ActiveEngine)->GetMagnetos();
270 if (ActiveEngine < 0) {
271 if (Propulsion->GetEngine(0)->GetStarter()) return 1.0;
274 if (Propulsion->GetEngine(ActiveEngine)->GetStarter()) return 1.0;
278 if (ActiveEngine < 0) return FCS->GetMixtureCmd(0);
279 else return FCS->GetMixtureCmd(ActiveEngine);
281 if (ActiveEngine < 0) return FCS->GetMixturePos(0);
282 else return FCS->GetMixturePos(ActiveEngine);
284 return Position->GetHOverB();
285 case FG_PITCH_TRIM_CMD:
286 return FCS->GetPitchTrimCmd();
288 cerr << "FGState::GetParameter() - No handler for parameter " << paramdef[val_idx] << endl;
294 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 float FGState::GetParameter(string val_string) {
297 return GetParameter(coeffdef[val_string]);
300 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 eParam FGState::GetParameterIndex(string val_string) {
303 return coeffdef[val_string];
306 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 void FGState::SetParameter(eParam val_idx, float val) {
310 case FG_ELEVATOR_POS:
319 case FG_SPDBRAKE_POS:
322 case FG_SPOILERS_POS:
328 case FG_THROTTLE_POS:
329 FCS->SetThrottlePos(ActiveEngine,val);
332 FCS->SetMixturePos(ActiveEngine,val);
335 case FG_ELEVATOR_CMD:
344 case FG_SPDBRAKE_CMD:
347 case FG_SPOILERS_CMD:
353 case FG_THROTTLE_CMD:
354 FCS->SetThrottleCmd(ActiveEngine,val);
357 FCS->SetMixtureCmd(ActiveEngine,val);
360 Propulsion->GetEngine(ActiveEngine)->SetMagnetos(val); // need to account for -1
364 Propulsion->GetEngine(ActiveEngine)->SetStarter(false); // need to account for -1
365 else if (val >= 0.001)
366 Propulsion->GetEngine(ActiveEngine)->SetStarter(true); // need to account for -1
368 case FG_ACTIVE_ENGINE:
369 ActiveEngine = (int)val;
372 case FG_LEFT_BRAKE_CMD:
375 case FG_CENTER_BRAKE_CMD:
378 case FG_RIGHT_BRAKE_CMD:
383 if (val < -0.01) Output->Disable();
384 else if (val > 0.01) Output->Enable();
385 else Output->Toggle();
389 cerr << "Parameter '" << val_idx << "' (" << paramdef[val_idx] << ") not handled" << endl;
393 //***************************************************************************
395 // Reset: Assume all angles READ FROM FILE IN DEGREES !!
398 bool FGState::Reset(string path, string acname, string fname)
405 float latitude, longitude, h;
406 float wdir, wmag, wnorth, weast;
409 resetDef = path + "/" + acname + "/" + fname + ".xml";
411 resetDef = path + ";" + acname + ";" + fname + ".xml";
414 FGConfigFile resetfile(resetDef);
415 if (!resetfile.IsOpen()) return false;
417 resetfile.GetNextConfigLine();
418 token = resetfile.GetValue();
419 if (token != "initialize") {
420 cerr << "The reset file " << resetDef
421 << " does not appear to be a reset file" << endl;
425 resetfile.GetNextConfigLine();
427 while (token != "/initialize" && token != "EOF") {
428 if (token == "UBODY") resetfile >> U;
429 if (token == "VBODY") resetfile >> V;
430 if (token == "WBODY") resetfile >> W;
431 if (token == "LATITUDE") resetfile >> latitude;
432 if (token == "LONGITUDE") resetfile >> longitude;
433 if (token == "PHI") resetfile >> phi;
434 if (token == "THETA") resetfile >> tht;
435 if (token == "PSI") resetfile >> psi;
436 if (token == "ALTITUDE") resetfile >> h;
437 if (token == "WINDDIR") resetfile >> wdir;
438 if (token == "VWIND") resetfile >> wmag;
444 Position->SetLatitude(latitude*DEGTORAD);
445 Position->SetLongitude(longitude*DEGTORAD);
448 wnorth = wmag*KTSTOFPS*cos(wdir*DEGTORAD);
449 weast = wmag*KTSTOFPS*sin(wdir*DEGTORAD);
451 Initialize(U, V, W, phi*DEGTORAD, tht*DEGTORAD, psi*DEGTORAD,
452 latitude*DEGTORAD, longitude*DEGTORAD, h, wnorth, weast, 0.0);
457 //***************************************************************************
459 // Initialize: Assume all angles GIVEN IN RADIANS !!
462 void FGState::Initialize(float U, float V, float W,
463 float phi, float tht, float psi,
464 float Latitude, float Longitude, float H,
465 float wnorth, float weast, float wdown)
469 FGColumnVector3 vAero;
471 Position->SetLatitude(Latitude);
472 Position->SetLongitude(Longitude);
477 vLocalEuler << phi << tht << psi;
478 Rotation->SetEuler(vLocalEuler);
480 InitMatrices(phi, tht, psi);
483 Translation->SetUVW(vUVW);
485 Atmosphere->SetWindNED(wnorth, weast, wdown);
487 vAero = vUVW + mTl2b*Atmosphere->GetWindNED();
489 if (vAero(eW) != 0.0)
490 alpha = vAero(eU)*vAero(eU) > 0.0 ? atan2(vAero(eW), vAero(eU)) : 0.0;
493 if (vAero(eV) != 0.0)
494 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;
498 Translation->SetAB(alpha, beta);
500 Vt = sqrt(U*U + V*V + W*W);
501 Translation->SetVt(Vt);
503 Translation->SetMach(Vt/Atmosphere->GetSoundSpeed());
505 qbar = 0.5*(U*U + V*V + W*W)*Atmosphere->GetDensity();
506 Translation->Setqbar(qbar);
508 vLocalVelNED = mTb2l*vUVW;
509 Position->SetvVel(vLocalVelNED);
512 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
514 void FGState::Initialize(FGInitialCondition *FGIC) {
518 float latitude, longitude;
519 float wnorth,weast, wdown;
521 latitude = FGIC->GetLatitudeRadIC();
522 longitude = FGIC->GetLongitudeRadIC();
523 h = FGIC->GetAltitudeFtIC();
524 U = FGIC->GetUBodyFpsIC();
525 V = FGIC->GetVBodyFpsIC();
526 W = FGIC->GetWBodyFpsIC();
527 tht = FGIC->GetThetaRadIC();
528 phi = FGIC->GetPhiRadIC();
529 psi = FGIC->GetPsiRadIC();
530 wnorth = FGIC->GetWindNFpsIC();
531 weast = FGIC->GetWindEFpsIC();
532 wdown = FGIC->GetWindDFpsIC();
534 Position->SetSeaLevelRadius( FGIC->GetSeaLevelRadiusFtIC() );
535 Position->SetRunwayRadius( FGIC->GetSeaLevelRadiusFtIC() +
536 FGIC->GetTerrainAltitudeFtIC() );
538 // need to fix the wind speed args, here.
539 Initialize(U, V, W, phi, tht, psi, latitude, longitude, h, wnorth, weast, wdown);
542 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
544 bool FGState::StoreData(string fname) {
545 ofstream datafile(fname.c_str());
548 datafile << Translation->GetUVW(eU);
549 datafile << Translation->GetUVW(eV);
550 datafile << Translation->GetUVW(eW);
551 datafile << Position->GetLatitude();
552 datafile << Position->GetLongitude();
553 datafile << Rotation->GetEuler(ePhi);
554 datafile << Rotation->GetEuler(eTht);
555 datafile << Rotation->GetEuler(ePsi);
556 datafile << Position->Geth();
560 cerr << "Could not open dump file " << fname << endl;
565 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
567 void FGState::InitMatrices(float phi, float tht, float psi) {
568 float thtd2, psid2, phid2;
569 float Sthtd2, Spsid2, Sphid2;
570 float Cthtd2, Cpsid2, Cphid2;
588 Cphid2Cthtd2 = Cphid2*Cthtd2;
589 Cphid2Sthtd2 = Cphid2*Sthtd2;
590 Sphid2Sthtd2 = Sphid2*Sthtd2;
591 Sphid2Cthtd2 = Sphid2*Cthtd2;
593 vQtrn(1) = Cphid2Cthtd2*Cpsid2 + Sphid2Sthtd2*Spsid2;
594 vQtrn(2) = Sphid2Cthtd2*Cpsid2 - Cphid2Sthtd2*Spsid2;
595 vQtrn(3) = Cphid2Sthtd2*Cpsid2 + Sphid2Cthtd2*Spsid2;
596 vQtrn(4) = Cphid2Cthtd2*Spsid2 - Sphid2Sthtd2*Cpsid2;
601 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
603 void FGState::CalcMatrices(void) {
604 float Q0Q0, Q1Q1, Q2Q2, Q3Q3;
605 float Q0Q1, Q0Q2, Q0Q3, Q1Q2;
608 Q0Q0 = vQtrn(1)*vQtrn(1);
609 Q1Q1 = vQtrn(2)*vQtrn(2);
610 Q2Q2 = vQtrn(3)*vQtrn(3);
611 Q3Q3 = vQtrn(4)*vQtrn(4);
612 Q0Q1 = vQtrn(1)*vQtrn(2);
613 Q0Q2 = vQtrn(1)*vQtrn(3);
614 Q0Q3 = vQtrn(1)*vQtrn(4);
615 Q1Q2 = vQtrn(2)*vQtrn(3);
616 Q1Q3 = vQtrn(2)*vQtrn(4);
617 Q2Q3 = vQtrn(3)*vQtrn(4);
619 mTl2b(1,1) = Q0Q0 + Q1Q1 - Q2Q2 - Q3Q3;
620 mTl2b(1,2) = 2*(Q1Q2 + Q0Q3);
621 mTl2b(1,3) = 2*(Q1Q3 - Q0Q2);
622 mTl2b(2,1) = 2*(Q1Q2 - Q0Q3);
623 mTl2b(2,2) = Q0Q0 - Q1Q1 + Q2Q2 - Q3Q3;
624 mTl2b(2,3) = 2*(Q2Q3 + Q0Q1);
625 mTl2b(3,1) = 2*(Q1Q3 + Q0Q2);
626 mTl2b(3,2) = 2*(Q2Q3 - Q0Q1);
627 mTl2b(3,3) = Q0Q0 - Q1Q1 - Q2Q2 + Q3Q3;
633 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
635 void FGState::IntegrateQuat(FGColumnVector3 vPQR, int rate) {
636 vQdot(1) = -0.5*(vQtrn(2)*vPQR(eP) + vQtrn(3)*vPQR(eQ) + vQtrn(4)*vPQR(eR));
637 vQdot(2) = 0.5*(vQtrn(1)*vPQR(eP) + vQtrn(3)*vPQR(eR) - vQtrn(4)*vPQR(eQ));
638 vQdot(3) = 0.5*(vQtrn(1)*vPQR(eQ) + vQtrn(4)*vPQR(eP) - vQtrn(2)*vPQR(eR));
639 vQdot(4) = 0.5*(vQtrn(1)*vPQR(eR) + vQtrn(2)*vPQR(eQ) - vQtrn(3)*vPQR(eP));
640 vQtrn += 0.5*dt*rate*(vlastQdot + vQdot);
647 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
649 FGColumnVector3& FGState::CalcEuler(void) {
650 if (mTl2b(3,3) == 0.0) mTl2b(3,3) = 0.0000001;
651 if (mTl2b(1,1) == 0.0) mTl2b(1,1) = 0.0000001;
653 vEuler(ePhi) = atan2(mTl2b(2,3), mTl2b(3,3));
654 vEuler(eTht) = asin(-mTl2b(1,3));
655 vEuler(ePsi) = atan2(mTl2b(1,2), mTl2b(1,1));
657 if (vEuler(ePsi) < 0.0) vEuler(ePsi) += 2*M_PI;
662 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664 FGMatrix33& FGState::GetTs2b(float alpha, float beta)
666 float ca, cb, sa, sb;
687 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
689 void FGState::ReportState(void) {
690 char out[80], flap[10], gear[10];
692 cout << endl << " JSBSim State" << endl;
693 snprintf(out,80," Weight: %7.0f lbs. CG: %5.1f, %5.1f, %5.1f inches\n",
694 FDMExec->GetMassBalance()->GetWeight(),
695 FDMExec->GetMassBalance()->GetXYZcg(1),
696 FDMExec->GetMassBalance()->GetXYZcg(2),
697 FDMExec->GetMassBalance()->GetXYZcg(3));
699 if( FCS->GetDfPos() <= 0.01)
700 snprintf(flap,10,"Up");
702 snprintf(flap,10,"%2.0f",FCS->GetDfPos());
703 if(GroundReactions->GetGearUp() == true)
704 snprintf(gear,10,"Up");
706 snprintf(gear,10,"Down");
707 snprintf(out,80, " Flaps: %3s Gear: %4s\n",flap,gear);
709 snprintf(out,80, " Speed: %4.0f KCAS Mach: %5.2f\n",
710 FDMExec->GetAuxiliary()->GetVcalibratedKTS(),
711 GetParameter(FG_MACH) );
713 snprintf(out,80, " Altitude: %7.0f ft. AGL Altitude: %7.0f ft.\n",
715 Position->GetDistanceAGL() );
717 snprintf(out,80, " Angle of Attack: %6.2f deg Pitch Angle: %6.2f deg\n",
718 GetParameter(FG_ALPHA)*RADTODEG,
719 Rotation->Gettht()*RADTODEG );
721 snprintf(out,80, " Flight Path Angle: %6.2f deg Climb Rate: %5.0f ft/min\n",
722 Position->GetGamma()*RADTODEG,
723 Position->Gethdot()*60 );
725 snprintf(out,80, " Normal Load Factor: %4.2f g's Pitch Rate: %5.2f deg/s\n",
726 Aerodynamics->GetNlf(),
727 GetParameter(FG_PITCHRATE)*RADTODEG );
729 snprintf(out,80, " Heading: %3.0f deg true Sideslip: %5.2f deg\n",
730 Rotation->Getpsi()*RADTODEG,
731 GetParameter(FG_BETA)*RADTODEG );
733 snprintf(out,80, " Bank Angle: %5.2f deg\n",
734 Rotation->Getphi()*RADTODEG );
736 snprintf(out,80, " Elevator: %5.2f deg Left Aileron: %5.2f deg Rudder: %5.2f deg\n",
737 GetParameter(FG_ELEVATOR_POS)*RADTODEG,
738 GetParameter(FG_AILERON_POS)*RADTODEG,
739 GetParameter(FG_RUDDER_POS)*RADTODEG );
741 snprintf(out,80, " Throttle: %5.2f%c\n",
742 FCS->GetThrottlePos(0),'%' );
745 snprintf(out,80, " Wind Components: %5.2f kts head wind, %5.2f kts cross wind\n",
746 FDMExec->GetAuxiliary()->GetHeadWind()*jsbFPSTOKTS,
747 FDMExec->GetAuxiliary()->GetCrossWind()*jsbFPSTOKTS );
750 snprintf(out,80, " Ground Speed: %4.0f knots , Ground Track: %3.0f deg true\n",
751 Position->GetVground()*jsbFPSTOKTS,
752 Position->GetGroundTrack()*RADTODEG );
756 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
758 void FGState::Debug(void)
760 //TODO: Add your source code here