From 021a9db9bec46b39069a8b9188b1beffa5bdfd7c Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Thu, 16 Feb 2017 16:38:54 +0100 Subject: [PATCH] YASim add surface id and export surface positions to prop tree after model compile. --- src/FDM/YASim/FGFDM.cpp | 3 +++ src/FDM/YASim/Surface.cpp | 23 +++++++++++++++++++++++ src/FDM/YASim/Surface.hpp | 9 +++++++++ 3 files changed, 35 insertions(+) diff --git a/src/FDM/YASim/FGFDM.cpp b/src/FDM/YASim/FGFDM.cpp index 0ff599eb0..fb4e5104d 100644 --- a/src/FDM/YASim/FGFDM.cpp +++ b/src/FDM/YASim/FGFDM.cpp @@ -21,6 +21,7 @@ #include "Rotor.hpp" #include "Rotorpart.hpp" #include "Hitch.hpp" +#include "Surface.hpp" #include "FGFDM.hpp" @@ -118,6 +119,8 @@ Airplane* FGFDM::getAirplane() void FGFDM::init() { + //reset id generator, needed on simulator reset/re-init + Surface::resetIDgen(); _turb_magnitude_norm = fgGetNode("/environment/turbulence/magnitude-norm", true); _turb_rate_hz = fgGetNode("/environment/turbulence/rate-hz", true); diff --git a/src/FDM/YASim/Surface.cpp b/src/FDM/YASim/Surface.cpp index dc1a4200a..4386671c9 100644 --- a/src/FDM/YASim/Surface.cpp +++ b/src/FDM/YASim/Surface.cpp @@ -1,10 +1,15 @@ +#include
#include "Math.hpp" #include "Surface.hpp" + namespace yasim { +int Surface::s_idGenerator = 0; Surface::Surface( Version * version ) : _version(version) { + // create id for surface + _id = s_idGenerator++; // Start in a "sane" mode, so unset stuff doesn't freak us out _c0 = 1; _cx = _cy = _cz = 1; @@ -30,12 +35,21 @@ Surface::Surface( Version * version ) : _slatAlpha = 0; _spoilerLift = 1; _inducedDrag = 1; + _surfN = fgGetNode("/fdm/yasim/surfaces", true); + if (_surfN != 0) + _surfN = _surfN->getChild("surface", _id, true); } + void Surface::setPosition(float* p) { int i; for(i=0; i<3; i++) _pos[i] = p[i]; + if (_surfN != 0) { + _surfN->getNode("pos-x", true)->setFloatValue(p[0]); + _surfN->getNode("pos-y", true)->setFloatValue(p[1]); + _surfN->getNode("pos-z", true)->setFloatValue(p[2]); + } } void Surface::getPosition(float* out) @@ -136,7 +150,10 @@ void Surface::setSpoilerParams(float liftPenalty, float dragPenalty) void Surface::setFlapPos(float pos) { + if (_flapPos != pos) { _flapPos = pos; + if (_surfN != 0) _surfN->getNode("flap-pos", true)->setFloatValue(pos); + } } void Surface::setFlapEffectiveness(float effectiveness) @@ -152,12 +169,18 @@ double Surface::getFlapEffectiveness() void Surface::setSlatPos(float pos) { + if (_slatPos != pos) { _slatPos = pos; + if (_surfN != 0) _surfN->getNode("slat-pos", true)->setFloatValue(pos); + } } void Surface::setSpoilerPos(float pos) { + if (_spoilerPos != pos) { _spoilerPos = pos; + if (_surfN != 0) _surfN->getNode("spoiler-pos", true)->setFloatValue(pos); + } } // Calculate the aerodynamic force given a wind vector v (in the diff --git a/src/FDM/YASim/Surface.hpp b/src/FDM/YASim/Surface.hpp index 660efb2f9..43c477332 100644 --- a/src/FDM/YASim/Surface.hpp +++ b/src/FDM/YASim/Surface.hpp @@ -1,6 +1,7 @@ #ifndef _SURFACE_HPP #define _SURFACE_HPP +#include #include "Version.hpp" namespace yasim { @@ -10,9 +11,15 @@ namespace yasim { // front, and flaps act (in both lift and drag) toward the back. class Surface { + static int s_idGenerator; + int _id; //index for property tree + public: Surface( Version * version ); + int getID() { return _id; }; + static void resetIDgen() { s_idGenerator = 0; }; + // Position of this surface in local coords void setPosition(float* p); void getPosition(float* out); @@ -75,6 +82,8 @@ public: void calcForce(float* v, float rho, float* forceOut, float* torqueOut); private: + SGPropertyNode_ptr _surfN; + float stallFunc(float* v); float flapLift(float alpha); float controlDrag(float lift, float drag);