]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/YASim.cxx
Add support for a turbo prop condition lever.
[flightgear.git] / src / FDM / YASim / YASim.cxx
index 98bf6e78f3d2c6cd05e927fa068a763851517a0c..9f7594b2e7c3b2cb34af00b70ad975157f16b6c1 100644 (file)
@@ -1,12 +1,12 @@
+
 #include <simgear/debug/logstream.hxx>
+#include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/sg_path.hxx>
-#include <simgear/scene/model/location.hxx>
 #include <simgear/scene/model/placement.hxx>
 #include <simgear/xml/easyxml.hxx>
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
-#include <Model/acmodel.hxx>
 
 #include "FGFDM.hpp"
 #include "Atmosphere.hpp"
@@ -36,32 +36,6 @@ static const float W2HP = 1.3416e-3;
 static const float INHG2PA = 3386.389;
 static const float SLUG2KG = 14.59390;
 
-void YASim::printDEBUG()
-{
-    static int debugCount = 0;
-    
-    debugCount++;
-    if(debugCount >= 3) {
-       debugCount = 0;
-
-//     printf("N1 %5.1f N2 %5.1f FF %7.1f EPR %4.2f EGT %6.1f\n",
-//            fgGetFloat("/engines/engine[0]/n1"),
-//            fgGetFloat("/engines/engine[0]/n2"),
-//            fgGetFloat("/engines/engine[0]/fuel-flow-gph"),
-//            fgGetFloat("/engines/engine[0]/epr"),
-//            fgGetFloat("/engines/engine[0]/egt"));
-
-//     printf("gear: %f\n", fgGetFloat("/controls/gear/gear-down"));
-
-//     printf("alpha %5.1f beta %5.1f\n", get_Alpha()*57.3, get_Beta()*57.3);
-
-//     printf("pilot: %f %f %f\n",
-//            fgGetDouble("/sim/view/pilot/x-offset-m"),
-//            fgGetDouble("/sim/view/pilot/y-offset-m"),
-//            fgGetDouble("/sim/view/pilot/z-offset-m"));
-    }
-}
-
 YASim::YASim(double dt)
 {
 //     set_delta_t(dt);
@@ -168,17 +142,6 @@ void YASim::init()
        node->setDoubleValue("yoffset-in", pos[1]);
        node->setDoubleValue("zoffset-in", pos[2]);
     }
-//     for(i=0; i<m->numThrusters(); i++) {
-//     // Sanify the initial input conditions
-//     char buf[64];
-//     sprintf(buf, "/controls/engines/engine[%d]/throttle", i);        fgSetFloat(buf, 0);
-//     sprintf(buf, "/controls/engines/engine[%d]/mixture", i);         fgSetFloat(buf, 1);
-//     sprintf(buf, "/controls/engines/engine[%d]/propeller-pitch", i); fgSetFloat(buf, 1);
-//     sprintf(buf, "/controls/engines/engine[%d]/augmentation", i);     fgSetFloat(buf, 0);
-//     }
-
-//     fgSetFloat("/controls/flight/slats", 0);
-//     fgSetFloat("/controls/flight/spoilers", 0);
 
     // Are we at ground level?  If so, lift the plane up so the gear
     // clear the ground.
@@ -197,13 +160,6 @@ void YASim::init()
        fgSetBool("/controls/gear/gear-down", true);
     }
 
-    // The pilot's eyepoint
-    float pilot[3];
-    a->getPilotPos(pilot);
-//     fgSetFloat("/sim/view/pilot/x-offset-m", -pilot[0]);
-//     fgSetFloat("/sim/view/pilot/y-offset-m", -pilot[1]);
-//     fgSetFloat("/sim/view/pilot/z-offset-m", pilot[2]);
-
     // Blank the state, and copy in ours
     State s;
     m->setState(&s);
@@ -218,21 +174,22 @@ void YASim::init()
 void YASim::update(double dt)
 {
     if (is_suspended())
-      return;
+        return;
 
     int iterations = _calc_multiloop(dt);
 
     // If we're crashed, then we don't care
-    if(_fdm->getAirplane()->getModel()->isCrashed())
-      return;
+    if(_fdm->getAirplane()->getModel()->isCrashed()) {
+        if(!fgGetBool("/sim/crashed"))
+            fgSetBool("/sim/crashed", true);
+        return;
+    }
 
     int i;
     for(i=0; i<iterations; i++) {
-           copyToYASim(false);
-           _fdm->iterate(_dt);
-           copyFromYASim();
-
-           printDEBUG();
+        copyToYASim(false);
+        _fdm->iterate(_dt);
+        copyFromYASim();
     }
 }
 
@@ -252,8 +209,8 @@ void YASim::copyToYASim(bool copyState)
     wind[1] = get_V_east_airmass() * FT2M * -1.0;
     wind[2] = get_V_down_airmass() * FT2M * -1.0;
 
-    // Get ground elevation from the FGinterface's FGlocation data
-    double ground = getACModel()->get3DModel()->getSGLocation()->get_cur_elev_m();
+    // Get ground elevation
+    double ground = fgGetDouble("/position/ground-elev-m");
     // cout << "YASIM: ground = " << ground << endl;
 
     float pressure = fgGetFloat("/environment/pressure-inhg") * INHG2PA;
@@ -268,7 +225,7 @@ void YASim::copyToYASim(bool copyState)
     Glue::xyz2nedMat(lat, lon, xyz2ned);
 
     // position
-    Glue::geod2xyz(lat, lon, alt, s.pos);
+    sgGeodToCart(lat, lon, alt, s.pos);
 
     // orientation
     Glue::euler2orient(roll, pitch, hdg, s.orient);
@@ -326,8 +283,8 @@ void YASim::copyToYASim(bool copyState)
     // us, find the (geodetic) up vector normal to the ground, then
     // use that to find the final (radius) term of the plane equation.
     double xyz[3], gplane[3]; float up[3];
-    Glue::geod2xyz(lat, lon, ground, xyz);
-    Glue::geodUp(xyz, up); // FIXME, needless reverse computation...
+    sgGeodToCart(lat, lon, ground, xyz);
+    Glue::geodUp(lat, lon, up); // FIXME, needless reverse computation...
     int i;
     for(i=0; i<3; i++) gplane[i] = up[i];
     double rad = gplane[0]*xyz[0] + gplane[1]*xyz[1] + gplane[2]*xyz[2];
@@ -390,7 +347,7 @@ void YASim::copyFromYASim()
 
     // position
     double lat, lon, alt;
-    Glue::xyz2geod(s->pos, &lat, &lon, &alt);
+    sgCartToGeod(s->pos, &lat, &lon, &alt);
     _set_Geodetic_Position(lat, lon, alt*M2FT);
 
     // UNUSED
@@ -486,28 +443,4 @@ void YASim::copyFromYASim()
        node->setBoolValue("wow", g->getCompressFraction() != 0);
        node->setFloatValue("compression-norm", g->getCompressFraction());
     }
-
-    for(i=0; i<model->numThrusters(); i++) {
-        SGPropertyNode * node = fgGetNode("engines/engine", i, true);
-        Thruster* t = model->getThruster(i);
-
-       node->setBoolValue("running", t->isRunning());
-       node->setBoolValue("cranking", t->isCranking());
-
-        float tmp[3];
-        t->getThrust(tmp);
-       node->setDoubleValue("prop-thrust", Math::mag3(tmp) * KG2LBS / 9.8);
-
-        PropEngine* pe = t->getPropEngine();
-        if(pe) {
-           node->setDoubleValue("rpm", pe->getOmega() * RAD2RPM);
-
-            pe->getTorque(tmp);
-            float power = Math::mag3(tmp) * pe->getOmega();
-            float maxPower = pe->getPistonEngine()->getMaxPower();
-
-           node->setDoubleValue("max-hp", maxPower * W2HP);
-           node->setDoubleValue("power-pct", 100 * power/maxPower);
-        }
-    }
 }