1
0
Fork 0

YASim: export surface data to property tree.

This commit is contained in:
Henning Stahlke 2017-02-06 18:39:30 +01:00
parent d322ded552
commit d4688d206a
2 changed files with 41 additions and 2 deletions

View file

@ -19,6 +19,7 @@
#include "Hitch.hpp" #include "Hitch.hpp"
#include "Glue.hpp" #include "Glue.hpp"
#include "Ground.hpp" #include "Ground.hpp"
#include <simgear/props/props.hxx>
#include "Model.hpp" #include "Model.hpp"
namespace yasim { namespace yasim {
@ -416,6 +417,9 @@ void Model::calcForces(State* s)
// point is different due to rotation. // point is different due to rotation.
float faero[3]; float faero[3];
faero[0] = faero[1] = faero[2] = 0; faero[0] = faero[1] = faero[2] = 0;
int id = 0;
SGPropertyNode_ptr n = fgGetNode("/fdm/yasim/surfaces", true);
SGPropertyNode_ptr surfN;
for(i=0; i<_surfaces.size(); i++) { for(i=0; i<_surfaces.size(); i++) {
Surface* sf = (Surface*)_surfaces.get(i); Surface* sf = (Surface*)_surfaces.get(i);
@ -426,11 +430,27 @@ void Model::calcForces(State* s)
float force[3], torque[3]; float force[3], torque[3];
sf->calcForce(vs, _rho, force, torque); sf->calcForce(vs, _rho, force, torque);
id = sf->getID();
if (n != 0) {
surfN = n->getChild("surface", id, true);
surfN->getNode("f-abs", true)->setFloatValue(Math::mag3(force));
surfN->getNode("f-x", true)->setFloatValue(force[0]);
surfN->getNode("f-y", true)->setFloatValue(force[1]);
surfN->getNode("f-z", true)->setFloatValue(force[2]);
}
Math::add3(faero, force, faero); Math::add3(faero, force, faero);
_body.addForce(pos, force); _body.addForce(pos, force);
_body.addTorque(torque); _body.addTorque(torque);
} }
float ld0 = faero[2]/faero[0];
n = fgGetNode("/fdm/yasim/forces", true);
if (n != 0) {
n->getNode("f0-aero-x-drag", true)->setFloatValue(faero[0]);
n->getNode("f0-aero-y-side", true)->setFloatValue(faero[1]);
n->getNode("f0-aero-z-lift", true)->setFloatValue(faero[2]);
}
for (j=0; j<_rotorgear.getRotors()->size();j++) for (j=0; j<_rotorgear.getRotors()->size();j++)
{ {
Rotor* r = (Rotor *)_rotorgear.getRotors()->get(j); Rotor* r = (Rotor *)_rotorgear.getRotors()->get(j);
@ -482,9 +502,18 @@ void Model::calcForces(State* s)
fz *= _groundEffect; fz *= _groundEffect;
Math::mul3(fz, ground, geForce); Math::mul3(fz, ground, geForce);
_body.addForce(geForce); _body.addForce(geForce);
} }
n = fgGetNode("/fdm/yasim/forces", true);
if (n != 0) {
float ld = (geForce[2]+faero[2])/(geForce[0]+faero[0]);
n->getNode("gndeff-f-x", true)->setFloatValue(geForce[0]);
n->getNode("gndeff-f-y", true)->setFloatValue(geForce[1]);
n->getNode("gndeff-f-z", true)->setFloatValue(geForce[2]);
n->getNode("wing-gnd-dist", true)->setFloatValue(dist);
n->getNode("gndeff-ld-ld0", true)->setFloatValue(ld/ld0);
}
} }
// Convert the velocity and rotation vectors to local coordinates // Convert the velocity and rotation vectors to local coordinates
float lrot[3], lv[3]; float lrot[3], lv[3];
Math::vmul33(s->orient, s->rot, lrot); Math::vmul33(s->orient, s->rot, lrot);

View file

@ -224,6 +224,12 @@ void Surface::calcForce(float* v, float rho, float* out, float* torque)
// Diddle the Z force according to our configuration // Diddle the Z force according to our configuration
float stallMul = stallFunc(out); float stallMul = stallFunc(out);
if (_surfN != 0) {
_surfN->getNode("wind-loc-x", true)->setFloatValue(lwind[0]);
_surfN->getNode("wind-loc-y", true)->setFloatValue(lwind[1]);
_surfN->getNode("wind-loc-z", true)->setFloatValue(lwind[2]);
_surfN->getNode("stall-base-factor", true)->setFloatValue(stallMul);
}
stallMul *= 1 + _spoilerPos * (_spoilerLift - 1); stallMul *= 1 + _spoilerPos * (_spoilerLift - 1);
float stallLift = (stallMul - 1) * _cz * out[2]; float stallLift = (stallMul - 1) * _cz * out[2];
float flaplift = flapLift(out[2]); float flaplift = flapLift(out[2]);
@ -305,11 +311,15 @@ float Surface::stallFunc(float* v)
if(v[0] == 0) return 1; if(v[0] == 0) return 1;
float alpha = Math::abs(v[2]/v[0]); float alpha = Math::abs(v[2]/v[0]);
if (_surfN != 0)
_surfN->getNode("alpha-deg", true)->setFloatValue(alpha*57.295779513);
// Wacky use of indexing, see setStall*() methods. // Wacky use of indexing, see setStall*() methods.
int fwdBak = v[0] > 0; // set if this is "backward motion" int fwdBak = v[0] > 0; // set if this is "backward motion"
int posNeg = v[2] < 0; // set if the airflow is toward -z int posNeg = v[2] < 0; // set if the airflow is toward -z
int i = (fwdBak<<1) | posNeg; int i = (fwdBak<<1) | posNeg;
if (_surfN != 0)
_surfN->getNode("mode", true)->setValue(i);
float stallAlpha = _stalls[i]; float stallAlpha = _stalls[i];
if(stallAlpha == 0) if(stallAlpha == 0)