]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPropeller.cpp
Synced with latest JSBSim. X15 works for me, but C172 segfaults.
[flightgear.git] / src / FDM / JSBSim / FGPropeller.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGPropeller.cpp
4  Author:       Jon S. Berndt
5  Date started: 08/24/00
6  Purpose:      Encapsulates the propeller object
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 HISTORY
31 --------------------------------------------------------------------------------
32 08/24/00  JSB  Created
33
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 INCLUDES
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38 #include "FGPropeller.h"
39
40 static const char *IdSrc = "$Id$";
41 static const char *IdHdr = ID_PROPELLER;
42
43 extern short debug_lvl;
44
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 CLASS IMPLEMENTATION
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48
49
50 FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(exec)
51 {
52   string token;
53   int rows, cols;
54
55   Name = Prop_cfg->GetValue("NAME");
56   cout << "\n    Propeller Name: " << Name << endl;
57   Prop_cfg->GetNextConfigLine();
58   while (Prop_cfg->GetValue() != "/FG_PROPELLER") {
59     *Prop_cfg >> token;
60     if (token == "IXX") {
61       *Prop_cfg >> Ixx;
62       cout << "      IXX = " << Ixx << endl;
63     } else if (token == "DIAMETER") {
64       *Prop_cfg >> Diameter;
65       Diameter /= 12.0;
66       cout << "      Diameter = " << Diameter << " ft." << endl;
67     } else if (token == "NUMBLADES") {
68       *Prop_cfg >> numBlades;
69       cout << "      Number of Blades  = " << numBlades << endl;
70     } else if (token == "EFFICIENCY") {
71        *Prop_cfg >> rows >> cols;
72        if (cols == 1) Efficiency = new FGTable(rows);
73              else           Efficiency = new FGTable(rows, cols);
74        *Efficiency << *Prop_cfg;
75        cout << "      Efficiency: " <<  endl;
76        Efficiency->Print();
77     } else if (token == "C_THRUST") {
78        *Prop_cfg >> rows >> cols;
79        if (cols == 1) cThrust = new FGTable(rows);
80              else           cThrust = new FGTable(rows, cols);
81        *cThrust << *Prop_cfg;
82        cout << "      Thrust Coefficient: " <<  endl;
83        cThrust->Print();
84     } else if (token == "C_POWER") {
85        *Prop_cfg >> rows >> cols;
86        if (cols == 1) cPower = new FGTable(rows);
87              else           cPower = new FGTable(rows, cols);
88        *cPower << *Prop_cfg;
89        cout << "      Power Coefficient: " <<  endl;
90        cPower->Print();
91     } else if (token == "EOF") {
92        cout << "      End of file reached" <<  endl;
93        break;
94     } else {
95       cout << "Unhandled token in Propeller config file: " << token << endl;
96     }
97   }
98
99   Type = ttPropeller;
100   RPM = 0;
101
102   if (debug_lvl & 2) cout << "Instantiated: FGPropeller" << endl;
103 }
104
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106
107 FGPropeller::~FGPropeller()
108 {
109   if (Efficiency) delete Efficiency;
110   if (cThrust)    delete cThrust;
111   if (cPower)     delete cPower;
112   if (debug_lvl & 2) cout << "Destroyed:    FGPropeller" << endl;
113 }
114
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 //
117 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
118 // We need the velocity with respect to the wind.
119 //
120 // Note that PowerAvailable is the excess power available after the drag of the
121 // propeller has been subtracted. At equilibrium, PowerAvailable will be zero -
122 // indicating that the propeller will not accelerate or decelerate.
123 // Remembering that Torque * omega = Power, we can derive the torque on the
124 // propeller and its acceleration to give a new RPM. The current RPM will be
125 // used to calculate thrust.
126 //
127 // Because RPM could be zero, we need to be creative about what RPM is stated as.
128
129 float FGPropeller::Calculate(float PowerAvailable)
130 {
131   float J, C_Thrust, omega;
132   float Vel = (fdmex->GetTranslation()->GetUVW())(1);
133   float rho = fdmex->GetAtmosphere()->GetDensity();
134   float RPS = RPM/60.0;
135
136   if (RPM > 0.10) {
137     J = Vel / (Diameter * RPM / 60.0);
138   } else {
139     J = 0.0;
140   }
141
142   if (MaxPitch == MinPitch) { // Fixed pitch prop
143     C_Thrust = cThrust->GetValue(J);
144   } else {                    // Variable pitch prop
145     C_Thrust = cThrust->GetValue(J, Pitch);
146   }
147
148   Thrust = C_Thrust*RPS*RPS*Diameter*Diameter*Diameter*Diameter*rho;
149   vFn(1) = Thrust;
150   omega = RPS*2.0*M_PI;
151
152   if (omega <= 5) omega = 1.0;
153
154   Torque = PowerAvailable / omega;
155   RPM = (RPS + ((Torque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
156   return Thrust; // return thrust in pounds
157 }
158
159 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160
161 float FGPropeller::GetPowerRequired(void)
162 {
163   if (RPM <= 0.10) return 0.0; // If the prop ain't turnin', the fuel ain't burnin'.
164
165   float cPReq, RPS = RPM / 60.0;
166
167   float J = (fdmex->GetTranslation()->GetUVW())(1) / (Diameter * RPS);
168   float rho = fdmex->GetAtmosphere()->GetDensity();
169
170   if (MaxPitch == MinPitch) { // Fixed pitch prop
171     cPReq = cPower->GetValue(J);
172   } else {                    // Variable pitch prop
173     cPReq = cPower->GetValue(J, Pitch);
174   }
175
176   PowerRequired = cPReq*RPS*RPS*RPS*Diameter*Diameter*Diameter*Diameter
177                                                        *Diameter*rho;
178   return PowerRequired;
179 }
180
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182
183 void FGPropeller::Debug(void)
184 {
185     //TODO: Add your source code here
186 }
187