Fix sending the correct pressure altitude for a pilot position

* Before this commit, only the true altitude was known for an aircraft situation. The pressure altitude was not available anywhere yet.
* This caused a wrong altitude in radar clients.
* We fix this reading the pressure altitude from the simulators and set it in the own aircraft situation.
* MS Flight Simulators have the pressure altitude in the APIs available.
* For X-Plane and emulated simulator, we need to calculate it from the pressure at sea level.
* Finally, we use the new available pressure altitude to send it to the FSD server.

Maniphest Tasks: Ref T223
This commit is contained in:
Roland Winklmeier
2018-01-12 13:30:30 +01:00
committed by Klaus Basan
parent 51a90a9a71
commit de4fe44156
30 changed files with 298 additions and 43 deletions

View File

@@ -9,8 +9,10 @@
#include "situationform.h"
#include "ui_situationform.h"
#include "blackmisc/pq/pressure.h"
#include "blackmisc/pq/angle.h"
#include "blackmisc/stringutils.h"
#include "blackmisc/logmessage.h"
#include <QDoubleValidator>
using namespace BlackMisc;
@@ -29,14 +31,19 @@ namespace BlackGui
ui->le_Bank->setValidator(new QDoubleValidator(-180.0 + CAngleUnit::deg().getEpsilon(), 180.0, 3, ui->le_Bank));
ui->le_Pitch->setValidator(new QDoubleValidator(-180.0 + CAngleUnit::deg().getEpsilon(), 180.0, 3, ui->le_Pitch));
ui->le_Pressure->setValidator(new QDoubleValidator(980.0, 1046.0, 2, ui->le_Pressure));
connect(ui->hs_Bank, &QSlider::valueChanged, this, &CSituationForm::bankSliderChanged);
connect(ui->hs_Pitch, &QSlider::valueChanged, this, &CSituationForm::pitchSliderChanged);
connect(ui->hs_Pressure, &QSlider::valueChanged, this, &CSituationForm::pressureSliderChanged);
connect(ui->le_Bank, &QLineEdit::editingFinished, this, &CSituationForm::bankEntered);
connect(ui->le_Pitch, &QLineEdit::editingFinished, this, &CSituationForm::pitchEntered);
connect(ui->le_Pressure, &QLineEdit::editingFinished, this, &CSituationForm::pressureEntered);
connect(ui->tb_ResetBank, &QToolButton::clicked, this, &CSituationForm::resetBank);
connect(ui->tb_ResetPitch, &QToolButton::clicked, this, &CSituationForm::resetPitch);
connect(ui->tb_ResetPressure, &QToolButton::clicked, this, &CSituationForm::resetPressure);
connect(ui->pb_Set, &QPushButton::clicked, this, &CSituationForm::changeAircraftSituation);
connect(ui->pb_SetEnvironment, &QPushButton::clicked, this, &CSituationForm::changeAircraftSituation);
connect(ui->comp_Coordinate, &CCoordinateForm::changeCoordinate, this, &CSituationForm::changeAircraftSituation);
}
@@ -50,9 +57,13 @@ namespace BlackGui
CAircraftSituation CSituationForm::getSituation() const
{
CAircraftSituation s(ui->comp_Coordinate->getCoordinate());
const BlackMisc::Geo::CCoordinateGeodetic position = ui->comp_Coordinate->getCoordinate();
CAircraftSituation s(position);
s.setBank(this->getBankAngle());
s.setPitch(this->getPitchAngle());
CAltitude pressureAltitude(position.geodeticHeight().toPressureAltitude(this->getBarometricPressureMsl()));
s.setPressureAltitude(pressureAltitude);
return s;
}
@@ -84,6 +95,20 @@ namespace BlackGui
return CAngle::normalizeDegrees180(vd, RoundDigits);
}
double CSituationForm::getBarometricPressureMslMillibar() const
{
const QString v(ui->le_Pressure->text().replace(',', '.'));
bool ok;
double vd = v.toDouble(&ok);
if (!ok) { vd = 1013.25; }
return vd;
}
CPressure CSituationForm::getBarometricPressureMsl() const
{
return CPressure (getBarometricPressureMslMillibar(), CPressureUnit::mbar());
}
void CSituationForm::setReadOnly(bool readonly)
{
ui->comp_Coordinate->setReadOnly(readonly);
@@ -128,6 +153,13 @@ namespace BlackGui
ui->le_Pitch->setText(QString::number(value));
}
void CSituationForm::pressureSliderChanged(int value)
{
const int pressure = qRound(this->getBarometricPressureMslMillibar());
if (value == pressure) { return; } // avoid roundtrips
ui->le_Pressure->setText(QString::number(value));
}
void CSituationForm::bankEntered()
{
const double ad = this->getBankAngleDegrees();
@@ -161,5 +193,22 @@ namespace BlackGui
ui->le_Pitch->setText("0");
ui->hs_Pitch->setValue(0);
}
void CSituationForm::pressureEntered()
{
const double pd = this->getBarometricPressureMslMillibar();
QString n = QString::number(pd, 'g', 4 + RoundDigits);
if (ui->le_Pressure->validator()) { dotToLocaleDecimalPoint(n); }
ui->le_Pressure->setText(n);
const int pi = qRound(pd);
if (pi == ui->hs_Pressure->value()) { return; } // avoid roundtrips
ui->hs_Pressure->setValue(pi);
}
void CSituationForm::resetPressure()
{
ui->le_Pressure->setText("1013.00");
ui->hs_Pressure->setValue(1013);
}
} // ns
} // ns

View File

@@ -74,12 +74,21 @@ namespace BlackGui
//! Get pitch angle
double getPitchAngleDegrees() const;
//! Get barometric pressure at mean sea level
BlackMisc::PhysicalQuantities::CPressure getBarometricPressureMsl() const;
//! Get pressure at mean sea level
double getBarometricPressureMslMillibar() const;
void bankSliderChanged(int value);
void pitchSliderChanged(int value);
void pressureSliderChanged(int value);
void bankEntered();
void resetBank();
void pitchEntered();
void resetPitch();
void pressureEntered();
void resetPressure();
QScopedPointer<Ui::CSituationForm> ui;
};

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>386</width>
<height>324</height>
<width>512</width>
<height>439</height>
</rect>
</property>
<property name="windowTitle">
@@ -37,7 +37,7 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gl_Situation" columnstretch="1,1,1,3">
<layout class="QGridLayout" name="gl_Situation" columnstretch="1,0,0,0">
<item row="0" column="0">
<widget class="QLabel" name="lbl_Bank">
<property name="text">
@@ -110,7 +110,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<spacer name="vs_Situation">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -145,7 +145,7 @@
</property>
</widget>
</item>
<item row="2" column="3" alignment="Qt::AlignRight">
<item row="3" column="3" alignment="Qt::AlignRight">
<widget class="QPushButton" name="pb_Set">
<property name="text">
<string>set</string>
@@ -183,6 +183,112 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_Environment">
<property name="title">
<string>Environment</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QFrame" name="comp_Environment">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gl_Environment" columnstretch="1,0,0,0">
<item row="0" column="0">
<widget class="QLabel" name="lbl_Pressure">
<property name="text">
<string>Pressure MSL (980 - 1046 mbar)</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="le_Pressure">
<property name="text">
<string>1013.00</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="tb_ResetPressure">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../blackmisc/blackmisc.qrc">
<normaloff>:/diagona/icons/diagona/icons/cross-white.png</normaloff>:/diagona/icons/diagona/icons/cross-white.png</iconset>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSlider" name="hs_Pressure">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>980</number>
</property>
<property name="maximum">
<number>1046</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="value">
<number>1013</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="invertedControls">
<bool>false</bool>
</property>
<property name="tickPosition">
<enum>QSlider::TicksAbove</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
<item row="1" column="3" alignment="Qt::AlignRight">
<widget class="QPushButton" name="pb_SetEnvironment">
<property name="text">
<string>set</string>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>