]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_engine.cpp
Updates to the UIUCModel code. This includes some big compile time
[flightgear.git] / src / FDM / UIUCModel / uiuc_engine.cpp
1 /**********************************************************************
2
3  FILENAME:     uiuc_engine.cpp
4
5 ----------------------------------------------------------------------
6
7  DESCRIPTION:  determine the engine forces and moments
8                
9 ----------------------------------------------------------------------
10
11  STATUS:       alpha version
12
13 ----------------------------------------------------------------------
14
15  REFERENCES:   simple and c172 models based on portions of 
16                c172_engine.c, called from ls_model;
17                cherokee model based on cherokee_engine.c
18
19 ----------------------------------------------------------------------
20
21  HISTORY:      01/30/2000   initial release
22                06/18/2001   (RD) Added Throttle_pct_input.
23
24 ----------------------------------------------------------------------
25
26  AUTHOR(S):    Bipin Sehgal       <bsehgal@uiuc.edu>
27                Jeff Scott         <jscott@mail.com>
28                Robert Deters      <rdeters@uiuc.edu>
29                Michael Selig      <m-selig@uiuc.edu>
30
31 ----------------------------------------------------------------------
32
33  VARIABLES:
34
35 ----------------------------------------------------------------------
36
37  INPUTS:       -engine model
38
39 ----------------------------------------------------------------------
40
41  OUTPUTS:      -F_X_engine
42                -F_Z_engine
43                -M_m_engine
44
45 ----------------------------------------------------------------------
46
47  CALLED BY:   uiuc_wrapper.cpp 
48
49 ----------------------------------------------------------------------
50
51  CALLS TO:     none
52
53 ----------------------------------------------------------------------
54
55  COPYRIGHT:    (C) 2000 by Michael Selig
56
57  This program is free software; you can redistribute it and/or
58  modify it under the terms of the GNU General Public License
59  as published by the Free Software Foundation.
60
61  This program is distributed in the hope that it will be useful,
62  but WITHOUT ANY WARRANTY; without even the implied warranty of
63  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
64  GNU General Public License for more details.
65
66  You should have received a copy of the GNU General Public License
67  along with this program; if not, write to the Free Software
68  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
69  USA or view http://www.gnu.org/copyleft/gpl.html.
70
71 **********************************************************************/
72 #include <simgear/compiler.h>
73
74 #include "uiuc_engine.h"
75
76 #if !defined (SG_HAVE_NATIVE_SGI_COMPILERS)
77 SG_USING_STD(cerr);
78 #endif
79
80 void uiuc_engine() 
81 {
82   stack command_list;
83   string linetoken1;
84   string linetoken2;
85
86   if (Throttle_pct_input)
87     {
88       double Throttle_pct_input_endTime = Throttle_pct_input_timeArray[Throttle_pct_input_ntime];
89       if (Simtime >= Throttle_pct_input_startTime && 
90           Simtime <= (Throttle_pct_input_startTime + Throttle_pct_input_endTime))
91         {
92           double time = Simtime - Throttle_pct_input_startTime;
93           Throttle_pct = uiuc_1Dinterpolation(Throttle_pct_input_timeArray,
94                          Throttle_pct_input_dTArray,
95                          Throttle_pct_input_ntime,
96                          time);
97         }
98     }
99   
100   Throttle[3] = Throttle_pct;
101
102   command_list = engineParts -> getCommands();
103
104   /*
105   if (command_list.begin() == command_list.end())
106   {
107         cerr << "ERROR: Engine not specified. Aircraft cannot fly without the engine" << endl;
108         exit(-1);
109   }
110   */
111  
112   for (LIST command_line = command_list.begin(); command_line!=command_list.end(); ++command_line)
113     {
114       //cout << *command_line << endl;
115       
116       linetoken1 = engineParts -> getToken(*command_line, 1);
117       linetoken2 = engineParts -> getToken(*command_line, 2);
118       
119       switch(engine_map[linetoken2])
120         {
121         case simpleSingle_flag:
122           {
123             F_X_engine = Throttle[3] * simpleSingleMaxThrust;
124             break;
125           }
126         case c172_flag:
127           {
128             //c172 engine lines ... looks like 0.83 is just a thrust increase
129             F_X_engine = Throttle[3] * 350 / 0.83;
130             F_Z_engine = Throttle[3] * 4.9 / 0.83;
131             M_m_engine = F_X_engine * 0.734 * cbar;
132             break;
133           }
134         case cherokee_flag:
135           {
136             static float
137               dP = (180.0-117.0)*745.7,   // Watts
138               dn = (2700.0-2350.0)/60.0,  // d_rpm (I mean d_rps, in seconds)
139               D  = 6.17*0.3048,           // prop diameter
140               dPh = (58.0-180.0)*745.7,   // change of power as function of height
141               dH = 25000.0*0.3048;
142
143             float
144               n,   // [rps]
145               H,   // altitude [m]
146               J,   // advance ratio (ratio of horizontal speed to prop tip speed)
147               T,   // thrust [N]
148               V,   // velocity [m/s]
149               P,   // power [W]
150               eta_engine; // engine efficiency
151
152             /* assumption -> 0.0 <= Throttle[3] <=1.0 */
153             P = fabs(Throttle[3]) * 180.0 * 745.7; /*180.0*745.7 ->max avail power [W]*/
154             n = dn/dP * (P-117.0*745.7) + 2350.0/60.0;
155
156             /*  V  [m/s]   */
157             V = (V_rel_wind < 10.0 ? 10.0 : V_rel_wind*0.3048);
158             J = V / n / D;
159
160             /* Propeller efficiency */
161             eta_engine = (J < 0.7 ? ((0.8-0.55)/(.7-.3)*(J-0.3) + 0.55) : 
162                           (J > 0.85 ? ((0.6-0.8)/(1.0-0.85)*(J-0.85) + 0.8) : 0.8));
163
164             /* power on Altitude */
165             H = Altitude * 0.3048;       /* H == Altitude [m] */
166             P *= (dPh/dH * H + 180.0*745.7) / (180.0*745.7);
167             T = eta_engine * P/V;        /* Thrust [N] */ 
168
169             /*assumption: Engine's line of thrust passes through cg */
170             F_X_engine = T * 0.2248;     /* F_X_engine in lb */
171             F_Y_engine = 0.0;
172             F_Z_engine = 0.0;
173             break;
174           }
175         case forcemom_flag:
176           {
177             double Xp_input_endTime = Xp_input_timeArray[Xp_input_ntime];
178             if (Simtime >= Xp_input_startTime && 
179                 Simtime <= (Xp_input_startTime + Xp_input_endTime))
180               {
181                 double time = Simtime - Xp_input_startTime;
182                 F_X_engine = uiuc_1Dinterpolation(Xp_input_timeArray,
183                                                   Xp_input_XpArray,
184                                                   Xp_input_ntime,
185                                                   time);
186               }
187             double Zp_input_endTime = Zp_input_timeArray[Zp_input_ntime];
188             if (Simtime >= Zp_input_startTime && 
189                 Simtime <= (Zp_input_startTime + Zp_input_endTime))
190               {
191                 double time = Simtime - Zp_input_startTime;
192                 F_Z_engine = uiuc_1Dinterpolation(Zp_input_timeArray,
193                                                   Zp_input_ZpArray,
194                                                   Zp_input_ntime,
195                                                   time);
196               }
197             double Mp_input_endTime = Mp_input_timeArray[Mp_input_ntime];
198             if (Simtime >= Mp_input_startTime && 
199                 Simtime <= (Mp_input_startTime + Mp_input_endTime))
200               {
201                 double time = Simtime - Mp_input_startTime;
202                 M_m_engine = uiuc_1Dinterpolation(Mp_input_timeArray,
203                                                   Mp_input_MpArray,
204                                                   Mp_input_ntime,
205                                                   time);
206               }
207           }
208         };
209     }
210   return;
211 }
212
213 // end uiuc_engine.cpp