]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_coefficients.cpp
Units bug.
[flightgear.git] / src / FDM / UIUCModel / uiuc_coefficients.cpp
1 /**********************************************************************
2
3  FILENAME:     uiuc_coefficients.cpp
4
5 ----------------------------------------------------------------------
6
7  DESCRIPTION:  computes aggregated aerodynamic coefficients
8
9 ----------------------------------------------------------------------
10
11  STATUS:       alpha version
12
13 ----------------------------------------------------------------------
14
15  REFERENCES:   
16
17 ----------------------------------------------------------------------
18
19  HISTORY:      01/29/2000   initial release
20                02/01/2000   (JS) changed map name from aeroData to 
21                             aeroPart
22                02/18/2000   (JS) added calls to 1Dinterpolation 
23                             function from CLfa and CDfa switches
24                02/24/2000   added icing model functions
25                02/29/2000   (JS) added calls to 2Dinterpolation 
26                             function from CLfade, CDfade, Cmfade, 
27                             CYfada, CYfbetadr, Clfada, Clfbetadr, 
28                             Cnfada, and Cnfbetadr switches
29                04/15/2000   (JS) broke up into multiple 
30                             uiuc_coef_xxx functions
31                06/18/2001   (RD) Added initialization of Std_Alpha and
32                             Std_Beta.  Added aileron_input and rudder_input.
33                             Added pilot_elev_no, pilot_ail_no, and
34                             pilot_rud_no.
35                07/05/2001   (RD) Added pilot_(elev,ail,rud)_no=false
36                01/11/2002   (AP) Added call to uiuc_iceboot()
37                12/02/2002   (RD) Moved icing demo interpolations to its
38                             own function
39                
40 ----------------------------------------------------------------------
41
42  AUTHOR(S):    Bipin Sehgal       <bsehgal@uiuc.edu>
43                Jeff Scott         <jscott@mail.com>
44                Robert Deters      <rdeters@uiuc.edu>
45                Ann Peedikayil     <peedikay@uiuc.edu>
46 ----------------------------------------------------------------------
47
48  VARIABLES:
49
50 ----------------------------------------------------------------------
51
52  INPUTS:       -V_rel_wind (or U_body)
53                -dyn_on_speed
54                -ice on/off
55                -phugoid on/off
56
57 ----------------------------------------------------------------------
58
59  OUTPUTS:      -CL
60                -CD
61                -Cm
62                -CY
63                -Cl
64                -Cn
65
66 ----------------------------------------------------------------------
67
68  CALLED BY:    uiuc_wrapper
69
70 ----------------------------------------------------------------------
71
72  CALLS TO:     uiuc_coef_lift
73                uiuc_coef_drag
74                uiuc_coef_pitch
75                uiuc_coef_sideforce
76                uiuc_coef_roll
77                uiuc_coef_yaw
78                uiuc_controlInput
79
80 ----------------------------------------------------------------------
81
82  COPYRIGHT:    (C) 2000 by Michael Selig
83
84  This program is free software; you can redistribute it and/or
85  modify it under the terms of the GNU General Public License
86  as published by the Free Software Foundation.
87
88  This program is distributed in the hope that it will be useful,
89  but WITHOUT ANY WARRANTY; without even the implied warranty of
90  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
91  GNU General Public License for more details.
92
93  You should have received a copy of the GNU General Public License
94  along with this program; if not, write to the Free Software
95  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
96  USA or view http://www.gnu.org/copyleft/gpl.html.
97
98 **********************************************************************/
99
100 #include "uiuc_coefficients.h"
101
102 void uiuc_coefficients(double dt)
103 {
104   static string uiuc_coefficients_error = " (from uiuc_coefficients.cpp) ";
105   double l_trim, l_defl;
106   double V_rel_wind_dum, U_body_dum;
107
108   if (Alpha_init_true && Simtime==0)
109     Std_Alpha = Alpha_init;
110
111   if (Beta_init_true && Simtime==0)
112     Std_Beta = Beta_init;
113
114   // calculate rate derivative nondimensionalization factors
115   // check if speed is sufficient to compute dynamic pressure terms
116   if (dyn_on_speed==0) 
117     {
118       uiuc_warnings_errors(5, uiuc_coefficients_error);
119     }
120   if (nondim_rate_V_rel_wind || use_V_rel_wind_2U)         // c172_aero uses V_rel_wind
121     {
122       if (V_rel_wind > dyn_on_speed)
123         {
124           cbar_2U = cbar / (2.0 * V_rel_wind);
125           b_2U    = bw /   (2.0 * V_rel_wind);
126           // chord_h is the horizontal tail chord
127           ch_2U   = chord_h /   (2.0 * V_rel_wind);
128         }
129       else if (use_dyn_on_speed_curve1)
130         {
131           V_rel_wind_dum = dyn_on_speed_zero + V_rel_wind * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
132           cbar_2U        = cbar / (2.0 * V_rel_wind_dum);
133           b_2U           = bw /   (2.0 * V_rel_wind_dum);
134           ch_2U          = chord_h /   (2.0 * V_rel_wind_dum);
135           Std_Alpha_dot      = 0.0;
136         }
137       else
138         {
139           cbar_2U   = 0.0;
140           b_2U      = 0.0;
141           ch_2U     = 0.0;
142           Std_Alpha_dot = 0.0;
143         }
144     }
145   else if(use_abs_U_body_2U)      // use absolute(U_body)
146     {
147       if (fabs(U_body) > dyn_on_speed)
148         {
149           cbar_2U = cbar / (2.0 * fabs(U_body));
150           b_2U    = bw /   (2.0 * fabs(U_body));
151           ch_2U   = chord_h /   (2.0 * fabs(U_body));
152         }
153       else if (use_dyn_on_speed_curve1)
154         {
155           U_body_dum = dyn_on_speed_zero + fabs(U_body) * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
156           cbar_2U    = cbar / (2.0 * U_body_dum);
157           b_2U       = bw /   (2.0 * U_body_dum);
158           ch_2U      = chord_h /   (2.0 * U_body_dum);
159           Std_Alpha_dot  = 0.0;
160         }
161       else
162         {
163           cbar_2U   = 0.0;
164           b_2U      = 0.0;
165           ch_2U     = 0.0;
166           Std_Alpha_dot = 0.0;
167         }
168     }
169   else      // use U_body
170     {
171       if (U_body > dyn_on_speed)
172         {
173           cbar_2U = cbar / (2.0 * U_body);
174           b_2U    = bw /   (2.0 * U_body);
175           ch_2U   = chord_h /   (2.0 * U_body);
176         }
177       else if (use_dyn_on_speed_curve1)
178         {
179           U_body_dum = dyn_on_speed_zero + U_body * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
180           cbar_2U    = cbar / (2.0 * U_body_dum);
181           b_2U       = bw /   (2.0 * U_body_dum);
182           ch_2U      = chord_h /   (2.0 * U_body_dum);
183           Std_Alpha_dot  = 0.0;
184           beta_flow_clean_tail = cbar_2U;
185         }
186       else
187         {
188           cbar_2U   = 0.0;
189           b_2U      = 0.0;
190           ch_2U     = 0.0;
191           Std_Alpha_dot = 0.0;
192         }
193     }
194
195   // check if speed is sufficient to "trust" Std_Alpha_dot value
196   if (use_Alpha_dot_on_speed)
197     {
198       if (V_rel_wind     < Alpha_dot_on_speed)
199           Std_Alpha_dot = 0.0;
200     }
201
202
203   // check to see if icing model engaged
204   if (ice_model)
205     {
206       uiuc_iceboot(dt);
207       uiuc_ice_eta();
208     }
209
210   // check to see if data files are used for control deflections
211   if (outside_control == false)
212     {
213       pilot_elev_no = false;
214       pilot_ail_no = false;
215       pilot_rud_no = false;
216     }
217   if (elevator_step || elevator_singlet || elevator_doublet || elevator_input || aileron_input || rudder_input || flap_pos_input)
218     {
219       uiuc_controlInput();
220     }
221
222   //if (Simtime >=10.0)
223   //  {
224   //    ap_hh_on = 1;
225   //    ap_Psi_ref_rad = 0*DEG_TO_RAD;
226   //  }
227
228   if (ap_pah_on || ap_alh_on || ap_rah_on || ap_hh_on)
229     {
230       uiuc_auto_pilot(dt);
231     }
232
233   CD = CX = CL = CZ = Cm = CY = Cl = Cn = 0.0;
234   CLclean_wing = CLiced_wing = CLclean_tail = CLiced_tail = 0.0;
235   CZclean_wing = CZiced_wing = CZclean_tail = CZiced_tail = 0.0;
236   CXclean_wing = CXiced_wing = CXclean_tail = CXiced_tail = 0.0;
237   CL_clean = CL_iced = 0.0;
238   CY_clean = CY_iced = 0.0;
239   CD_clean = CD_iced = 0.0;
240   Cm_iced = Cm_clean = 0.0;
241   Cl_iced = Cl_clean = 0.0;
242   Cn_iced = Cn_clean = 0.0;
243
244   uiuc_coef_lift();
245   uiuc_coef_drag();
246   uiuc_coef_pitch();
247   uiuc_coef_sideforce();
248   uiuc_coef_roll();
249   uiuc_coef_yaw();
250
251   //uncomment next line to always run icing functions
252   //nonlin_ice_case = 1;
253
254   if (nonlin_ice_case)
255     {
256       if (eta_from_file)
257         {
258           if (eta_tail_input) {
259             double time = Simtime - eta_tail_input_startTime;
260             eta_tail = uiuc_1Dinterpolation(eta_tail_input_timeArray,
261                                             eta_tail_input_daArray,
262                                             eta_tail_input_ntime,
263                                             time);
264           }
265           if (eta_wing_left_input) {
266             double time = Simtime - eta_wing_left_input_startTime;
267             eta_wing_left = uiuc_1Dinterpolation(eta_wing_left_input_timeArray,
268                                                  eta_wing_left_input_daArray,
269                                                  eta_wing_left_input_ntime,
270                                                  time);
271           }
272           if (eta_wing_right_input) {
273             double time = Simtime - eta_wing_right_input_startTime;
274             eta_wing_right = uiuc_1Dinterpolation(eta_wing_right_input_timeArray,
275                                                   eta_wing_right_input_daArray,
276                                                   eta_wing_right_input_ntime,
277                                                   time);
278           }
279         }
280
281       delta_CL = delta_CD = delta_Cm = delta_Cl = delta_Cn = 0.0;
282       Calc_Iced_Forces();
283       add_ice_effects();
284       tactilefadefI = 0.0;
285       if (eta_tail == 0.2 && tactile_pitch && tactilefadef)
286         {
287           if (tactilefadef_nice == 1)
288             tactilefadefI = uiuc_3Dinterp_quick(tactilefadef_fArray,
289                                            tactilefadef_aArray_nice,
290                                            tactilefadef_deArray_nice,
291                                            tactilefadef_tactileArray,
292                                            tactilefadef_na_nice,
293                                            tactilefadef_nde_nice,
294                                            tactilefadef_nf,
295                                            flap_pos,
296                                            Std_Alpha,
297                                            elevator);
298           else
299             tactilefadefI = uiuc_3Dinterpolation(tactilefadef_fArray,
300                                             tactilefadef_aArray,
301                                             tactilefadef_deArray,
302                                             tactilefadef_tactileArray,
303                                             tactilefadef_nAlphaArray,
304                                             tactilefadef_nde,
305                                             tactilefadef_nf,
306                                             flap_pos,
307                                             Std_Alpha,
308                                             elevator);
309         }
310       else if (demo_tactile)
311         {
312           double time = Simtime - demo_tactile_startTime;
313           tactilefadefI = uiuc_1Dinterpolation(demo_tactile_timeArray,
314                                                demo_tactile_daArray,
315                                                demo_tactile_ntime,
316                                                time);
317         }
318       if (icing_demo)
319         uiuc_icing_demo();
320     }
321
322   if (pilot_ail_no)
323     {
324       if (aileron <=0)
325         Lat_control = - aileron / damax * RAD_TO_DEG;
326       else
327         Lat_control = - aileron / damin * RAD_TO_DEG;
328     }
329
330   // can go past real limits
331   // add flag to behave like trim_case2 later
332   if (pilot_elev_no)
333     {
334       if (outside_control == false)
335         {
336           l_trim = elevator_tab;
337           l_defl = elevator - elevator_tab;
338           if (l_trim <=0 )
339             Long_trim = l_trim / demax * RAD_TO_DEG;
340           else
341             Long_trim = l_trim / demin * RAD_TO_DEG;
342           if (l_defl <= 0)
343             Long_control = l_defl / demax * RAD_TO_DEG;
344           else
345             Long_control = l_defl / demin * RAD_TO_DEG;
346         }
347     }
348
349   if (pilot_rud_no)
350     {
351       if (rudder <=0)
352         Rudder_pedal = - rudder / drmax * RAD_TO_DEG;
353       else
354         Rudder_pedal = - rudder / drmin * RAD_TO_DEG;
355     }
356
357   return;
358 }
359
360 // end uiuc_coefficients.cpp