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