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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 # include <simgear/compiler.h>
43 # if defined(sgi) && !defined(__GNUC__)
54 static const char *IdSrc = "$Id$";
55 static const char *IdHdr = ID_STATE;
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 FGState::FGState(FGFDMExec* fdex)
72 Aircraft = FDMExec->GetAircraft();
73 Propagate = FDMExec->GetPropagate();
74 Auxiliary = FDMExec->GetAuxiliary();
75 FCS = FDMExec->GetFCS();
76 Atmosphere = FDMExec->GetAtmosphere();
77 Aerodynamics = FDMExec->GetAerodynamics();
78 GroundReactions = FDMExec->GetGroundReactions();
79 Propulsion = FDMExec->GetPropulsion();
80 PropertyManager = FDMExec->GetPropertyManager();
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 void FGState::Initialize(FGInitialCondition *FGIC)
100 Propagate->SetInitialState( FGIC );
103 Atmosphere->SetWindNED( FGIC->GetWindNFpsIC(),
104 FGIC->GetWindEFpsIC(),
105 FGIC->GetWindDFpsIC() );
107 FGColumnVector3 vAeroUVW;
108 vAeroUVW = Propagate->GetUVW() + Propagate->GetTl2b()*Atmosphere->GetWindNED();
111 if (vAeroUVW(eW) != 0.0)
112 alpha = vAeroUVW(eU)*vAeroUVW(eU) > 0.0 ? atan2(vAeroUVW(eW), vAeroUVW(eU)) : 0.0;
115 if (vAeroUVW(eV) != 0.0)
116 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;
120 Auxiliary->SetAB(alpha, beta);
122 double Vt = vAeroUVW.Magnitude();
123 Auxiliary->SetVt(Vt);
125 Auxiliary->SetMach(Vt/Atmosphere->GetSoundSpeed());
127 double qbar = 0.5*Vt*Vt*Atmosphere->GetDensity();
128 Auxiliary->Setqbar(qbar);
131 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 void FGState::bind(void)
135 PropertyManager->Tie("sim-time-sec", this, &FGState::Getsim_time);
138 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 // The bitmasked value choices are as follows:
140 // unset: In this case (the default) JSBSim would only print
141 // out the normally expected messages, essentially echoing
142 // the config files as they are read. If the environment
143 // variable is not set, debug_lvl is set to 1 internally
144 // 0: This requests JSBSim not to output any messages
146 // 1: This value explicity requests the normal JSBSim
148 // 2: This value asks for a message to be printed out when
149 // a class is instantiated
150 // 4: When this value is set, a message is displayed when a
151 // FGModel object executes its Run() method
152 // 8: When this value is set, various runtime state variables
153 // are printed out periodically
154 // 16: When set various parameters are sanity checked and
155 // a message is printed out when they go out of bounds
157 void FGState::Debug(int from)
159 if (debug_lvl <= 0) return;
161 if (debug_lvl & 1) { // Standard console startup message output
162 if (from == 0) { // Constructor
166 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
167 if (from == 0) cout << "Instantiated: FGState" << endl;
168 if (from == 1) cout << "Destroyed: FGState" << endl;
170 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
172 if (debug_lvl & 8 ) { // Runtime state variables
174 if (debug_lvl & 16) { // Sanity checking
176 if (debug_lvl & 64) {
177 if (from == 0) { // Constructor
178 cout << IdSrc << endl;
179 cout << IdHdr << endl;