From 2a5261f3f6fad41ab6d891768242b7a21f601c58 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 5 May 2018 04:44:23 +0200 Subject: [PATCH] Ref T261, interpolator PBH in own file --- src/blackmisc/simulation/interpolator.cpp | 48 -------------- src/blackmisc/simulation/interpolator.h | 30 --------- src/blackmisc/simulation/interpolatorpbh.cpp | 67 ++++++++++++++++++++ src/blackmisc/simulation/interpolatorpbh.h | 55 ++++++++++++++++ 4 files changed, 122 insertions(+), 78 deletions(-) create mode 100644 src/blackmisc/simulation/interpolatorpbh.cpp create mode 100644 src/blackmisc/simulation/interpolatorpbh.h diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index dbfc34ca4..019a1528d 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -222,54 +222,6 @@ namespace BlackMisc return currentSituation; } - CHeading CInterpolatorPbh::getHeading() const - { - // HINT: VTOL aircraft can change pitch/bank without changing position, planes cannot - // Interpolate heading: HDG = (HdgB - HdgA) * t + HdgA - const CHeading headingBegin = m_oldSituation.getHeading(); - CHeading headingEnd = m_newSituation.getHeading(); - - if ((headingEnd - headingBegin).value(CAngleUnit::deg()) < -180) - { - headingEnd += CHeading(360, CHeading::Magnetic, CAngleUnit::deg()); - } - - if ((headingEnd - headingBegin).value(CAngleUnit::deg()) > 180) - { - headingEnd -= CHeading(360, CHeading::Magnetic, CAngleUnit::deg()); - } - - return CHeading((headingEnd - headingBegin) - * m_simulationTimeFraction - + headingBegin, - headingBegin.getReferenceNorth()); - } - - CAngle CInterpolatorPbh::getPitch() const - { - // Interpolate Pitch: Pitch = (PitchB - PitchA) * t + PitchA - const CAngle pitchBegin = m_oldSituation.getPitch(); - const CAngle pitchEnd = m_newSituation.getPitch(); - const CAngle pitch = (pitchEnd - pitchBegin) * m_simulationTimeFraction + pitchBegin; - return pitch; - } - - CAngle CInterpolatorPbh::getBank() const - { - // Interpolate bank: Bank = (BankB - BankA) * t + BankA - const CAngle bankBegin = m_oldSituation.getBank(); - const CAngle bankEnd = m_newSituation.getBank(); - const CAngle bank = (bankEnd - bankBegin) * m_simulationTimeFraction + bankBegin; - return bank; - } - - CSpeed CInterpolatorPbh::getGroundSpeed() const - { - return (m_newSituation.getGroundSpeed() - m_oldSituation.getGroundSpeed()) - * m_simulationTimeFraction - + m_oldSituation.getGroundSpeed(); - } - template CAircraftParts CInterpolator::getInterpolatedParts( qint64 currentTimeMsSinceEpoch, diff --git a/src/blackmisc/simulation/interpolator.h b/src/blackmisc/simulation/interpolator.h index 6b333e497..458fb1eb7 100644 --- a/src/blackmisc/simulation/interpolator.h +++ b/src/blackmisc/simulation/interpolator.h @@ -134,36 +134,6 @@ namespace BlackMisc const Derived *derived() const { return static_cast(this); } }; - //! Simple interpolator for pitch, bank, heading, groundspeed - class BLACKMISC_EXPORT CInterpolatorPbh - { - public: - //! Constructor - //! @{ - CInterpolatorPbh() {} - CInterpolatorPbh(const Aviation::CAircraftSituation &older, const Aviation::CAircraftSituation &newer) : m_oldSituation(older), m_newSituation(newer) {} - CInterpolatorPbh(double time, const Aviation::CAircraftSituation &older, const Aviation::CAircraftSituation &newer) : m_simulationTimeFraction(time), m_oldSituation(older), m_newSituation(newer) {} - //! @} - - //! Getter - //! @{ - Aviation::CHeading getHeading() const; - PhysicalQuantities::CAngle getPitch() const; - PhysicalQuantities::CAngle getBank() const; - PhysicalQuantities::CSpeed getGroundSpeed() const; - const Aviation::CAircraftSituation &getOldSituation() const { return m_oldSituation; } - const Aviation::CAircraftSituation &getNewSituation() const { return m_newSituation; } - //! @} - - //! Change time fraction - void setTimeFraction(double tf) { m_simulationTimeFraction = tf; } - - private: - double m_simulationTimeFraction = 0.0; - Aviation::CAircraftSituation m_oldSituation; - Aviation::CAircraftSituation m_newSituation; - }; - //! Status of interpolation struct BLACKMISC_EXPORT CInterpolationStatus { diff --git a/src/blackmisc/simulation/interpolatorpbh.cpp b/src/blackmisc/simulation/interpolatorpbh.cpp new file mode 100644 index 000000000..b348c202c --- /dev/null +++ b/src/blackmisc/simulation/interpolatorpbh.cpp @@ -0,0 +1,67 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "interpolatorpbh.h" + +using namespace BlackMisc::Aviation; +using namespace BlackMisc::PhysicalQuantities; + +namespace BlackMisc +{ + namespace Simulation + { + CHeading CInterpolatorPbh::getHeading() const + { + // HINT: VTOL aircraft can change pitch/bank without changing position, planes cannot + // Interpolate heading: HDG = (HdgB - HdgA) * t + HdgA + const CHeading headingBegin = m_oldSituation.getHeading(); + CHeading headingEnd = m_newSituation.getHeading(); + + if ((headingEnd - headingBegin).value(CAngleUnit::deg()) < -180) + { + headingEnd += CHeading(360, CHeading::Magnetic, CAngleUnit::deg()); + } + + if ((headingEnd - headingBegin).value(CAngleUnit::deg()) > 180) + { + headingEnd -= CHeading(360, CHeading::Magnetic, CAngleUnit::deg()); + } + + return CHeading((headingEnd - headingBegin) + * m_simulationTimeFraction + + headingBegin, + headingBegin.getReferenceNorth()); + } + + CAngle CInterpolatorPbh::getPitch() const + { + // Interpolate Pitch: Pitch = (PitchB - PitchA) * t + PitchA + const CAngle pitchBegin = m_oldSituation.getPitch(); + const CAngle pitchEnd = m_newSituation.getPitch(); + const CAngle pitch = (pitchEnd - pitchBegin) * m_simulationTimeFraction + pitchBegin; + return pitch; + } + + CAngle CInterpolatorPbh::getBank() const + { + // Interpolate bank: Bank = (BankB - BankA) * t + BankA + const CAngle bankBegin = m_oldSituation.getBank(); + const CAngle bankEnd = m_newSituation.getBank(); + const CAngle bank = (bankEnd - bankBegin) * m_simulationTimeFraction + bankBegin; + return bank; + } + + CSpeed CInterpolatorPbh::getGroundSpeed() const + { + return (m_newSituation.getGroundSpeed() - m_oldSituation.getGroundSpeed()) + * m_simulationTimeFraction + + m_oldSituation.getGroundSpeed(); + } + } // namespace +} // namespace diff --git a/src/blackmisc/simulation/interpolatorpbh.h b/src/blackmisc/simulation/interpolatorpbh.h new file mode 100644 index 000000000..3a4f43104 --- /dev/null +++ b/src/blackmisc/simulation/interpolatorpbh.h @@ -0,0 +1,55 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_SIMULATION_INTERPOLATORPBH_H +#define BLACKMISC_SIMULATION_INTERPOLATORPBH_H + +#include "blackmisc/aviation/aircraftsituation.h" +#include "blackmisc/aviation/heading.h" +#include "blackmisc/pq/angle.h" +#include "blackmisc/pq/speed.h" + +namespace BlackMisc +{ + namespace Simulation + { + //! Simple interpolator for pitch, bank, heading, groundspeed + class CInterpolatorPbh + { + public: + //! Constructor + //! @{ + CInterpolatorPbh() {} + CInterpolatorPbh(const Aviation::CAircraftSituation &older, const Aviation::CAircraftSituation &newer) : m_oldSituation(older), m_newSituation(newer) {} + CInterpolatorPbh(double time, const Aviation::CAircraftSituation &older, const Aviation::CAircraftSituation &newer) : m_simulationTimeFraction(time), m_oldSituation(older), m_newSituation(newer) {} + //! @} + + //! Getter + //! @{ + Aviation::CHeading getHeading() const; + PhysicalQuantities::CAngle getPitch() const; + PhysicalQuantities::CAngle getBank() const; + PhysicalQuantities::CSpeed getGroundSpeed() const; + const Aviation::CAircraftSituation &getOldSituation() const { return m_oldSituation; } + const Aviation::CAircraftSituation &getNewSituation() const { return m_newSituation; } + //! @} + + //! Change time fraction + void setTimeFraction(double tf) { m_simulationTimeFraction = tf; } + + private: + double m_simulationTimeFraction = 0.0; + Aviation::CAircraftSituation m_oldSituation; + Aviation::CAircraftSituation m_newSituation; + }; + } // namespace +} // namespace +#endif // guard