]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGPropeller.cpp
Updates to JSBSim and FDM interface.
[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 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 CLASS IMPLEMENTATION
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47
48 FGPropeller::FGPropeller(FGFDMExec* exec, FGConfigFile* Prop_cfg) : FGThruster(exec)
49 {
50   string token;
51   int rows, cols;
52
53   MaxPitch = MinPitch = P_Factor = Sense = 0.0;
54
55   Name = Prop_cfg->GetValue("NAME");
56   Prop_cfg->GetNextConfigLine();
57   while (Prop_cfg->GetValue() != "/FG_PROPELLER") {
58     *Prop_cfg >> token;
59     if (token == "IXX") {
60       *Prop_cfg >> Ixx;
61     } else if (token == "DIAMETER") {
62       *Prop_cfg >> Diameter;
63       Diameter /= 12.0;
64     } else if (token == "NUMBLADES") {
65       *Prop_cfg >> numBlades;
66     } else if (token == "MINPITCH") {
67       *Prop_cfg >> MinPitch;
68     } else if (token == "MAXPITCH") {
69       *Prop_cfg >> MaxPitch;
70     } else if (token == "P_FACTOR") {
71       *Prop_cfg >> P_Factor;
72     } else if (token == "SENSE") {
73       *Prop_cfg >> Sense;
74     } else if (token == "EFFICIENCY") {
75       *Prop_cfg >> rows >> cols;
76       if (cols == 1) Efficiency = new FGTable(rows);
77             else           Efficiency = new FGTable(rows, cols);
78       *Efficiency << *Prop_cfg;
79     } else if (token == "C_THRUST") {
80       *Prop_cfg >> rows >> cols;
81       if (cols == 1) cThrust = new FGTable(rows);
82             else           cThrust = new FGTable(rows, cols);
83       *cThrust << *Prop_cfg;
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     } else if (token == "EOF") {
90       cerr << "      End of file reached" <<  endl;
91       break;
92     } else {
93       cerr << "Unhandled token in Propeller config file: " << token << endl;
94     }
95   }
96
97   if (debug_lvl > 0) {
98     cout << "\n    Propeller Name: " << Name << endl;
99     cout << "      IXX = " << Ixx << endl;
100     cout << "      Diameter = " << Diameter << " ft." << endl;
101     cout << "      Number of Blades  = " << numBlades << endl;
102     cout << "      Minimum Pitch  = " << MinPitch << endl;
103     cout << "      Maximum Pitch  = " << MaxPitch << endl;
104     if (P_Factor > 0.0) cout << "      P-Factor = " << P_Factor << endl;
105     if (Sense > 0.0) {
106       cout << "      Rotation Sense = CW (viewed from pilot looking forward)" << endl;
107     } else if (Sense < 0.0) {
108       cout << "      Rotation Sense = CCW (viewed from pilot looking forward)" << endl;
109     } else {
110       cout << "      Rotation Sense = indeterminate" << endl;
111     }
112     cout << "      Efficiency: " <<  endl;
113     Efficiency->Print();
114     cout << "      Thrust Coefficient: " <<  endl;
115     cThrust->Print();
116     cout << "      Power Coefficient: " <<  endl;
117     cPower->Print();
118   }
119
120   Type = ttPropeller;
121   RPM = 0;
122
123   if (debug_lvl & 2) cout << "Instantiated: FGPropeller" << endl;
124 }
125
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
128 FGPropeller::~FGPropeller()
129 {
130   if (Efficiency) delete Efficiency;
131   if (cThrust)    delete cThrust;
132   if (cPower)     delete cPower;
133   if (debug_lvl & 2) cout << "Destroyed:    FGPropeller" << endl;
134 }
135
136 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 //
138 // We must be getting the aerodynamic velocity here, NOT the inertial velocity.
139 // We need the velocity with respect to the wind.
140 //
141 // Note that PowerAvailable is the excess power available after the drag of the
142 // propeller has been subtracted. At equilibrium, PowerAvailable will be zero -
143 // indicating that the propeller will not accelerate or decelerate.
144 // Remembering that Torque * omega = Power, we can derive the torque on the
145 // propeller and its acceleration to give a new RPM. The current RPM will be
146 // used to calculate thrust.
147 //
148 // Because RPM could be zero, we need to be creative about what RPM is stated as.
149
150 float FGPropeller::Calculate(float PowerAvailable)
151 {
152   float J, C_Thrust, omega;
153   float Vel = (fdmex->GetTranslation()->GetvAero())(1);
154   float rho = fdmex->GetAtmosphere()->GetDensity();
155   float RPS = RPM/60.0;
156   float alpha, beta;
157
158   if (RPM > 0.10) {
159     J = Vel / (Diameter * RPM / 60.0);
160   } else {
161     J = 0.0;
162   }
163
164   if (MaxPitch == MinPitch) { // Fixed pitch prop
165     C_Thrust = cThrust->GetValue(J);
166   } else {                    // Variable pitch prop
167     C_Thrust = cThrust->GetValue(J, Pitch);
168   }
169
170   if (P_Factor > 0.0001) {
171     alpha = fdmex->GetTranslation()->Getalpha();
172     beta  = fdmex->GetTranslation()->Getbeta();
173     SetLocationY(P_Factor*alpha*fabs(Sense)/Sense);
174     SetLocationZ(P_Factor*beta*fabs(Sense)/Sense);
175   } else if (P_Factor < 0.000) {
176     cerr << "P-Factor value in config file must be greater than zero" << endl;
177   }
178
179   Thrust = C_Thrust*RPS*RPS*Diameter*Diameter*Diameter*Diameter*rho;
180   vFn(1) = Thrust;
181   omega = RPS*2.0*M_PI;
182
183   // Must consider rotated axis for propeller (V-22, helicopter case)
184   // FIX THIS !!
185   vH(eX) = Ixx*omega*fabs(Sense)/Sense;
186   vH(eY) = 0.0;
187   vH(eZ) = 0.0;
188
189   if (omega <= 5) omega = 1.0;
190
191   Torque = PowerAvailable / omega;
192   RPM = (RPS + ((Torque / Ixx) / (2.0 * M_PI)) * deltaT) * 60.0;
193   return Thrust; // return thrust in pounds
194 }
195
196 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197
198 float FGPropeller::GetPowerRequired(void)
199 {
200   if (RPM <= 0.10) return 0.0; // If the prop ain't turnin', the fuel ain't burnin'.
201
202   float cPReq, RPS = RPM / 60.0;
203
204   float J = (fdmex->GetTranslation()->GetvAero())(1) / (Diameter * RPS);
205   float rho = fdmex->GetAtmosphere()->GetDensity();
206
207   if (MaxPitch == MinPitch) { // Fixed pitch prop
208     cPReq = cPower->GetValue(J);
209   } else {                    // Variable pitch prop
210     cPReq = cPower->GetValue(J, Pitch);
211   }
212
213   PowerRequired = cPReq*RPS*RPS*RPS*Diameter*Diameter*Diameter*Diameter
214                                                        *Diameter*rho;
215   return PowerRequired;
216 }
217
218 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
219
220 void FGPropeller::Debug(void)
221 {
222     //TODO: Add your source code here
223 }
224