]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/steam.cxx
Update from JSBSim
[flightgear.git] / src / Cockpit / steam.cxx
index 3c4f93b62e38cbdafa6a86f6531d2147199dd421..6b4a2a86ab5c1ffa196cf5f77bd43956bd32a2c9 100644 (file)
 #  include <config.h>
 #endif
 
-#if defined( FG_HAVE_NATIVE_SGI_COMPILERS )
-#  include <iostream.h>
-#else
-#  include <iostream>
-#endif
+#include <simgear/compiler.h>
+
+#include STL_IOSTREAM
 
 #include <simgear/constants.h>
 #include <simgear/math/sg_types.hxx>
 #include <simgear/misc/props.hxx>
 #include <Aircraft/aircraft.hxx>
-#include <Main/bfi.hxx>
-#include <NetworkOLK/features.hxx>
 
-FG_USING_NAMESPACE(std);
+SG_USING_NAMESPACE(std);
 
 #include "radiostack.hxx"
 #include "steam.hxx"
@@ -49,9 +45,6 @@ static bool isTied = false;
 // Declare the functions that read the variables
 ////////////////////////////////////////////////////////////////////////
 
-// Anything that reads the BFI directly is not implemented at all!
-
-
 double FGSteam::the_STATIC_inhg = 29.92;
 double FGSteam::the_ALT_ft = 0.0;  // Indicated altitude
 double FGSteam::get_ALT_ft() { _CatchUp(); return the_ALT_ft; }
@@ -63,7 +56,7 @@ void FGSteam::set_ALT_datum_mb ( double datum_mb ) {
     the_ALT_datum_mb = datum_mb;
 }
 
-double FGSteam::get_ASI_kias() { return FGBFI::getAirspeed(); }
+double FGSteam::get_ASI_kias() { return fgGetDouble("/velocities/airspeed-kt"); }
 
 double FGSteam::the_VSI_case = 29.92;
 double FGSteam::the_VSI_fps = 0.0;
@@ -107,32 +100,36 @@ int FGSteam::_UpdatesPending = 1000000;  /* Forces filter to reset */
 
 void FGSteam::update ( int timesteps )
 {
-        if (!isTied) {
-         isTied = true;
-         fgTie("/steam/airspeed", FGSteam::get_ASI_kias);
-         fgTie("/steam/altitude", FGSteam::get_ALT_ft);
-         fgTie("/steam/altimeter-datum-mb",
-               FGSteam::get_ALT_datum_mb, FGSteam::set_ALT_datum_mb,
-               false);  /* don't modify the value */
-         fgTie("/steam/turn-rate", FGSteam::get_TC_std);
-         fgTie("/steam/slip-skid", FGSteam::get_TC_rad);
-         fgTie("/steam/vertical-speed", FGSteam::get_VSI_fps);
-         fgTie("/steam/gyro-compass", FGSteam::get_DG_deg);
-         fgTie("/steam/vor1", FGSteam::get_HackVOR1_deg);
-         fgTie("/steam/vor2", FGSteam::get_HackVOR2_deg);
-         fgTie("/steam/glidescope1", FGSteam::get_HackGS_deg);
-         fgTie("/steam/adf", FGSteam::get_HackADF_deg);
-         fgTie("/steam/gyro-compass-error",
-               FGSteam::get_DG_err,
-               FGSteam::set_DG_err);
-         fgTie("/steam/mag-compass", FGSteam::get_MH_deg);
-       }
-       _UpdatesPending += timesteps;
+    if (!isTied) {
+        isTied = true;
+        fgTie("/steam/airspeed-kt", FGSteam::get_ASI_kias);
+       fgSetArchivable("/steam/airspeed-kt");
+        fgTie("/steam/altitude-ft", FGSteam::get_ALT_ft);
+       fgSetArchivable("/steam/altitude-ft");
+        fgTie("/steam/altimeter-datum-mb",
+              FGSteam::get_ALT_datum_mb, FGSteam::set_ALT_datum_mb,
+              false);  /* don't modify the value */
+       fgSetArchivable("/steam/altimeter-datum-mb");
+        fgTie("/steam/turn-rate", FGSteam::get_TC_std);
+       fgSetArchivable("/steam/turn-rate");
+        fgTie("/steam/slip-skid", FGSteam::get_TC_rad);
+       fgSetArchivable("/steam/slip-skid");
+        fgTie("/steam/vertical-speed-fpm", FGSteam::get_VSI_fps);
+       fgSetArchivable("/steam/vertical-speed-fpm");
+        fgTie("/steam/gyro-compass-deg", FGSteam::get_DG_deg);
+       fgSetArchivable("/steam/gyro-compass-deg");
+        fgTie("/steam/adf-deg", FGSteam::get_HackADF_deg);
+       fgSetArchivable("/steam/adf-deg");
+        fgTie("/steam/gyro-compass-error-deg",
+              FGSteam::get_DG_err, FGSteam::set_DG_err,
+              false);  /* don't modify the value */
+       fgSetArchivable("/steam/gyro-compass-error-deg");
+        fgTie("/steam/mag-compass-deg", FGSteam::get_MH_deg);
+       fgSetArchivable("/steam/mag-compass-deg");
+    }
+    _UpdatesPending += timesteps;
 }
 
-#undef DF1
-#undef DF2
-
 
 /* tc should be (elapsed_time_between_updates / desired_smoothing_time) */
 void FGSteam::set_lowpass ( double *outthe, double inthe, double tc )
@@ -169,11 +166,10 @@ void FGSteam::set_lowpass ( double *outthe, double inthe, double tc )
 double pressInHgToAltFt(double p_inhg)
 {
     // Ref. Aviation Formulary, Ed Williams, www.best.com/~williams/avform.htm
-    const double P_0 = 29.92126;  // Std. MSL pressure, inHg. (=10135.25 mb)
+    const double P_0 = 29.92126;  // Std. MSL pressure, inHg. (=1013.25 mb)
     const double p_Tr = 0.2233609 * P_0;  // Pressure at tropopause, same units.
     const double h_Tr = 36089.24;  // Alt of tropopause, ft. (=11.0 km)
 
-    // return (P_0 - p_inhg) * 1000.0;  // ### crude approx. for low alt's
     if (p_inhg > p_Tr)  // 0.0 to 11.0 km
        return (1.0 - pow((p_inhg / P_0), 1.0 / 5.2558797)) / 6.8755856e-6;
     return h_Tr + log10(p_inhg / p_Tr) / -4.806346e-5;  // 11.0 to 20.0 km
@@ -181,6 +177,21 @@ double pressInHgToAltFt(double p_inhg)
 }
 
 
+// Convert altitude to air pressure by ICAO Standard Atmosphere
+double altFtToPressInHg(double alt_ft)
+{
+    // Ref. Aviation Formulary, Ed Williams, www.best.com/~williams/avform.htm
+    const double P_0 = 29.92126;  // Std. MSL pressure, inHg. (=1013.25 mb)
+    const double p_Tr = 0.2233609 * P_0;  // Pressure at tropopause, same units.
+    const double h_Tr = 36089.24;  // Alt of tropopause, ft. (=11.0 km)
+
+    if (alt_ft < h_Tr)  // 0.0 to 11.0 km
+       return P_0 * pow(1.0 - 6.8755856e-6 * alt_ft, 5.2558797);
+    return p_Tr * exp(-4.806346e-5 * (alt_ft - h_Tr));  // 11.0 to 20.0 km
+    // We could put more code for higher altitudes here.
+}
+
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Here the fun really begins
@@ -192,7 +203,7 @@ void FGSteam::_CatchUp()
   {    double dt = _UpdatesPending * 1.0 / 
            fgGetInt("/sim/model-hz"); // FIXME: inefficient
         double AccN, AccE, AccU;
-       int i /*,j*/;
+       /* int i, j; */
        double d, the_ENGINE_rpm;
 
 #if 0
@@ -237,7 +248,6 @@ void FGSteam::_CatchUp()
        More subtle flaw is having it not move or a travel limit
        occasionally due to some dirt in the tube or on the ball.
        */
-       // the_TC_rad = - ( FGBFI::getSideSlip () ); /* incorrect */
        d = - current_aircraft.fdm_state->get_A_Z_pilot();
        if ( d < 1 ) d = 1;
        set_lowpass ( & the_TC_rad,
@@ -253,9 +263,9 @@ void FGSteam::_CatchUp()
        */
        set_lowpass ( & the_TC_std,
                current_aircraft.fdm_state->get_Phi_dot ()
-                       * RAD_TO_DEG / 20.0 +
+                       * SGD_RADIANS_TO_DEGREES / 20.0 +
                current_aircraft.fdm_state->get_Psi_dot ()
-                       * RAD_TO_DEG / 3.0  , dt );
+                       * SGD_RADIANS_TO_DEGREES / 3.0  , dt );
 
        /**************************
        We want to know the pilot accelerations,
@@ -268,15 +278,17 @@ void FGSteam::_CatchUp()
        if ( fabs(the_TC_rad) > 0.2 )
        {       /* Massive sideslip jams it; it stops turning */
                the_MH_degps = 0.0;
-               the_MH_err   = FGBFI::getHeading () - the_MH_deg;
+               the_MH_err   = fgGetDouble("/orientation/heading-deg") - the_MH_deg;
        } else
        {       double MagDip, MagVar, CosDip;
                double FrcN, FrcE, FrcU, AccTot;
                double EdgN, EdgE, EdgU;
                double TrqN, TrqE, TrqU, Torque;
                /* Find a force vector towards exact magnetic north */
-               MagVar = FGBFI::getMagVar() / RAD_TO_DEG;
-               MagDip = FGBFI::getMagDip() / RAD_TO_DEG;
+               MagVar = fgGetDouble("/environment/magnetic-variation-deg") 
+                    / SGD_RADIANS_TO_DEGREES;
+               MagDip = fgGetDouble("/environment/magnetic-dip-deg")
+                    / SGD_RADIANS_TO_DEGREES;
                CosDip = cos ( MagDip );
                FrcN = CosDip * cos ( MagVar );
                FrcE = CosDip * sin ( MagVar );
@@ -287,8 +299,8 @@ void FGSteam::_CatchUp()
                if ( AccTot > 1.0 )  AccTot = sqrt ( AccTot );
                                else AccTot = 1.0;
                /* Force applies to north marking on compass card */
-               EdgN = cos ( the_MH_err / RAD_TO_DEG );
-               EdgE = sin ( the_MH_err / RAD_TO_DEG );
+               EdgN = cos ( the_MH_err / SGD_RADIANS_TO_DEGREES );
+               EdgE = sin ( the_MH_err / SGD_RADIANS_TO_DEGREES );
                EdgU = 0.0;
                /* Apply the force to the edge to get torques */
                TrqN = EdgE * FrcU - EdgU * FrcE;
@@ -306,7 +318,7 @@ void FGSteam::_CatchUp()
                }
                if ( the_MH_err >  180.0 ) the_MH_err -= 360.0; else
                if ( the_MH_err < -180.0 ) the_MH_err += 360.0;
-               the_MH_deg  = FGBFI::getHeading () - the_MH_err;
+               the_MH_deg  = fgGetDouble("/orientation/heading-deg") - the_MH_err;
        }
 
        /**************************
@@ -314,7 +326,7 @@ void FGSteam::_CatchUp()
        scaling capability for the vacuum pump later on.
        When we have a real engine model, we can ask it.
        */
-       the_ENGINE_rpm = controls.get_throttle(0) * 26.0;
+       the_ENGINE_rpm = globals->get_controls()->get_throttle(0) * 26.0;
 
        /**************************
        First, we need to know what the static line is reporting,
@@ -322,13 +334,8 @@ void FGSteam::_CatchUp()
        We filter the actual value by one second to
        account for the line impedance of the plumbing.
        */
-       double static_inhg = 29.92; 
-       i = (int) FGBFI::getAltitude();
-       while ( i > 9000 )
-       {       static_inhg *= 0.707;
-               i -= 9000;
-       }
-       static_inhg *= ( 1.0 - 0.293 * i / 9000.0 );
+       double static_inhg
+            = altFtToPressInHg(fgGetDouble("/position/altitude-ft"));
        set_lowpass ( & the_STATIC_inhg, static_inhg, dt ); 
 
        /*
@@ -388,10 +395,10 @@ void FGSteam::_CatchUp()
 > put in those insidious turning errors ... for now anyway.
 */
        if ( _UpdatesPending > 999999 )
-           the_DG_err = FGBFI::getMagVar();
+           the_DG_err = fgGetDouble("/environment/magnetic-variation-deg");
        the_DG_degps = 0.01; /* HACK! */
        if (dt<1.0) the_DG_err += dt * the_DG_degps;
-       the_DG_deg = FGBFI::getHeading () - the_DG_err;
+       the_DG_deg = fgGetDouble("/orientation/heading-deg") - the_DG_err;
 
        /**************************
        Finished updates, now clear the timer 
@@ -408,14 +415,17 @@ void FGSteam::_CatchUp()
 ////////////////////////////////////////////////////////////////////////
 
 
+#if 0
+
 double FGSteam::get_HackGS_deg () {
     if ( current_radiostack->get_nav1_inrange() && 
         current_radiostack->get_nav1_has_gs() )
     {
        double x = current_radiostack->get_nav1_gs_dist();
-       double y = (FGBFI::getAltitude() - current_radiostack->get_nav1_elev())
-           * FEET_TO_METER;
-       double angle = atan2( y, x ) * RAD_TO_DEG;
+       double y = (fgGetDouble("/position/altitude-ft")
+                    - current_radiostack->get_nav1_elev())
+           * SG_FEET_TO_METER;
+       double angle = atan2( y, x ) * SGD_RADIANS_TO_DEGREES;
        return (current_radiostack->get_nav1_target_gs() - angle) * 5.0;
     } else {
        return 0.0;
@@ -429,9 +439,9 @@ double FGSteam::get_HackVOR1_deg () {
     if ( current_radiostack->get_nav1_inrange() ) {
         r = current_radiostack->get_nav1_heading()
            - current_radiostack->get_nav1_radial();
-       cout << "Radial = " << current_radiostack->get_nav1_radial() 
-            << "  Bearing = " << current_radiostack->get_nav1_heading()
-            << endl;
+       // cout << "Radial = " << current_radiostack->get_nav1_radial() 
+       //      << "  Bearing = " << current_radiostack->get_nav1_heading()
+       //      << endl;
     
        if (r> 180.0) r-=360.0; else
            if (r<-180.0) r+=360.0;
@@ -466,6 +476,7 @@ double FGSteam::get_HackVOR2_deg () {
 
     return r;
 }
+#endif
 
 
 double FGSteam::get_HackOBS1_deg () {
@@ -479,18 +490,18 @@ double FGSteam::get_HackOBS2_deg () {
 
 
 double FGSteam::get_HackADF_deg () {
-    double r;
+    static double last_r = 0;
 
     if ( current_radiostack->get_adf_inrange() ) {
-       r = current_radiostack->get_adf_heading() - FGBFI::getHeading();
-
+       double r = current_radiostack->get_adf_heading()
+            - fgGetDouble("/orientation/heading-deg");
+       last_r = r;
        // cout << "Radial = " << current_radiostack->get_adf_heading() 
        //      << "  Heading = " << FGBFI::getHeading() << endl;
+       return r;
     } else {
-       r = 0.0;
+       return last_r;
     }
-
-    return r;
 }