Changed interpolator (preliminary) to work with PQs and new classes, added stubs for unit tests in BlackCore

This commit is contained in:
Klaus Basan
2013-04-27 02:09:42 +02:00
parent 5eac9be7d5
commit c5b9c48cd6
31 changed files with 645 additions and 363 deletions

View File

@@ -3,26 +3,17 @@ TEMPLATE = subdirs
CONFIG += ordered
WITH_BLACKMISC = ON
WITH_BLACKCORE = ON
WITH_BLACKD = ON
WITH_BLACKBOX = ON
WITH_SAMPLES = ON
#WITH_DRIVER_FSX = ON
#WITH_DRIVER_FS9 = ON
#WITH_DRIVER_XPLANE = ON
#WITH_UNITTESTS = ON
#WITH_DOXYGEN = ON
equals(WITH_BLACKMISC, ON) {
SUBDIRS += src/blackmisc
}
@@ -66,6 +57,7 @@ equals(WITH_SAMPLES, ON) {
equals(WITH_UNITTESTS, ON) {
SUBDIRS += tests/blackmisc/test_blackmisc.pro
SUBDIRS += tests/blackcore/test_blackcore.pro
}
equals(WITH_DOXYGEN, ON) {

View File

@@ -1,5 +1,5 @@
QT += core
QT -= gui
# GUI required for matrix classes
QT += core gui
TARGET = sample_geo2ecef
TEMPLATE = app
@@ -8,11 +8,9 @@ CONFIG += console
CONFIG -= app_bundle
DEPENDPATH += . ../../src
INCLUDEPATH += . ../../src
SOURCES += *.cpp
LIBS += -L../../lib -lblackcore -lblackmisc
win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \
@@ -21,6 +19,3 @@ else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \
../../lib/libblackcore.a
DESTDIR = ../../bin

View File

@@ -1,3 +1,8 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "samplesvectormatrix.h"
#include "samplesgeo.h"
#include "samplesgeodetictoecef.h"

View File

@@ -1,5 +1,5 @@
QT += core
QT -= gui
# GUI required for matrix classes
QT += core gui
TARGET = sample_geo2ecef
TEMPLATE = app
@@ -8,11 +8,9 @@ CONFIG += console
CONFIG -= app_bundle
DEPENDPATH += . ../../src
INCLUDEPATH += . ../../src
SOURCES += *.cpp
LIBS += -L../../lib -lblackcore -lblackmisc
win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \
@@ -21,6 +19,3 @@ else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \
../../lib/libblackcore.a
DESTDIR = ../../bin

View File

@@ -1,79 +1,80 @@
#include <QCoreApplication>
#include <QElapsedTimer>
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <iostream>
#include "blackcore/matrix_3d.h"
#include "blackcore/vector_geo.h"
#include "blackcore/vector_3d.h"
#include "blackmisc/coordinatetransformation.h"
#include "blackmisc/pqangle.h"
#include "blackcore/interpolator.h"
#include "blackmisc/context.h"
#include "blackmisc/debug.h"
#include <QCoreApplication>
#include <QElapsedTimer>
#include <iostream>
using namespace std;
using namespace BlackCore;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Math;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Aviation;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug());
QElapsedTimer timer;
CVectorGeo myGeo(48.123, 11.75, 400);
CVector3D vecNed(1, 0, 0);
CVector3D vecEcef;
// CCoordinateGeodetic myGeo(48.123, 11.75, 400);
// CVector3D vecNed(1, 0, 0);
// CVector3D vecEcef;
CInterpolator interpolator;
interpolator.initialize();
CVectorGeo vecGeo(48.340733, 11.750565, 100);
CVectorGeo vecGeo2(48.344727, 11.805153, 100);
CCoordinateGeodetic vecGeo(48.340733, 11.750565, 100);
CCoordinateGeodetic vecGeo2(48.344727, 11.805153, 100);
cout << "Start position: " << endl;
vecGeo.print();
cout << "End position: " << endl;
vecGeo2.print();
cout << "Start position: " << vecGeo << endl;
cout << "End position: " << vecGeo2 << endl;
timer.start();
// CVectorGeo pos, double groundVelocity, double heading, double pitch, double bank
interpolator.pushUpdate(vecGeo, 20, 80, 0, 0);
interpolator.pushUpdate(vecGeo2, 20, 250, 0, 0);
CAngle zeroAngle(0, CAngleUnit::deg());
CSpeed speed(20, CSpeedUnit::kts());
CCoordinateNed ned;
ned = interpolator.pushUpdate(vecGeo, speed, CHeading(80, false, CAngleUnit::deg()), zeroAngle, zeroAngle);
cout << "Interpolator NED 1: " << ned << endl;
ned = interpolator.pushUpdate(vecGeo2, speed, CHeading(250, false, CAngleUnit::deg()), zeroAngle, zeroAngle);
cout << "Interpolator NED 2: " << ned << endl;
double duration = timer.nsecsElapsed();
TPlaneState teststate;
timer.restart();
timer.restart();
interpolator.stateNow(&teststate);
CEcef pos = teststate.position;
CVector3D vel = teststate.velocity;
CNed ned = teststate.velNED;
CCoordinateEcef pos = teststate.position;
CVector3D vel = teststate.velocity;
ned = teststate.velNED;
duration = timer.nsecsElapsed();
timer.restart();
CVectorGeo resultGeo = pos.toGeodetic();
CCoordinateTransformation::toGeodetic(pos);
timer.restart();
CCoordinateGeodetic resultGeo = CCoordinateTransformation::toGeodetic(pos);
duration = timer.nsecsElapsed();
cout << "End position: " << endl;
resultGeo.print();
cout << "End position: " << resultGeo << endl;
cout << "End velocity: " << vel << endl;
cout << "End " << ned << endl;
cout << "Heading: ";
cout << teststate.orientation.heading.switchUnit(CAngleUnit::deg()) << endl;
cout << endl;
cout << "End velocity: " << endl;
vel.print();
cout << endl;
cout << "Heading: " << endl;
cout << teststate.orientation.heading << endl;
cout << endl;
cout << duration << " nanoseconds" << endl;
cout << duration << " nanoseconds" << endl;
return a.exec();
}

View File

@@ -1,18 +1,17 @@
QT += core
QT -= gui
TARGET = sample_interpolator
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
DEPENDPATH += . ../../src
INCLUDEPATH += . ../../src
SOURCES += *.cpp
LIBS += -L../../lib -lblackcore -lblackmisc
win32: PRE_TARGETDEPS += ../../lib/blackmisc.lib \
@@ -21,6 +20,3 @@ else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \
../../lib/libblackcore.a
DESTDIR = ../../bin

View File

@@ -1,3 +1,4 @@
# GUI is required for the matrix classes
QT += network
TARGET = blackcore
@@ -5,25 +6,21 @@ TEMPLATE = lib
CONFIG += staticlib
INCLUDEPATH += ..
DEPENDPATH += . ..
linux-g++* {
QMAKE_CXXFLAGS += -std=c++0x
QMAKE_CXXFLAGS += -std=c++0x
}
#PRECOMPILED_HEADER = stdpch.h
precompile_header:!isEmpty(PRECOMPILED_HEADER) {
DEFINES += USING_PCH
}
DEFINES += USING_PCH
}
DEFINES += LOG_IN_FILE
HEADERS += *.h
SOURCES += *.cpp
DESTDIR = ../../lib

View File

@@ -1,155 +1,149 @@
#include <iostream>
#include "blackcore/matrix_3d.h"
#include "blackcore/vector_geo.h"
#include "blackcore/mathematics.h"
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "blackcore/interpolator.h"
#include "blackcore/constants.h"
#include <iostream>
using namespace BlackMisc::Geo;
using namespace BlackMisc::Math;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Aviation;
namespace BlackCore
{
CInterpolator::CInterpolator()
: m_state_begin(NULL), m_state_end(NULL)
/*
* Constructor
*/
CInterpolator::CInterpolator() : m_state_begin(nullptr), m_state_end(nullptr)
{
m_time.start();
}
/*
* Virtual destructor
*/
CInterpolator::~CInterpolator()
{
delete m_state_begin;
delete m_state_end;
delete m_state_begin;
delete m_state_end;
}
void CInterpolator::initialize()
/*
* Initialize
*/
void CInterpolator::initialize() {}
/*
* Push an update
*/
CCoordinateNed CInterpolator::pushUpdate(const CCoordinateGeodetic &pos, const CSpeed &groundSpeed, const CHeading &heading, const CAngle &pitch, const CAngle &bank)
{
}
void CInterpolator::pushUpdate(CVectorGeo pos, double groundVelocity, double heading, double pitch, double bank)
{
CNed vNED;
if ( m_state_begin == NULL )
CCoordinateNed velocityNED;
if (m_state_begin == nullptr)
{
m_state_begin = new TPlaneState();
m_state_begin = new TPlaneState();
m_state_begin->position = CCoordinateTransformation::toEcef(pos);
m_state_begin->orientation.heading = heading;
m_state_begin->orientation.pitch = pitch;
m_state_begin->orientation.bank = bank;
m_state_begin->groundspeed = groundSpeed;
m_state_begin->position = pos.toCartesian();
m_state_begin->orientation.heading = heading*Constants::DegToRad;
m_state_begin->orientation.pitch = pitch*Constants::DegToRad;
m_state_begin->orientation.bank = bank*Constants::DegToRad;
m_state_begin->groundspeed = groundVelocity * Constants::KnotsToMeterPerSecond;
velocityNED =
CCoordinateNed(pos,
cos(m_state_begin->orientation.heading.value(CAngleUnit::rad())) * m_state_begin->groundspeed.value(CSpeedUnit::m_s()),
sin(m_state_begin->orientation.heading.value(CAngleUnit::rad())) * m_state_begin->groundspeed.value(CSpeedUnit::m_s()), 0);
vNED.setNorth( cos(m_state_begin->orientation.heading)*m_state_begin->groundspeed );
vNED.setEast( sin(m_state_begin->orientation.heading)*m_state_begin->groundspeed );
vNED.setDown(0);
vNED.setPosition(pos);
m_state_begin->velocity = vNED.toECEF();
m_state_begin->timestamp = 0;
return;
}
else
{
stateNow(m_state_begin);
m_state_begin->velocity = CCoordinateTransformation::toEcef(velocityNED).toMathVector();
m_state_begin->timestamp = 0;
return velocityNED;
}
if ( m_state_end == NULL )
{
m_state_end = new TPlaneState();
}
stateNow(m_state_begin);
if (m_state_end == nullptr) m_state_end = new TPlaneState();
m_state_end->reset();
m_state_end->timestamp = m_time.elapsed();
m_state_end->position = CCoordinateTransformation::toEcef(pos);
m_state_end->orientation.heading = CHeading(normalizeRadians(heading), false);
m_state_end->orientation.pitch = normalizeRadians(pitch);
m_state_end->orientation.bank = normalizeRadians(bank);
m_state_end->groundspeed = groundSpeed;
m_state_end->position = pos.toCartesian();
m_state_end->orientation.heading = normalizeRadians(heading*Constants::DegToRad);
m_state_end->orientation.pitch = normalizeRadians(pitch*Constants::DegToRad);
m_state_end->orientation.bank = normalizeRadians(bank*Constants::DegToRad);
m_state_end->groundspeed = groundVelocity*Constants::KnotsToMeterPerSecond;
vNED.setNorth( cos(m_state_end->orientation.heading)*m_state_end->groundspeed );
vNED.setEast( sin(m_state_end->orientation.heading)*m_state_end->groundspeed );
vNED.setDown(0);
vNED.setPosition(pos);
m_state_end->velocity = vNED.toECEF();
std::cout << " Interpolator End velocity: " << std::endl;
vNED.print();
std::cout << std::endl;
velocityNED =
CCoordinateNed(pos,
cos(m_state_end->orientation.heading.value(CAngleUnit::rad())) * m_state_end->groundspeed.value(CSpeedUnit::m_s()),
sin(m_state_end->orientation.heading.value(CAngleUnit::rad())) * m_state_end->groundspeed.value(CSpeedUnit::m_s()), 0);
m_state_end->velocity = CCoordinateTransformation::toEcef(velocityNED).toMathVector();
m_timeEnd = 5;
double m_TFpow4 = CMath::cubic(m_timeEnd) * m_timeEnd;
double m_TFpow4 = CMath::cubic(m_timeEnd) * m_timeEnd;
m_a = m_state_begin->velocity * CMath::square(m_timeEnd);
m_a += m_state_end->velocity * CMath::square(m_timeEnd);
m_a += m_state_begin->position * m_timeEnd * 2;
m_a -= m_state_end->position * m_timeEnd * 2;
m_a += m_state_begin->position.toMathVector() * m_timeEnd * 2;
m_a -= m_state_end->position.toMathVector() * m_timeEnd * 2;
m_a *= 6;
m_a /= m_TFpow4;
m_b = m_state_begin->velocity * CMath::cubic(m_timeEnd) * (-2) - m_state_end->velocity * CMath::cubic(m_timeEnd);
m_b = m_b - m_state_begin->position * CMath::square(m_timeEnd) * 3 + m_state_end->position * CMath::square(m_timeEnd) * 3;
m_b = m_b * 2 / ( m_TFpow4 );
m_b = m_b - m_state_begin->position.toMathVector() * CMath::square(m_timeEnd) * 3 + m_state_end->position.toMathVector() * CMath::square(m_timeEnd) * 3;
m_b = m_b * 2 / (m_TFpow4);
return velocityNED;
}
bool CInterpolator::isValid()
/*
* Valid object?
*/
bool CInterpolator::isValid() const
{
return (m_state_begin && m_state_end);
}
/*
* Calculate current state
*/
bool CInterpolator::stateNow(TPlaneState *state)
{
if ( !isValid() )
return false;
if (!this->isValid()) return false;
double time = 5;
/*!
Plane Position
*/
// Plane Position
double timePow2 = CMath::square(time);
double timePow3 = CMath::cubic(time);
CEcef pos;
pos = m_b*3*timePow2*m_timeEnd + m_a * timePow3 * m_timeEnd - m_b * 3 * time * CMath::square(m_timeEnd) - m_a * time* CMath::cubic(m_timeEnd);
pos += m_state_begin->position*(-6)*time + m_state_begin->position*6*m_timeEnd + m_state_end->position*6*time;
pos /= 6*m_timeEnd;
CCoordinateEcef pos(m_b * 3 * timePow2 * m_timeEnd + m_a * timePow3 * m_timeEnd - m_b * 3 * time * CMath::square(m_timeEnd) - m_a * time * CMath::cubic(m_timeEnd));
pos += m_state_begin->position * (-6) * time + m_state_begin->position * 6 * m_timeEnd + m_state_end->position * 6 * time;
pos /= 6 * m_timeEnd;
state->position = pos;
CEcef vel;
vel.zeros();
vel = m_a * ( 3 * m_timeEnd * CMath::square(time) - CMath::cubic(m_timeEnd));
vel += m_b * ( 6 * m_timeEnd * time - 3 * CMath::square(m_timeEnd)) + (m_state_end->position - m_state_begin->position) * 6;
vel /= 6*m_timeEnd;
state->velocity = vel;
state->velNED = vel.toNED(pos.toGeodetic());
/*!
Plane Orientation
*/
double vEast = state->velNED.East();
double vNorth = state->velNED.North();
double fraction = vNorth / vEast;
double heading = atan2 (vNorth, vEast);
CVector3D vel(m_a * (3 * m_timeEnd * CMath::square(time) - CMath::cubic(m_timeEnd)));
vel += m_b * (6 * m_timeEnd * time - 3 * CMath::square(m_timeEnd)) + (m_state_end->position - m_state_begin->position).toMathVector() * 6;
vel /= 6 * m_timeEnd;
state->orientation.heading = heading * Constants::RadToDeg;
state->velocity = vel;
state->velNED = CCoordinateTransformation::toNed(CCoordinateEcef(vel), CCoordinateTransformation::toGeodetic(pos));
return true;
// Plane Orientation
double vEast = state->velNED.east();
double vNorth = state->velNED.north();
state->orientation.heading = CHeading(atan2(vNorth, vEast), false, CAngleUnit::rad());
return true;
}
double CInterpolator::normalizeRadians(double radian)
/*
* Normalize radians, clarify what happens here
*/
CAngle CInterpolator::normalizeRadians(const CAngle &angle) const
{
return radian - Constants::TwoPI * floor(0.5 + radian / Constants::TwoPI);
double radian = angle.value(CAngleUnit::rad());
radian = radian - BlackMisc::Math::TwoPI * floor(0.5 + radian / BlackMisc::Math::TwoPI);
return CAngle(radian, CAngleUnit::rad());
}
} // namespace BlackCore
} // namespace

View File

@@ -1,79 +1,116 @@
//! Copyright (C) 2013 Roland Winklmeier
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef INTERPOLATOR_H
#define INTERPOLATOR_H
#ifndef BLACKCORE_INTERPOLATOR_H
#define BLACKCORE_INTERPOLATOR_H
#include "blackmisc/coordinatetransformation.h"
#include "blackmisc/pqspeed.h"
#include "blackmisc/avheading.h"
#include <QElapsedTimer>
#include "blackcore/vector_geo.h"
#include <blackcore/ecef.h>
#include "blackcore/vector_3d.h"
#include "blackcore/ned.h"
#include "blackcore/ecef.h"
#include "blackcore/constants.h"
namespace BlackCore
{
/*!
* \typedef Plane's orientation
*/
typedef struct
{
double heading;
double pitch;
double bank;
BlackMisc::Aviation::CHeading heading; // honestly I think this is a track TODO
BlackMisc::PhysicalQuantities::CAngle pitch;
BlackMisc::PhysicalQuantities::CAngle bank;
} TOrientation;
/*!
* \typedef Plane's state
*/
typedef struct
{
void reset()
{
}
/*!
* \brief Reset data
*/
void reset() {}
qint64 timestamp;
CEcef position;
TOrientation orientation;
double groundspeed;
CVector3D velocity;
CNed velNED;
qint64 timestamp;
TOrientation orientation;
BlackMisc::PhysicalQuantities::CSpeed groundspeed;
BlackMisc::Math::CVector3D velocity;
BlackMisc::Geo::CCoordinateEcef position;
BlackMisc::Geo::CCoordinateNed velNED;
} TPlaneState;
/*!
* \brief Interpolator, calculation inbetween positions
*/
class CInterpolator
{
public:
/*!
* \brief Default constructor
*/
CInterpolator();
virtual ~CInterpolator();
/*!
* \brief Virtual destructor
*/
virtual ~CInterpolator();
/*!
* \brief Init object
*/
void initialize();
void pushUpdate(CVectorGeo pos, double groundVelocity, double heading, double pitch, double bank);
/*!
* \brief Push an update
* \param pos
* \param groundSpeed
* \param heading
* \param pitch
* \param bank
* \return
*/
BlackMisc::Geo::CCoordinateNed pushUpdate(const BlackMisc::Geo::CCoordinateGeodetic &pos,
const BlackMisc::PhysicalQuantities::CSpeed &groundSpeed,
const BlackMisc::Aviation::CHeading &heading,
const BlackMisc::PhysicalQuantities::CAngle &pitch,
const BlackMisc::PhysicalQuantities::CAngle &bank);
bool isValid();
/*!
* \brief Valid state?
* \return
*/
bool isValid() const;
/*!
* \brief Calculate current state
* \param state
* \return
*/
bool stateNow(TPlaneState *state);
bool stateNow(TPlaneState *state);
private:
double normalizeRadians(double radian);
QElapsedTimer m_time;
TPlaneState *m_state_begin;
TPlaneState *m_state_end;
bool m_valid;
CVector3D m_a;
CVector3D m_b;
double m_timeEnd;
double m_timeBegin;
BlackMisc::Math::CVector3D m_a;
BlackMisc::Math::CVector3D m_b;
QElapsedTimer m_time;
TPlaneState *m_state_begin;
TPlaneState *m_state_end;
bool m_valid;
double m_timeEnd;
double m_timeBegin;
/*!
* \brief Normalize radians
* \param angle
* \return
*/
BlackMisc::PhysicalQuantities::CAngle normalizeRadians(const BlackMisc::PhysicalQuantities::CAngle &angle) const;
};
} // namespace BlackCore
#endif // INTERPOLATOR_H
#endif // guard

View File

@@ -1,48 +1,53 @@
#include <blackcore/simulator.h>
#include <blackcore/vector_geo.h>
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "blackcore/simulator.h"
#include "blackmisc/coordinategeodetic.h"
#include "blackcore/plane.h"
#include "blackcore/multiplayer.h"
#include "blackmisc/avheading.h"
namespace BlackCore {
using namespace BlackMisc::Geo;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Aviation;
CMultiPlayer::CMultiPlayer()
: m_isRunning(false)
namespace BlackCore
{
CMultiPlayer::CMultiPlayer() : m_isRunning(false)
{
registerMessageFunction(this, &CMultiPlayer::onPositionUpdate);
m_simulator = ISimulator::createDriver(ISimulator::FSX);
}
void CMultiPlayer::start()
{
if (m_isRunning)
return;
if (m_isRunning) return;
m_isRunning = true;
}
void CMultiPlayer::stop()
{
if (!m_isRunning)
return;
if (!m_isRunning) return;
m_isRunning = false;
}
void CMultiPlayer::run()
{
TPlaneManager::iterator it;
for (it = m_multiplayer_planes.begin(); it != m_multiplayer_planes.end(); ++it)
{
if (needsToRemoved(it.value()))
{
removePlane(it.value());
it = m_multiplayer_planes.erase(it);
}
{
TPlaneManager::iterator it;
for (it = m_multiplayer_planes.begin(); it != m_multiplayer_planes.end(); ++it)
{
if (needsToRemoved(it.value()))
{
removePlane(it.value());
it = m_multiplayer_planes.erase(it);
}
if (areAIPlanesEnabled())
it.value()->render();
}
if (areAIPlanesEnabled())
it.value()->render();
}
}
bool CMultiPlayer::isKnown(const QString &callsign) const
@@ -60,37 +65,38 @@ void CMultiPlayer::onPositionUpdate(const FSD::FSD_MSG_Plane_Position *plane_pos
QString callsign = plane_position->Callsign();
CPlane *plane;
plane = getPlane(callsign);
CVectorGeo position(plane_position->Latitude(), plane_position->Longitude(), plane_position->Altitude());
FS_PBH pitchBankHeading;
pitchBankHeading.pbh = plane_position->PBH();
//! TODO: Pitch Bank Heading and a timestamp
if (plane)
{
plane->addPosition(position, plane_position->Speed(), pitchBankHeading.hdg, pitchBankHeading.pitch, pitchBankHeading.bank);
}
else
plane = getPlane(callsign);
if (!plane)
{
plane = new CPlane(callsign, m_simulator);
addPlane(plane);
plane->addPosition(position, plane_position->Speed(), pitchBankHeading.hdg, pitchBankHeading.pitch, pitchBankHeading.bank);
}
CCoordinateGeodetic position(plane_position->Latitude(), plane_position->Longitude(), plane_position->Altitude());
FS_PBH pitchBankHeading;
pitchBankHeading.pbh = plane_position->PBH();
// TODO: Pitch Bank Heading and a timestamp
// TODO: Usage of physical quantities with FSD::FSD_MSG_Plane_Position
plane->addPosition(position,
CSpeed(plane_position->Speed(), CSpeedUnit::kts()),
CHeading((qint32)pitchBankHeading.hdg, false, CAngleUnit::deg()),
CAngle((qint32)pitchBankHeading.pitch, CAngleUnit::deg()),
CAngle((qint32)pitchBankHeading.bank, CAngleUnit::deg()));
}
void CMultiPlayer::addPlane(CPlane *plane)
{
m_multiplayer_planes.insert(plane->Callsign(), plane);
m_multiplayer_planes.insert(plane->callsign(), plane);
}
void CMultiPlayer::removePlane(CPlane *plane)
{
qint32 id;
m_simulator->removePlane(id);
qint32 id;
m_simulator->removePlane(id);
}
} //! namespace BlackCore
} // namespace

View File

@@ -1,36 +1,54 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "blackcore/plane.h"
#include "blackcore/interpolator.h"
#include "blackcore/simulator.h"
#include "blackmisc/debug.h"
namespace BlackCore {
using namespace BlackMisc::Geo;
using namespace BlackMisc::PhysicalQuantities;
CPlane::CPlane()
: m_interpolator(NULL), m_driver(NULL)
{
}
namespace BlackCore
{
CPlane::CPlane(const QString &callsign, ISimulator *driver)
: m_callsign(callsign), m_interpolator(NULL), m_driver(driver)
{
m_interpolator = new CInterpolator();
/*
* Default constructor
*/
CPlane::CPlane() : m_interpolator(nullptr), m_driver(nullptr) { }
Q_ASSERT(m_interpolator);
Q_ASSERT(driver);
}
/*
* Constructor
*/
CPlane::CPlane(const QString &callsign, ISimulator *driver) : m_callsign(callsign), m_interpolator(NULL), m_driver(driver)
{
m_interpolator = new CInterpolator();
Q_ASSERT(m_interpolator);
Q_ASSERT(driver);
}
void CPlane::addPosition(const CVectorGeo &position, double groundVelocity, double heading, double pitch, double bank)
{
Q_ASSERT(m_interpolator);
m_interpolator->pushUpdate(position, groundVelocity, heading, pitch, bank);
}
void CPlane::render()
{
//m_driver->updatePositionAndSpeed();
}
/*
* Add a position
*/
void CPlane::addPosition(const CCoordinateGeodetic &position, const CSpeed &groundVelocity, const BlackMisc::Aviation::CHeading &heading, const CAngle &pitch, const CAngle &bank)
{
Q_ASSERT(m_interpolator);
m_interpolator->pushUpdate(position, groundVelocity, heading, pitch, bank);
}
/*
* Render this object
*/
void CPlane::render()
{
// void
}
/*
* Last update timestamp
*/
double CPlane::getLastUpdateTime() const
{
return 0;
}
} // namespace BlackCore

View File

@@ -1,53 +1,80 @@
//! Copyright (C) 2013 Roland Winklmeier
//! This Source Code Form is subject to the terms of the Mozilla Public
//! License, v. 2.0. If a copy of the MPL was not distributed with this
//! file, You can obtain one at http://mozilla.org/MPL/2.0/
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef PLANE_H
#define PLANE_H
#ifndef BLACKCORE_PLANE_H
#define BLACKCORE_PLANE_H
#include "blackcore/interpolator.h"
#include <QString>
namespace BlackCore
{
namespace BlackCore {
class ISimulator;
class ISimulator;
class CInterpolator;
class CVectorGeo;
/*!
* \brief Plane class
*/
class CPlane
{
public:
class CPlane
{
public:
enum ESquawkMode {Standby = 'S',
Charlie = 'N',
Ident = 'Y'
};
enum ESquawkMode {Standby = 'S',
Charlie = 'N',
Ident = 'Y'};
/*!
* \brief Default constructor
*/
CPlane();
CPlane();
CPlane(const QString &callsign, ISimulator *driver);
/*!
* \brief Constructor
* \param callsign
* \param driver
*/
CPlane(const QString &callsign, ISimulator *driver);
/*!
* \brief Add a position (for the interpolator)
* \param position
* \param groundVelocity
* \param heading
* \param pitch
* \param bank
*/
void addPosition(const BlackMisc::Geo::CCoordinateGeodetic &position,
const BlackMisc::PhysicalQuantities::CSpeed &groundVelocity,
const BlackMisc::Aviation::CHeading &heading,
const BlackMisc::PhysicalQuantities::CAngle &pitch,
const BlackMisc::PhysicalQuantities::CAngle &bank);
/*!
* \brief Returns the callsign of the multiplayer plane
* \return
*/
QString callsign() { return m_callsign; }
/*!
* \brief render
*/
void render();
void addPosition(const CVectorGeo &position, double groundVelocity, double heading, double pitch, double bank);
/*!
* \brief Last updated timestamp
* \return
*/
double getLastUpdateTime() const;
//! Returns the callsign of the multiplayer plane
/*!
\return callsign.
*/
inline QString& Callsign() { return m_callsign; }
void render();
double getLastUpdateTime();
private:
private:
QString m_callsign;
CInterpolator *m_interpolator;
ISimulator *m_driver;
};
QString m_callsign;
CInterpolator *m_interpolator;
ISimulator *m_driver;
};
} // namespace BlackCore
#endif // PLANE_H
#endif // guard

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2013 VATSIM Community
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -32,12 +32,14 @@ public:
* \brief Default constructor: 0 heading true
*/
CHeading() : CAngle(0, BlackMisc::PhysicalQuantities::CAngleUnit::rad()), m_magnetic(true) {}
/*!
* \brief Constructor
* \param value
* \param magnetic
* \param unit
*/
CHeading(double value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_magnetic(magnetic) {}
/*!
* \brief Constructor
@@ -46,53 +48,68 @@ public:
* \param unit
*/
CHeading(int value, bool magnetic, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CAngle(value, unit), m_magnetic(magnetic) {}
/*!
* \brief Constructor by CAngle
* \param heading
* \param magnetic
*/
CHeading(CAngle heading, bool magnetic) : CAngle(), m_magnetic(magnetic) {
CHeading(CAngle heading, bool magnetic) : CAngle(), m_magnetic(magnetic)
{
CAngle::operator =(heading);
}
/*!
* \brief Copy constructor
* \param otherHeading
*/
CHeading(const CHeading &otherHeading) : CAngle(otherHeading), m_magnetic(otherHeading.m_magnetic) {}
/*!
* \brief Assignment operator =
* \param otherHeading
* @return
*/
CHeading &operator =(const CHeading &otherHeading);
/*!
* \brief Equal operator ==
* \param otherHeading
* @return
*/
bool operator ==(const CHeading &otherHeading);
/*!
* \brief Unequal operator ==
* \param otherHeading
* @return
*/
bool operator !=(const CHeading &otherHeading);
/*!
* \brief Magnetic heading?
* \return
*/
bool isMagneticHeading() const {
return this->m_magnetic;
}
bool isMagneticHeading() const { return this->m_magnetic; }
/*!
* \brief True heading?
* \return
*/
bool isTrueHeading() const {
return !this->m_magnetic;
bool isTrueHeading() const { return !this->m_magnetic; }
/*!
* \brief Switch heading unit
* \param newUnit
* \return
*/
CHeading &switchUnit(const BlackMisc::PhysicalQuantities::CAngleUnit &newUnit)
{
CAngle::switchUnit(newUnit);
return (*this);
}
};
} // namespace
} // namespace
#endif // BLACKMISC_AVHEADING_H
#endif // guard

View File

@@ -1,4 +0,0 @@
#ifndef AVIATION_H
#define AVIATION_H
#endif // AVIATION_H

View File

@@ -9,8 +9,8 @@ INCLUDEPATH += ..
# PRECOMPILED_HEADER = stdpch.h
precompile_header:!isEmpty(PRECOMPILED_HEADER) {
DEFINES += USING_PCH
}
DEFINES += USING_PCH
}
DEFINES += LOG_IN_FILE

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2013 VATSIM Community / authors
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -34,7 +34,7 @@ public:
* \brief Constructor by math vector
* \param vector
*/
CCoordinateEcef(const BlackMisc::Math::CVector3D vector) : CVector3DBase(vector.i(), vector.j(), vector.k()) {}
explicit CCoordinateEcef(const BlackMisc::Math::CVector3D vector) : CVector3DBase(vector.i(), vector.j(), vector.k()) {}
/*!
* \brief x

View File

@@ -14,10 +14,31 @@ namespace BlackMisc
{
namespace Geo
{
/*!
* \brief Interface for geodetic ccordinates
*/
class ICoordinateGeodetic
{
/*!
* \brief Latitude
* \return
*/
virtual CLatitude latitude() const = 0;
/*!
* \brief Longitude
* \return
*/
virtual CLongitude longitude() const = 0;
};
/*!
* \brief Geodetic coordinate
*/
class CCoordinateGeodetic : public CBaseStreamStringifier<CCoordinateGeodetic>
class CCoordinateGeodetic :
public CBaseStreamStringifier<CCoordinateGeodetic>,
public ICoordinateGeodetic
{
private:
@@ -97,20 +118,24 @@ public:
/*!
* \brief Switch unit of latitude / longitude
* \param unit
* \return
*/
void switchUnit(const BlackMisc::PhysicalQuantities::CAngleUnit &unit)
CCoordinateGeodetic &switchUnit(const BlackMisc::PhysicalQuantities::CAngleUnit &unit)
{
this->m_latitude.switchUnit(unit);
this->m_longitude.switchUnit(unit);
return (*this);
}
/*!
* \brief Switch unit of height
* \param unit
* \return
*/
void switchUnit(const BlackMisc::PhysicalQuantities::CLengthUnit &unit)
CCoordinateGeodetic &switchUnit(const BlackMisc::PhysicalQuantities::CLengthUnit &unit)
{
this->m_height.switchUnit(unit);
return (*this);
}
/*!

View File

@@ -69,7 +69,7 @@ public:
* \brief Constructor by math vector
* \param vector
*/
CCoordinateNed(const BlackMisc::Math::CVector3D vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(), m_hasReferencePosition(false) {}
explicit CCoordinateNed(const BlackMisc::Math::CVector3D vector) : CVector3DBase(vector.i(), vector.j(), vector.k()), m_referencePosition(), m_hasReferencePosition(false) {}
/*!
* \brief Constructor by math vector and reference position

View File

@@ -237,7 +237,7 @@ CCoordinateGeodetic CCoordinateTransformation::toGeodetic(const CCoordinateEcef
}
double latRad = atan2(sphi, cphi);
double lonRad = -atan2(-slam, clam); // Negative signs return lon in [-180, 180)
double lonRad = -atan2(-slam, clam); // Negative signs return lon degrees [-180, 180)
CCoordinateGeodetic result(
CLatitude(latRad, CAngleUnit::rad()),
CLongitude(lonRad, CAngleUnit::rad()),

View File

@@ -0,0 +1,16 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BLACKCORETEST_H
#define BLACKCORETEST_H
/*!
* @namespace BlackCoreTest
* Unit tests for BlackCore. Unit tests do have their own namespace, so
* the regular namespace BlackCore is completely free of unit tests.
* Add any new tests to TestMain::unitMain as shown there.
*/
#endif // guard

21
tests/blackcore/main.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include "testblackcoremain.h"
#include <QCoreApplication>
#include <QDebug>
using namespace BlackCoreTest;
/*!
* Starter for test cases
* \brief main
* \param argc
* \param argv
* \return
*/
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
CBlackCoreTestMain::unitMain(argc, argv);
// bye
return a.exec();
}

View File

@@ -0,0 +1,29 @@
QT += core testlib
TARGET = test_blackcore
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
DEPENDPATH += . ../../src/blackmisc
INCLUDEPATH += . ../../src
HEADERS += *.h
SOURCES += *.cpp
win32-msvc* {
PRE_TARGETDEPS += ../../lib/blackmisc.lib
PRE_TARGETDEPS += ../../lib/blackcore.lib
LIBS += ../../lib/blackmisc.lib
LIBS += ../../lib/blackcore.lib
}
!win32-msvc* {
PRE_TARGETDEPS += ../../lib/libblackmisc.a
PRE_TARGETDEPS += ../../lib/libblackcore.a
LIBS += ../../lib/libblackmisc.a
LIBS += ../../lib/libblackcore.a
}
DESTDIR = ../../bin

View File

@@ -0,0 +1,23 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "testblackcoremain.h"
#include "testinterpolator.h"
namespace BlackCoreTest
{
/*
* Starting main, equivalent to QTEST_APPLESS_MAIN for multiple test classes.
*/
int CBlackCoreTestMain::unitMain(int argc, char *argv[])
{
int status = 0;
{
CTestInterpolator interpolatorTests;
status |= QTest::qExec(&interpolatorTests, argc, argv);
}
return status;
}
} // namespace

View File

@@ -0,0 +1,32 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BLACKCORETEST_TESTMAIN_H
#define BLACKCORETEST_TESTMAIN_H
#include <QtTest/QtTest>
namespace BlackCoreTest
{
/*!
* Class firing all unit tests in this namespace.
* Avoids clashes with other main(..) functions and allows to fire the test cases
* simply from any other main.
*/
class CBlackCoreTestMain
{
public:
/*!
* \brief Starting all
* \param argc
* \param argv
* \return
*/
static int unitMain(int argc, char *argv[]);
};
}
#endif // guard

View File

@@ -0,0 +1,21 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "testinterpolator.h"
using namespace BlackCore;
namespace BlackCoreTest
{
/*
* Interpolator tests
*/
void CTestInterpolator::interpolatorBasics()
{
CInterpolator c;
QVERIFY2(!c.isValid(), "Default interpolator should not be valid");
}
} // namespace

View File

@@ -0,0 +1,39 @@
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BLACKCORETEST_TESTAVIATIONBASE_H
#define BLACKCORETEST_TESTAVIATIONBASE_H
#include "blackcore/interpolator.h"
#include <QtTest/QtTest>
namespace BlackCoreTest
{
/*!
* \brief Interpolator classes basic tests
*/
class CTestInterpolator : public QObject
{
Q_OBJECT
public:
/*!
* \brief Standard test case constructor
* \param parent
*/
explicit CTestInterpolator(QObject *parent = 0) : QObject(parent) {}
private slots:
/*!
* \brief Basic unit tests for interpolator
*/
void interpolatorBasics();
};
} // namespace
#endif // guard

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2013 VATSIM Community / authors
/* Copyright (C) 2013 VATSIM Community / contributors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -6,11 +6,11 @@
#ifndef BLACKMISCTEST_H
#define BLACKMISCTEST_H
/**
/*!
* @namespace BlackMiscTest
* Unit test for BlackMisc. Unit test do have their own namespace, so
* Unit tests for BlackMisc. Unit tests do have their own namespace, so
* the regular namespace BlackMisc is completely free of unit tests.
* Add any new tests to TestMain::unitMain as shown there in the pattern.
* Add any new tests to TestMain::unitMain as shown there.
*/
#endif // BLACKMISCTEST_H
#endif // guard

View File

@@ -1,11 +1,11 @@
#include "testblackmiscmain.h"
#include <QCoreApplication>
#include <QDebug>
#include "testmain.h"
using namespace BlackMiscTest;
/*!
* Starter for testcases
* Starter for test cases
* \brief main
* \param argc
* \param argv
@@ -14,7 +14,7 @@ using namespace BlackMiscTest;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
CTestMain::unitMain(argc, argv);
CBlackMiscTestMain::unitMain(argc, argv);
// bye
return a.exec();

View File

@@ -3,14 +3,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "testmain.h"
#include "testblackmiscmain.h"
namespace BlackMiscTest
{
/*
* Starting main, equivalent to QTEST_APPLESS_MAIN for multiple test classes.
*/
int CTestMain::unitMain(int argc, char *argv[])
int CBlackMiscTestMain::unitMain(int argc, char *argv[])
{
int status = 0;
{

View File

@@ -16,11 +16,11 @@ namespace BlackMiscTest
{
/*!
* Class firing of all unit tests in this namespace.
* Class firing all unit tests in this namespace.
* Avoids clashes with other main(..) functions and allows to fire the test cases
* simply from any other main.
*/
class CTestMain
class CBlackMiscTestMain
{
public:
/*!
@@ -33,4 +33,4 @@ public:
};
}
#endif // BLACKMISCTEST_TESTMAIN_H
#endif // guard

View File