]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Surface.cpp
YASim airborne start-up
[flightgear.git] / src / FDM / YASim / Surface.cpp
index 3ac62b524c105a17baf0317ad7695f3d513c578f..db977f58a943e217f2acbb7ea9d6ecf9354bf6d4 100644 (file)
@@ -25,6 +25,7 @@ Surface::Surface()
     _slatDrag = _spoilerDrag = _flapDrag = 1;
 
     _flapLift = 0;
+    _flapEffectiveness = 1;
     _slatAlpha = 0;
     _spoilerLift = 1;
     _inducedDrag = 1;
@@ -132,6 +133,17 @@ void Surface::setFlap(float pos)
     _flapPos = pos;
 }
 
+void Surface::setFlapEffectiveness(float effectiveness)
+{
+    _flapEffectiveness = effectiveness;
+}
+
+double Surface::getFlapEffectiveness()
+{
+    return _flapEffectiveness;
+}
+
+
 void Surface::setSlat(float pos)
 {
     _slatPos = pos;
@@ -158,6 +170,13 @@ void Surface::calcForce(float* v, float rho, float* out, float* torque)
        return;
     }
 
+    // special case this so the logic below doesn't produce a non-zero
+    // force; should probably have a "no force" flag instead...
+    if(_cx == 0. && _cy == 0. && _cz == 0.) {
+        for(int i=0; i<3; i++) out[i] = torque[i] = 0.;
+        return;
+    }
+
     Math::mul3(1/vel, v, out);
 
     // Convert to the surface's coordinates
@@ -202,7 +221,6 @@ void Surface::calcForce(float* v, float rho, float* out, float* torque)
     out[1] *= _cy;
 
     // Diddle the induced drag
-    float IDMUL = 0.5;
     Math::mul3(-1*_inducedDrag*out[2]*lwind[2], lwind, lwind);
     Math::add3(lwind, out, out);
 
@@ -219,6 +237,31 @@ void Surface::calcForce(float* v, float rho, float* out, float* torque)
     Math::mul3(scale, torque, torque);
 }
 
+#if 0
+void Surface::test()
+{
+    static const float DEG2RAD = 0.0174532925199;
+    float v[3], force[3], torque[3];
+    float rho = Atmosphere::getStdDensity(0);
+    float spd = 30;
+
+    setFlap(0);
+    setSlat(0);
+    setSpoiler(0);
+
+    for(float angle = -90; angle<90; angle += 0.01) {
+        float rad = angle * DEG2RAD;
+        v[0] = spd * -Math::cos(rad);
+        v[1] = 0;
+        v[2] = spd * Math::sin(rad);
+        calcForce(v, rho, force, torque);
+        float lift = force[2] * Math::cos(rad) + force[0] * Math::sin(rad);
+        //__builtin_printf("%f %f\n", angle, lift);
+        __builtin_printf("%f %f\n", angle, torque[2]);
+    }
+}
+#endif
+
 // Returns a multiplier for the "plain" force equations that
 // approximates an airfoil's lift/stall curve.
 float Surface::stallFunc(float* v)
@@ -230,7 +273,7 @@ float Surface::stallFunc(float* v)
 
     // Wacky use of indexing, see setStall*() methods.
     int fwdBak = v[0] > 0; // set if this is "backward motion"
-    int posNeg = v[2] < 0; // set if the lift is toward -z
+    int posNeg = v[2] < 0; // set if the airflow is toward -z
     int i = (fwdBak<<1) | posNeg;
 
     float stallAlpha = _stalls[i];
@@ -263,17 +306,20 @@ float Surface::stallFunc(float* v)
 // stall alpha
 float Surface::flapLift(float alpha)
 {
-    float flapLift = _cz * _flapPos * (_flapLift-1);
+    float flapLift = _cz * _flapPos * (_flapLift-1) * _flapEffectiveness;
+
+    if(_stalls[0] == 0)
+        return 0;
 
     if(alpha < 0) alpha = -alpha;
     if(alpha < _stalls[0])
         return flapLift;
     else if(alpha > _stalls[0] + _widths[0])
-        return 1;
+        return 0;
 
     float frac = (alpha - _stalls[0]) / _widths[0];
     frac = frac*frac*(3-2*frac);
-    return flapLift * (1-frac) + frac;
+    return flapLift * (1-frac);
 }
 
 float Surface::controlDrag(float lift, float drag)