]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGEngine.cpp
Latest updates from the JSBSim project.
[flightgear.git] / src / FDM / JSBSim / FGEngine.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
2  \r
3  Module:       FGEngine.cpp\r
4  Author:       Jon Berndt\r
5  Date started: 01/21/99\r
6  Called by:    FGAircraft\r
7  \r
8  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------\r
9  \r
10  This program is free software; you can redistribute it and/or modify it under\r
11  the terms of the GNU General Public License as published by the Free Software\r
12  Foundation; either version 2 of the License, or (at your option) any later\r
13  version.\r
14  \r
15  This program is distributed in the hope that it will be useful, but WITHOUT\r
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
18  details.\r
19  \r
20  You should have received a copy of the GNU General Public License along with\r
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple\r
22  Place - Suite 330, Boston, MA  02111-1307, USA.\r
23  \r
24  Further information about the GNU General Public License can also be found on\r
25  the world wide web at http://www.gnu.org.\r
26  \r
27 FUNCTIONAL DESCRIPTION\r
28 --------------------------------------------------------------------------------\r
29 See header file.\r
30  \r
31 HISTORY\r
32 --------------------------------------------------------------------------------\r
33 01/21/99   JSB   Created\r
34 09/03/99   JSB   Changed Rocket thrust equation to correct -= Thrust instead of\r
35                  += Thrust (thanks to Tony Peden)\r
36  \r
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
38 INCLUDES\r
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
40 \r
41 #ifdef FGFS\r
42 #  include <simgear/compiler.h>\r
43 #  ifdef SG_HAVE_STD_INCLUDES\r
44 #    include <fstream>\r
45 #  else\r
46 #    include <fstream.h>\r
47 #  endif\r
48 #else\r
49 #  if defined(sgi) && !defined(__GNUC__)\r
50 #    include <fstream.h>\r
51 #  else\r
52 #    include <fstream>\r
53 #  endif\r
54 #endif\r
55 \r
56 #include "FGEngine.h"\r
57 #include "FGTank.h"\r
58 \r
59 static const char *IdSrc = "$Id$";\r
60 static const char *IdHdr = ID_ENGINE;\r
61 \r
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
63 CLASS IMPLEMENTATION\r
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/\r
65 \r
66 \r
67 FGEngine::FGEngine(FGFDMExec* exec) {\r
68   FDMExec     = exec;\r
69   State       = FDMExec->GetState();\r
70   Atmosphere  = FDMExec->GetAtmosphere();\r
71   FCS         = FDMExec->GetFCS();\r
72   Propulsion  = FDMExec->GetPropulsion();\r
73   Aircraft    = FDMExec->GetAircraft();\r
74   Translation = FDMExec->GetTranslation();\r
75   Rotation    = FDMExec->GetRotation();\r
76   Position    = FDMExec->GetPosition();\r
77   Auxiliary   = FDMExec->GetAuxiliary();\r
78   Output      = FDMExec->GetOutput();\r
79 \r
80   Mixture = 1.0;                // FIXME: get actual value\r
81 \r
82   Thrust = PctPower = 0.0;\r
83   Starved = Flameout = false;\r
84   Running = false;\r
85   Cranking = Starter = false;\r
86 \r
87   if (debug_lvl & 2) cout << "Instantiated: FGEngine" << endl;\r
88   TrimMode = false;\r
89 }\r
90 \r
91 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
92 \r
93 FGEngine::~FGEngine()\r
94 {\r
95   if (debug_lvl & 2) cout << "Destroyed:    FGEngine" << endl;\r
96 }\r
97 \r
98 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
99 // This base class function should be called from within the\r
100 // derived class' Calculate() function before any other calculations are done.\r
101 // This base class method removes fuel from the fuel tanks as appropriate,\r
102 // and sets the starved flag if necessary.\r
103 \r
104 void FGEngine::ConsumeFuel(void) {\r
105   float Fshortage, Oshortage;\r
106   FGTank* Tank;\r
107 \r
108   if (TrimMode) return;\r
109 \r
110   Fshortage = Oshortage = 0.0;\r
111   for (unsigned int i=0; i<SourceTanks.size(); i++) {\r
112     Tank = Propulsion->GetTank(i);\r
113     if (Tank->GetType() == FGTank::ttFUEL) {\r
114       Fshortage += Tank->Reduce(CalcFuelNeed()/Propulsion->GetnumSelectedFuelTanks());\r
115     } else {\r
116       Oshortage += Tank->Reduce(CalcOxidizerNeed()/Propulsion->GetnumSelectedOxiTanks());\r
117     }\r
118   }\r
119 \r
120   if (Fshortage < 0.00 || Oshortage < 0.00) Starved = true;\r
121   else Starved = false;\r
122 }\r
123 \r
124 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
125 \r
126 float FGEngine::CalcFuelNeed(void) {\r
127   FuelNeed = SLFuelFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();\r
128   return FuelNeed;\r
129 }\r
130 \r
131 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
132 \r
133 float FGEngine::CalcOxidizerNeed(void) {\r
134   OxidizerNeed = SLOxiFlowMax*PctPower*State->Getdt()*Propulsion->GetRate();\r
135   return OxidizerNeed;\r
136 }\r
137 \r
138 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
139 \r
140 void FGEngine::SetPlacement(float x, float y, float z, float pitch, float yaw) {\r
141   X = x;\r
142   Y = y;\r
143   Z = z;\r
144   EnginePitch = pitch;\r
145   EngineYaw = yaw;\r
146 }\r
147 \r
148 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
149 \r
150 void FGEngine::AddFeedTank(int tkID)\r
151 {\r
152   SourceTanks.push_back(tkID);\r
153 }\r
154 \r
155 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
156 \r
157 void FGEngine::Debug(void)\r
158 {\r
159     //TODO: Add your source code here\r
160 }\r
161 \r