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 Std_Alpha and
32 Std_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()
37 12/02/2002 (RD) Moved icing demo interpolations to its
40 ----------------------------------------------------------------------
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 ----------------------------------------------------------------------
50 ----------------------------------------------------------------------
52 INPUTS: -V_rel_wind (or U_body)
57 ----------------------------------------------------------------------
66 ----------------------------------------------------------------------
68 CALLED BY: uiuc_wrapper
70 ----------------------------------------------------------------------
72 CALLS TO: uiuc_coef_lift
80 ----------------------------------------------------------------------
82 COPYRIGHT: (C) 2000 by Michael Selig
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.
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.
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.
98 **********************************************************************/
100 #include "uiuc_coefficients.h"
102 void uiuc_coefficients(double dt)
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 static bool ap_pah_on_prev = false;
109 static bool ap_alh_on_prev = false;
112 if (Alpha_init_true && Simtime==0)
113 Std_Alpha = Alpha_init;
115 if (Beta_init_true && Simtime==0)
116 Std_Beta = Beta_init;
118 // calculate rate derivative nondimensionalization factors
119 // check if speed is sufficient to compute dynamic pressure terms
122 uiuc_warnings_errors(5, uiuc_coefficients_error);
124 if (nondim_rate_V_rel_wind || use_V_rel_wind_2U) // c172_aero uses V_rel_wind
126 if (V_rel_wind > dyn_on_speed)
128 cbar_2U = cbar / (2.0 * V_rel_wind);
129 b_2U = bw / (2.0 * V_rel_wind);
130 // ch is the horizontal tail chord
131 ch_2U = ch / (2.0 * V_rel_wind);
133 else if (use_dyn_on_speed_curve1)
135 V_rel_wind_dum = dyn_on_speed_zero + V_rel_wind * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
136 cbar_2U = cbar / (2.0 * V_rel_wind_dum);
137 b_2U = bw / (2.0 * V_rel_wind_dum);
138 ch_2U = ch / (2.0 * V_rel_wind_dum);
149 else if(use_abs_U_body_2U) // use absolute(U_body)
151 if (fabs(U_body) > dyn_on_speed)
153 cbar_2U = cbar / (2.0 * fabs(U_body));
154 b_2U = bw / (2.0 * fabs(U_body));
155 ch_2U = ch / (2.0 * fabs(U_body));
157 else if (use_dyn_on_speed_curve1)
159 U_body_dum = dyn_on_speed_zero + fabs(U_body) * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
160 cbar_2U = cbar / (2.0 * U_body_dum);
161 b_2U = bw / (2.0 * U_body_dum);
162 ch_2U = ch / (2.0 * U_body_dum);
175 if (U_body > dyn_on_speed)
177 cbar_2U = cbar / (2.0 * U_body);
178 b_2U = bw / (2.0 * U_body);
179 ch_2U = ch / (2.0 * U_body);
181 else if (use_dyn_on_speed_curve1)
183 U_body_dum = dyn_on_speed_zero + U_body * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
184 cbar_2U = cbar / (2.0 * U_body_dum);
185 b_2U = bw / (2.0 * U_body_dum);
186 ch_2U = ch / (2.0 * U_body_dum);
188 beta_flow_clean_tail = cbar_2U;
199 // check if speed is sufficient to "trust" Std_Alpha_dot value
200 if (use_Alpha_dot_on_speed)
202 if (V_rel_wind < Alpha_dot_on_speed)
207 // check to see if icing model engaged
214 // check to see if data files are used for control deflections
215 if (outside_control == false)
217 pilot_elev_no = false;
218 pilot_ail_no = false;
219 pilot_rud_no = false;
221 if (elevator_step || elevator_singlet || elevator_doublet || elevator_input || aileron_input || rudder_input || flap_pos_input)
226 if (ap_pah_on && icing_demo==false)
228 double V_rel_wind_ms;
229 V_rel_wind_ms = V_rel_wind * 0.3048;
230 ap_Theta_ref_rad = ap_Theta_ref_deg * DEG_TO_RAD;
231 if (ap_pah_on_prev == false)
233 elevator = pah_ap(Theta, Theta_dot, ap_Theta_ref_rad, V_rel_wind_ms, dt,
235 if (elevator*RAD_TO_DEG <= -1*demax)
236 elevator = -1*demax * DEG_TO_RAD;
237 if (elevator*RAD_TO_DEG >= demin)
238 elevator = demin * DEG_TO_RAD;
242 if (ap_alh_on && icing_demo==false)
244 double V_rel_wind_ms;
246 V_rel_wind_ms = V_rel_wind * 0.3048;
247 ap_alt_ref_m = ap_alt_ref_ft * 0.3048;
248 Altitude_m = Altitude * 0.3048;
249 if (ap_alh_on_prev == false)
251 elevator = alh_ap(Theta, Theta_dot, ap_alt_ref_m, Altitude_m,
252 V_rel_wind_ms, dt, ap_alh_init);
253 if (elevator*RAD_TO_DEG <= -1*demax)
254 elevator = -1*demax * DEG_TO_RAD;
255 if (elevator*RAD_TO_DEG >= demin)
256 elevator = demin * DEG_TO_RAD;
260 CD = CX = CL = CZ = Cm = CY = Cl = Cn = 0.0;
261 CLclean_wing = CLiced_wing = CLclean_tail = CLiced_tail = 0.0;
262 CZclean_wing = CZiced_wing = CZclean_tail = CZiced_tail = 0.0;
263 CXclean_wing = CXiced_wing = CXclean_tail = CXiced_tail = 0.0;
264 CL_clean = CL_iced = 0.0;
265 CY_clean = CY_iced = 0.0;
266 CD_clean = CD_iced = 0.0;
267 Cm_iced = Cm_clean = 0.0;
268 Cl_iced = Cl_clean = 0.0;
269 Cn_iced = Cn_clean = 0.0;
274 uiuc_coef_sideforce();
278 //uncomment next line to always run icing functions
279 //nonlin_ice_case = 1;
285 if (eta_tail_input) {
286 double time = Simtime - eta_tail_input_startTime;
287 eta_tail = uiuc_1Dinterpolation(eta_tail_input_timeArray,
288 eta_tail_input_daArray,
289 eta_tail_input_ntime,
292 if (eta_wing_left_input) {
293 double time = Simtime - eta_wing_left_input_startTime;
294 eta_wing_left = uiuc_1Dinterpolation(eta_wing_left_input_timeArray,
295 eta_wing_left_input_daArray,
296 eta_wing_left_input_ntime,
299 if (eta_wing_right_input) {
300 double time = Simtime - eta_wing_right_input_startTime;
301 eta_wing_right = uiuc_1Dinterpolation(eta_wing_right_input_timeArray,
302 eta_wing_right_input_daArray,
303 eta_wing_right_input_ntime,
308 delta_CL = delta_CD = delta_Cm = delta_Cl = delta_Cn = 0.0;
312 if (eta_tail == 0.2 && tactile_pitch && tactilefadef)
314 if (tactilefadef_nice == 1)
315 tactilefadefI = uiuc_3Dinterp_quick(tactilefadef_fArray,
316 tactilefadef_aArray_nice,
317 tactilefadef_deArray_nice,
318 tactilefadef_tactileArray,
319 tactilefadef_na_nice,
320 tactilefadef_nde_nice,
326 tactilefadefI = uiuc_3Dinterpolation(tactilefadef_fArray,
328 tactilefadef_deArray,
329 tactilefadef_tactileArray,
330 tactilefadef_nAlphaArray,
337 else if (demo_tactile)
339 double time = Simtime - demo_tactile_startTime;
340 tactilefadefI = uiuc_1Dinterpolation(demo_tactile_timeArray,
341 demo_tactile_daArray,
352 Lat_control = - aileron / damax * RAD_TO_DEG;
354 Lat_control = - aileron / damin * RAD_TO_DEG;
357 // can go past real limits
358 // add flag to behave like trim_case2 later
361 if (outside_control == false)
363 l_trim = elevator_tab;
364 l_defl = elevator - elevator_tab;
366 Long_trim = l_trim / demax * RAD_TO_DEG;
368 Long_trim = l_trim / demin * RAD_TO_DEG;
370 Long_control = l_defl / demax * RAD_TO_DEG;
372 Long_control = l_defl / demin * RAD_TO_DEG;
379 Rudder_pedal = - rudder / drmax * RAD_TO_DEG;
381 Rudder_pedal = - rudder / drmin * RAD_TO_DEG;
387 // end uiuc_coefficients.cpp