]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_coefficients.cpp
Port over remaining Point3D usage to the more type and unit safe SG* classes.
[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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
96
97 **********************************************************************/
98
99 #include "uiuc_coefficients.h"
100
101 void uiuc_coefficients(double dt)
102 {
103   static string uiuc_coefficients_error = " (from uiuc_coefficients.cpp) ";
104   double l_trim, l_defl;
105   double V_rel_wind_dum, U_body_dum;
106
107   if (Alpha_init_true && Simtime==0)
108     Std_Alpha = Alpha_init;
109
110   if (Beta_init_true && Simtime==0)
111     Std_Beta = Beta_init;
112
113   // calculate rate derivative nondimensionalization factors
114   // check if speed is sufficient to compute dynamic pressure terms
115   if (dyn_on_speed==0) 
116     {
117       uiuc_warnings_errors(5, uiuc_coefficients_error);
118     }
119   if (nondim_rate_V_rel_wind || use_V_rel_wind_2U)         // c172_aero uses V_rel_wind
120     {
121       if (V_rel_wind > dyn_on_speed)
122         {
123           cbar_2U = cbar / (2.0 * V_rel_wind);
124           b_2U    = bw /   (2.0 * V_rel_wind);
125           // chord_h is the horizontal tail chord
126           ch_2U   = chord_h /   (2.0 * V_rel_wind);
127         }
128       else if (use_dyn_on_speed_curve1)
129         {
130           V_rel_wind_dum = dyn_on_speed_zero + V_rel_wind * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
131           cbar_2U        = cbar / (2.0 * V_rel_wind_dum);
132           b_2U           = bw /   (2.0 * V_rel_wind_dum);
133           ch_2U          = chord_h /   (2.0 * V_rel_wind_dum);
134           Std_Alpha_dot      = 0.0;
135         }
136       else
137         {
138           cbar_2U   = 0.0;
139           b_2U      = 0.0;
140           ch_2U     = 0.0;
141           Std_Alpha_dot = 0.0;
142         }
143     }
144   else if(use_abs_U_body_2U)      // use absolute(U_body)
145     {
146       if (fabs(U_body) > dyn_on_speed)
147         {
148           cbar_2U = cbar / (2.0 * fabs(U_body));
149           b_2U    = bw /   (2.0 * fabs(U_body));
150           ch_2U   = chord_h /   (2.0 * fabs(U_body));
151         }
152       else if (use_dyn_on_speed_curve1)
153         {
154           U_body_dum = dyn_on_speed_zero + fabs(U_body) * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
155           cbar_2U    = cbar / (2.0 * U_body_dum);
156           b_2U       = bw /   (2.0 * U_body_dum);
157           ch_2U      = chord_h /   (2.0 * U_body_dum);
158           Std_Alpha_dot  = 0.0;
159         }
160       else
161         {
162           cbar_2U   = 0.0;
163           b_2U      = 0.0;
164           ch_2U     = 0.0;
165           Std_Alpha_dot = 0.0;
166         }
167     }
168   else      // use U_body
169     {
170       if (U_body > dyn_on_speed)
171         {
172           cbar_2U = cbar / (2.0 * U_body);
173           b_2U    = bw /   (2.0 * U_body);
174           ch_2U   = chord_h /   (2.0 * U_body);
175         }
176       else if (use_dyn_on_speed_curve1)
177         {
178           U_body_dum = dyn_on_speed_zero + U_body * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
179           cbar_2U    = cbar / (2.0 * U_body_dum);
180           b_2U       = bw /   (2.0 * U_body_dum);
181           ch_2U      = chord_h /   (2.0 * U_body_dum);
182           Std_Alpha_dot  = 0.0;
183           beta_flow_clean_tail = cbar_2U;
184         }
185       else
186         {
187           cbar_2U   = 0.0;
188           b_2U      = 0.0;
189           ch_2U     = 0.0;
190           Std_Alpha_dot = 0.0;
191         }
192     }
193
194   // check if speed is sufficient to "trust" Std_Alpha_dot value
195   if (use_Alpha_dot_on_speed)
196     {
197       if (V_rel_wind     < Alpha_dot_on_speed)
198           Std_Alpha_dot = 0.0;
199     }
200
201
202   // check to see if icing model engaged
203   if (ice_model)
204     {
205       uiuc_iceboot(dt);
206       uiuc_ice_eta();
207     }
208
209   // check to see if data files are used for control deflections
210   if (outside_control == false)
211     {
212       pilot_elev_no = false;
213       pilot_ail_no = false;
214       pilot_rud_no = false;
215     }
216   if (elevator_step || elevator_singlet || elevator_doublet || elevator_input || aileron_input || rudder_input || flap_pos_input)
217     {
218       uiuc_controlInput();
219     }
220
221   //if (Simtime >=10.0)
222   //  {
223   //    ap_hh_on = 1;
224   //    ap_Psi_ref_rad = 0*DEG_TO_RAD;
225   //  }
226
227   if (ap_pah_on || ap_alh_on || ap_rah_on || ap_hh_on)
228     {
229       uiuc_auto_pilot(dt);
230     }
231
232   CD = CX = CL = CZ = Cm = CY = Cl = Cn = 0.0;
233   CLclean_wing = CLiced_wing = CLclean_tail = CLiced_tail = 0.0;
234   CZclean_wing = CZiced_wing = CZclean_tail = CZiced_tail = 0.0;
235   CXclean_wing = CXiced_wing = CXclean_tail = CXiced_tail = 0.0;
236   CL_clean = CL_iced = 0.0;
237   CY_clean = CY_iced = 0.0;
238   CD_clean = CD_iced = 0.0;
239   Cm_iced = Cm_clean = 0.0;
240   Cl_iced = Cl_clean = 0.0;
241   Cn_iced = Cn_clean = 0.0;
242
243   uiuc_coef_lift();
244   uiuc_coef_drag();
245   uiuc_coef_pitch();
246   uiuc_coef_sideforce();
247   uiuc_coef_roll();
248   uiuc_coef_yaw();
249
250   //uncomment next line to always run icing functions
251   //nonlin_ice_case = 1;
252
253   if (nonlin_ice_case)
254     {
255       if (eta_from_file)
256         {
257           if (eta_tail_input) {
258             double time = Simtime - eta_tail_input_startTime;
259             eta_tail = uiuc_1Dinterpolation(eta_tail_input_timeArray,
260                                             eta_tail_input_daArray,
261                                             eta_tail_input_ntime,
262                                             time);
263           }
264           if (eta_wing_left_input) {
265             double time = Simtime - eta_wing_left_input_startTime;
266             eta_wing_left = uiuc_1Dinterpolation(eta_wing_left_input_timeArray,
267                                                  eta_wing_left_input_daArray,
268                                                  eta_wing_left_input_ntime,
269                                                  time);
270           }
271           if (eta_wing_right_input) {
272             double time = Simtime - eta_wing_right_input_startTime;
273             eta_wing_right = uiuc_1Dinterpolation(eta_wing_right_input_timeArray,
274                                                   eta_wing_right_input_daArray,
275                                                   eta_wing_right_input_ntime,
276                                                   time);
277           }
278         }
279
280       delta_CL = delta_CD = delta_Cm = delta_Cl = delta_Cn = 0.0;
281       Calc_Iced_Forces();
282       add_ice_effects();
283       tactilefadefI = 0.0;
284       if (eta_tail == 0.2 && tactile_pitch && tactilefadef)
285         {
286           if (tactilefadef_nice == 1)
287             tactilefadefI = uiuc_3Dinterp_quick(tactilefadef_fArray,
288                                            tactilefadef_aArray_nice,
289                                            tactilefadef_deArray_nice,
290                                            tactilefadef_tactileArray,
291                                            tactilefadef_na_nice,
292                                            tactilefadef_nde_nice,
293                                            tactilefadef_nf,
294                                            flap_pos,
295                                            Std_Alpha,
296                                            elevator);
297           else
298             tactilefadefI = uiuc_3Dinterpolation(tactilefadef_fArray,
299                                             tactilefadef_aArray,
300                                             tactilefadef_deArray,
301                                             tactilefadef_tactileArray,
302                                             tactilefadef_nAlphaArray,
303                                             tactilefadef_nde,
304                                             tactilefadef_nf,
305                                             flap_pos,
306                                             Std_Alpha,
307                                             elevator);
308         }
309       else if (demo_tactile)
310         {
311           double time = Simtime - demo_tactile_startTime;
312           tactilefadefI = uiuc_1Dinterpolation(demo_tactile_timeArray,
313                                                demo_tactile_daArray,
314                                                demo_tactile_ntime,
315                                                time);
316         }
317       if (icing_demo)
318         uiuc_icing_demo();
319     }
320
321   if (pilot_ail_no)
322     {
323       if (aileron <=0)
324         Lat_control = - aileron / damax * RAD_TO_DEG;
325       else
326         Lat_control = - aileron / damin * RAD_TO_DEG;
327     }
328
329   // can go past real limits
330   // add flag to behave like trim_case2 later
331   if (pilot_elev_no)
332     {
333       if (outside_control == false)
334         {
335           l_trim = elevator_tab;
336           l_defl = elevator - elevator_tab;
337           if (l_trim <=0 )
338             Long_trim = l_trim / demax * RAD_TO_DEG;
339           else
340             Long_trim = l_trim / demin * RAD_TO_DEG;
341           if (l_defl <= 0)
342             Long_control = l_defl / demax * RAD_TO_DEG;
343           else
344             Long_control = l_defl / demin * RAD_TO_DEG;
345         }
346     }
347
348   if (pilot_rud_no)
349     {
350       if (rudder <=0)
351         Rudder_pedal = - rudder / drmax * RAD_TO_DEG;
352       else
353         Rudder_pedal = - rudder / drmin * RAD_TO_DEG;
354     }
355
356   return;
357 }
358
359 // end uiuc_coefficients.cpp