]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPiston.cpp
Synced to latest version of JSBSim which [hopefully] includes all of Erik's
[flightgear.git] / src / FDM / JSBSim / FGPiston.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGPiston.cpp
4  Author:       Jon S. Berndt
5  Date started: 09/12/2000
6  Purpose:      This module models a Piston engine
7
8  ------------- Copyright (C) 2000  Jon S. Berndt (jsb@hal-pc.org) --------------
9
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
13  version.
14
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
18  details.
19
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.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
30 This class descends from the FGEngine class and models a Piston engine based on
31 parameters given in the engine config file for this class
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 09/12/2000  JSB  Created
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "FGDefs.h"
42 #include "FGPiston.h"
43
44 static const char *IdSrc = "$Id$";
45 static const char *IdHdr = ID_PISTON;
46
47 extern short debug_lvl;
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 CLASS IMPLEMENTATION
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 FGPiston::FGPiston(FGFDMExec* exec, FGConfigFile* Eng_cfg) : FGEngine(exec)
54 {
55   string token;
56
57   Name = Eng_cfg->GetValue("NAME");
58   Eng_cfg->GetNextConfigLine();
59   while (Eng_cfg->GetValue() != "/FG_PISTON") {
60     *Eng_cfg >> token;
61     if      (token == "BRAKEHORSEPOWER") *Eng_cfg >> BrakeHorsePower;
62     else if (token == "MAXTHROTTLE")     *Eng_cfg >> MaxThrottle;
63     else if (token == "MINTHROTTLE")     *Eng_cfg >> MinThrottle;
64     else if (token == "SLFUELFLOWMAX")   *Eng_cfg >> SLFuelFlowMax;
65     else if (token == "SPEEDSLOPE")      *Eng_cfg >> SpeedSlope;
66     else if (token == "SPEEDINTERCEPT")  *Eng_cfg >> SpeedIntercept;
67     else if (token == "ALTITUDESLOPE")   *Eng_cfg >> AltitudeSlope;
68     else cerr << "Unhandled token in Engine config file: " << token << endl;
69   }
70
71   if (debug_lvl > 0) {
72     cout << "\n    Engine Name: " << Name << endl;
73     cout << "      BrakeHorsePower = " << BrakeHorsePower << endl;
74     cout << "      MaxThrottle = " << MaxThrottle << endl;
75     cout << "      MinThrottle = " << MinThrottle << endl;
76     cout << "      SLFuelFlowMax = " << SLFuelFlowMax << endl;
77     cout << "      SpeedSlope = " << SpeedSlope << endl;
78     cout << "      SpeedIntercept = " << SpeedIntercept << endl;
79     cout << "      AltitudeSlope = " << AltitudeSlope << endl;
80   }
81
82   Type = etPiston;
83   EngineNumber = 0;
84
85   if (debug_lvl & 2) cout << "Instantiated: FGPiston" << endl;
86 }
87
88 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89
90 FGPiston::~FGPiston()
91 {
92   if (debug_lvl & 2) cout << "Destroyed:    FGPiston" << endl;
93 }
94
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96
97 float FGPiston::Calculate(float PowerRequired)
98 {
99   float h,EngineMaxPower;
100
101   ConsumeFuel();
102
103   Throttle = FCS->GetThrottlePos(EngineNumber);
104
105   h = Position->Geth();
106
107   if (h < 0) h = 0;
108
109   EngineMaxPower = (1 + AltitudeSlope*h)*BrakeHorsePower;
110   PowerAvailable = Throttle*EngineMaxPower*HPTOFTLBSSEC - PowerRequired;
111   
112   return PowerAvailable;
113 }
114
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
117 void FGPiston::Debug(void)
118 {
119     //TODO: Add your source code here
120 }
121