]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/YASim.cxx
Interpolate the twist linearly over the wing.
[flightgear.git] / src / FDM / YASim / YASim.cxx
index 5c93abad359182e2da45bba6e42440139a3b4d53..f8c109abd27be3cf2cb89ac5cb8286e80abfb862 100644 (file)
@@ -3,7 +3,9 @@
 #include <simgear/xml/easyxml.hxx>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
-#include <Scenery/scenery.hxx>
+#include <Model/acmodel.hxx>
+#include <Model/model.hxx>
+#include <Main/location.hxx>
 
 #include "FGFDM.hpp"
 #include "Atmosphere.hpp"
@@ -28,6 +30,8 @@ static const float MPS2KTS = 3600.0/1852.0;
 static const float CM2GALS = 264.172037284; // gallons/cubic meter
 static const float KG2LBS = 2.20462262185;
 static const float W2HP = 1.3416e-3;
+static const float INHG2PA = 3386.389;
+static const float SLUG2KG = 14.59390;
 
 void YASim::printDEBUG()
 {
@@ -57,7 +61,7 @@ void YASim::printDEBUG()
 
 YASim::YASim(double dt)
 {
-    set_delta_t(dt);
+//     set_delta_t(dt);
     _fdm = new FGFDM();
 
     _dt = dt;
@@ -74,16 +78,18 @@ void YASim::report()
     float drag = 1000 * a->getDragCoefficient();
 
     SG_LOG(SG_FLIGHT,SG_INFO,"YASim solution results:");
-    SG_LOG(SG_FLIGHT,SG_INFO,"      Iterations: "<<a->getSolutionIterations());
-    SG_LOG(SG_FLIGHT,SG_INFO,"Drag Coefficient: "<< drag);
-    SG_LOG(SG_FLIGHT,SG_INFO,"      Lift Ratio: "<<a->getLiftRatio());
-    SG_LOG(SG_FLIGHT,SG_INFO,"      Cruise AoA: "<< aoa);
-    SG_LOG(SG_FLIGHT,SG_INFO,"  Tail Incidence: "<< tail);
+    SG_LOG(SG_FLIGHT,SG_INFO,"       Iterations: "<<a->getSolutionIterations());
+    SG_LOG(SG_FLIGHT,SG_INFO," Drag Coefficient: "<< drag);
+    SG_LOG(SG_FLIGHT,SG_INFO,"       Lift Ratio: "<<a->getLiftRatio());
+    SG_LOG(SG_FLIGHT,SG_INFO,"       Cruise AoA: "<< aoa);
+    SG_LOG(SG_FLIGHT,SG_INFO,"   Tail Incidence: "<< tail);
+    SG_LOG(SG_FLIGHT,SG_INFO,"Approach Elevator: "<<a->getApproachElevator());
+    
 
     float cg[3];
     char buf[256];
     a->getModel()->getBody()->getCG(cg);
-    sprintf(buf, "            CG: %.1f, %.1f, %.1f", cg[0], cg[1], cg[2]);
+    sprintf(buf, "            CG: %.3f, %.3f, %.3f", cg[0], cg[1], cg[2]);
     SG_LOG(SG_FLIGHT, SG_INFO, buf);
 
     if(a->getFailureMsg()) {
@@ -160,8 +166,7 @@ void YASim::init()
 
     // Are we at ground level?  If so, lift the plane up so the gear
     // clear the ground.
-    double runway_altitude =
-      fgGetDouble("/environment/ground-elevation-m") * SG_METER_TO_FEET;
+    double runway_altitude = get_Runway_altitude();
     fgSetBool("/controls/gear-down", false);
     if(get_Altitude() - runway_altitude < 50) {
        float minGearZ = 1e18;
@@ -194,8 +199,13 @@ void YASim::init()
     set_inited(true);
 }
 
-void YASim::update(int iterations)
+void YASim::update(double dt)
 {
+    if (is_suspended())
+      return;
+
+    int iterations = _calc_multiloop(dt);
+
     // If we're crashed, then we don't care
     if(_fdm->getAirplane()->getModel()->isCrashed())
       return;
@@ -226,19 +236,14 @@ void YASim::copyToYASim(bool copyState)
     wind[1] = get_V_east_airmass() * FT2M * -1.0;
     wind[2] = get_V_down_airmass() * FT2M * -1.0;
 
-    // The ground elevation doesn't come from FGInterface; query it
-    // from the scenery and set it for others to find.
-    double ground = scenery.get_cur_elev();
-    _set_Runway_altitude(ground * FT2M);
+    // Get ground elevation from the FGinterface's FGlocation data
+    double ground = getACModel()->get3DModel()->getFGLocation()->get_cur_elev_m();
     // cout << "YASIM: ground = " << ground << endl;
 
-    // You'd this this would work, but it doesn't.  These values are
-    // always zero.  Use a "standard" pressure intstead.
-    //
-    // float pressure = get_Static_pressure();
-    // float temp = get_Static_temperature();
-    float pressure = Atmosphere::getStdPressure(alt);
-    float temp = Atmosphere::getStdTemperature(alt);
+    float pressure = fgGetFloat("/environment/pressure-inhg") * INHG2PA;
+    float temp = fgGetFloat("/environment/temperature-degc") + 273.15;
+    float dens = fgGetFloat("/environment/density-slugft3") 
+        * SLUG2KG * M2FT*M2FT*M2FT;
 
     // Convert and set:
     Model* model = _fdm->getAirplane()->getModel();
@@ -275,7 +280,7 @@ void YASim::copyToYASim(bool copyState)
     model->setGroundPlane(gplane, rad);
 
     // air
-    model->setAir(pressure, temp);
+    model->setAir(pressure, temp, dens);
 }
 
 // All the settables:
@@ -367,13 +372,11 @@ void YASim::copyFromYASim()
     _set_Velocities_Wind_Body(v[0]*M2FT, -v[1]*M2FT, -v[2]*M2FT);
     _set_V_rel_wind(Math::mag3(v)*M2FT); // units?
 
-
-    // These don't work, use a dummy based on altitude
-    // float P = get_Static_pressure();
-    // float T = get_Static_temperature();
-    float P = Atmosphere::getStdPressure(alt);
-    float T = Atmosphere::getStdTemperature(alt);
-    _set_V_equiv_kts(Atmosphere::calcVEAS(v[0], P, T)*MPS2KTS);
+    float P = fgGetDouble("/environment/pressure-inhg") * INHG2PA;
+    float T = fgGetDouble("/environment/temperature-degC") + 273.15;
+    float D = fgGetFloat("/environment/density-slugft3")
+        *SLUG2KG * M2FT*M2FT*M2FT;
+    _set_V_equiv_kts(Atmosphere::calcVEAS(v[0], P, T, D)*MPS2KTS);
     _set_V_calibrated_kts(Atmosphere::calcVCAS(v[0], P, T)*MPS2KTS);
     _set_Mach_number(Atmosphere::calcMach(v[0], T));
 
@@ -386,7 +389,12 @@ void YASim::copyFromYASim()
     _set_Accels_CG_Body(M2FT*v[0], -M2FT*v[1], -M2FT*v[2]);
 
     _fdm->getAirplane()->getPilotAccel(v);
-    _set_Accels_Pilot_Body(M2FT*v[0], M2FT*v[1], -M2FT*v[2]);
+    _set_Accels_Pilot_Body(-M2FT*v[0], M2FT*v[1], M2FT*v[2]);
+
+    // There is no property for pilot G's, but I need it for a panel
+    // instrument.  Hack this in here, and REMOVE IT WHEN IT FINDS A
+    // REAL HOME!
+    fgSetFloat("/accelerations/pilot-g", -v[2]/9.8);
 
     // The one appears (!) to want inverted pilot acceleration
     // numbers, in G's...
@@ -430,10 +438,6 @@ void YASim::copyFromYASim()
        node->setBoolValue("running", t->isRunning());
        node->setBoolValue("cranking", t->isCranking());
 
-        // Note: assumes all tanks have the same fuel density!
-       node->setDoubleValue("fuel-flow-gph", CM2GALS * t->getFuelFlow()
-                            / airplane->getFuelDensity(0));
-
         float tmp[3];
         t->getThrust(tmp);
        node->setDoubleValue("prop-thrust", Math::mag3(tmp) * KG2LBS / 9.8);