]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPiston.cpp
Latest round of JSBSim updates.
[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 "FGPiston.h"
42
43 static const char *IdSrc = "$Id$";
44 static const char *IdHdr = ID_PISTON;
45
46 extern short debug_lvl;
47
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 CLASS IMPLEMENTATION
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52 FGPiston::FGPiston(FGFDMExec* exec, FGConfigFile* Eng_cfg) : FGEngine(exec)
53 {
54   string token;
55
56   Name = Eng_cfg->GetValue("NAME");
57   cout << "\n    Engine Name: " << Name << endl;
58   Eng_cfg->GetNextConfigLine();
59   while (Eng_cfg->GetValue() != "/FG_PISTON") {
60     *Eng_cfg >> token;
61     if (token == "BRAKEHORSEPOWER") {
62       *Eng_cfg >> BrakeHorsePower;
63       cout << "      BrakeHorsePower = " << BrakeHorsePower << endl;
64     } else if (token == "MAXTHROTTLE") {
65       *Eng_cfg >> MaxThrottle;
66       cout << "      MaxThrottle = " << MaxThrottle << endl;
67     } else if (token == "MINTHROTTLE") {
68       *Eng_cfg >> MinThrottle;
69       cout << "      MinThrottle = " << MinThrottle << endl;
70     } else if (token == "SLFUELFLOWMAX") {
71       *Eng_cfg >> SLFuelFlowMax;
72       cout << "      SLFuelFlowMax = " << SLFuelFlowMax << endl;
73     } else if (token == "SPEEDSLOPE") {
74       *Eng_cfg >> SpeedSlope;
75       cout << "      SpeedSlope = " << SpeedSlope << endl;
76     } else if (token == "SPEEDINTERCEPT") {
77       *Eng_cfg >> SpeedIntercept;
78       cout << "      SpeedIntercept = " << SpeedIntercept << endl;
79     } else if (token == "ALTITUDESLOPE") {
80       *Eng_cfg >> AltitudeSlope;
81       cout << "      AltitudeSlope = " << AltitudeSlope << endl;
82     } else {
83       cout << "Unhandled token in Engine config file: " << token << endl;
84     }
85   }
86
87   EngineNumber = 0;
88
89   if (debug_lvl & 2) cout << "Instantiated: FGPiston" << endl;
90 }
91
92 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93
94 FGPiston::~FGPiston()
95 {
96   if (debug_lvl & 2) cout << "Destroyed:    FGPiston" << endl;
97 }
98
99 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100
101 float FGPiston::Calculate(float PowerRequired)
102 {
103   float h,EngineMaxPower;
104
105   ConsumeFuel();
106
107   Throttle = FCS->GetThrottlePos(EngineNumber);
108
109   h = Position->Geth();
110
111   if (h < 0) h = 0;
112
113   EngineMaxPower = (1 + AltitudeSlope*h)*BrakeHorsePower;
114   PowerAvailable = Throttle*EngineMaxPower*HPTOFTLBSSEC - PowerRequired;
115   
116   return PowerAvailable;
117 }
118
119 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120
121 void FGPiston::Debug(void)
122 {
123     //TODO: Add your source code here
124 }
125