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.
5 // Written by David Luff, started 2000.
6 // Based on code by Phil Schubert, started 1999.
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <simgear/compiler.h>
33 SG_USING_STD(ofstream);
39 // These constants should probably be moved eventually
40 float CONVERT_CUBIC_INCHES_TO_METERS_CUBED;
41 float CONVERT_HP_TO_WATTS;
43 // Properties of working fluids
44 float Cp_air; // J/KgK
45 float Cp_fuel; // J/KgK
46 float calorific_value_fuel; // W/Kg
47 float rho_fuel; // kg/m^3
48 float rho_air; // kg/m^3
51 float p_amb_sea_level; // Sea level ambient pressure in Pascals
52 float p_amb; // Ambient pressure at current altitude in Pascals
53 float T_amb; // ditto deg Kelvin
56 float Throttle_Lever_Pos; // 0 = Closed, 100 = Fully Open
57 float Propeller_Lever_Pos; // 0 = Full Course 100 = Full Fine
58 float Mixture_Lever_Pos; // 0 = Idle Cut Off 100 = Full Rich
59 int mag_pos; // 0=off, 1=left, 2=right, 3=both.
66 // Engine Specific Variables that should be read in from a config file
67 float MaxHP; // Horsepower
68 float displacement; // Cubic inches
69 float displacement_SI; //m^3 (derived from above rather than read in)
70 float engine_inertia; //kg.m^2
71 float prop_inertia; //kg.m^2
72 float Max_Fuel_Flow; // Units??? Do we need this variable any more??
74 // 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.
75 float Max_Manifold_Pressure; // inches Hg - typical manifold pressure at full throttle and typical max rpm
76 float Min_Manifold_Pressure; // inches Hg - typical manifold pressure at idle (closed throttle)
77 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.
78 float Min_RPM; // rpm - possibly redundant ???
79 float Mag_Derate_Percent; // Percentage reduction in power when mags are switched from 'both' to either 'L' or 'R'
80 float Gear_Ratio; // Gearing between engine and propellor
81 float n_R; // Number of cycles per power stroke - 2 for a 4 stroke engine.
83 // Engine Variables not read in from config file
85 float Percentage_Power; // Power output as percentage of maximum power output
86 float Manifold_Pressure; // Inches Hg
87 float Fuel_Flow_gals_hr; // USgals/hour
88 float Torque_lbft; // lb-ft
89 float Torque_SI; // Nm
90 float CHT; // Cylinder head temperature deg K
91 float CHT_degF; // Ditto in deg Fahrenheit
93 float Oil_Pressure; // PSI
94 float Oil_Temp; // Deg C
95 float current_oil_temp; // deg K
96 /**** one of these is superfluous !!!!***/
97 float HP; // Current power output in HP
98 float Power_SI; // Current power output in Watts
100 float angular_velocity_SI; // rad/s
101 float Torque_FMEP; // The component of Engine torque due to FMEP (Nm)
102 float Torque_Imbalance; // difference between engine and prop torque
103 float EGT; // Exhaust gas temperature deg K
104 float EGT_degF; // Exhaust gas temperature deg Fahrenheit
105 float volumetric_efficiency;
106 float combustion_efficiency;
107 float equivalence_ratio; // ratio of stoichiometric AFR over actual AFR
108 float thi_sea_level; // the equivalence ratio we would be running at assuming sea level air denisity in the manifold
109 float v_dot_air; // volume flow rate of air into engine - m^3/s
110 float m_dot_air; // mass flow rate of air into engine - kg/s
111 float m_dot_fuel; // mass flow rate of fuel into engine - kg/s
112 float swept_volume; // total engine swept volume - m^3
113 /********* swept volume or the geometry used to calculate it should be in the config read section surely ??? ******/
114 float True_Manifold_Pressure; //in Hg - actual manifold gauge pressure
115 float rho_air_manifold; // denisty of air in the manifold - kg/m^3
116 float R_air; // Gas constant of air (287) UNITS???
117 float delta_T_exhaust; // Temperature change of exhaust this time step - degK
118 float heat_capacity_exhaust; // exhaust gas specific heat capacity - J/kgK
119 float enthalpy_exhaust; // Enthalpy at current exhaust gas conditions - UNITS???
120 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
121 float abstract_mixture; //temporary hack
122 float angular_acceleration; //rad/s^2
123 float FMEP; //Friction Mean Effective Pressure (Pa)
125 // Various bits of housekeeping describing the engines state.
126 bool running; // flag to indicate the engine is running self sustaining
127 bool cranking; // flag to indicate the engine is being cranked
128 int crank_counter; // Number of iterations that the engine has been cranked non-stop
129 bool spark; // flag to indicate a spark is available
130 bool fuel; // flag to indicate fuel is available
132 // Propellor Variables
133 float FGProp1_RPS; // rps
134 float prop_torque; // Nm
135 float prop_thrust; // Newtons
136 double prop_diameter; // meters
137 double blade_angle; // degrees
142 // Calculate Engine RPM based on Propellor Lever Position
143 float Calc_Engine_RPM(float Position);
145 // Calculate Manifold Pressure based on throttle lever position
146 // Note that this is simplistic and needs altering to include engine speed effects
147 float Calc_Manifold_Pressure( float LeverPosn, float MaxMan, float MinMan);
149 // Calculate combustion efficiency based on equivalence ratio
150 float Lookup_Combustion_Efficiency(float thi_actual);
152 // Calculate percentage of best power mixture power based on equivalence ratio
153 float Power_Mixture_Correlation(float thi_actual);
155 // Calculate exhaust gas temperature change
156 float Calculate_Delta_T_Exhaust(void);
158 // Calculate cylinder head temperature
161 // Calculate exhaust gas temperature
164 // Calculate fuel flow in gals/hr
165 void Calc_Fuel_Flow_Gals_Hr(void);
167 // Calculate current percentage power
168 void Calc_Percentage_Power(bool mag_left, bool mag_right);
170 // Calculate Oil Temperature
171 float Calc_Oil_Temp (float oil_temp);
173 // Calculate Oil Pressure
174 float Calc_Oil_Press (float Oil_Temp, float Engine_RPM);
176 // Propeller calculations.
177 void Do_Prop_Calcs(void);
185 // outfile.open("FGNewEngine.dat", ios::out|ios::trunc);
193 // set initial default values
194 void init(double dt);
196 // update the engine model based on current control positions
199 inline void set_IAS( float value ) { IAS = value; }
200 inline void set_Throttle_Lever_Pos( float value ) {
201 Throttle_Lever_Pos = value;
203 inline void set_Propeller_Lever_Pos( float value ) {
204 Propeller_Lever_Pos = value;
206 inline void set_Mixture_Lever_Pos( float value ) {
207 Mixture_Lever_Pos = value;
209 // set the magneto switch position
210 inline void set_Magneto_Switch_Pos( int value ) {
213 inline void setStarterFlag( bool flag ) {
216 // set ambient pressure - takes pounds per square foot
217 inline void set_p_amb( float value ) {
218 p_amb = value * 47.88026;
219 // Convert to Pascals
221 // set ambient temperature - takes degrees Rankine
222 inline void set_T_amb( float value ) {
223 T_amb = value * 0.555555555556;
224 // Convert to degrees Kelvin
228 inline float get_RPM() const { return RPM; }
229 inline float get_Manifold_Pressure() const { return True_Manifold_Pressure; }
230 // inline float get_Rho() const { return Rho; }
231 inline float get_MaxHP() const { return MaxHP; }
232 inline float get_Percentage_Power() const { return Percentage_Power; }
233 inline float get_EGT() const { return EGT_degF; } // Returns EGT in Fahrenheit
234 inline float get_CHT() const { return CHT_degF; } // Note this returns CHT in Fahrenheit
235 inline float get_prop_thrust_SI() const { return prop_thrust; }
236 inline float get_prop_thrust_lbs() const { return (prop_thrust * 0.2248); }
237 inline float get_fuel_flow_gals_hr() const { return (Fuel_Flow_gals_hr); }
238 inline float get_oil_temp() const { return ((current_oil_temp * 1.8) - 459.67); }
239 inline bool getRunningFlag() const { return running; }
240 inline bool getCrankingFlag() const { return cranking; }
241 inline bool getStarterFlag() const { return starter; }
245 #endif // _IO360_HXX_