]> git.mxchange.org Git - flightgear.git/blob - src/FDM/UIUCModel/uiuc_coefficients.cpp
Robert Deters:
[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 Alpha and
32                             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_bootTime()
37                
38 ----------------------------------------------------------------------
39
40  AUTHOR(S):    Bipin Sehgal       <bsehgal@uiuc.edu>
41                Jeff Scott         <jscott@mail.com>
42                Robert Deters      <rdeters@uiuc.edu>
43                Ann Peedikayil     <peedikay@uiuc.edu>
44 ----------------------------------------------------------------------
45
46  VARIABLES:
47
48 ----------------------------------------------------------------------
49
50  INPUTS:       -V_rel_wind (or U_body)
51                -dyn_on_speed
52                -ice on/off
53                -phugoid on/off
54
55 ----------------------------------------------------------------------
56
57  OUTPUTS:      -CL
58                -CD
59                -Cm
60                -CY
61                -Cl
62                -Cn
63
64 ----------------------------------------------------------------------
65
66  CALLED BY:    uiuc_wrapper
67
68 ----------------------------------------------------------------------
69
70  CALLS TO:     uiuc_coef_lift
71                uiuc_coef_drag
72                uiuc_coef_pitch
73                uiuc_coef_sideforce
74                uiuc_coef_roll
75                uiuc_coef_yaw
76                uiuc_controlInput
77
78 ----------------------------------------------------------------------
79
80  COPYRIGHT:    (C) 2000 by Michael Selig
81
82  This program is free software; you can redistribute it and/or
83  modify it under the terms of the GNU General Public License
84  as published by the Free Software Foundation.
85
86  This program is distributed in the hope that it will be useful,
87  but WITHOUT ANY WARRANTY; without even the implied warranty of
88  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
89  GNU General Public License for more details.
90
91  You should have received a copy of the GNU General Public License
92  along with this program; if not, write to the Free Software
93  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
94  USA or view http://www.gnu.org/copyleft/gpl.html.
95
96 **********************************************************************/
97
98 #include "uiuc_coefficients.h"
99 #include "uiuc_warnings_errors.h"
100 #include <string.h>
101
102
103 void uiuc_coefficients(double dt)
104 {
105   static string uiuc_coefficients_error = " (from uiuc_coefficients.cpp) ";
106   double l_trim, l_defl;
107   double V_rel_wind_dum, U_body_dum;
108
109   if (Alpha_init_true && Simtime==0)
110     Alpha = Alpha_init;
111
112   if (Beta_init_true && Simtime==0)
113     Beta = Beta_init;
114
115   // calculate rate derivative nondimensionalization factors
116   // check if speed is sufficient to compute dynamic pressure terms
117   if (dyn_on_speed==0) 
118     {
119       uiuc_warnings_errors(5, uiuc_coefficients_error);
120     }
121   if (nondim_rate_V_rel_wind || use_V_rel_wind_2U)         // c172_aero uses V_rel_wind
122     {
123       if (V_rel_wind > dyn_on_speed)
124         {
125           cbar_2U = cbar / (2.0 * V_rel_wind);
126           b_2U    = bw /   (2.0 * V_rel_wind);
127           // ch is the horizontal tail chord
128           ch_2U   = ch /   (2.0 * V_rel_wind);
129         }
130       else if (use_dyn_on_speed_curve1)
131         {
132           V_rel_wind_dum = dyn_on_speed_zero + V_rel_wind * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
133           cbar_2U        = cbar / (2.0 * V_rel_wind_dum);
134           b_2U           = bw /   (2.0 * V_rel_wind_dum);
135           ch_2U          = ch /   (2.0 * V_rel_wind_dum);
136           Alpha_dot      = 0.0;
137         }
138       else
139         {
140           cbar_2U   = 0.0;
141           b_2U      = 0.0;
142           ch_2U     = 0.0;
143           Alpha_dot = 0.0;
144         }
145     }
146   else if(use_abs_U_body_2U)      // use absolute(U_body)
147     {
148       if (fabs(U_body) > dyn_on_speed)
149         {
150           cbar_2U = cbar / (2.0 * fabs(U_body));
151           b_2U    = bw /   (2.0 * fabs(U_body));
152           ch_2U   = ch /   (2.0 * fabs(U_body));
153         }
154       else if (use_dyn_on_speed_curve1)
155         {
156           U_body_dum = dyn_on_speed_zero + fabs(U_body) * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
157           cbar_2U    = cbar / (2.0 * U_body_dum);
158           b_2U       = bw /   (2.0 * U_body_dum);
159           ch_2U      = ch /   (2.0 * U_body_dum);
160           Alpha_dot  = 0.0;
161         }
162       else
163         {
164           cbar_2U   = 0.0;
165           b_2U      = 0.0;
166           ch_2U     = 0.0;
167           Alpha_dot = 0.0;
168         }
169     }
170   else      // use U_body
171     {
172       if (U_body > dyn_on_speed)
173         {
174           cbar_2U = cbar / (2.0 * U_body);
175           b_2U    = bw /   (2.0 * U_body);
176           ch_2U   = ch /   (2.0 * U_body);
177         }
178       else if (use_dyn_on_speed_curve1)
179         {
180           U_body_dum = dyn_on_speed_zero + U_body * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
181           cbar_2U    = cbar / (2.0 * U_body_dum);
182           b_2U       = bw /   (2.0 * U_body_dum);
183           ch_2U      = ch /   (2.0 * U_body_dum);
184           Alpha_dot  = 0.0;
185           beta_flow_clean_tail = cbar_2U;
186         }
187       else
188         {
189           cbar_2U   = 0.0;
190           b_2U      = 0.0;
191           ch_2U     = 0.0;
192           Alpha_dot = 0.0;
193         }
194     }
195
196   // check if speed is sufficient to "trust" Alpha_dot value
197   if (use_Alpha_dot_on_speed)
198     {
199       if (V_rel_wind     < Alpha_dot_on_speed)
200           Alpha_dot = 0.0;
201     }
202
203
204   // check to see if icing model engaged
205   if (ice_model)
206     {
207       uiuc_iceboot(dt);
208       uiuc_ice_eta();
209     }
210
211   // check to see if data files are used for control deflections
212   if (outside_control == false)
213     {
214       pilot_elev_no = false;
215       pilot_ail_no = false;
216       pilot_rud_no = false;
217     }
218   if (elevator_step || elevator_singlet || elevator_doublet || elevator_input || aileron_input || rudder_input || flap_pos_input)
219     {
220       uiuc_controlInput();
221     }
222
223   if (icing_demo)
224     {
225       if (demo_ap_pah_on){
226         double time = Simtime - demo_ap_pah_on_startTime;
227         ap_pah_on = uiuc_1Dinterpolation(demo_ap_pah_on_timeArray,
228                                          demo_ap_pah_on_daArray,
229                                          demo_ap_pah_on_ntime,
230                                          time);
231       }
232       if (demo_ap_Theta_ref_deg){
233         double time = Simtime - demo_ap_Theta_ref_deg_startTime;
234         ap_Theta_ref_deg = uiuc_1Dinterpolation(demo_ap_Theta_ref_deg_timeArray,
235                                                 demo_ap_Theta_ref_deg_daArray,
236                                                 demo_ap_Theta_ref_deg_ntime,
237                                                 time);
238       }
239     }
240   if (ap_pah_on)
241     {
242       double V_rel_wind_ms;
243       V_rel_wind_ms = V_rel_wind * 0.3048;
244       ap_Theta_ref_rad = ap_Theta_ref_deg * DEG_TO_RAD;
245       elevator = pah_ap(Theta, Theta_dot, ap_Theta_ref_rad, V_rel_wind_ms, dt);
246       if (elevator*RAD_TO_DEG <= -1*demax)
247         elevator = -1*demax * DEG_TO_RAD;
248       if (elevator*RAD_TO_DEG >= demin)
249         elevator = demin * DEG_TO_RAD;
250       pilot_elev_no=true;
251     }
252
253   CD = CX = CL = CZ = Cm = CY = Cl = Cn = 0.0;
254   CLclean_wing = CLiced_wing = CLclean_tail = CLiced_tail = 0.0;
255   CZclean_wing = CZiced_wing = CZclean_tail = CZiced_tail = 0.0;
256   CXclean_wing = CXiced_wing = CXclean_tail = CXiced_tail = 0.0;
257   CL_clean = CL_iced = 0.0;
258   CY_clean = CY_iced = 0.0;
259   CD_clean = CD_iced = 0.0;
260   Cm_iced = Cm_clean = 0.0;
261   Cl_iced = Cl_clean = 0.0;
262   Cn_iced = Cn_clean = 0.0;
263
264   uiuc_coef_lift();
265   uiuc_coef_drag();
266   uiuc_coef_pitch();
267   uiuc_coef_sideforce();
268   uiuc_coef_roll();
269   uiuc_coef_yaw();
270
271   //uncomment next line to always run icing functions
272   //nonlin_ice_case = 1;
273
274   if (nonlin_ice_case)
275     {
276       if (eta_from_file)
277         {
278           if (eta_tail_input) {
279             double time = Simtime - eta_tail_input_startTime;
280             eta_tail = uiuc_1Dinterpolation(eta_tail_input_timeArray,
281                                             eta_tail_input_daArray,
282                                             eta_tail_input_ntime,
283                                             time);
284           }
285           if (eta_wing_left_input) {
286             double time = Simtime - eta_wing_left_input_startTime;
287             eta_wing_left = uiuc_1Dinterpolation(eta_wing_left_input_timeArray,
288                                                  eta_wing_left_input_daArray,
289                                                  eta_wing_left_input_ntime,
290                                                  time);
291           }
292           if (eta_wing_right_input) {
293             double time = Simtime - eta_wing_right_input_startTime;
294             eta_wing_right = uiuc_1Dinterpolation(eta_wing_right_input_timeArray,
295                                                   eta_wing_right_input_daArray,
296                                                   eta_wing_right_input_ntime,
297                                                   time);
298           }
299         }
300
301       delta_CL = delta_CD = delta_Cm = delta_Cl = delta_Cn = 0.0;
302       Calc_Iced_Forces();
303       add_ice_effects();
304       tactilefadefI = 0.0;
305       if (eta_tail == 0.2 && tactile_pitch && tactilefadef)
306         {
307           if (tactilefadef_nice == 1)
308             tactilefadefI = uiuc_3Dinterp_quick(tactilefadef_fArray,
309                                            tactilefadef_aArray_nice,
310                                            tactilefadef_deArray_nice,
311                                            tactilefadef_tactileArray,
312                                            tactilefadef_na_nice,
313                                            tactilefadef_nde_nice,
314                                            tactilefadef_nf,
315                                            flap_pos,
316                                            Alpha,
317                                            elevator);
318           else
319             tactilefadefI = uiuc_3Dinterpolation(tactilefadef_fArray,
320                                             tactilefadef_aArray,
321                                             tactilefadef_deArray,
322                                             tactilefadef_tactileArray,
323                                             tactilefadef_nAlphaArray,
324                                             tactilefadef_nde,
325                                             tactilefadef_nf,
326                                             flap_pos,
327                                             Alpha,
328                                             elevator);
329         }
330       else if (demo_tactile)
331         {
332           double time = Simtime - demo_tactile_startTime;
333           tactilefadefI = uiuc_1Dinterpolation(demo_tactile_timeArray,
334                                                demo_tactile_daArray,
335                                                demo_tactile_ntime,
336                                                time);
337         }
338       if (icing_demo)
339         {
340           if (demo_eps_alpha_max) {
341             double time = Simtime - demo_eps_alpha_max_startTime;
342             eps_alpha_max = uiuc_1Dinterpolation(demo_eps_alpha_max_timeArray,
343                                                  demo_eps_alpha_max_daArray,
344                                                  demo_eps_alpha_max_ntime,
345                                                  time);
346           }
347           if (demo_eps_pitch_max) {
348             double time = Simtime - demo_eps_pitch_max_startTime;
349             eps_pitch_max = uiuc_1Dinterpolation(demo_eps_pitch_max_timeArray,
350                                                   demo_eps_pitch_max_daArray,
351                                                   demo_eps_pitch_max_ntime,
352                                                   time);
353           }
354           if (demo_eps_pitch_min) {
355             double time = Simtime - demo_eps_pitch_min_startTime;
356             eps_pitch_min = uiuc_1Dinterpolation(demo_eps_pitch_min_timeArray,
357                                                  demo_eps_pitch_min_daArray,
358                                                  demo_eps_pitch_min_ntime,
359                                                  time);
360           }
361           if (demo_eps_roll_max) {
362             double time = Simtime - demo_eps_roll_max_startTime;
363             eps_roll_max = uiuc_1Dinterpolation(demo_eps_roll_max_timeArray,
364                                                 demo_eps_roll_max_daArray,
365                                                 demo_eps_roll_max_ntime,
366                                                 time);
367           }
368           if (demo_eps_thrust_min) {
369             double time = Simtime - demo_eps_thrust_min_startTime;
370             eps_thrust_min = uiuc_1Dinterpolation(demo_eps_thrust_min_timeArray,
371                                                   demo_eps_thrust_min_daArray,
372                                                   demo_eps_thrust_min_ntime,
373                                                   time);
374           }
375           if (demo_eps_airspeed_max) {
376             double time = Simtime - demo_eps_airspeed_max_startTime;
377             eps_airspeed_max = uiuc_1Dinterpolation(demo_eps_airspeed_max_timeArray,
378                                                  demo_eps_airspeed_max_daArray,
379                                                  demo_eps_airspeed_max_ntime,
380                                                  time);
381           }
382           if (demo_eps_airspeed_min) {
383             double time = Simtime - demo_eps_airspeed_min_startTime;
384             eps_airspeed_min = uiuc_1Dinterpolation(demo_eps_airspeed_min_timeArray,
385                                                  demo_eps_airspeed_min_daArray,
386                                                  demo_eps_airspeed_min_ntime,
387                                                  time);
388           }
389           if (demo_eps_flap_max) {
390             double time = Simtime - demo_eps_flap_max_startTime;
391             eps_flap_max = uiuc_1Dinterpolation(demo_eps_flap_max_timeArray,
392                                                 demo_eps_flap_max_daArray,
393                                                 demo_eps_flap_max_ntime,
394                                                 time);
395           }
396           if (demo_boot_cycle_tail) {
397             double time = Simtime - demo_boot_cycle_tail_startTime;
398             boot_cycle_tail = uiuc_1Dinterpolation(demo_boot_cycle_tail_timeArray,
399                                                   demo_boot_cycle_tail_daArray,
400                                                   demo_boot_cycle_tail_ntime,
401                                                   time);
402           }
403           if (demo_boot_cycle_wing_left) {
404             double time = Simtime - demo_boot_cycle_wing_left_startTime;
405             boot_cycle_wing_left = uiuc_1Dinterpolation(demo_boot_cycle_wing_left_timeArray,
406                                              demo_boot_cycle_wing_left_daArray,
407                                              demo_boot_cycle_wing_left_ntime,
408                                              time);
409           }
410           if (demo_boot_cycle_wing_right) {
411             double time = Simtime - demo_boot_cycle_wing_right_startTime;
412             boot_cycle_wing_right = uiuc_1Dinterpolation(demo_boot_cycle_wing_right_timeArray,
413                                             demo_boot_cycle_wing_right_daArray,
414                                             demo_boot_cycle_wing_right_ntime,
415                                             time);
416           }
417           if (demo_eps_pitch_input) {
418             double time = Simtime - demo_eps_pitch_input_startTime;
419             eps_pitch_input = uiuc_1Dinterpolation(demo_eps_pitch_input_timeArray,
420                                                   demo_eps_pitch_input_daArray,
421                                                   demo_eps_pitch_input_ntime,
422                                                   time);
423           }
424           if (demo_ice_tail) {
425             double time = Simtime - demo_ice_tail_startTime;
426             ice_tail = uiuc_1Dinterpolation(demo_ice_tail_timeArray,
427                                             demo_ice_tail_daArray,
428                                             demo_ice_tail_ntime,
429                                             time);
430           }
431           if (demo_ice_left) {
432             double time = Simtime - demo_ice_left_startTime;
433             ice_left = uiuc_1Dinterpolation(demo_ice_left_timeArray,
434                                             demo_ice_left_daArray,
435                                             demo_ice_left_ntime,
436                                             time);
437           }
438           if (demo_ice_right) {
439             double time = Simtime - demo_ice_right_startTime;
440             ice_right = uiuc_1Dinterpolation(demo_ice_right_timeArray,
441                                              demo_ice_right_daArray,
442                                              demo_ice_right_ntime,
443                                              time);
444           }
445         }
446     }
447
448   if (pilot_ail_no)
449     {
450       if (aileron <=0)
451         Lat_control = - aileron / damax * RAD_TO_DEG;
452       else
453         Lat_control = - aileron / damin * RAD_TO_DEG;
454     }
455
456   // can go past real limits
457   // add flag to behave like trim_case2 later
458   if (pilot_elev_no)
459     {
460       if (outside_control == false)
461         {
462           l_trim = elevator_tab;
463           l_defl = elevator - elevator_tab;
464           if (l_trim <=0 )
465             Long_trim = l_trim / demax * RAD_TO_DEG;
466           else
467             Long_trim = l_trim / demin * RAD_TO_DEG;
468           if (l_defl <= 0)
469             Long_control = l_defl / demax * RAD_TO_DEG;
470           else
471             Long_control = l_defl / demin * RAD_TO_DEG;
472         }
473     }
474
475   if (pilot_rud_no)
476     {
477       if (rudder <=0)
478         Rudder_pedal = - rudder / drmax * RAD_TO_DEG;
479       else
480         Rudder_pedal = - rudder / drmin * RAD_TO_DEG;
481     }
482
483   return;
484 }
485
486 // end uiuc_coefficients.cpp