From dbf21b1ca80f1505d916df9fb8bcd380128e4f3d Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Sat, 11 Mar 2017 22:41:57 +0100 Subject: [PATCH] YASim calculate max CG range (on x-axis) from gear positions, to implement checks later (a better guesstimate will follow). --- src/FDM/YASim/Airplane.cpp | 21 +++++++++++++++++++++ src/FDM/YASim/Airplane.hpp | 9 ++++++++- src/FDM/YASim/FGFDM.cpp | 5 +++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/FDM/YASim/Airplane.cpp b/src/FDM/YASim/Airplane.cpp index 767e07cec..e5e4e1845 100644 --- a/src/FDM/YASim/Airplane.cpp +++ b/src/FDM/YASim/Airplane.cpp @@ -57,6 +57,8 @@ Airplane::Airplane() _failureMsg = 0; _wingsN = 0; + _cgMaxX = -1e6; + _cgMinX = 1e6; } Airplane::~Airplane() @@ -238,6 +240,10 @@ void Airplane::addGear(Gear* gear) g->gear = gear; g->surf = 0; _gears.add(g); + float pos[3]; + g->gear->getPosition(pos); + if (pos[0] > _cgMaxX) _cgMaxX = pos[0]; + if (pos[0] < _cgMinX) _cgMinX = pos[0]; } void Airplane::addThruster(Thruster* thruster, float mass, float* cg) @@ -320,6 +326,14 @@ void Airplane::setupState(const float aoa, const float speed, const float gla, S s->pos[2] = 1; } +/** + * @brief add contact point for crash detection + * used to add wingtips and fuselage nose and tail + * + * @param pos ... + * @return void + */ + void Airplane::addContactPoint(float* pos) { ContactRec* c = new ContactRec; @@ -522,6 +536,13 @@ void Airplane::compileGear(GearRec* gr) _surfs.add(s); } +/** + * @brief add "fake gear" per contact point + * + * + * @return void + */ + void Airplane::compileContactPoints() { // Figure it will compress by 20cm diff --git a/src/FDM/YASim/Airplane.hpp b/src/FDM/YASim/Airplane.hpp index 3d98c2358..43e570778 100644 --- a/src/FDM/YASim/Airplane.hpp +++ b/src/FDM/YASim/Airplane.hpp @@ -102,7 +102,10 @@ public: static void setupState(const float aoa, const float speed, const float gla, yasim::State* s); // utility void loadApproachControls(); void loadCruiseControls(); - + + float getCGMinX() { return _cgMinX; } + float getCGMaxX() { return _cgMaxX; } + private: struct Tank { float pos[3]; float cap; float fill; float density; int handle; }; @@ -182,6 +185,10 @@ private: float _tailIncidence; Control _approachElevator; const char* _failureMsg; + + // hard limits for cg from gear positions + float _cgMaxX; + float _cgMinX; }; }; // namespace yasim diff --git a/src/FDM/YASim/FGFDM.cpp b/src/FDM/YASim/FGFDM.cpp index 28942e81e..5f21f67e1 100644 --- a/src/FDM/YASim/FGFDM.cpp +++ b/src/FDM/YASim/FGFDM.cpp @@ -130,7 +130,12 @@ void FGFDM::init() // alias to older name fgGetNode("/yasim/gross-weight-lbs", true)->alias(_gross_weight_lbs); + // write some compile time information to property tree _yasimN->getNode("config-version",true)->setIntValue(_airplane.getVersion()); + _yasimN->getNode("model/cg-x-min",true)->setFloatValue(_airplane.getCGMinX()); + _yasimN->getNode("model/cg-x-max",true)->setFloatValue(_airplane.getCGMaxX()); + + // prepare nodes for write at runtime _cg_x = _yasimN->getNode("cg-x-m", true); _cg_y = _yasimN->getNode("cg-y-m", true); _cg_z = _yasimN->getNode("cg-z-m", true);