| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGPropulsion.h |
| 4 | Author: Jon S. Berndt |
| 5 | Date started: 08/20/00 |
| 6 | |
| 7 | ------------- Copyright (C) 1999 Jon S. Berndt ([email protected]) ------------- |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify it under |
| 10 | the terms of the GNU Lesser General Public License as published by the Free Software |
| 11 | Foundation; either version 2 of the License, or (at your option) any later |
| 12 | version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 17 | details. |
| 18 | |
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | |
| 23 | Further information about the GNU Lesser General Public License can also be found on |
| 24 | the world wide web at http://www.gnu.org. |
| 25 | |
| 26 | HISTORY |
| 27 | -------------------------------------------------------------------------------- |
| 28 | 08/20/00 JSB Created |
| 29 | |
| 30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 31 | SENTRY |
| 32 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 33 | |
| 34 | #ifndef FGPROPULSION_H |
| 35 | #define FGPROPULSION_H |
| 36 | |
| 37 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 38 | INCLUDES |
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 40 | |
| 41 | #include <vector> |
| 42 | #include <iosfwd> |
| 43 | |
| 44 | #include "simgear/props/propertyObject.hxx" |
| 45 | #include "FGModel.h" |
| 46 | #include "propulsion/FGEngine.h" |
| 47 | #include "math/FGMatrix33.h" |
| 48 | |
| 49 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 50 | FORWARD DECLARATIONS |
| 51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 52 | |
| 53 | namespace JSBSim { |
| 54 | |
| 55 | class FGTank; |
| 56 | class FGEngine; |
| 57 | |
| 58 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 59 | CLASS DOCUMENTATION |
| 60 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 61 | |
| 62 | /** Propulsion management class. |
| 63 | The Propulsion class is the container for the entire propulsion system, which is |
| 64 | comprised of engines, and tanks. Once the Propulsion class gets the config file, |
| 65 | it reads in the \<propulsion> section. Then: |
| 66 | |
| 67 | -# The appropriate engine type instance is created |
| 68 | -# At least one tank object is created, and is linked to an engine. |
| 69 | |
| 70 | At Run time each engine's Calculate() method is called. |
| 71 | |
| 72 | <h3>Configuration File Format:</h3> |
| 73 | |
| 74 | @code |
| 75 | <propulsion> |
| 76 | <engine file="{string}"> |
| 77 | ... see FGEngine, FGThruster, and class for engine type ... |
| 78 | </engine> |
| 79 | ... more engines ... |
| 80 | <tank type="{FUEL | OXIDIZER}"> |
| 81 | ... see FGTank ... |
| 82 | </tank> |
| 83 | ... more tanks ... |
| 84 | <dump-rate unit="{LBS/MIN | KG/MIN}"> {number} </dump-rate> |
| 85 | <refuel-rate unit="{LBS/MIN | KG/MIN}"> {number} </refuel-rate> |
| 86 | </propulsion> |
| 87 | @endcode |
| 88 | |
| 89 | @author Jon S. Berndt |
| 90 | @see |
| 91 | FGEngine |
| 92 | FGTank |
| 93 | */ |
| 94 | |
| 95 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 96 | CLASS DECLARATION |
| 97 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 98 | |
| 99 | class JSBSIM_API FGPropulsion : public FGModel |
| 100 | { |
| 101 | public: |
| 102 | /// Constructor |
| 103 | FGPropulsion(FGFDMExec*); |
| 104 | /// Destructor |
| 105 | ~FGPropulsion() override; |
| 106 | |
| 107 | /** Executes the propulsion model. |
| 108 | The initial plan for the FGPropulsion class calls for Run() to be executed, |
| 109 | calculating the power available from the engine. |
| 110 | Can pass in a value indicating if the executive is directing the simulation to Hold. |
| 111 | @param Holding if true, the executive has been directed to hold the sim from |
| 112 | advancing time. Some models may ignore this flag, such as the Input |
| 113 | model, which may need to be active to listen on a socket for the |
| 114 | "Resume" command to be given. |
| 115 | @return false if no error */ |
| 116 | bool Run(bool Holding) override; |
| 117 | |
| 118 | bool InitModel(void) override; |
| 119 | |
| 120 | /** Loads the propulsion system (engine[s] and tank[s]). |
| 121 | Characteristics of the propulsion system are read in from the config file. |
| 122 | @param el pointer to an XML element that contains the engine information. |
| 123 | @return true if successfully loaded, otherwise false */ |
| 124 | bool Load(Element* el) override; |
| 125 | |
| 126 | /// Retrieves the number of engines defined for the aircraft. |
| 127 | unsigned int GetNumEngines(void) const {return (unsigned int)Engines.size();} |
| 128 | |
| 129 | /** Retrieves an engine object pointer from the list of engines. |
| 130 | @param index the engine index within the vector container |
| 131 | @return the address of the specific engine, or zero if no such engine is |
| 132 | available */ |
| 133 | FGEngine* GetEngine(unsigned int index) const { |
| 134 | if (index < Engines.size()) return Engines[index]; |
| 135 | else return 0L; } |
| 136 | |
| 137 | /// Retrieves the number of tanks defined for the aircraft. |
| 138 | unsigned int GetNumTanks(void) const {return (unsigned int)Tanks.size();} |
| 139 | |
| 140 | /** Retrieves a tank object pointer from the list of tanks. |
| 141 | @param index the tank index within the vector container |
| 142 | @return the address of the specific tank, or zero if no such tank is |
| 143 | available */ |
| 144 | FGTank* GetTank(unsigned int index) const { |
| 145 | if (index < Tanks.size()) return Tanks[index]; |
| 146 | else return 0L; } |
| 147 | |
| 148 | /** Returns the number of fuel tanks currently actively supplying fuel */ |
| 149 | int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;} |
| 150 | |
| 151 | /** Returns the number of oxidizer tanks currently actively supplying oxidizer */ |
| 152 | int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;} |
| 153 | |
| 154 | /** Loops the engines until thrust output steady (used for trimming) */ |
| 155 | bool GetSteadyState(void); |
| 156 | |
| 157 | /** Sets up the engines as running */ |
| 158 | void InitRunning(int n); |
| 159 | |
| 160 | std::string GetPropulsionStrings(const std::string& delimiter) const; |
| 161 | std::string GetPropulsionValues(const std::string& delimiter) const; |
| 162 | std::string GetPropulsionTankReport(); |
| 163 | |
| 164 | const FGColumnVector3& GetForces(void) const {return vForces; } |
| 165 | double GetForces(int n) const { return vForces(n);} |
| 166 | const FGColumnVector3& GetMoments(void) const {return vMoments;} |
| 167 | double GetMoments(int n) const {return vMoments(n);} |
| 168 | |
| 169 | double Transfer(int source, int target, double amount); |
| 170 | void DoRefuel(double time_slice); |
| 171 | void DumpFuel(double time_slice); |
| 172 | |
| 173 | const FGColumnVector3& GetTanksMoment(void); |
| 174 | double GetTanksWeight(void) const; |
| 175 | |
| 176 | SGPath FindFullPathName(const SGPath& path) const override; |
| 177 | inline int GetActiveEngine(void) const {return ActiveEngine;} |
| 178 | inline bool GetFuelFreeze(void) const {return FuelFreeze;} |
| 179 | |
| 180 | void SetMagnetos(int setting); |
| 181 | void SetStarter(int setting); |
| 182 | int GetStarter(void) const; |
| 183 | void SetCutoff(int setting=0); |
| 184 | int GetCutoff(void) const; |
| 185 | void SetActiveEngine(int engine); |
| 186 | void SetFuelFreeze(bool f); |
| 187 | const FGMatrix33& CalculateTankInertias(void); |
| 188 | |
| 189 | struct FGEngine::Inputs in; |
| 190 | |
| 191 | private: |
| 192 | std::vector <FGEngine*> Engines; |
| 193 | std::vector <FGTank*> Tanks; |
| 194 | unsigned int numSelectedFuelTanks; |
| 195 | unsigned int numSelectedOxiTanks; |
| 196 | unsigned int numFuelTanks; |
| 197 | unsigned int numOxiTanks; |
| 198 | unsigned int numEngines; |
| 199 | unsigned int numTanks; |
| 200 | int ActiveEngine; |
| 201 | FGColumnVector3 vForces; |
| 202 | FGColumnVector3 vMoments; |
| 203 | FGColumnVector3 vTankXYZ; |
| 204 | FGColumnVector3 vXYZtank_arm; |
| 205 | FGMatrix33 tankJ; |
| 206 | simgear::PropertyObject<bool> refuel; |
| 207 | simgear::PropertyObject<bool> dump; |
| 208 | bool FuelFreeze; |
| 209 | simgear::PropertyObject<double> TotalFuelQuantity; |
| 210 | simgear::PropertyObject<double> TotalOxidizerQuantity; |
| 211 | double DumpRate; |
| 212 | double RefuelRate; |
| 213 | bool IsBound; |
| 214 | bool HavePistonEngine; |
| 215 | bool HaveTurbineEngine; |
| 216 | bool HaveTurboPropEngine; |
| 217 | bool HaveRocketEngine; |
| 218 | bool HaveElectricEngine; |
| 219 | void ConsumeFuel(FGEngine* engine); |
| 220 | |
| 221 | bool ReadingEngine; |
| 222 | |
| 223 | void bind(); |
| 224 | void Debug(int from) override; |
| 225 | }; |
| 226 | } |
| 227 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 228 | #endif |