]> git.mxchange.org Git - flightgear.git/blobdiff - 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
index dcc800c2b7339dd48fdc46a42ab6f4874419f19f..d56c2f40934f5d8bd544699932120132a62cd67a 100644 (file)
                             Cnfada, and Cnfbetadr switches
               04/15/2000   (JS) broke up into multiple 
                            uiuc_coef_xxx functions
-              06/18/2001   (RD) Added initialization of Alpha and
-                           Beta.  Added aileron_input and rudder_input.
+              06/18/2001   (RD) Added initialization of Std_Alpha and
+                           Std_Beta.  Added aileron_input and rudder_input.
                            Added pilot_elev_no, pilot_ail_no, and
                            pilot_rud_no.
               07/05/2001   (RD) Added pilot_(elev,ail,rud)_no=false
-              01/11/2002   (AP) Added call to uiuc_bootTime()
+              01/11/2002   (AP) Added call to uiuc_iceboot()
+               12/02/2002   (RD) Moved icing demo interpolations to its
+                            own function
               
 ----------------------------------------------------------------------
 
 
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- USA or view http://www.gnu.org/copyleft/gpl.html.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 **********************************************************************/
 
 #include "uiuc_coefficients.h"
 
-
 void uiuc_coefficients(double dt)
 {
+  static string uiuc_coefficients_error = " (from uiuc_coefficients.cpp) ";
   double l_trim, l_defl;
   double V_rel_wind_dum, U_body_dum;
 
   if (Alpha_init_true && Simtime==0)
-    Alpha = Alpha_init;
+    Std_Alpha = Alpha_init;
 
   if (Beta_init_true && Simtime==0)
-    Beta = Beta_init;
+    Std_Beta = Beta_init;
 
   // calculate rate derivative nondimensionalization factors
   // check if speed is sufficient to compute dynamic pressure terms
+  if (dyn_on_speed==0) 
+    {
+      uiuc_warnings_errors(5, uiuc_coefficients_error);
+    }
   if (nondim_rate_V_rel_wind || use_V_rel_wind_2U)         // c172_aero uses V_rel_wind
     {
       if (V_rel_wind > dyn_on_speed)
        {
          cbar_2U = cbar / (2.0 * V_rel_wind);
          b_2U    = bw /   (2.0 * V_rel_wind);
-         // ch is the horizontal tail chord
-         ch_2U   = ch /   (2.0 * V_rel_wind);
+         // chord_h is the horizontal tail chord
+         ch_2U   = chord_h /   (2.0 * V_rel_wind);
        }
       else if (use_dyn_on_speed_curve1)
        {
          V_rel_wind_dum = dyn_on_speed_zero + V_rel_wind * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
          cbar_2U        = cbar / (2.0 * V_rel_wind_dum);
          b_2U           = bw /   (2.0 * V_rel_wind_dum);
-         ch_2U          = ch /   (2.0 * V_rel_wind_dum);
-         Alpha_dot      = 0.0;
+         ch_2U          = chord_h /   (2.0 * V_rel_wind_dum);
+         Std_Alpha_dot      = 0.0;
        }
       else
        {
          cbar_2U   = 0.0;
          b_2U      = 0.0;
          ch_2U     = 0.0;
-         Alpha_dot = 0.0;
+         Std_Alpha_dot = 0.0;
        }
     }
   else if(use_abs_U_body_2U)      // use absolute(U_body)
@@ -142,22 +147,22 @@ void uiuc_coefficients(double dt)
        {
          cbar_2U = cbar / (2.0 * fabs(U_body));
          b_2U    = bw /   (2.0 * fabs(U_body));
-         ch_2U   = ch /   (2.0 * fabs(U_body));
+         ch_2U   = chord_h /   (2.0 * fabs(U_body));
        }
       else if (use_dyn_on_speed_curve1)
        {
          U_body_dum = dyn_on_speed_zero + fabs(U_body) * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
          cbar_2U    = cbar / (2.0 * U_body_dum);
          b_2U       = bw /   (2.0 * U_body_dum);
-         ch_2U      = ch /   (2.0 * U_body_dum);
-         Alpha_dot  = 0.0;
+         ch_2U      = chord_h /   (2.0 * U_body_dum);
+         Std_Alpha_dot  = 0.0;
        }
       else
        {
          cbar_2U   = 0.0;
          b_2U      = 0.0;
          ch_2U     = 0.0;
-         Alpha_dot = 0.0;
+         Std_Alpha_dot = 0.0;
        }
     }
   else      // use U_body
@@ -166,15 +171,15 @@ void uiuc_coefficients(double dt)
        {
          cbar_2U = cbar / (2.0 * U_body);
          b_2U    = bw /   (2.0 * U_body);
-         ch_2U   = ch /   (2.0 * U_body);
+         ch_2U   = chord_h /   (2.0 * U_body);
        }
       else if (use_dyn_on_speed_curve1)
        {
          U_body_dum = dyn_on_speed_zero + U_body * (dyn_on_speed - dyn_on_speed_zero)/dyn_on_speed;
          cbar_2U    = cbar / (2.0 * U_body_dum);
          b_2U       = bw /   (2.0 * U_body_dum);
-         ch_2U      = ch /   (2.0 * U_body_dum);
-         Alpha_dot  = 0.0;
+         ch_2U      = chord_h /   (2.0 * U_body_dum);
+         Std_Alpha_dot  = 0.0;
          beta_flow_clean_tail = cbar_2U;
        }
       else
@@ -182,15 +187,15 @@ void uiuc_coefficients(double dt)
          cbar_2U   = 0.0;
          b_2U      = 0.0;
          ch_2U     = 0.0;
-         Alpha_dot = 0.0;
+         Std_Alpha_dot = 0.0;
        }
     }
 
-  // check if speed is sufficient to "trust" Alpha_dot value
+  // check if speed is sufficient to "trust" Std_Alpha_dot value
   if (use_Alpha_dot_on_speed)
     {
       if (V_rel_wind     < Alpha_dot_on_speed)
-         Alpha_dot = 0.0;
+         Std_Alpha_dot = 0.0;
     }
 
 
@@ -202,18 +207,38 @@ void uiuc_coefficients(double dt)
     }
 
   // check to see if data files are used for control deflections
-  pilot_elev_no = false;
-  pilot_ail_no = false;
-  pilot_rud_no = false;
-  if (elevator_step || elevator_singlet || elevator_doublet || elevator_input || aileron_input || rudder_input)
+  if (outside_control == false)
+    {
+      pilot_elev_no = false;
+      pilot_ail_no = false;
+      pilot_rud_no = false;
+    }
+  if (elevator_step || elevator_singlet || elevator_doublet || elevator_input || aileron_input || rudder_input || flap_pos_input)
     {
       uiuc_controlInput();
     }
 
+  //if (Simtime >=10.0)
+  //  {
+  //    ap_hh_on = 1;
+  //    ap_Psi_ref_rad = 0*DEG_TO_RAD;
+  //  }
+
+  if (ap_pah_on || ap_alh_on || ap_rah_on || ap_hh_on)
+    {
+      uiuc_auto_pilot(dt);
+    }
+
   CD = CX = CL = CZ = Cm = CY = Cl = Cn = 0.0;
   CLclean_wing = CLiced_wing = CLclean_tail = CLiced_tail = 0.0;
   CZclean_wing = CZiced_wing = CZclean_tail = CZiced_tail = 0.0;
   CXclean_wing = CXiced_wing = CXclean_tail = CXiced_tail = 0.0;
+  CL_clean = CL_iced = 0.0;
+  CY_clean = CY_iced = 0.0;
+  CD_clean = CD_iced = 0.0;
+  Cm_iced = Cm_clean = 0.0;
+  Cl_iced = Cl_clean = 0.0;
+  Cn_iced = Cn_clean = 0.0;
 
   uiuc_coef_lift();
   uiuc_coef_drag();
@@ -221,18 +246,76 @@ void uiuc_coefficients(double dt)
   uiuc_coef_sideforce();
   uiuc_coef_roll();
   uiuc_coef_yaw();
-  if (ice_case)
+
+  //uncomment next line to always run icing functions
+  //nonlin_ice_case = 1;
+
+  if (nonlin_ice_case)
     {
-      eta_tail = sublimation(OATemperature_F, eta_tail, dt);
-      eta_wing_left = sublimation(OATemperature_F, eta_wing_left, dt);
-      eta_wing_right = sublimation(OATemperature_F, eta_wing_right, dt);
-      //removed shed until new model is created
-      //eta_tail = shed(0.0, eta_tail, OATemperature_F, 0.0, dt);
-      //eta_wing_left = shed(0.0, eta_wing_left, OATemperature_F, 0.0, dt);
-      //eta_wing_right = shed(0.0, eta_wing_right, OATemperature_F, 0.0, dt);
-      
+      if (eta_from_file)
+       {
+         if (eta_tail_input) {
+           double time = Simtime - eta_tail_input_startTime;
+           eta_tail = uiuc_1Dinterpolation(eta_tail_input_timeArray,
+                                           eta_tail_input_daArray,
+                                           eta_tail_input_ntime,
+                                           time);
+         }
+         if (eta_wing_left_input) {
+           double time = Simtime - eta_wing_left_input_startTime;
+           eta_wing_left = uiuc_1Dinterpolation(eta_wing_left_input_timeArray,
+                                                eta_wing_left_input_daArray,
+                                                eta_wing_left_input_ntime,
+                                                time);
+         }
+         if (eta_wing_right_input) {
+           double time = Simtime - eta_wing_right_input_startTime;
+           eta_wing_right = uiuc_1Dinterpolation(eta_wing_right_input_timeArray,
+                                                 eta_wing_right_input_daArray,
+                                                 eta_wing_right_input_ntime,
+                                                 time);
+         }
+       }
+
+      delta_CL = delta_CD = delta_Cm = delta_Cl = delta_Cn = 0.0;
       Calc_Iced_Forces();
       add_ice_effects();
+      tactilefadefI = 0.0;
+      if (eta_tail == 0.2 && tactile_pitch && tactilefadef)
+       {
+         if (tactilefadef_nice == 1)
+           tactilefadefI = uiuc_3Dinterp_quick(tactilefadef_fArray,
+                                          tactilefadef_aArray_nice,
+                                          tactilefadef_deArray_nice,
+                                          tactilefadef_tactileArray,
+                                          tactilefadef_na_nice,
+                                          tactilefadef_nde_nice,
+                                          tactilefadef_nf,
+                                          flap_pos,
+                                          Std_Alpha,
+                                          elevator);
+         else
+           tactilefadefI = uiuc_3Dinterpolation(tactilefadef_fArray,
+                                           tactilefadef_aArray,
+                                           tactilefadef_deArray,
+                                           tactilefadef_tactileArray,
+                                           tactilefadef_nAlphaArray,
+                                           tactilefadef_nde,
+                                           tactilefadef_nf,
+                                           flap_pos,
+                                           Std_Alpha,
+                                           elevator);
+       }
+      else if (demo_tactile)
+       {
+         double time = Simtime - demo_tactile_startTime;
+         tactilefadefI = uiuc_1Dinterpolation(demo_tactile_timeArray,
+                                              demo_tactile_daArray,
+                                              demo_tactile_ntime,
+                                              time);
+       }
+      if (icing_demo)
+       uiuc_icing_demo();
     }
 
   if (pilot_ail_no)
@@ -243,18 +326,23 @@ void uiuc_coefficients(double dt)
        Lat_control = - aileron / damin * RAD_TO_DEG;
     }
 
+  // can go past real limits
+  // add flag to behave like trim_case2 later
   if (pilot_elev_no)
     {
-      l_trim = elevator_tab;
-      l_defl = elevator - elevator_tab;
-      if (l_trim <=0 )
-       Long_trim = l_trim / demax * RAD_TO_DEG;
-      else
-       Long_trim = l_trim / demin * RAD_TO_DEG;
-      if (l_defl <= 0)
-       Long_control = l_defl / demax * RAD_TO_DEG;
-      else
-       Long_control = l_defl / demin * RAD_TO_DEG;
+      if (outside_control == false)
+       {
+         l_trim = elevator_tab;
+         l_defl = elevator - elevator_tab;
+         if (l_trim <=0 )
+           Long_trim = l_trim / demax * RAD_TO_DEG;
+         else
+           Long_trim = l_trim / demin * RAD_TO_DEG;
+         if (l_defl <= 0)
+           Long_control = l_defl / demax * RAD_TO_DEG;
+         else
+           Long_control = l_defl / demin * RAD_TO_DEG;
+       }
     }
 
   if (pilot_rud_no)