]> git.mxchange.org Git - flightgear.git/blob - src/FDM/ps-10520c.cxx
78ffb24a9aee1c1b732f1f7a1097d57fca35887c
[flightgear.git] / src / FDM / ps-10520c.cxx
1 // Module:        10520c.c
2 //  Author:       Phil Schubert
3 //  Date started: 12/03/99
4 //  Purpose:      Models a Continental IO-520-M Engine
5 //  Called by:    FGSimExec
6 // 
7 //  Copyright (C) 1999  Philip L. Schubert (philip@zedley.com)
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 // 02111-1307, USA.
23 //
24 // Further information about the GNU General Public License can also
25 // be found on the world wide web at http://www.gnu.org.
26 //
27 // FUNCTIONAL DESCRIPTION
28 // ------------------------------------------------------------------------
29 // Models a Continental IO-520-M engine. This engine is used in Cessna
30 // 210, 310, Beechcraft Bonaza and Baron C55. The equations used below
31 // were determined by a first and second order curve fits using Excel. 
32 // The data is from the Cessna Aircraft Corporations Engine and Flight
33 // Computer for C310. Part Number D3500-13
34 // 
35 // ARGUMENTS
36 // ------------------------------------------------------------------------
37 // 
38 // 
39 // HISTORY
40 // ------------------------------------------------------------------------
41 // 12/03/99     PLS     Created
42 // 07/03/99     PLS     Added Calculation of Density, and Prop_Torque
43 // 07/03/99     PLS     Restructered Variables to allow easier implementation
44 //                      of Classes
45 // 15/03/99     PLS     Added Oil Pressure
46 // 19/8/2000               PLS     Updated E-mail address - This version compiles
47 //  19/8/2000              PLS          Set Max Prop blade angle to prevent prop exeeding 90
48 // ------------------------------------------------------------------------
49 // INCLUDES
50 // ------------------------------------------------------------------------
51
52 #include <iostream.h>
53 // #include <stdio.h>
54 #include <math.h>
55 // #include "10520c.h"
56
57 // ------------------------------------------------------------------------
58 // CODE
59 // ------------------------------------------------------------------------
60
61 // prototype definitions
62 // These should be in a header file 10520c.h
63
64 float Density (float x);
65 void  ShowRho (float x);
66
67 float IAS_to_FPS (float x);
68 void ShowFPS(float x);
69
70 float Get_Throttle (float x);
71 void Show_Throttle (float x);
72
73 float Manifold_Pressure (float x, float z);
74 void Show_Manifold_Pressure (float x);
75
76 float CHT (float Fuel_Flow, float Mixture, float IAS);
77 void Show_CHT (float x);
78
79 float Oil_Temp (float x, float y);
80 void Show_Oil_Temp (float x);
81
82 float Oil_Press (float Oil_Temp, float Engine_RPM);
83 void Show_Oil_Press (float x);
84
85 int main()
86
87 {
88     // Declare local variables
89     int num = 0; // Not used. Counting variables
90     int num2 = 100;  // Not used.
91     float ManXRPM = 0;
92     float Vo = 0;
93     float V1 = 0;
94
95
96         // Set up the new variables
97     float Blade_Station = 30;
98     float Rho = 0.002378;
99     float FGProp_Area = 1.405/3;
100     float PI = 3.1428571;
101
102     // Input Variables
103     float IAS = 0; 
104     cout << "Enter IAS  ";
105     // cin  >> IAS;
106     IAS = 85;
107     cout << endl;
108  
109
110     // 0 = Closed, 100 = Fully Open
111     float FGEng1_Throttle_Lever_Pos = 75;
112     // 0 = Full Course 100 = Full Fine
113     float FGEng1_Propeller_Lever_Pos = 75;      
114     // 0 = Idle Cut Off 100 = Full Rich
115     float FGEng1_Mixture_Lever_Pos = 100;
116
117     // Environmental Variables
118
119     // Temp Variation from ISA (Deg F)
120     float FG_ISA_VAR = 0;
121     // Pressure Altitude  1000's of Feet
122     float FG_Pressure_Ht = 0;
123
124     // Parameters that alter the operation of the engine.
125     // Yes = 1. Is there Fuel Available. Calculated elsewhere
126     int FGEng1_Fuel_Available = 1;
127     // Off = 0. Reduces power by 3 % for same throttle setting
128     int FGEng1_Alternate_Air_Pos =0;
129     // 1 = On.   Reduces power by 5 % for same power lever settings
130     int FGEng1_Magneto_Left = 1;
131     // 1 = On.  Ditto, Both of the above though do not alter fuel flow
132     int FGEng1_Magneto_Right = 1;
133
134     // There needs to be a section in here to trap silly values, like
135     // 0, otherwise they will crash the calculations
136
137     //  Engine Specific Variables used by this program that have limits.
138     //  Will be set in a parameter file to be read in to create
139     //  and instance for each engine.
140     float FGEng_Max_Manifold_Pressure = 29.50;
141     float FGEng_Max_RPM = 2700;
142     float FGEng_Min_RPM = 1000;
143     float FGEng_Max_Fuel_Flow = 130;
144     float FGEng_Mag_Derate_Percent = 5;
145     float FGEng_MaxHP = 285;
146     float FGEng_Gear_Ratio = 1;
147
148     // Initialise Engine Variables used by this instance
149     float FGEng1_Percentage_Power = 0;
150     float FGEng1_Manifold_Pressure = 29.00;     // Inches
151     float FGEng1_RPM = 500;
152     float FGEng1_Fuel_Flow = 0;                 // lbs/hour
153     float FGEng1_Torque = 0;
154     float FGEng1_CHT = 370;
155     float FGEng1_Mixture = 14;
156     float FGEng1_Oil_Pressure = 0;              // PSI
157     float FGEng1_Oil_Temp = 85;                 // Deg C
158     float FGEng1_HP = 0;
159     float FGEng1_RPS = 0;
160     float Torque_Imbalance = 0;
161     float FGEng1_Desired_RPM = 0;
162
163     // Initialise Propellor Variables used by this instance
164     float FGProp1_Angular_V = 0;
165     float FGProp1_Coef_Drag =  0.6;
166     float FGProp1_Torque = 0;
167     float FGProp1_Thrust = 0;
168     float FGProp1_RPS = 0;
169     float FGProp1_Coef_Lift = 0.1;
170     float Alpha1 = 13.5;
171     float FGProp1_Blade_Angle = 13.5;
172     float FGProp_Fine_Pitch_Stop = 13.5;
173     float FGProp_Course_Pitch_Stop = 55;
174
175     // cout << "Enter Blade Angle  ";
176     // cin  >> FGProp1_Blade_Angle;
177     // cout << endl;
178
179     cout << " Number of Iterations ";
180     // cin >> num2;
181     num2 = 100;
182     cout << endl;
183
184     cout << " Throttle % ";
185     // cin >> FGEng1_Throttle_Lever_Pos;
186     FGEng1_Throttle_Lever_Pos = 50;
187     cout << endl;
188
189     cout << " Prop % ";
190     // cin >> FGEng1_Propeller_Lever_Pos;
191     FGEng1_Propeller_Lever_Pos = 100;
192     cout << endl;
193
194     //==================================================================
195     // Engine & Environmental Inputs from elsewhere
196
197     // Calculate Air Density (Rho) - In FG this is calculated in 
198     // FG_Atomoshere.cxx
199
200     Rho = Density(FG_Pressure_Ht); // In FG FG_Pressure_Ht is "h"
201     ShowRho(Rho);
202
203   
204     // Calculate Manifold Pressure (Engine 1) as set by throttle opening
205
206     FGEng1_Manifold_Pressure = Manifold_Pressure(FGEng1_Throttle_Lever_Pos,
207                                                  FGEng1_Manifold_Pressure );
208     Show_Manifold_Pressure(FGEng1_Manifold_Pressure);
209
210     // Calculate Desired RPM as set by Prop Lever Position.
211     // Actual engine RPM may be different
212     // The governed max RPM at 100% Prop Lever Position =  FGEng_MaxRPM
213     // The governed minimum RPM at 0% Prop Lever Position = FGEng_Min_RPM
214     // The actual minimum RPM of the engine can be < FGEng_Min_RPM if there is insufficient 
215     //  engine torque to counter act the propeller torque at  FGProp_Fine_Pitch_Stop
216
217     FGEng1_RPM = (FGEng1_Propeller_Lever_Pos * (FGEng_Max_RPM - FGEng_Min_RPM) /100)
218         + FGEng_Min_RPM ;
219
220         // * ((FGEng_Max_RPM + FGEng_Min_RPM) / 100);
221     
222     if (FGEng1_RPM >= 2700) {
223         FGEng1_RPM = 2700;
224     }
225     FGEng1_Desired_RPM = FGEng1_RPM;
226
227     cout << "Desired RPM = " << FGEng1_Desired_RPM << endl;
228
229     //==================================================================
230     // Engine Power & Torque Calculations
231     
232     // Loop until stable - required for testing only
233     for (num = 1; num < num2; num++) {
234         cout << endl << "====================" << endl;
235         cout << "MP Inches = " << FGEng1_Manifold_Pressure << "\t";
236         cout << FGEng1_RPM << "  RPM" << "\t";
237
238         // For a givem Manifold Pressure and RPM calculate the % Power
239         // Multiply Manifold Pressure by RPM
240         ManXRPM = FGEng1_Manifold_Pressure * FGEng1_RPM;
241         cout << ManXRPM << endl;
242
243         //  Calculate % Power
244         FGEng1_Percentage_Power = (+ 7E-09 * ManXRPM * ManXRPM) 
245             + ( + 7E-04 * ManXRPM) - 0.1218;
246         cout << "percent power = " << FGEng1_Percentage_Power <<  "%" << "\t";
247
248         // Adjust for Temperature - Temperature above Standard decrease
249         // power % by 7/120 per degree F increase, and incease power for
250         // temps below at the same ratio
251         FGEng1_Percentage_Power = FGEng1_Percentage_Power - (FG_ISA_VAR * 7 /120);
252         cout << " adjusted T = " << FGEng1_Percentage_Power <<  "%" << "\t";
253         
254         // Adjust for Altitude. In this version a linear variation is
255         // used. Decrease 1% for each 1000' increase in Altitde
256         FGEng1_Percentage_Power = FGEng1_Percentage_Power 
257             + (FG_Pressure_Ht * 12/10000);      
258         cout << " adjusted A = " << FGEng1_Percentage_Power <<  "%" << "\t";
259
260         // Now Calculate Fuel Flow based on % Power Best Power Mixture
261         FGEng1_Fuel_Flow = FGEng1_Percentage_Power
262             * FGEng_Max_Fuel_Flow / 100;
263         // cout << FGEng1_Fuel_Flow << " lbs/hr"<< endl;
264         
265         // Now Derate engine for the effects of Bad/Switched off magnetos
266         if (FGEng1_Magneto_Left == 0 && FGEng1_Magneto_Right == 0) {
267             // cout << "Both OFF\n";
268             FGEng1_Percentage_Power = 0;
269         } else if (FGEng1_Magneto_Left && FGEng1_Magneto_Right) {
270             // cout << "Both On    ";
271         } else if (FGEng1_Magneto_Left == 0 || FGEng1_Magneto_Right== 0) {
272             // cout << "1 Magneto Failed   ";
273                                 
274             FGEng1_Percentage_Power = FGEng1_Percentage_Power * 
275                 ((100 - FGEng_Mag_Derate_Percent)/100);
276             //  cout << FGEng1_Percentage_Power <<  "%" << "\t";
277         }       
278
279         // Calculate Engine Horsepower
280
281         FGEng1_HP = FGEng1_Percentage_Power * FGEng_MaxHP/100;
282
283         // Calculate Engine Torque
284
285         FGEng1_Torque = FGEng1_HP * 5252 / FGEng1_RPM;
286         cout << FGEng1_Torque << "Ft/lbs" << "\t";
287
288         // Calculate Cylinder Head Temperature
289         FGEng1_CHT = CHT (FGEng1_Fuel_Flow, FGEng1_Mixture, IAS);
290         // Show_CHT (FGEng1_CHT);
291
292         // Calculate Oil Pressure
293         FGEng1_Oil_Pressure = Oil_Press (FGEng1_Oil_Temp, FGEng1_RPM);
294         // Show_Oil_Press(FGEng1_Oil_Pressure);
295
296         
297         //==============================================================
298
299         // Now do the Propellor Calculations
300
301         // Revs per second
302         FGProp1_RPS = FGEng1_RPM * FGEng_Gear_Ratio/60;
303         // cout << FGProp1_RPS << " RPS" <<  endl;
304
305         //Radial Flow Vector (V2) Ft/sec at Ref Blade Station (usually 30")
306         FGProp1_Angular_V = FGProp1_RPS * 2 * PI * (Blade_Station / 12);
307         cout << "Angular Velocity " << FGProp1_Angular_V << endl;
308
309         // Axial Flow Vector (Vo) Ft/sec
310         // Some further work required here to allow for inflow at low speeds
311         // Vo = (IAS + 20) * 1.688888;
312         Vo = IAS_to_FPS(IAS + 20);
313         // ShowFPS ( Vo );
314
315         // cout << Vo << "Axial Velocity" << endl;
316
317         // Relative Velocity (V1)
318         V1 = sqrt((FGProp1_Angular_V * FGProp1_Angular_V) +
319                   (Vo * Vo));
320         cout << "Relative Velocity " << V1 << endl;
321     
322         if ( FGProp1_Blade_Angle >= FGProp_Course_Pitch_Stop )  {
323             FGProp1_Blade_Angle = FGProp_Course_Pitch_Stop;
324         }
325
326         cout << FGProp1_Blade_Angle << " Prop Blade Angle" << endl;
327
328         // Blade Angle of Attack (Alpha1)
329
330         Alpha1 = FGProp1_Blade_Angle -(atan(Vo / FGProp1_Angular_V) * (180/PI));
331         // cout << Alpha1 << " Alpha1" << endl;
332
333         cout << "  Alpha1 = " << Alpha1
334              << "  Blade angle = " << FGProp1_Blade_Angle
335              << "  Vo = " << Vo
336              << "  FGProp1_Angular_V = " << FGProp1_Angular_V << endl;
337
338         // Calculate Coefficient of Drag at Alpha1
339         FGProp1_Coef_Drag = (0.0005 * (Alpha1 * Alpha1)) + (0.0003 * Alpha1)
340             + 0.0094;
341         //      cout << FGProp1_Coef_Drag << " Coef Drag" << endl;
342
343         // Calculate Coefficient of Lift at Alpha1
344         FGProp1_Coef_Lift = -(0.0026 * (Alpha1 * Alpha1)) + (0.1027 * Alpha1)
345             + 0.2295;
346         // cout << FGProp1_Coef_Lift << " Coef Lift " << endl;
347
348         // Covert Alplha1 to Radians
349         // Alpha1 = Alpha1 * PI / 180;
350
351         //  Calculate Prop Torque
352         FGProp1_Torque = (0.5 * Rho * (V1 * V1) * FGProp_Area
353                           * ((FGProp1_Coef_Lift * sin(Alpha1 * PI / 180))
354                              + (FGProp1_Coef_Drag * cos(Alpha1 * PI / 180))))
355             * (Blade_Station/12);
356         cout << "Prop Torque = " << FGProp1_Torque << endl;
357
358         //  Calculate Prop Thrust
359         FGProp1_Thrust = 0.5 * Rho * (V1 * V1) * FGProp_Area
360             * ((FGProp1_Coef_Lift * cos(Alpha1 * PI / 180))
361                - (FGProp1_Coef_Drag * sin(Alpha1 * PI / 180)));
362         cout << " Prop Thrust = " << FGProp1_Thrust <<  endl;
363
364         // End of Propeller Calculations   
365         //==============================================================
366
367
368
369         Torque_Imbalance = FGProp1_Torque - FGEng1_Torque; 
370         //  cout <<  Torque_Imbalance << endl;
371
372         if (Torque_Imbalance > 20) {
373             FGEng1_RPM -= 14.5;
374             // FGProp1_RPM -= 25;
375             FGProp1_Blade_Angle -= 0.75;
376         }
377
378         if (FGProp1_Blade_Angle < FGProp_Fine_Pitch_Stop) {
379             FGProp1_Blade_Angle = FGProp_Fine_Pitch_Stop;
380         }
381         if (Torque_Imbalance < -20) {
382             FGEng1_RPM += 14.5;
383             // FGProp1_RPM += 25;
384             FGProp1_Blade_Angle += 0.75;
385         }
386
387         if (FGEng1_RPM >= 2700) {
388             FGEng1_RPM = 2700;
389         }
390
391
392         // cout << FGEng1_RPM << " Blade_Angle  " << FGProp1_Blade_Angle << endl << endl;
393
394     }
395
396
397     return (0);
398 }
399
400
401
402
403 // Functions
404
405 // Calculate Air Density - Rho
406 float Density ( float x )
407 {
408     float y ;
409     y = ((9E-08 * x * x) - (7E-08 * x) + 0.0024);
410     return(y);
411 }
412
413 // Show Air Density Calculations
414 void ShowRho (float x)
415 {
416     cout << "Rho = ";
417     cout << x << endl;
418 }
419
420
421
422
423
424 // Calculate Speed in FPS given Knots CAS
425 float IAS_to_FPS (float x)
426 {
427     float y;
428     y = x * 1.68888888;
429     return (y);
430 }
431
432 // Show Feet per Second
433 void ShowFPS (float x)
434 {
435     cout << "Feet/sec = ";
436     cout << x << endl;
437 }
438
439
440
441 // Calculate Manifold Pressure based on Throttle lever Position
442
443 float Manifold_Pressure ( float x, float z)
444 {
445     float y;  
446     // if ( x < = 0 )
447     //   {
448     //  x = 0.00001;
449     //  }
450     y = x * z / 100;
451     return (y);
452 }
453
454 // Show Manifold Pressure
455 void  Show_Manifold_Pressure (float x)
456 {
457     cout << "Manifold Pressure  = ";
458     cout << x << endl;
459 }
460
461 // Calculate Oil Temperature
462
463 float Oil_Temp (float Fuel_Flow, float Mixture, float IAS)
464 {
465     float Oil_Temp = 85;
466         
467     return (Oil_Temp);
468 }
469
470 // Show Oil Temperature
471
472 void Show_Oil_Temp (float x)
473 {
474     cout << "Oil Temperature (F) = ";
475     cout << x << endl;
476 }
477
478
479 // Calculate Oil Pressure
480
481 float Oil_Press (float Oil_Temp, float Engine_RPM)
482 {
483     float Oil_Pressure = 0;                     //PSI
484     float Oil_Press_Relief_Valve = 60;  //PSI
485     float Oil_Press_RPM_Max = 1800;
486     float Design_Oil_Temp = 85;         //Celsius
487     float Oil_Viscosity_Index = 0.25;   // PSI/Deg C
488     float Temp_Deviation = 0;           // Deg C
489
490     Oil_Pressure = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * Engine_RPM;
491         
492     // Pressure relief valve opens at Oil_Press_Relief_Valve PSI setting
493     if (Oil_Pressure >= Oil_Press_Relief_Valve) 
494         {
495             Oil_Pressure = Oil_Press_Relief_Valve;
496         }
497         
498     // Now adjust pressure according to Temp which affects the viscosity
499         
500     Oil_Pressure += (Design_Oil_Temp - Oil_Temp) * Oil_Viscosity_Index; 
501         
502     return (Oil_Pressure);
503 }
504
505 // Show Oil Pressure
506 void Show_Oil_Press (float x)
507 {
508     cout << "Oil Pressure (PSI) = ";
509     cout << x << endl;
510 }
511
512
513
514 // Calculate Cylinder Head Temperature
515
516 float CHT (float Fuel_Flow, float Mixture, float IAS)
517 {
518     float CHT = 350;
519         
520     return (CHT);
521 }
522
523 // Show Cyl Head Temperature
524
525 void Show_CHT (float x)
526 {
527     cout << "CHT (F) = ";
528     cout << x << endl;
529 }