1 /**********************************************************************
3 FILENAME: uiuc_coefficients.cpp
5 ----------------------------------------------------------------------
7 DESCRIPTION: computes aggregated aerodynamic coefficients
9 ----------------------------------------------------------------------
13 ----------------------------------------------------------------------
17 ----------------------------------------------------------------------
19 HISTORY: 01/29/2000 initial release
20 02/01/2000 (JS) changed map name from aeroData to
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
35 07/05/2001 (RD) Added pilot_(elev,ail,rud)_no=false
36 01/11/2002 (AP) Added call to uiuc_bootTime()
38 ----------------------------------------------------------------------
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 ----------------------------------------------------------------------
48 ----------------------------------------------------------------------
50 INPUTS: -V_rel_wind (or U_body)
55 ----------------------------------------------------------------------
64 ----------------------------------------------------------------------
66 CALLED BY: uiuc_wrapper
68 ----------------------------------------------------------------------
70 CALLS TO: uiuc_coef_lift
78 ----------------------------------------------------------------------
80 COPYRIGHT: (C) 2000 by Michael Selig
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.
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.
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.
96 **********************************************************************/
98 #include "uiuc_coefficients.h"
99 #include "uiuc_warnings_errors.h"
103 void uiuc_coefficients(double dt)
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;
109 if (Alpha_init_true && Simtime==0)
112 if (Beta_init_true && Simtime==0)
115 // calculate rate derivative nondimensionalization factors
116 // check if speed is sufficient to compute dynamic pressure terms
119 uiuc_warnings_errors(5, uiuc_coefficients_error);
121 if (nondim_rate_V_rel_wind || use_V_rel_wind_2U) // c172_aero uses V_rel_wind
123 if (V_rel_wind > dyn_on_speed)
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);
130 else if (use_dyn_on_speed_curve1)
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);
146 else if(use_abs_U_body_2U) // use absolute(U_body)
148 if (fabs(U_body) > dyn_on_speed)
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));
154 else if (use_dyn_on_speed_curve1)
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);
172 if (U_body > dyn_on_speed)
174 cbar_2U = cbar / (2.0 * U_body);
175 b_2U = bw / (2.0 * U_body);
176 ch_2U = ch / (2.0 * U_body);
178 else if (use_dyn_on_speed_curve1)
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);
185 beta_flow_clean_tail = cbar_2U;
196 // check if speed is sufficient to "trust" Alpha_dot value
197 if (use_Alpha_dot_on_speed)
199 if (V_rel_wind < Alpha_dot_on_speed)
204 // check to see if icing model engaged
211 // check to see if data files are used for control deflections
212 if (outside_control == false)
214 pilot_elev_no = false;
215 pilot_ail_no = false;
216 pilot_rud_no = false;
218 if (elevator_step || elevator_singlet || elevator_doublet || elevator_input || aileron_input || rudder_input || flap_pos_input)
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,
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,
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;
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;
267 uiuc_coef_sideforce();
271 //uncomment next line to always run icing functions
272 //nonlin_ice_case = 1;
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,
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,
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,
301 delta_CL = delta_CD = delta_Cm = delta_Cl = delta_Cn = 0.0;
305 if (eta_tail == 0.2 && tactile_pitch && tactilefadef)
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,
319 tactilefadefI = uiuc_3Dinterpolation(tactilefadef_fArray,
321 tactilefadef_deArray,
322 tactilefadef_tactileArray,
323 tactilefadef_nAlphaArray,
330 else if (demo_tactile)
332 double time = Simtime - demo_tactile_startTime;
333 tactilefadefI = uiuc_1Dinterpolation(demo_tactile_timeArray,
334 demo_tactile_daArray,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
425 double time = Simtime - demo_ice_tail_startTime;
426 ice_tail = uiuc_1Dinterpolation(demo_ice_tail_timeArray,
427 demo_ice_tail_daArray,
432 double time = Simtime - demo_ice_left_startTime;
433 ice_left = uiuc_1Dinterpolation(demo_ice_left_timeArray,
434 demo_ice_left_daArray,
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,
451 Lat_control = - aileron / damax * RAD_TO_DEG;
453 Lat_control = - aileron / damin * RAD_TO_DEG;
456 // can go past real limits
457 // add flag to behave like trim_case2 later
460 if (outside_control == false)
462 l_trim = elevator_tab;
463 l_defl = elevator - elevator_tab;
465 Long_trim = l_trim / demax * RAD_TO_DEG;
467 Long_trim = l_trim / demin * RAD_TO_DEG;
469 Long_control = l_defl / demax * RAD_TO_DEG;
471 Long_control = l_defl / demin * RAD_TO_DEG;
478 Rudder_pedal = - rudder / drmax * RAD_TO_DEG;
480 Rudder_pedal = - rudder / drmin * RAD_TO_DEG;
486 // end uiuc_coefficients.cpp