]> git.mxchange.org Git - flightgear.git/blob - src/FDM/LaRCsim/IO360.hxx
resync JSBSim
[flightgear.git] / src / FDM / LaRCsim / IO360.hxx
1 // IO360.hxx - a piston engine model currently for the IO360 engine fitted to the C172
2 //             but with the potential to model other naturally aspirated piston engines
3 //             given appropriate config input.
4 //
5 // Written by David Luff, started 2000.
6 // Based on code by Phil Schubert, started 1999.
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22
23 #ifndef _IO360_HXX_
24 #define _IO360_HXX_
25
26 #include <simgear/compiler.h>
27
28 #include <math.h>
29
30 class FGNewEngine {
31
32 private:
33
34     // These constants should probably be moved eventually
35     float CONVERT_CUBIC_INCHES_TO_METERS_CUBED;
36     float CONVERT_HP_TO_WATTS;
37
38     // Properties of working fluids
39     float Cp_air;               // J/KgK
40     float Cp_fuel;              // J/KgK
41     float calorific_value_fuel; // W/Kg
42     float rho_fuel;             // kg/m^3
43     float rho_air;              // kg/m^3
44
45     // environment inputs
46     float p_amb_sea_level;      // Sea level ambient pressure in Pascals
47     float p_amb;                // Ambient pressure at current altitude in Pascals
48     float T_amb;                // ditto deg Kelvin
49
50     // Control inputs
51     float Throttle_Lever_Pos;   // 0 = Closed, 100 = Fully Open
52     float Propeller_Lever_Pos;  // 0 = Full Course 100 = Full Fine
53     float Mixture_Lever_Pos;    // 0 = Idle Cut Off 100 = Full Rich
54     int mag_pos;                // 0=off, 1=left, 2=right, 3=both.
55     bool starter;
56
57     //misc
58     float IAS;
59     double time_step;
60
61     // Engine Specific Variables that should be read in from a config file
62     float MaxHP;                // Horsepower
63     float displacement;         // Cubic inches
64     float displacement_SI;      //m^3 (derived from above rather than read in)
65     float engine_inertia;       //kg.m^2
66     float prop_inertia;         //kg.m^2
67     float Max_Fuel_Flow;        // Units??? Do we need this variable any more??
68
69     // Engine specific variables that maybe should be read in from config but are pretty generic and won't vary much for a naturally aspirated piston engine.
70     float Max_Manifold_Pressure;    // inches Hg - typical manifold pressure at full throttle and typical max rpm
71     float Min_Manifold_Pressure;    // inches Hg - typical manifold pressure at idle (closed throttle)
72     float Max_RPM;              // rpm - this is really a bit of a hack and could be make redundant if the prop model works properly and takes tips at speed of sound into account.
73     float Min_RPM;              // rpm - possibly redundant ???
74     float Mag_Derate_Percent;   // Percentage reduction in power when mags are switched from 'both' to either 'L' or 'R'
75     float Gear_Ratio;           // Gearing between engine and propellor
76     float n_R;                  // Number of cycles per power stroke - 2 for a 4 stroke engine.
77
78     // Engine Variables not read in from config file
79     float RPM;                  // rpm
80     float Percentage_Power;     // Power output as percentage of maximum power output
81     float Manifold_Pressure;    // Inches Hg
82     float Fuel_Flow_gals_hr;    // USgals/hour
83     float Torque_lbft;          // lb-ft                
84     float Torque_SI;            // Nm
85     float CHT;                  // Cylinder head temperature deg K
86     float CHT_degF;             // Ditto in deg Fahrenheit
87     float Mixture;
88     float Oil_Pressure;         // PSI
89     float Oil_Temp;             // Deg C
90     float current_oil_temp;     // deg K
91     /**** one of these is superfluous !!!!***/
92     float HP;                   // Current power output in HP
93     float Power_SI;             // Current power output in Watts
94     float RPS;
95     float angular_velocity_SI;  // rad/s
96     float Torque_FMEP;          // The component of Engine torque due to FMEP (Nm)
97     float Torque_Imbalance;     // difference between engine and prop torque
98     float EGT;                  // Exhaust gas temperature deg K
99     float EGT_degF;             // Exhaust gas temperature deg Fahrenheit
100     float volumetric_efficiency;
101     float combustion_efficiency;
102     float equivalence_ratio;    // ratio of stoichiometric AFR over actual AFR 
103     float thi_sea_level;        // the equivalence ratio we would be running at assuming sea level air denisity in the manifold
104     float v_dot_air;            // volume flow rate of air into engine  - m^3/s
105     float m_dot_air;            // mass flow rate of air into engine - kg/s
106     float m_dot_fuel;           // mass flow rate of fuel into engine - kg/s
107     float swept_volume;         // total engine swept volume - m^3
108     /********* swept volume or the geometry used to calculate it should be in the config read section surely ??? ******/
109     float True_Manifold_Pressure;   //in Hg - actual manifold gauge pressure
110     float rho_air_manifold;     // denisty of air in the manifold - kg/m^3
111     float R_air;                // Gas constant of air (287) UNITS???
112     float delta_T_exhaust;      // Temperature change of exhaust this time step - degK
113     float heat_capacity_exhaust;    // exhaust gas specific heat capacity - J/kgK
114     float enthalpy_exhaust;         // Enthalpy at current exhaust gas conditions - UNITS???
115     float Percentage_of_best_power_mixture_power;   // Current power as a percentage of what power we would have at the same conditions but at best power mixture
116     float abstract_mixture;     //temporary hack
117     float angular_acceleration; //rad/s^2
118     float FMEP;                 //Friction Mean Effective Pressure (Pa)
119
120     // Various bits of housekeeping describing the engines state.
121     bool  running;              // flag to indicate the engine is running self sustaining
122     bool  cranking;             // flag to indicate the engine is being cranked
123     int   crank_counter;        // Number of iterations that the engine has been cranked non-stop
124     bool  spark;                // flag to indicate a spark is available
125     bool  fuel;                 // flag to indicate fuel is available
126
127     // Propellor Variables
128     float FGProp1_RPS;          // rps
129     float prop_torque;          // Nm
130     float prop_thrust;          // Newtons
131     double prop_diameter;       // meters
132     double blade_angle;         // degrees
133
134
135 // MEMBER FUNCTIONS
136     
137     // Calculate Engine RPM based on Propellor Lever Position
138     float Calc_Engine_RPM(float Position);
139
140     // Calculate Manifold Pressure based on throttle lever position
141     // Note that this is simplistic and needs altering to include engine speed effects
142     float Calc_Manifold_Pressure( float LeverPosn, float MaxMan, float MinMan);
143
144     // Calculate combustion efficiency based on equivalence ratio
145     float Lookup_Combustion_Efficiency(float thi_actual);
146
147     // Calculate percentage of best power mixture power based on equivalence ratio
148     float Power_Mixture_Correlation(float thi_actual);
149
150     // Calculate exhaust gas temperature change
151     float Calculate_Delta_T_Exhaust(void);
152
153     // Calculate cylinder head temperature
154     void Calc_CHT(void);
155
156     // Calculate exhaust gas temperature
157     void Calc_EGT(void);
158
159     // Calculate fuel flow in gals/hr
160     void Calc_Fuel_Flow_Gals_Hr(void);
161
162     // Calculate current percentage power
163     void Calc_Percentage_Power(bool mag_left, bool mag_right);
164
165     // Calculate Oil Temperature
166     float Calc_Oil_Temp (float oil_temp);
167     
168     // Calculate Oil Pressure
169     float Calc_Oil_Press (float Oil_Temp, float Engine_RPM);
170
171     // Propeller calculations.
172     void Do_Prop_Calcs(void);
173
174 public:
175
176 //    ofstream outfile;
177
178     //constructor
179     FGNewEngine() {
180 //      outfile.open("FGNewEngine.dat", ios::out|ios::trunc);
181     }
182
183     //destructor
184     ~FGNewEngine() {
185 //      outfile.close();
186     }
187
188     // set initial default values
189     void init(double dt);
190
191     // update the engine model based on current control positions
192     void update();
193
194     inline void set_IAS( float value ) { IAS = value; }
195     inline void set_Throttle_Lever_Pos( float value ) {
196         Throttle_Lever_Pos = value;
197     }
198     inline void set_Propeller_Lever_Pos( float value ) {
199         Propeller_Lever_Pos = value;
200     }
201     inline void set_Mixture_Lever_Pos( float value ) {
202         Mixture_Lever_Pos = value;
203     }
204     // set the magneto switch position
205     inline void set_Magneto_Switch_Pos( int value ) {
206         mag_pos = value;
207     }
208     inline void setStarterFlag( bool flag ) {
209         starter = flag;
210     }
211     // set ambient pressure - takes pounds per square foot
212     inline void set_p_amb( float value ) { 
213         p_amb = value * 47.88026;
214         // Convert to Pascals
215     }
216     // set ambient temperature - takes degrees Rankine
217     inline void set_T_amb( float value ) { 
218         T_amb = value * 0.555555555556;
219         // Convert to degrees Kelvin
220     }
221
222     // accessors
223     inline float get_RPM() const { return RPM; }
224     inline float get_Manifold_Pressure() const { return True_Manifold_Pressure; }
225  //   inline float get_Rho() const { return Rho; }
226     inline float get_MaxHP() const { return MaxHP; }
227     inline float get_Percentage_Power() const { return Percentage_Power; }
228     inline float get_EGT() const { return EGT_degF; }    // Returns EGT in Fahrenheit
229     inline float get_CHT() const { return CHT_degF; }    // Note this returns CHT in Fahrenheit
230     inline float get_prop_thrust_SI() const { return prop_thrust; }
231     inline float get_prop_thrust_lbs() const { return (prop_thrust * 0.2248); }
232     inline float get_fuel_flow_gals_hr() const { return (Fuel_Flow_gals_hr); }
233     inline float get_oil_temp() const { return ((current_oil_temp * 1.8) - 459.67); }
234     inline bool getRunningFlag() const { return running; }
235     inline bool getCrankingFlag() const { return cranking; }
236     inline bool getStarterFlag() const { return starter; }
237 };
238
239
240 #endif // _IO360_HXX_