From d322ded552b910c085014aae3b495044b1799af2 Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Sun, 12 Feb 2017 15:26:03 +0100 Subject: [PATCH] YASim bugfix: ground effect did not calculate wingspan correctly; Variable name clarification; Add Wing::getWingArea, separate Wing::getWingSpan and Wing::getBase. --- src/FDM/YASim/Airplane.cpp | 22 ++++++++++++++++------ src/FDM/YASim/Model.cpp | 29 ++++++++++++++++------------- src/FDM/YASim/Model.hpp | 4 ++-- src/FDM/YASim/Wing.cpp | 38 +++++++------------------------------- src/FDM/YASim/Wing.hpp | 25 +++++++++++++++++-------- 5 files changed, 58 insertions(+), 60 deletions(-) diff --git a/src/FDM/YASim/Airplane.cpp b/src/FDM/YASim/Airplane.cpp index 6fc987002..b4f100a90 100644 --- a/src/FDM/YASim/Airplane.cpp +++ b/src/FDM/YASim/Airplane.cpp @@ -471,25 +471,33 @@ void Airplane::addContactPoint(float* pos) float Airplane::compileWing(Wing* w) { + // Make sure it's initialized. The surfaces will pop out with + // total drag coefficients equal to their areas, which is what we + // want. + w->compile(); + // The tip of the wing is a contact point float tip[3]; + // need compile() before getTip()! w->getTip(tip); addContactPoint(tip); if(w->isMirrored()) { tip[1] *= -1; addContactPoint(tip); + tip[1] *= -1; //undo mirror } if (_wingsN != 0) { _wingsN->getNode("tip-x", true)->setFloatValue(tip[0]); _wingsN->getNode("tip-y", true)->setFloatValue(tip[1]); _wingsN->getNode("tip-z", true)->setFloatValue(tip[2]); + w->getBase(tip); + _wingsN->getNode("base-x", true)->setFloatValue(tip[0]); + _wingsN->getNode("base-y", true)->setFloatValue(tip[1]); + _wingsN->getNode("base-z", true)->setFloatValue(tip[2]); + _wingsN->getNode("wingspan", true)->setFloatValue(w->getWingSpan()); + _wingsN->getNode("wingarea", true)->setFloatValue(w->getWingArea()); } - // Make sure it's initialized. The surfaces will pop out with - // total drag coefficients equal to their areas, which is what we - // want. - w->compile(); - float wgt = 0; float dragSum = 0; for(int i=0; inumSurfaces(); i++) { @@ -764,7 +772,9 @@ void Airplane::compile() if(_wing) { float gepos[3]; float gespan = 0; - gespan = _wing->getGroundEffect(gepos); + gespan = _wing->getWingSpan(); + _wing->getBase(gepos); + // where does the hard coded factor 0.15 come from? _model.setGroundEffect(gepos, gespan, 0.15f); } diff --git a/src/FDM/YASim/Model.cpp b/src/FDM/YASim/Model.cpp index 25b28a1e2..74418ab94 100644 --- a/src/FDM/YASim/Model.cpp +++ b/src/FDM/YASim/Model.cpp @@ -66,9 +66,9 @@ Model::Model() _hook = 0; _launchbar = 0; - _groundEffectSpan = 0; + _wingSpan = 0; _groundEffect = 0; - for(i=0; i<3; i++) _wingCenter[i] = 0; + for(i=0; i<3; i++) _geRefPoint[i] = 0; _global_ground[0] = 0; _global_ground[1] = 0; _global_ground[2] = 1; _global_ground[3] = -100000; @@ -289,8 +289,8 @@ Ground* Model::getGroundCallback(void) void Model::setGroundEffect(float* pos, float span, float mul) { - Math::set3(pos, _wingCenter); - _groundEffectSpan = span; + Math::set3(pos, _geRefPoint); + _wingSpan = span; _groundEffect = mul; } @@ -470,16 +470,19 @@ void Model::calcForces(State* s) // Account for ground effect by multiplying the vertical force // component by an amount linear with the fraction of the wingspan // above the ground. - if ((_groundEffectSpan != 0) && (_groundEffect != 0 )) + if ((_wingSpan != 0) && (_groundEffect != 0 )) { - float dist = ground[3] - Math::dot3(ground, _wingCenter); - if(dist > 0 && dist < _groundEffectSpan) { - float fz = Math::dot3(faero, ground); - fz *= (_groundEffectSpan - dist) / _groundEffectSpan; - fz *= _groundEffect; - Math::mul3(fz, ground, faero); - _body.addForce(faero); - } + // distance between ground and wing ref. point + float dist = ground[3] - Math::dot3(ground, _geRefPoint); + float fz = 0; + float geForce[3]; + if(dist > 0 && dist < _wingSpan) { + fz = Math::dot3(faero, ground); + fz *= (_wingSpan - dist) / _wingSpan; + fz *= _groundEffect; + Math::mul3(fz, ground, geForce); + _body.addForce(geForce); + } } // Convert the velocity and rotation vectors to local coordinates diff --git a/src/FDM/YASim/Model.hpp b/src/FDM/YASim/Model.hpp index 7c31b8ac8..8f4d0bad8 100644 --- a/src/FDM/YASim/Model.hpp +++ b/src/FDM/YASim/Model.hpp @@ -96,9 +96,9 @@ private: Launchbar* _launchbar; Vector _hitches; - float _groundEffectSpan; + float _wingSpan; float _groundEffect; - float _wingCenter[3]; + float _geRefPoint[3]; Ground* _ground_cb; double _global_ground[4]; diff --git a/src/FDM/YASim/Wing.cpp b/src/FDM/YASim/Wing.cpp index 34c056680..48f41798c 100644 --- a/src/FDM/YASim/Wing.cpp +++ b/src/FDM/YASim/Wing.cpp @@ -1,4 +1,3 @@ -#include "Math.hpp" #include "Surface.hpp" #include "Wing.hpp" @@ -228,30 +227,6 @@ void Wing::setSlatPos(float val) ((Surface*)_slatSurfs.get(i))->setSlatPos(val); } -float Wing::getGroundEffect(float* posOut) -{ - int i; - for(i=0; i<3; i++) posOut[i] = _base[i]; - float span = _length * Math::cos(_sweep) * Math::cos(_dihedral); - span = 2*(span + Math::abs(_base[2])); - return span; -} - -void Wing::getTip(float* tip) -{ - tip[0] = -Math::tan(_sweep); - tip[1] = Math::cos(_dihedral); - tip[2] = Math::sin(_dihedral); - Math::unit3(tip, tip); - Math::mul3(_length, tip, tip); - Math::add3(_base, tip, tip); -} - -bool Wing::isMirrored() -{ - return _mirror; -} - void Wing::compile() { // Have we already been compiled? @@ -306,12 +281,13 @@ void Wing::compile() Math::unit3(left, left); // Calculate coordinates for the root and tip of the wing - float root[3], tip[3]; + float root[3]; Math::set3(_base, root); - Math::set3(left, tip); - Math::mul3(_length, tip, tip); - Math::add3(root, tip, tip); - + Math::set3(left, _tip); + Math::mul3(_length, _tip, _tip); + Math::add3(root, _tip, _tip); + _wingspan = Math::abs(2*_tip[1]); + // The wing's Y axis will be the "left" vector. The Z axis will // be perpendicular to this and the local (!) X axis, because we // want motion along the local X axis to be zero AoA (i.e. in the @@ -363,7 +339,7 @@ void Wing::compile() for(j=0; j