]> git.mxchange.org Git - flightgear.git/commitdiff
Adds a basic FDM model for LaRCsim debugging purposes.
authormselig <mselig>
Fri, 25 Jul 2003 17:53:13 +0000 (17:53 +0000)
committermselig <mselig>
Fri, 25 Jul 2003 17:53:13 +0000 (17:53 +0000)
src/FDM/LaRCsim/LaRCsim.cxx
src/FDM/LaRCsim/basic_aero.c [new file with mode: 0644]
src/FDM/LaRCsim/basic_aero.h [new file with mode: 0644]
src/FDM/LaRCsim/basic_engine.c [new file with mode: 0644]
src/FDM/LaRCsim/basic_gear.c [new file with mode: 0644]
src/FDM/LaRCsim/basic_init.c [new file with mode: 0644]
src/FDM/LaRCsim/basic_init.h [new file with mode: 0644]

index 5c3026d2e374b192b2b0f8e83b241fc7f253e7a7..5683feb48896dff609928e8d790fea90d1262d67 100644 (file)
@@ -66,6 +66,22 @@ FGLaRCsim::FGLaRCsim( double dt ) {
         I_xz = 0.000000E+00;
     }
 
+    if ( !strcmp(aero->getStringValue(), "basic") ) {
+        copy_to_LaRCsim(); // initialize all of LaRCsim's vars
+
+        //this should go away someday -- formerly done in fg_init.cxx
+       Mass = 2./32.174;
+       I_xx   = 0.0454;
+       I_yy   = 0.0191;
+       I_zz   = 0.0721;
+       I_xz   = 0;
+//     Mass = 8.547270E+01;
+//     I_xx = 1.048000E+03;
+//     I_yy = 3.000000E+03;
+//     I_zz = 3.530000E+03;
+//     I_xz = 0.000000E+00;
+    }
+
     ls_set_model_dt(dt);
     
     // Initialize our little engine that hopefully might
@@ -161,14 +177,85 @@ void FGLaRCsim::update( double dt ) {
                        * dt);
        }
 
+       // Apparently the IO360 thrust model is not working.  
+       // F_X_engine is zero here.
        F_X_engine = eng.get_prop_thrust_lbs();
-       // cout << "F_X_engine = " << F_X_engine << '\n';
-       // end c172 if block
 
        Flap_handle = 30.0 * globals->get_controls()->get_flaps();
     }
     // done with c172-larcsim if-block
 
+    if ( !strcmp(aero->getStringValue(), "basic") ) {
+        // set control inputs
+        // cout << "V_calibrated_kts = " << V_calibrated_kts << '\n';
+       eng.set_IAS( V_calibrated_kts );
+       eng.set_Throttle_Lever_Pos( globals->get_controls()->get_throttle( 0 )
+                                   * 100.0 );
+       eng.set_Propeller_Lever_Pos( 100 );
+        eng.set_Mixture_Lever_Pos( globals->get_controls()->get_mixture( 0 )
+                                  * 100.0 );
+       eng.set_Magneto_Switch_Pos( globals->get_controls()->get_magnetos(0) );
+       eng.setStarterFlag( globals->get_controls()->get_starter(0) );
+       eng.set_p_amb( Static_pressure );
+       eng.set_T_amb( Static_temperature );
+
+       // update engine model
+       eng.update();
+
+       // Fake control-surface positions
+       fgSetDouble("/surface-positions/flap-pos-norm",
+                   fgGetDouble("/controls/flight/flaps"));
+                               // FIXME: ignoring trim
+       fgSetDouble("/surface-positions/elevator-pos-norm",
+                   fgGetDouble("/controls/flight/elevator"));
+                               // FIXME: ignoring trim
+       fgSetDouble("/surface-positions/left-aileron-pos-norm",
+                   fgGetDouble("/controls/flight/aileron"));
+                               // FIXME: ignoring trim
+       fgSetDouble("/surface-positions/right-aileron-pos-norm",
+                   -1 * fgGetDouble("/controls/flight/aileron"));
+                               // FIXME: ignoring trim
+       fgSetDouble("/surface-positions/rudder-pos-norm",
+                   fgGetDouble("/controls/flight/rudder"));
+
+       // copy engine state values onto "bus"
+       fgSetDouble("/engines/engine/rpm", eng.get_RPM());
+       fgSetDouble("/engines/engine/mp-osi", eng.get_Manifold_Pressure());
+       fgSetDouble("/engines/engine/max-hp", eng.get_MaxHP());
+       fgSetDouble("/engines/engine/power-pct", eng.get_Percentage_Power());
+       fgSetDouble("/engines/engine/egt-degf", eng.get_EGT());
+       fgSetDouble("/engines/engine/cht-degf", eng.get_CHT());
+       fgSetDouble("/engines/engine/prop-thrust", eng.get_prop_thrust_SI());
+       fgSetDouble("/engines/engine/fuel-flow-gph",
+                   eng.get_fuel_flow_gals_hr());
+       fgSetDouble("/engines/engine/oil-temperature-degf",
+                   eng.get_oil_temp());
+       fgSetDouble("/engines/engine/running", eng.getRunningFlag());
+       fgSetDouble("/engines/engine/cranking", eng.getCrankingFlag());
+
+       static const SGPropertyNode *fuel_freeze
+           = fgGetNode("/sim/freeze/fuel");
+
+       if ( ! fuel_freeze->getBoolValue() ) {
+           //Assume we are using both tanks equally for now
+           fgSetDouble("/consumables/fuel/tank[0]/level-gal_us",
+                       fgGetDouble("/consumables/fuel/tank[0]/level-gal_us")
+                       - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
+                       * dt);
+           fgSetDouble("/consumables/fuel/tank[1]/level-gal_us",
+                       fgGetDouble("/consumables/fuel/tank[1]/level-gal_us")
+                       - (eng.get_fuel_flow_gals_hr() / (2 * 3600))
+                       * dt);
+       }
+
+       // Apparently the IO360 thrust model is not working.  
+       // F_X_engine is zero here.
+       F_X_engine = eng.get_prop_thrust_lbs();
+
+       Flap_handle = 30.0 * globals->get_controls()->get_flaps();
+    }
+    // done with basic-larcsim if-block
+
     double save_alt = 0.0;
 
     // lets try to avoid really screwing up the LaRCsim model
@@ -183,11 +270,14 @@ void FGLaRCsim::update( double dt ) {
     Long_trim = globals->get_controls()->get_elevator_trim();
     Rudder_pedal = globals->get_controls()->get_rudder() / speed_up->getIntValue();
 
-    if ( !strcmp(aero->getStringValue(), "c172") ) {
-        Use_External_Engine = 1;
-    } else {
-        Use_External_Engine = 0;
-    }
+    // IO360.cxx for the C172 thrust is broken (not sure why).  
+    // So force C172 to use engine model in c172_engine.c instead of the IO360.cxx.
+    //      if ( !strcmp(aero->getStringValue(), "c172") ) {
+    //          Use_External_Engine = 1;
+    //      } else {
+    //          Use_External_Engine = 0;
+    //      }
+    Use_External_Engine = 0;
 
     Throttle_pct = globals->get_controls()->get_throttle( 0 ) * 1.0;
 
diff --git a/src/FDM/LaRCsim/basic_aero.c b/src/FDM/LaRCsim/basic_aero.c
new file mode 100644 (file)
index 0000000..e518531
--- /dev/null
@@ -0,0 +1,473 @@
+/***************************************************************************
+
+  TITLE:        basic_aero
+                
+----------------------------------------------------------------------------
+
+  FUNCTION:      aerodynamics model based on stability derivatives 
+                 + tweaks for nonlinear aero
+
+----------------------------------------------------------------------------
+
+  MODULE STATUS: developmental
+
+----------------------------------------------------------------------------
+
+  GENEALOGY:     based on aero model from crrcsim code (Drela's aero model)
+
+----------------------------------------------------------------------------
+
+  DESIGNED BY:
+                
+  CODED BY:             Michael Selig
+                
+  MAINTAINED BY:        Michael Selig
+
+----------------------------------------------------------------------------
+
+  MODIFICATION HISTORY:
+                
+  DATE          PURPOSE                                                                                         BY
+  7/25/03       LaRCsim debugging purposes
+
+----------------------------------------------------------------------------
+
+  REFERENCES:
+  
+----------------------------------------------------------------------------
+
+  CALLED BY:
+
+----------------------------------------------------------------------------
+
+  CALLS TO:
+
+----------------------------------------------------------------------------
+
+  INPUTS:       
+
+----------------------------------------------------------------------------
+
+  OUTPUTS:
+
+--------------------------------------------------------------------------*/
+
+
+        
+#include "ls_generic.h"
+#include "ls_cockpit.h"
+#include "ls_constants.h"
+#include "ls_types.h"
+#include "basic_aero.h"
+
+#include <math.h>
+#include <stdio.h>
+
+
+#ifdef USENZ
+#define NZ generic_.n_cg_body_v[2]
+#else
+#define NZ 1
+#endif          
+
+
+extern COCKPIT cockpit_;
+
+
+void basic_aero(SCALAR dt, int Initialize)
+// Calculate forces and moments for the current time step.  If Initialize is
+// zero, then re-initialize coefficients by reading in the coefficient file.
+{
+ static int init = 0;
+ static SCALAR elevator_drela, aileron_drela, rudder_drela;
+
+ SCALAR C_ref;
+ SCALAR B_ref;
+ SCALAR S_ref;
+ SCALAR U_ref;
+ /*  SCALAR Mass; */
+ /*  SCALAR I_xx; */
+ /*  SCALAR I_yy; */
+ /*  SCALAR I_zz; */
+ /*  SCALAR I_xz; */
+ SCALAR Alpha_0;
+ SCALAR Cm_0;
+ SCALAR CL_0;
+ SCALAR CL_max;
+ SCALAR CL_min;
+ SCALAR CD_prof;
+ SCALAR Uexp_CD;
+ SCALAR CL_a;
+ SCALAR Cm_a;
+ SCALAR CY_b;
+ SCALAR Cl_b;
+ SCALAR Cn_b;
+ SCALAR CL_q;
+ SCALAR Cm_q;
+ SCALAR CY_p;
+ SCALAR Cl_p;
+ SCALAR Cn_p;
+ SCALAR CY_r;
+ SCALAR Cl_r;
+ SCALAR Cn_r;
+ SCALAR CL_de;
+ SCALAR Cm_de;
+ SCALAR CY_dr;
+ SCALAR Cl_dr;
+ SCALAR Cn_dr;
+ SCALAR CY_da;
+ SCALAR Cl_da;
+ SCALAR Cn_da;
+ SCALAR eta_loc;
+ SCALAR CG_arm;
+ SCALAR CL_drop;
+ SCALAR CD_stall = 0.05;
+ int stalling;
+ SCALAR span_eff;
+ SCALAR CL_CD0;
+ SCALAR CD_CLsq;
+ SCALAR CD_AIsq;
+ SCALAR CD_ELsq;
+ SCALAR Phat, Qhat, Rhat;  // dimensionless rotation rates
+ SCALAR CL_left, CL_cent, CL_right; // CL values across the span
+ SCALAR dCL_left,dCL_cent,dCL_right; // stall-induced CL changes
+ SCALAR dCD_left,dCD_cent,dCD_right; // stall-induced CD changes
+ SCALAR dCl,dCn,dCl_stall,dCn_stall;  // stall-induced roll,yaw moments
+ SCALAR dCm_stall;  // Stall induced pitching moment.
+ SCALAR CL_wing, CD_all, CD_scaled, Cl_w;
+ SCALAR Cl_r_mod,Cn_p_mod;
+ SCALAR CL_drela,CD_drela,Cx_drela,Cy_drela,Cz_drela,Cl_drela,Cm_drela,Cn_drela;
+ SCALAR QS;
+ SCALAR G_11,G_12,G_13;
+ SCALAR G_21,G_22,G_23;
+ SCALAR G_31,G_32,G_33;
+ SCALAR U_body_X,U_body_Y,U_body_Z;
+ SCALAR V_body_X,V_body_Y,V_body_Z;
+ SCALAR W_body_X,W_body_Y,W_body_Z;
+ SCALAR P_atmo,Q_atmo,R_atmo;
+
+ // set the parameters
+
+ C_ref = 0.551667;
+ B_ref = 6.55000;
+ S_ref = 3.61111;
+ U_ref = 19.6850;
+ Alpha_0 = 0.349066E-01;
+ Cm_0 = -0.112663E-01;
+ CL_0 = 0.563172;
+ CL_max = 1.10000;
+ CL_min = -0.600000;
+ CD_prof = 0.200000E-01;
+ Uexp_CD = -0.500000;
+ CL_a = 5.50360;
+ Cm_a = -0.575335;
+ CY_b = -0.415610;
+ Cl_b = -0.250926;
+ Cn_b = 0.567069E-01;
+ CL_q = 7.50999;
+ Cm_q = -11.4975;
+ CY_p = -0.423820;
+ Cl_p = -0.611798;
+ Cn_p = -0.740898E-01;
+ CY_r = 0.297540;
+ Cl_r = 0.139581;
+ Cn_r = -0.687755E-01;
+ CL_de = 0.162000;
+ Cm_de = -0.597537;
+ CY_dr = 0.000000E+00;
+ Cl_dr = 0.000000E+00;
+ Cn_dr = 0.000000E+00;
+ CY_da = -0.135890;
+ Cl_da = -0.307921E-02;
+ Cn_da = 0.527143E-01;
+ span_eff = 0.95;
+ CL_CD0 = 0.0;
+ CD_CLsq = 0.01;
+ CD_AIsq = 0.0;
+ CD_ELsq = 0.0;
+ eta_loc = 0.3;
+ CG_arm = 0.25;
+ CL_drop = 0.5;
+
+ if (!init)
+  {
+   init = -1;
+  }  
+
+ // jan's data goes -.5 to .5 while
+ // fgfs data goes +- 1.
+ // so I need to divide by 2 below.
+  elevator = Long_control + Long_trim;
+  aileron  = Lat_control;
+  rudder   = Rudder_pedal;
+
+  elevator = elevator * 0.5;
+  aileron  = aileron * 0.5;
+  rudder   = rudder * 0.5;
+
+
+
+//  printf("%f\n",V_rel_wind);
+
+  /* compute gradients of Local velocities w.r.t. Body coordinates
+      G_11  =  dU_local/dx_body
+      G_12  =  dU_local/dy_body   etc.  */
+
+  /*
+  G_11 = U_atmo_X*T_local_to_body_11
+       + U_atmo_Y*T_local_to_body_12
+       + U_atmo_Z*T_local_to_body_13;
+  G_12 = U_atmo_X*T_local_to_body_21
+       + U_atmo_Y*T_local_to_body_22
+       + U_atmo_Z*T_local_to_body_23;
+  G_13 = U_atmo_X*T_local_to_body_31
+       + U_atmo_Y*T_local_to_body_32
+       + U_atmo_Z*T_local_to_body_33;
+
+  G_21 = V_atmo_X*T_local_to_body_11
+       + V_atmo_Y*T_local_to_body_12
+       + V_atmo_Z*T_local_to_body_13;
+  G_22 = V_atmo_X*T_local_to_body_21
+       + V_atmo_Y*T_local_to_body_22
+       + V_atmo_Z*T_local_to_body_23;
+  G_23 = V_atmo_X*T_local_to_body_31
+       + V_atmo_Y*T_local_to_body_32
+       + V_atmo_Z*T_local_to_body_33;
+
+  G_31 = W_atmo_X*T_local_to_body_11
+       + W_atmo_Y*T_local_to_body_12
+       + W_atmo_Z*T_local_to_body_13;
+  G_32 = W_atmo_X*T_local_to_body_21
+       + W_atmo_Y*T_local_to_body_22
+       + W_atmo_Z*T_local_to_body_23;
+  G_33 = W_atmo_X*T_local_to_body_31
+       + W_atmo_Y*T_local_to_body_32
+       + W_atmo_Z*T_local_to_body_33;
+  */
+
+  //printf("%f %f %f %f\n",W_atmo_X,W_atmo_Y,G_31,G_32);
+
+  /* now compute gradients of Body velocities w.r.t. Body coordinates */
+  /*  U_body_x  =  dU_body/dx_body   etc.  */
+
+  /*
+  U_body_X = T_local_to_body_11*G_11
+           + T_local_to_body_12*G_21
+           + T_local_to_body_13*G_31;
+  U_body_Y = T_local_to_body_11*G_12
+           + T_local_to_body_12*G_22
+           + T_local_to_body_13*G_32;
+  U_body_Z = T_local_to_body_11*G_13
+           + T_local_to_body_12*G_23
+           + T_local_to_body_13*G_33;
+                              
+  V_body_X = T_local_to_body_21*G_11
+           + T_local_to_body_22*G_21
+           + T_local_to_body_23*G_31;
+  V_body_Y = T_local_to_body_21*G_12
+           + T_local_to_body_22*G_22
+           + T_local_to_body_23*G_32;
+  V_body_Z = T_local_to_body_21*G_13
+           + T_local_to_body_22*G_23
+           + T_local_to_body_23*G_33;
+                              
+  W_body_X = T_local_to_body_31*G_11
+           + T_local_to_body_32*G_21
+           + T_local_to_body_33*G_31;
+  W_body_Y = T_local_to_body_31*G_12
+           + T_local_to_body_32*G_22
+           + T_local_to_body_33*G_32;
+  W_body_Z = T_local_to_body_31*G_13
+           + T_local_to_body_32*G_23
+           + T_local_to_body_33*G_33;
+  */
+
+  /* set rotation rates of airmass motion */
+  /*   BUG
+        P_atmo =  W_body_X;
+        Q_atmo = -W_body_Y;
+        R_atmo =  V_body_Z;
+  */
+      
+  /*
+        P_atmo =  W_body_Y;
+        Q_atmo = -W_body_X;
+        R_atmo =  V_body_X;
+  */
+
+        P_atmo = 0;
+        Q_atmo = 0;
+        R_atmo = 0;
+
+  //  printf("%f %f %f\n",P_atmo,Q_atmo,R_atmo);
+  if (V_rel_wind != 0)
+   {
+  /* set net effective dimensionless rotation rates */
+    Phat = (P_body - P_atmo) * B_ref / (2.0*V_rel_wind);
+    Qhat = (Q_body - Q_atmo) * C_ref / (2.0*V_rel_wind);
+    Rhat = (R_body - R_atmo) * B_ref / (2.0*V_rel_wind);
+   }
+  else
+   {
+    Phat=0;
+    Qhat=0;
+    Rhat=0;
+   }
+
+//  printf("Phat: %f Qhat: %f Rhat: %f\n",Phat,Qhat,Rhat);
+
+    /* compute local CL at three spanwise locations */
+  CL_left  = CL_0 + CL_a*(Std_Alpha - Alpha_0 - Phat*eta_loc);
+  CL_cent  = CL_0 + CL_a*(Std_Alpha - Alpha_0               );
+  CL_right = CL_0 + CL_a*(Std_Alpha - Alpha_0 + Phat*eta_loc);
+
+// printf("CL_left: %f CL_cent: %f CL_right: %f\n",CL_left,CL_cent,CL_right);
+
+    /* set CL-limit changes */
+  dCL_left  = 0.;
+  dCL_cent  = 0.;
+  dCL_right = 0.;
+
+  stalling=0;
+  if (CL_left  > CL_max)
+    {
+      dCL_left  = CL_max-CL_left -CL_drop; 
+      stalling=1;
+    }
+
+  if (CL_cent  > CL_max)
+    {
+      dCL_cent  = CL_max-CL_cent -CL_drop;
+      stalling=1;
+    }
+
+  if (CL_right > CL_max)
+    {
+      dCL_right = CL_max-CL_right -CL_drop;
+      stalling=1;      
+    }
+
+  if (CL_left  < CL_min)
+    {
+      dCL_left  = CL_min-CL_left -CL_drop;
+      stalling=1;
+    }
+
+  if (CL_cent  < CL_min)
+    {
+      dCL_cent  = CL_min-CL_cent -CL_drop; 
+      stalling=1;
+    }
+
+  if (CL_right < CL_min)
+    {
+      dCL_right = CL_min-CL_right -CL_drop;
+      stalling=1;
+    }
+
+  /* set average wing CL */
+  CL_wing = CL_0 + CL_a*(Std_Alpha-Alpha_0)
+          + 0.25*dCL_left + 0.5*dCL_cent + 0.25*dCL_right;
+
+//  printf("CL_wing: %f\n",CL_wing);
+
+
+  /* correct profile CD for CL dependence and aileron dependence */
+  CD_all = CD_prof
+         + CD_CLsq*(CL_wing-CL_CD0)*(CL_wing-CL_CD0)
+         + CD_AIsq*aileron*aileron
+         + CD_ELsq*elevator*elevator;
+
+//  printf("CD_all:%lf\n",CD_all);
+
+    /* scale profile CD with Reynolds number via simple power law */
+ if (V_rel_wind > 0.1)
+ {
+  CD_scaled = CD_all*pow(((double)V_rel_wind/(double)U_ref),Uexp_CD);
+ }
+ else
+ {
+        CD_scaled=CD_all;
+ }
+
+//  printf("CD_scaled:%lf\n",CD_scaled);
+
+
+
+  /* Scale lateral cross-coupling derivatives with wing CL */
+  Cl_r_mod = Cl_r*CL_wing/CL_0;
+  Cn_p_mod = Cn_p*CL_wing/CL_0;
+
+  //  printf("Cl_r_mod: %f Cn_p_mod: %f\n",Cl_r_mod,Cn_p_mod);
+
+    /* total average CD with induced and stall contributions */
+  dCD_left  = CD_stall*dCL_left *dCL_left ;
+  dCD_cent  = CD_stall*dCL_cent *dCL_cent ;
+  dCD_right = CD_stall*dCL_right*dCL_right;
+
+  /* total CL, with pitch rate and elevator contributions */
+  CL_drela = (CL_wing + CL_q*Qhat + CL_de*elevator)*Cos_alpha;
+
+//  printf("CL:%f\n",CL);
+
+    /* assymetric stall will cause roll and yaw moments */
+  dCl =  0.45*-1*(dCL_right-dCL_left)*0.5*eta_loc;
+  dCn =  0.45*(dCD_right-dCD_left)*0.5*eta_loc;
+  dCm_stall = (0.25*dCL_left + 0.5*dCL_cent + 0.25*dCL_right)*CG_arm;
+
+//  printf("dCl: %f dCn:%f\n",dCl,dCn);
+
+    /* stall-caused moments in body axes */
+  dCl_stall = dCl*Cos_alpha - dCn*Sin_alpha;
+  dCn_stall = dCl*Sin_alpha + dCn*Cos_alpha;
+
+    /* total CD, with induced and stall contributions */
+
+  Cl_w = Cl_b*Std_Beta  + Cl_p*Phat + Cl_r_mod*Rhat
+       + dCl_stall  + Cl_da*aileron;
+  CD_drela = CD_scaled
+     + (CL*CL + 32.0*Cl_w*Cl_w)*S_ref/(B_ref*B_ref*3.14159*span_eff)
+     + 0.25*dCD_left + 0.5*dCD_cent + 0.25*dCD_right;
+
+  //printf("CL: %f CD:%f L/D:%f\n",CL,CD,CL/CD);
+
+    /* total forces in body axes */
+  Cx_drela = -CD_drela*Cos_alpha + CL_drela*Sin_alpha*Cos_beta*Cos_beta;
+  Cz_drela = -CD_drela*Sin_alpha - CL_drela*Cos_alpha*Cos_beta*Cos_beta;
+  Cy_drela = CY_b*Std_Beta  + CY_p*Phat + CY_r*Rhat + CY_dr*rudder;
+
+    /* total moments in body axes */
+  Cl_drela =        Cl_b*Std_Beta  + Cl_p*Phat + Cl_r_mod*Rhat + Cl_dr*rudder
+           + dCl_stall                               + Cl_da*aileron;
+  Cn_drela =        Cn_b*Std_Beta  + Cn_p_mod*Phat + Cn_r*Rhat + Cn_dr*rudder
+           + dCn_stall                               + Cn_da*aileron;
+  Cm_drela = Cm_0 + Cm_a*(Std_Alpha-Alpha_0) +dCm_stall
+                         + Cm_q*Qhat                 + Cm_de*elevator;
+
+    /* set dimensional forces and moments */
+  QS = 0.5*Density*V_rel_wind*V_rel_wind * S_ref;
+  
+  F_X_aero = Cx_drela * QS;
+  F_Y_aero = Cy_drela * QS;
+  F_Z_aero = Cz_drela * QS;
+
+  M_l_aero = Cl_drela * QS * B_ref;
+  M_m_aero = Cm_drela * QS * C_ref;
+  M_n_aero = Cn_drela * QS * B_ref;
+//  printf("%f %f %f %f %f %f\n",F_X_aero,F_Y_aero,F_Z_aero,M_l_aero,M_m_aero,M_n_aero);
+}
+
diff --git a/src/FDM/LaRCsim/basic_aero.h b/src/FDM/LaRCsim/basic_aero.h
new file mode 100644 (file)
index 0000000..dc07b4e
--- /dev/null
@@ -0,0 +1,81 @@
+/*basic_aero.h*/
+
+#ifndef __BASIC_AERO_H
+#define __BASIC_AERO_H
+
+
+
+#include <FDM/LaRCsim/ls_types.h>
+
+/*global declarations of aero model parameters*/
+
+   extern SCALAR CLadot;
+   extern SCALAR CLq;
+   extern SCALAR CLde;
+   extern SCALAR CLob;
+
+   extern SCALAR CLa;
+   extern SCALAR CLo;
+  
+  
+   extern SCALAR Cdob;
+   extern SCALAR Cda;  /*Not used*/
+   extern SCALAR Cdde;
+  
+   extern SCALAR Cma;
+   extern SCALAR Cmadot;
+   extern SCALAR Cmq;
+   extern SCALAR Cmob; 
+   extern SCALAR Cmde;
+  
+   extern SCALAR Clbeta;
+   extern SCALAR Clp;
+   extern SCALAR Clr;
+   extern SCALAR Clda;
+   extern SCALAR Cldr;
+  
+   extern SCALAR Cnbeta;
+   extern SCALAR Cnp;
+   extern SCALAR Cnr;
+   extern SCALAR Cnda;
+   extern SCALAR Cndr;
+  
+   extern SCALAR Cybeta;
+   extern SCALAR Cyp;
+   extern SCALAR Cyr;
+   extern SCALAR Cyda;
+   extern SCALAR Cydr;
+  
+  /*nondimensionalization quantities*/
+  /*units here are ft and lbs */
+   extern SCALAR cbar; /*mean aero chord ft*/
+   extern SCALAR b; /*wing span ft */
+   extern SCALAR Sw; /*wing planform surface area ft^2*/
+   extern SCALAR rPiARe; /*reciprocal of Pi*AR*e*/
+   extern SCALAR lbare;  /*elevator moment arm  MAC*/
+   
+   extern SCALAR Weight; /*lbs*/
+   extern SCALAR MaxTakeoffWeight,EmptyWeight;
+   extern SCALAR Cg;     /*%MAC*/
+   extern SCALAR Zcg;    /*%MAC*/
+  
+  
+  extern SCALAR CLwbh,CL,cm,cd,cn,cy,croll,cbar_2V,b_2V,qS,qScbar,qSb;
+  extern SCALAR CLo,Cdo,Cmo;
+  
+  extern SCALAR F_X_wind,F_Y_wind,F_Z_wind;
+  
+  extern SCALAR long_trim;
+
+  
+  extern SCALAR elevator, aileron, rudder;
+
+  
+  extern SCALAR Flap_Position;
+  extern int Flaps_In_Transit;
+  
+
+
+#endif
+
diff --git a/src/FDM/LaRCsim/basic_engine.c b/src/FDM/LaRCsim/basic_engine.c
new file mode 100644 (file)
index 0000000..e173407
--- /dev/null
@@ -0,0 +1,90 @@
+/***************************************************************************
+
+        TITLE:          basic_engine.c
+        
+----------------------------------------------------------------------------
+
+        FUNCTION:       dummy engine routine
+
+----------------------------------------------------------------------------
+
+        MODULE STATUS:  incomplete
+
+----------------------------------------------------------------------------
+
+        GENEALOGY:
+                                
+
+----------------------------------------------------------------------------
+
+        DESIGNED BY:    designer
+        
+        CODED BY:       programmer
+        
+        MAINTAINED BY:  maintainer
+
+----------------------------------------------------------------------------
+
+        MODIFICATION HISTORY:
+        
+        DATE    PURPOSE                                         BY
+
+        CURRENT RCS HEADER INFO:
+
+$Header$
+
+ * Revision 1.1  92/12/30  13:21:46  bjax
+ * Initial revision
+ * 
+
+----------------------------------------------------------------------------
+
+        REFERENCES:
+
+----------------------------------------------------------------------------
+
+        CALLED BY:      ls_model();
+
+----------------------------------------------------------------------------
+
+        CALLS TO:       none
+
+----------------------------------------------------------------------------
+
+        INPUTS:
+
+----------------------------------------------------------------------------
+
+        OUTPUTS:
+
+--------------------------------------------------------------------------*/
+#include <math.h>
+#include "ls_types.h"
+#include "ls_constants.h"
+#include "ls_generic.h"
+#include "ls_sim_control.h"
+#include "ls_cockpit.h"
+#include "basic_aero.h"
+
+extern SIM_CONTROL      sim_control_;
+
+void basic_engine( SCALAR dt, int init ) {
+  
+  // c172
+  //    F_X_engine = Throttle_pct * 421;
+  // neo 2m slope
+  F_X_engine = Throttle_pct * 8;
+  F_Y_engine = 0.0;
+  F_Z_engine = 0.0;
+  M_l_engine = 0.0;
+  M_m_engine = 0.0;
+  M_n_engine = 0.0;
+  
+  
+  //  printf("Throttle_pct %f\n", Throttle_pct);
+  //  printf("F_X_engine %f\n", F_X_engine);
+
+  
+}
+
+
diff --git a/src/FDM/LaRCsim/basic_gear.c b/src/FDM/LaRCsim/basic_gear.c
new file mode 100644 (file)
index 0000000..18d7cb5
--- /dev/null
@@ -0,0 +1,349 @@
+/***************************************************************************
+
+        TITLE:  gear
+        
+----------------------------------------------------------------------------
+
+        FUNCTION:       Landing gear model for example simulation
+
+----------------------------------------------------------------------------
+
+        MODULE STATUS:  developmental
+
+----------------------------------------------------------------------------
+
+        GENEALOGY:      Created 931012 by E. B. Jackson
+
+----------------------------------------------------------------------------
+
+        DESIGNED BY:    E. B. Jackson
+        
+        CODED BY:       E. B. Jackson
+        
+        MAINTAINED BY:  E. B. Jackson
+
+----------------------------------------------------------------------------
+
+        MODIFICATION HISTORY:
+        
+----------------------------------------------------------------------------
+
+        REFERENCES:
+
+----------------------------------------------------------------------------
+
+        CALLED BY:
+
+----------------------------------------------------------------------------
+
+        CALLS TO:
+
+----------------------------------------------------------------------------
+
+        INPUTS:
+
+----------------------------------------------------------------------------
+
+        OUTPUTS:
+
+--------------------------------------------------------------------------*/
+#include <math.h>
+#include "ls_types.h"
+#include "ls_constants.h"
+#include "ls_generic.h"
+#include "ls_cockpit.h"
+
+#define HEIGHT_AGL_WHEEL d_wheel_rwy_local_v[2]
+
+
+static void sub3( DATA v1[],  DATA v2[], DATA result[] )
+{
+    result[0] = v1[0] - v2[0];
+    result[1] = v1[1] - v2[1];
+    result[2] = v1[2] - v2[2];
+}
+
+static void add3( DATA v1[],  DATA v2[], DATA result[] )
+{
+    result[0] = v1[0] + v2[0];
+    result[1] = v1[1] + v2[1];
+    result[2] = v1[2] + v2[2];
+}
+
+static void cross3( DATA v1[],  DATA v2[], DATA result[] )
+{
+    result[0] = v1[1]*v2[2] - v1[2]*v2[1];
+    result[1] = v1[2]*v2[0] - v1[0]*v2[2];
+    result[2] = v1[0]*v2[1] - v1[1]*v2[0];
+}
+
+static void multtrans3x3by3( DATA m[][3], DATA v[], DATA result[] )
+{
+    result[0] = m[0][0]*v[0] + m[1][0]*v[1] + m[2][0]*v[2];
+    result[1] = m[0][1]*v[0] + m[1][1]*v[1] + m[2][1]*v[2];
+    result[2] = m[0][2]*v[0] + m[1][2]*v[1] + m[2][2]*v[2];
+}
+
+static void mult3x3by3( DATA m[][3], DATA v[], DATA result[] )
+{
+    result[0] = m[0][0]*v[0] + m[0][1]*v[1] + m[0][2]*v[2];
+    result[1] = m[1][0]*v[0] + m[1][1]*v[1] + m[1][2]*v[2];
+    result[2] = m[2][0]*v[0] + m[2][1]*v[1] + m[2][2]*v[2];
+}
+
+static void clear3( DATA v[] )
+{
+    v[0] = 0.; v[1] = 0.; v[2] = 0.;
+}
+
+void basic_gear()
+{
+char rcsid[] = "junk";
+#define NUM_WHEELS 4
+
+// char gear_strings[NUM_WHEELS][12]={"nose","right main", "left main", "tail skid"};
+  /*
+   * Aircraft specific initializations and data goes here
+   */
+   
+
+    static int num_wheels = NUM_WHEELS;             /* number of wheels  */
+    static DATA d_wheel_rp_body_v[NUM_WHEELS][3] =  /* X, Y, Z locations,full extension */
+    {
+        { .422,  0.,    .29 },             /*nose*/ /* in feet */
+        { 0.026, 0.006, .409 },        /*right main*/
+        { 0.026, -.006, .409 },        /*left main*/ 
+        { -1.32, 0, .17 }            /*tail skid */
+    };
+    // static DATA gear_travel[NUM_WHEELS] = /*in Z-axis*/
+           // { -0.5, 2.5, 2.5, 0};
+    static DATA spring_constant[NUM_WHEELS] =       /* springiness, lbs/ft */
+        { 2., .65, .65, 1. };
+    static DATA spring_damping[NUM_WHEELS] =        /* damping, lbs/ft/sec */
+        { 1.,  .3, .3, .5 };    
+    static DATA percent_brake[NUM_WHEELS] =         /* percent applied braking */
+        { 0.,  0.,  0., 0. };                       /* 0 = none, 1 = full */
+    static DATA caster_angle_rad[NUM_WHEELS] =      /* steerable tires - in */
+        { 0., 0., 0., 0};                                   /* radians, +CW */  
+  /*
+   * End of aircraft specific code
+   */
+    
+  /*
+   * Constants & coefficients for tyres on tarmac - ref [1]
+   */
+   
+    /* skid function looks like:
+     * 
+     *           mu  ^
+     *               |
+     *       max_mu  |       +          
+     *               |      /|          
+     *   sliding_mu  |     / +------    
+     *               |    /             
+     *               |   /              
+     *               +--+------------------------> 
+     *               |  |    |      sideward V
+     *               0 bkout skid
+     *                 V     V
+     */
+  
+  
+    static int it_rolls[NUM_WHEELS] = { 1,1,1,0};       
+        static DATA sliding_mu[NUM_WHEELS] = { 0.5, 0.5, 0.5, 0.3};     
+    static DATA rolling_mu[NUM_WHEELS] = { 0.01, 0.01, 0.01, 0.0};      
+    static DATA max_brake_mu[NUM_WHEELS] ={ 0.0, 0.6, 0.6, 0.0};        
+    static DATA max_mu       = 0.8;     
+    static DATA bkout_v      = 0.1;
+    static DATA skid_v       = 1.0;
+  /*
+   * Local data variables
+   */
+   
+    DATA d_wheel_cg_body_v[3];          /* wheel offset from cg,  X-Y-Z */
+    DATA d_wheel_cg_local_v[3];         /* wheel offset from cg,  N-E-D */
+    DATA d_wheel_rwy_local_v[3];        /* wheel offset from rwy, N-E-U */
+        DATA v_wheel_cg_local_v[3];    /*wheel velocity rel to cg N-E-D*/
+    // DATA v_wheel_body_v[3];          /* wheel velocity,        X-Y-Z */
+    DATA v_wheel_local_v[3];            /* wheel velocity,        N-E-D */
+    DATA f_wheel_local_v[3];            /* wheel reaction force,  N-E-D */
+    // DATA altitude_local_v[3];       /*altitude vector in local (N-E-D) i.e. (0,0,h)*/
+    // DATA altitude_body_v[3];        /*altitude vector in body (X,Y,Z)*/
+    DATA temp3a[3];
+    // DATA temp3b[3];
+    DATA tempF[3];
+    DATA tempM[3];      
+    DATA reaction_normal_force;         /* wheel normal (to rwy) force  */
+    DATA cos_wheel_hdg_angle, sin_wheel_hdg_angle;      /* temp storage */
+    DATA v_wheel_forward, v_wheel_sideward,  abs_v_wheel_sideward;
+    DATA forward_mu, sideward_mu;       /* friction coefficients        */
+    DATA beta_mu;                       /* breakout friction slope      */
+    DATA forward_wheel_force, sideward_wheel_force;
+
+    int i;                              /* per wheel loop counter */
+  
+  /*
+   * Execution starts here
+   */
+   
+    beta_mu = max_mu/(skid_v-bkout_v);
+    clear3( F_gear_v );         /* Initialize sum of forces...  */
+    clear3( M_gear_v );         /* ...and moments               */
+    
+  /*
+   * Put aircraft specific executable code here
+   */
+   
+    percent_brake[1] = Brake_pct[0];
+    percent_brake[2] = Brake_pct[1];
+    
+    caster_angle_rad[0] =
+        (0.01 + 0.04 * (1 - V_calibrated_kts / 130)) * Rudder_pedal;
+    
+    
+        for (i=0;i<num_wheels;i++)          /* Loop for each wheel */
+    {
+                /* printf("%s:\n",gear_strings[i]); */
+
+
+
+                /*========================================*/
+                /* Calculate wheel position w.r.t. runway */
+                /*========================================*/
+
+                
+                /* printf("\thgcg: %g, theta: %g,phi: %g\n",D_cg_above_rwy,Theta*RAD_TO_DEG,Phi*RAD_TO_DEG); */
+
+                
+                        /* First calculate wheel location w.r.t. cg in body (X-Y-Z) axes... */
+
+                sub3( d_wheel_rp_body_v[i], D_cg_rp_body_v, d_wheel_cg_body_v );
+
+                /* then converting to local (North-East-Down) axes... */
+
+                multtrans3x3by3( T_local_to_body_m,  d_wheel_cg_body_v, d_wheel_cg_local_v );
+                
+
+                /* Runway axes correction - third element is Altitude, not (-)Z... */
+
+                d_wheel_cg_local_v[2] = -d_wheel_cg_local_v[2]; /* since altitude = -Z */
+
+                /* Add wheel offset to cg location in local axes */
+
+                add3( d_wheel_cg_local_v, D_cg_rwy_local_v, d_wheel_rwy_local_v );
+
+                /* remove Runway axes correction so right hand rule applies */
+
+                d_wheel_cg_local_v[2] = -d_wheel_cg_local_v[2]; /* now Z positive down */
+
+                /*============================*/
+                /* Calculate wheel velocities */
+                /*============================*/
+
+                /* contribution due to angular rates */
+
+                cross3( Omega_body_v, d_wheel_cg_body_v, temp3a );
+
+                /* transform into local axes */
+
+                multtrans3x3by3( T_local_to_body_m, temp3a,v_wheel_cg_local_v );
+
+                /* plus contribution due to cg velocities */
+
+                add3( v_wheel_cg_local_v, V_local_rel_ground_v, v_wheel_local_v );
+
+                clear3(f_wheel_local_v);
+                reaction_normal_force=0;
+                if( HEIGHT_AGL_WHEEL < 0. ) 
+                        /*the wheel is underground -- which implies ground contact 
+                          so calculate reaction forces */ 
+                        {
+                        /*===========================================*/
+                        /* Calculate forces & moments for this wheel */
+                        /*===========================================*/
+
+                        /* Add any anticipation, or frame lead/prediction, here... */
+
+                                /* no lead used at present */
+
+                        /* Calculate sideward and forward velocities of the wheel 
+                                in the runway plane                                     */
+
+                        cos_wheel_hdg_angle = cos(caster_angle_rad[i] + Psi);
+                        sin_wheel_hdg_angle = sin(caster_angle_rad[i] + Psi);
+
+                        v_wheel_forward  = v_wheel_local_v[0]*cos_wheel_hdg_angle
+                                         + v_wheel_local_v[1]*sin_wheel_hdg_angle;
+                        v_wheel_sideward = v_wheel_local_v[1]*cos_wheel_hdg_angle
+                                         - v_wheel_local_v[0]*sin_wheel_hdg_angle;
+                        
+                    
+                /* Calculate normal load force (simple spring constant) */
+
+                reaction_normal_force = 0.;
+        
+                reaction_normal_force = spring_constant[i]*d_wheel_rwy_local_v[2]
+                                          - v_wheel_local_v[2]*spring_damping[i];
+                        /* printf("\treaction_normal_force: %g\n",reaction_normal_force); */
+
+                if (reaction_normal_force > 0.) reaction_normal_force = 0.;
+                        /* to prevent damping component from swamping spring component */
+
+
+                /* Calculate friction coefficients */
+
+                        if(it_rolls[i])
+                        {
+                           forward_mu = (max_brake_mu[i] - rolling_mu[i])*percent_brake[i] + rolling_mu[i];
+                           abs_v_wheel_sideward = sqrt(v_wheel_sideward*v_wheel_sideward);
+                           sideward_mu = sliding_mu[i];
+                           if (abs_v_wheel_sideward < skid_v) 
+                           sideward_mu = (abs_v_wheel_sideward - bkout_v)*beta_mu;
+                           if (abs_v_wheel_sideward < bkout_v) sideward_mu = 0.;
+                        }
+                        else
+                        {
+                                forward_mu=sliding_mu[i];
+                                sideward_mu=sliding_mu[i];
+                        }          
+
+                        /* Calculate foreward and sideward reaction forces */
+
+                        forward_wheel_force  =   forward_mu*reaction_normal_force;
+                        sideward_wheel_force =  sideward_mu*reaction_normal_force;
+                        if(v_wheel_forward < 0.) forward_wheel_force = -forward_wheel_force;
+                        if(v_wheel_sideward < 0.) sideward_wheel_force = -sideward_wheel_force;
+/*                      printf("\tFfwdgear: %g Fsidegear: %g\n",forward_wheel_force,sideward_wheel_force);
+ */
+                        /* Rotate into local (N-E-D) axes */
+
+                        f_wheel_local_v[0] = forward_wheel_force*cos_wheel_hdg_angle
+                                          - sideward_wheel_force*sin_wheel_hdg_angle;
+                        f_wheel_local_v[1] = forward_wheel_force*sin_wheel_hdg_angle
+                                          + sideward_wheel_force*cos_wheel_hdg_angle;
+                        f_wheel_local_v[2] = reaction_normal_force;       
+
+                         /* Convert reaction force from local (N-E-D) axes to body (X-Y-Z) */
+                        mult3x3by3( T_local_to_body_m, f_wheel_local_v, tempF );
+
+                        /* Calculate moments from force and offsets in body axes */
+
+                        cross3( d_wheel_cg_body_v, tempF, tempM );
+
+                        /* Sum forces and moments across all wheels */
+
+                        add3( tempF, F_gear_v, F_gear_v );
+                        add3( tempM, M_gear_v, M_gear_v );   
+
+
+                        }
+
+
+                
+                printf("\tN: %g,dZrwy: %g dZdotrwy: %g\n",reaction_normal_force,HEIGHT_AGL_WHEEL,v_wheel_cg_local_v[2]); 
+                printf("\tFxgear: %g Fygear: %g, Fzgear: %g\n",F_X_gear,F_Y_gear,F_Z_gear);
+                printf("\tMgear: %g, Lgear: %g, Ngear: %g\n\n",M_m_gear,M_l_gear,M_n_gear);
+                
+                
+    }
+}
diff --git a/src/FDM/LaRCsim/basic_init.c b/src/FDM/LaRCsim/basic_init.c
new file mode 100644 (file)
index 0000000..0bffda2
--- /dev/null
@@ -0,0 +1,79 @@
+/***************************************************************************
+
+        TITLE:  basic_init.c
+        
+----------------------------------------------------------------------------
+
+        FUNCTION:
+
+----------------------------------------------------------------------------
+
+        MODULE STATUS:  developmental
+
+----------------------------------------------------------------------------
+
+        GENEALOGY:
+
+----------------------------------------------------------------------------
+
+        DESIGNED BY:    EBJ
+        
+        CODED BY:       EBJ
+        
+        MAINTAINED BY:  EBJ
+
+----------------------------------------------------------------------------
+
+        MODIFICATION HISTORY:
+        
+----------------------------------------------------------------------------
+
+        REFERENCES:
+
+----------------------------------------------------------------------------
+
+        CALLED BY:
+
+----------------------------------------------------------------------------
+
+        CALLS TO:
+
+----------------------------------------------------------------------------
+
+        INPUTS:
+
+----------------------------------------------------------------------------
+
+        OUTPUTS:
+
+--------------------------------------------------------------------------*/
+#include "ls_types.h"
+#include "ls_generic.h"
+#include "ls_cockpit.h"
+#include "ls_constants.h"
+#include "basic_aero.h"
+
+void basic_init( void ) {
+
+  Throttle[3] = 0.2; 
+  
+  Dx_pilot = 0; Dy_pilot = 0; Dz_pilot = 0;
+/*    Mass=2300*INVG; */
+/*    I_xx=948; */
+/*    I_yy=1346; */
+/*    I_zz=1967; */
+/*    I_xz=0; */
+        Mass = 2./32.174;
+        I_xx   = 0.0454;
+        I_yy   = 0.0191;
+        I_zz   = 0.0721;
+        I_xz   = 0;
+
+
+  Flap_Position=Flap_handle;
+  Flaps_In_Transit=0;
+
+
+  
+  
+}
diff --git a/src/FDM/LaRCsim/basic_init.h b/src/FDM/LaRCsim/basic_init.h
new file mode 100644 (file)
index 0000000..259326f
--- /dev/null
@@ -0,0 +1,11 @@
+/* a quick navion_init.h */
+
+
+#ifndef _BASIC_INIT_H
+#define _BASIC_INIT_H
+
+
+void basic_init( void );
+
+
+#endif _BASIC_INIT_H