From add6c6b8a83d98ce53b679e1e4897497ff4deeb2 Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Tue, 25 Apr 2017 08:58:51 +0200 Subject: [PATCH] YASim: Airplane solver uses standard atmosphere so we can replaced atmosphere members with floats for altitude and pass those to setup atmo where needed directly from altitude. --- src/FDM/YASim/Airplane.cpp | 15 +++++++-------- src/FDM/YASim/Airplane.hpp | 4 ++-- src/FDM/YASim/Model.cpp | 2 +- src/FDM/YASim/Thruster.hpp | 3 ++- src/FDM/YASim/proptest.cpp | 4 +--- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/FDM/YASim/Airplane.cpp b/src/FDM/YASim/Airplane.cpp index f8a997d1c..3ae8cac67 100644 --- a/src/FDM/YASim/Airplane.cpp +++ b/src/FDM/YASim/Airplane.cpp @@ -125,7 +125,7 @@ void Airplane::updateGearState() void Airplane::setApproach(float speed, float altitude, float aoa, float fuel, float gla) { _approachSpeed = speed; - _approachAtmo.setStandard(altitude); + _approachAltitude = altitude; _approachAoA = aoa; _approachFuel = fuel; _approachGlideAngle = gla; @@ -134,7 +134,7 @@ void Airplane::setApproach(float speed, float altitude, float aoa, float fuel, f void Airplane::setCruise(float speed, float altitude, float fuel, float gla) { _cruiseSpeed = speed; - _cruiseAtmo.setStandard(altitude); + _cruiseAltitude = altitude; _cruiseAoA = 0; _tailIncidence = 0; _cruiseFuel = fuel; @@ -758,7 +758,7 @@ void Airplane::runCruise() { _cruiseState.setupState(_cruiseAoA, _cruiseSpeed,_cruiseGlideAngle); _model.setState(&_cruiseState); - _model.setAtmosphere(_cruiseAtmo); + _model.setStandardAtmosphere(_cruiseAltitude); // The control configuration loadControls(_cruiseControls); @@ -776,8 +776,7 @@ void Airplane::runCruise() for(int i=0; i<_thrusters.size(); i++) { Thruster* t = ((ThrustRec*)_thrusters.get(i))->thruster; t->setWind(wind); - t->setAir(_cruiseAtmo); - //Atmosphere::calcStdDensity(_cruiseP, _cruiseT)); + t->setStandardAtmosphere(_cruiseAltitude); } stabilizeThrust(); @@ -795,7 +794,7 @@ void Airplane::runApproach() { _approachState.setupState(_approachAoA, _approachSpeed,_approachGlideAngle); _model.setState(&_approachState); - _model.setAtmosphere(_approachAtmo); + _model.setStandardAtmosphere(_approachAltitude); // The control configuration loadControls(_approachControls); @@ -813,7 +812,7 @@ void Airplane::runApproach() for(int i=0; i<_thrusters.size(); i++) { Thruster* t = ((ThrustRec*)_thrusters.get(i))->thruster; t->setWind(wind); - t->setAir(_approachAtmo); + t->setStandardAtmosphere(_approachAltitude); } stabilizeThrust(); @@ -1058,7 +1057,7 @@ void Airplane::solveHelicopter() setupWeights(true); _controls.reset(); _model.getBody()->reset(); - _model.setAtmosphere(_cruiseAtmo); + _model.setStandardAtmosphere(_cruiseAltitude); } float Airplane::getCGMAC() diff --git a/src/FDM/YASim/Airplane.hpp b/src/FDM/YASim/Airplane.hpp index 9575d33c3..3a25cd226 100644 --- a/src/FDM/YASim/Airplane.hpp +++ b/src/FDM/YASim/Airplane.hpp @@ -169,7 +169,7 @@ private: Vector _cruiseControls; State _cruiseState; - Atmosphere _cruiseAtmo; + float _cruiseAltitude; float _cruiseSpeed{0}; float _cruiseWeight{0}; float _cruiseFuel{0}; @@ -177,7 +177,7 @@ private: Vector _approachControls; State _approachState; - Atmosphere _approachAtmo; + float _approachAltitude; float _approachSpeed {0}; float _approachAoA {0}; float _approachWeight {0}; diff --git a/src/FDM/YASim/Model.cpp b/src/FDM/YASim/Model.cpp index d3ef8e95b..c3383d0b7 100644 --- a/src/FDM/YASim/Model.cpp +++ b/src/FDM/YASim/Model.cpp @@ -127,7 +127,7 @@ void Model::initIteration() localWind(pos, _s, v, alt); t->setWind(v); - t->setAir(_atmo); + t->setAtmosphere(_atmo); t->integrate(_integrator.getInterval()); t->getTorque(v); diff --git a/src/FDM/YASim/Thruster.hpp b/src/FDM/YASim/Thruster.hpp index a5db4e1b1..210e88342 100644 --- a/src/FDM/YASim/Thruster.hpp +++ b/src/FDM/YASim/Thruster.hpp @@ -46,7 +46,8 @@ public: // Runtime instructions void setWind(const float* wind) { Math::set3(wind, _wind); }; - void setAir(Atmosphere a) { _atmo = a; }; + void setAtmosphere(Atmosphere a) { _atmo = a; }; + void setStandardAtmosphere(float altitude) { _atmo.setStandard(altitude); }; virtual void init() {} virtual void integrate(float dt)=0; virtual void stabilize()=0; diff --git a/src/FDM/YASim/proptest.cpp b/src/FDM/YASim/proptest.cpp index 6b1a8b98f..29a1aeec6 100644 --- a/src/FDM/YASim/proptest.cpp +++ b/src/FDM/YASim/proptest.cpp @@ -71,9 +71,7 @@ int main(int argc, char** argv) eng->setBoost(1); float alt = (argc > 2 ? atof(argv[2]) : 0) * FT2M; - Atmosphere atmo; - atmo.setStandard(alt); - pe->setAir(atmo); + pe->setStandardAtmosphere(alt); float speed = (argc > 3 ? atof(argv[3]) : 0) * KTS2MPS; float wind[3];