mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
Ref T261, interpolator PBH in own file
This commit is contained in:
committed by
Roland Winklmeier
parent
cb522fedd7
commit
2a5261f3f6
@@ -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 <typename Derived>
|
||||
CAircraftParts CInterpolator<Derived>::getInterpolatedParts(
|
||||
qint64 currentTimeMsSinceEpoch,
|
||||
|
||||
@@ -134,36 +134,6 @@ namespace BlackMisc
|
||||
const Derived *derived() const { return static_cast<const Derived *>(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
|
||||
{
|
||||
|
||||
67
src/blackmisc/simulation/interpolatorpbh.cpp
Normal file
67
src/blackmisc/simulation/interpolatorpbh.cpp
Normal file
@@ -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
|
||||
55
src/blackmisc/simulation/interpolatorpbh.h
Normal file
55
src/blackmisc/simulation/interpolatorpbh.h
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user