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 Lesser 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 Lesser General Public License for more
20 You should have received a copy of the GNU Lesser 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 Lesser 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 static const char *IdSrc = "$Id$";
46 static const char *IdHdr = ID_STATE;
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 FGState::FGState(FGFDMExec* fdex)
61 dt = 1.0/120.0; // a default timestep size. This is needed for when JSBSim is
62 // run in standalone mode with no initialization file.
64 Aircraft = FDMExec->GetAircraft();
65 Propagate = FDMExec->GetPropagate();
66 Auxiliary = FDMExec->GetAuxiliary();
67 FCS = FDMExec->GetFCS();
68 Atmosphere = FDMExec->GetAtmosphere();
69 Aerodynamics = FDMExec->GetAerodynamics();
70 GroundReactions = FDMExec->GetGroundReactions();
71 Propulsion = FDMExec->GetPropulsion();
72 PropertyManager = FDMExec->GetPropertyManager();
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 void FGState::Initialize(FGInitialCondition *FGIC)
92 Propagate->SetInitialState( FGIC );
95 Atmosphere->SetWindNED( FGIC->GetWindNFpsIC(),
96 FGIC->GetWindEFpsIC(),
97 FGIC->GetWindDFpsIC() );
99 FGColumnVector3 vAeroUVW;
100 vAeroUVW = Propagate->GetUVW() + Propagate->GetTl2b()*Atmosphere->GetTotalWindNED();
103 if (vAeroUVW(eW) != 0.0)
104 alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
107 if (vAeroUVW(eV) != 0.0)
108 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;
112 Auxiliary->SetAB(alpha, beta);
114 double Vt = vAeroUVW.Magnitude();
115 Auxiliary->SetVt(Vt);
117 Auxiliary->SetMach(Vt/Atmosphere->GetSoundSpeed());
119 double qbar = 0.5*Vt*Vt*Atmosphere->GetDensity();
120 Auxiliary->Setqbar(qbar);
123 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 void FGState::bind(void)
127 PropertyManager->Tie("sim-time-sec", this, &FGState::Getsim_time);
130 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 // The bitmasked value choices are as follows:
132 // unset: In this case (the default) JSBSim would only print
133 // out the normally expected messages, essentially echoing
134 // the config files as they are read. If the environment
135 // variable is not set, debug_lvl is set to 1 internally
136 // 0: This requests JSBSim not to output any messages
138 // 1: This value explicity requests the normal JSBSim
140 // 2: This value asks for a message to be printed out when
141 // a class is instantiated
142 // 4: When this value is set, a message is displayed when a
143 // FGModel object executes its Run() method
144 // 8: When this value is set, various runtime state variables
145 // are printed out periodically
146 // 16: When set various parameters are sanity checked and
147 // a message is printed out when they go out of bounds
149 void FGState::Debug(int from)
151 if (debug_lvl <= 0) return;
153 if (debug_lvl & 1) { // Standard console startup message output
154 if (from == 0) { // Constructor
158 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
159 if (from == 0) cout << "Instantiated: FGState" << endl;
160 if (from == 1) cout << "Destroyed: FGState" << endl;
162 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
164 if (debug_lvl & 8 ) { // Runtime state variables
166 if (debug_lvl & 16) { // Sanity checking
168 if (debug_lvl & 64) {
169 if (from == 0) { // Constructor
170 cout << IdSrc << endl;
171 cout << IdHdr << endl;