]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/LaRCsim/LaRCsim.cxx
I forgot a linker dependency. It really si time to figure out why these are all needed.
[flightgear.git] / src / FDM / LaRCsim / LaRCsim.cxx
index 32da763b5e16f045c79eadad7e6cb78b711d3bac..a8b9f305ec64dcead6296973d1dfefea6dbcbcf7 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,20 +270,23 @@ 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;
 
-    Brake_pct[0] = globals->get_controls()->get_brake( 1 );
-    Brake_pct[1] = globals->get_controls()->get_brake( 0 );
+    Brake_pct[0] = globals->get_controls()->get_brake_right();
+    Brake_pct[1] = globals->get_controls()->get_brake_left();
 
     // Inform LaRCsim of the local terrain altitude
     // Runway_altitude = get_Runway_altitude();
-    Runway_altitude = getACModel()->get3DModel()->getSGLocation()->get_cur_elev_m() * SG_METER_TO_FEET;
+    Runway_altitude = fgGetDouble("/position/ground-elev-m") * SG_METER_TO_FEET;
     // Weather
     /* V_north_airmass = get_V_north_airmass();
        V_east_airmass =  get_V_east_airmass();
@@ -222,26 +312,29 @@ void FGLaRCsim::update( double dt ) {
     // if flying uiuc, set some properties and over-ride some previous ones
     if ( !strcmp(aero->getStringValue(), "uiuc")) {
 
-      // surface positions
-      fgSetDouble("/surface-positions/rudder-pos-norm",             fgGetDouble("/controls/flight/rudder"));
-      fgSetDouble("/surface-positions/elevator-pos-norm",           fgGetDouble("/controls/flight/elevator")); // FIXME: ignoring trim
-      fgSetDouble("/surface-positions/right-aileron-pos-norm", -1 * fgGetDouble("/controls/flight/aileron")); // FIXME: ignoring trim
-      fgSetDouble("/surface-positions/left-aileron-pos-norm",       fgGetDouble("/controls/flight/aileron")); // FIXME: ignoring trim
+      // surface positions and other general properties
+      fgSetDouble("/surface-positions/flight/rudder-pos-norm",             fgGetDouble("/controls/flight/rudder"));
+      fgSetDouble("/surface-positions/flight/elevator-pos-norm",           fgGetDouble("/controls/flight/elevator")); // FIXME: ignoring trim
+      fgSetDouble("/surface-positions/flight/right-aileron-pos-norm", -1 * fgGetDouble("/controls/flight/aileron")); // FIXME: ignoring trim
+      fgSetDouble("/surface-positions/flight/left-aileron-pos-norm",       fgGetDouble("/controls/flight/aileron")); // FIXME: ignoring trim
+
+      // used by Instruments/accel.xml
+      fgSetDouble("/accelerations/pilot-g",   -N_Z_cg);
 
       Flap_handle = flap_max * globals->get_controls()->get_flaps();
 
       // flaps with transition occuring in uiuc_aerodeflections.cpp
       if (use_flaps) {
-      fgSetDouble("/surface-positions/flight/flap-pos-norm",               flap_pos_pct);
+      fgSetDouble("/surface-positions/flight/flap-pos-norm",               flap_pos_norm);
       }
 
       // spoilers with transition occurring in uiuc_aerodeflections.cpp
       if(use_spoilers) {
-       Spoiler_handle = spoiler_max * fgGetDouble("/controls/spoilers");
+       Spoiler_handle = spoiler_max * fgGetDouble("/controls/flight/spoilers");
       }
       // gear with transition occurring here in LaRCsim.cxx
       if (use_gear) {
-       if(fgGetBool("/controls/gear-down")) {
+       if(fgGetBool("/controls/gear/gear-down")) {
          Gear_handle = 1.0;
        }
        else {
@@ -281,30 +374,28 @@ void FGLaRCsim::update( double dt ) {
       }
       else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-jet")) {
        // uiuc jet aircraft, e.g. a4d
+       // used for setting the sound
        fgSetDouble("/engines/engine/n1", (75 + (globals->get_controls()->get_throttle( 0 ) * 100.0 )/400));
        fgSetDouble("/engines/engine/prop-thrust", (4000 + F_X_engine/2));
+       // used for setting the instruments
+       fgSetDouble("/engines/engine[0]/n1", (50 + (globals->get_controls()->get_throttle( 0 ) * 50)));
       }
       else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-sailplane")) {
        // uiuc sailplane, e.g. asw20
        fgSetDouble("/engines/engine/cranking", 0);
-       // set the wind speed for use in setting wind sound level
-       fgSetDouble("/velocities/V_rel_wind_kts", (V_rel_wind * 1.274));
       }
       else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-hangglider")) {
-       // uiuc sailplane, e.g. asw20
+       // uiuc hang glider, e.g. airwave
        fgSetDouble("/engines/engine/cranking", 0);
       }
       else if ( !strcmp(uiuc_type->getStringValue(), "uiuc-ornithopter")) {
-       // mechanical flapping wings
-       // flapping wings (using seahawk for now)
+       // flapping wings
        fgSetDouble("/canopy/position-norm", 0);
        fgSetDouble("/wing-phase/position-norm", sin(flapper_phi - 3 * LS_PI / 2));
-       //      fgSetDouble("/wing-phase/position-norm", fgGetDouble("/controls/rudder"));
        fgSetDouble("/wing-phase/position-deg", flapper_phi*RAD_TO_DEG);
        fgSetDouble("/wing-phase/position-one", 1);
        fgSetDouble("/thorax/volume", 0);
        fgSetDouble("/thorax/rpm",    0);
-       //      fgSetDouble("/wing-phase/position-norm", ((1+cos(flapper_phi - LS_PI/2))/2 -.36 ));
        //      fgSetDouble("/thorax/volume", ((1+sin(2*(flapper_phi+LS_PI)))/2));
        //      fgSetDouble("/thorax/rpm",    ((1+sin(2*(flapper_phi+LS_PI)))/2));
       }
@@ -314,14 +405,14 @@ void FGLaRCsim::update( double dt ) {
     // add Gamma_horiz_deg to properties, mss 021213
     if (use_gamma_horiz_on_speed) {
       if (V_rel_wind > gamma_horiz_on_speed) {
-       fgSetDouble("/orientation/Gamma_horiz_deg", (Gamma_horiz_rad * RAD_TO_DEG));
+       fgSetDouble("/orientation/gamma-horiz-deg", (Gamma_horiz_rad * RAD_TO_DEG));
       }
       else {
-       fgSetDouble("/orientation/Gamma_horiz_deg",  fgGetDouble("/orientation/heading-deg"));
+       fgSetDouble("/orientation/gamma-horiz-deg",  fgGetDouble("/orientation/heading-deg"));
       }
     }
     else {
-      fgSetDouble("/orientation/Gamma_horiz_deg",  fgGetDouble("/orientation/heading-deg"));
+      fgSetDouble("/orientation/gamma-horiz-deg",  fgGetDouble("/orientation/heading-deg"));
     }
     ls_update(multiloop);
 
@@ -603,10 +694,10 @@ bool FGLaRCsim::copy_from_LaRCsim() {
     // set_Gravity( Gravity );
     // set_Centrifugal_relief( Centrifugal_relief );
 
-    _set_Alpha( Alpha );
-    _set_Beta( Beta );
-    // set_Alpha_dot( Alpha_dot );
-    // set_Beta_dot( Beta_dot );
+    _set_Alpha( Std_Alpha );
+    _set_Beta( Std_Beta );
+    // set_Alpha_dot( Std_Alpha_dot );
+    // set_Beta_dot( Std_Beta_dot );
 
     // set_Cos_alpha( Cos_alpha );
     // set_Sin_alpha( Sin_alpha );