1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 --------------------------------------------------------------------------------
34 09/03/99 JSB Changed Rocket thrust equation to correct -= Thrust instead of
35 += Thrust (thanks to Tony Peden)
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 # include <simgear/compiler.h>
43 # ifdef SG_HAVE_STD_INCLUDES
49 # if defined(sgi) && !defined(__GNUC__)
61 static const char *IdSrc = "$Id$";
62 static const char *IdHdr = ID_ENGINE;
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 FGEngine::FGEngine(FGFDMExec* exec)
73 EnginePitch(0), EngineYaw(0),
74 SLFuelFlowMax(0), SLOxiFlowMax(0),
75 MaxThrottle(1.0), MinThrottle(0.0),
81 FuelNeed(0.0), OxidizerNeed(0.0),
82 Starved(false), Flameout(false), Running(false), Cranking(false),
83 Augmentation(false), Injection(false), Ignition(false),
84 Reversed(false), Cutoff(true), Nitrous(false),
89 ManifoldPressure_inHg(0.0),
90 ExhaustGasTemp_degK(0.0),
91 CylinderHeadTemp_degK(0.0),
95 State(FDMExec->GetState()),
96 Atmosphere(FDMExec->GetAtmosphere()),
97 FCS(FDMExec->GetFCS()),
98 Propulsion(FDMExec->GetPropulsion()),
99 Aircraft(FDMExec->GetAircraft()),
100 Translation(FDMExec->GetTranslation()),
101 Rotation(FDMExec->GetRotation()),
102 Position(FDMExec->GetPosition()),
103 Auxiliary(FDMExec->GetAuxiliary()),
104 Output(FDMExec->GetOutput())
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 FGEngine::~FGEngine()
116 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 // This base class function should be called from within the
118 // derived class' Calculate() function before any other calculations are done.
119 // This base class method removes fuel from the fuel tanks as appropriate,
120 // and sets the starved flag if necessary.
122 void FGEngine::ConsumeFuel(void)
124 double Fshortage, Oshortage;
127 if (TrimMode) return;
128 Fshortage = Oshortage = 0.0;
129 for (unsigned int i=0; i<SourceTanks.size(); i++) {
130 Tank = Propulsion->GetTank(i);
131 if (Tank->GetType() == FGTank::ttFUEL) {
132 Fshortage += Tank->Reduce(CalcFuelNeed()/Propulsion->GetnumSelectedFuelTanks());
134 Oshortage += Tank->Reduce(CalcOxidizerNeed()/Propulsion->GetnumSelectedOxiTanks());
138 if (Fshortage < 0.00 || Oshortage < 0.00) Starved = true;
139 else Starved = false;
142 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 double FGEngine::CalcFuelNeed(void) {
145 FuelNeed = SLFuelFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();
149 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 double FGEngine::CalcOxidizerNeed(void) {
152 OxidizerNeed = SLOxiFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();
156 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 void FGEngine::SetPlacement(double x, double y, double z, double pitch, double yaw) {
166 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 void FGEngine::AddFeedTank(int tkID)
170 SourceTanks.push_back(tkID);
173 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174 // The bitmasked value choices are as follows:
175 // unset: In this case (the default) JSBSim would only print
176 // out the normally expected messages, essentially echoing
177 // the config files as they are read. If the environment
178 // variable is not set, debug_lvl is set to 1 internally
179 // 0: This requests JSBSim not to output any messages
181 // 1: This value explicity requests the normal JSBSim
183 // 2: This value asks for a message to be printed out when
184 // a class is instantiated
185 // 4: When this value is set, a message is displayed when a
186 // FGModel object executes its Run() method
187 // 8: When this value is set, various runtime state variables
188 // are printed out periodically
189 // 16: When set various parameters are sanity checked and
190 // a message is printed out when they go out of bounds
192 void FGEngine::Debug(int from)
194 if (debug_lvl <= 0) return;
196 if (debug_lvl & 1) { // Standard console startup message output
197 if (from == 0) { // Constructor
201 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
202 if (from == 0) cout << "Instantiated: FGEngine" << endl;
203 if (from == 1) cout << "Destroyed: FGEngine" << endl;
205 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
207 if (debug_lvl & 8 ) { // Runtime state variables
209 if (debug_lvl & 16) { // Sanity checking
211 if (debug_lvl & 64) {
212 if (from == 0) { // Constructor
213 cout << IdSrc << endl;
214 cout << IdHdr << endl;