Commit 4574fd52 authored by Thomas Gubler's avatar Thomas Gubler

Merge pull request #592 from mavlink/hil_cleanup

HIL cleanup, ensure correct init in X-Plane
parents 7c0ad714 1bebc97d
...@@ -47,7 +47,7 @@ QGCFlightGearLink::QGCFlightGearLink(UASInterface* mav, QString startupArguments ...@@ -47,7 +47,7 @@ QGCFlightGearLink::QGCFlightGearLink(UASInterface* mav, QString startupArguments
flightGearVersion(0), flightGearVersion(0),
startupArguments(startupArguments), startupArguments(startupArguments),
_sensorHilEnabled(true), _sensorHilEnabled(true),
barometerOffsetkPa(0.0) barometerOffsetkPa(0.0f)
{ {
this->host = host; this->host = host;
this->port = port+mav->getUASID(); this->port = port+mav->getUASID();
......
...@@ -72,8 +72,6 @@ public slots: ...@@ -72,8 +72,6 @@ public slots:
protected: protected:
virtual void setName(QString name) = 0; virtual void setName(QString name) = 0;
static const unsigned int barometerOffsetkPa = 2;
signals: signals:
/** /**
* @brief This signal is emitted instantly when the link is connected * @brief This signal is emitted instantly when the link is connected
......
...@@ -48,10 +48,12 @@ QGCXPlaneLink::QGCXPlaneLink(UASInterface* mav, QString remoteHost, QHostAddress ...@@ -48,10 +48,12 @@ QGCXPlaneLink::QGCXPlaneLink(UASInterface* mav, QString remoteHost, QHostAddress
socket(NULL), socket(NULL),
process(NULL), process(NULL),
terraSync(NULL), terraSync(NULL),
barometerOffsetkPa(15.0f),
airframeID(QGCXPlaneLink::AIRFRAME_UNKNOWN), airframeID(QGCXPlaneLink::AIRFRAME_UNKNOWN),
xPlaneConnected(false), xPlaneConnected(false),
xPlaneVersion(0), xPlaneVersion(0),
simUpdateLast(QGC::groundTimeMilliseconds()), simUpdateLast(QGC::groundTimeMilliseconds()),
simUpdateFirst(0),
simUpdateLastText(QGC::groundTimeMilliseconds()), simUpdateLastText(QGC::groundTimeMilliseconds()),
simUpdateHz(0), simUpdateHz(0),
_sensorHilEnabled(true) _sensorHilEnabled(true)
...@@ -452,6 +454,10 @@ void QGCXPlaneLink::readBytes() ...@@ -452,6 +454,10 @@ void QGCXPlaneLink::readBytes()
{ {
xPlaneConnected = true; xPlaneConnected = true;
if (oldConnectionState != xPlaneConnected) {
simUpdateFirst = QGC::groundTimeMilliseconds();
}
for (unsigned i = 0; i < nsegs; i++) for (unsigned i = 0; i < nsegs; i++)
{ {
// Get index // Get index
...@@ -642,6 +648,11 @@ void QGCXPlaneLink::readBytes() ...@@ -642,6 +648,11 @@ void QGCXPlaneLink::readBytes()
qDebug() << "UNKNOWN PACKET:" << data; qDebug() << "UNKNOWN PACKET:" << data;
} }
// Wait for 0.5s before actually using the data, so that all fields are filled
if (QGC::groundTimeMilliseconds() - simUpdateFirst < 500) {
return;
}
// Send updated state // Send updated state
if (emitUpdate && (QGC::groundTimeMilliseconds() - simUpdateLast) > 3) if (emitUpdate && (QGC::groundTimeMilliseconds() - simUpdateLast) > 3)
{ {
......
...@@ -197,6 +197,7 @@ protected: ...@@ -197,6 +197,7 @@ protected:
float true_airspeed; float true_airspeed;
float groundspeed; float groundspeed;
float xmag, ymag, zmag, abs_pressure, diff_pressure, pressure_alt, temperature; float xmag, ymag, zmag, abs_pressure, diff_pressure, pressure_alt, temperature;
float barometerOffsetkPa;
float man_roll, man_pitch, man_yaw; float man_roll, man_pitch, man_yaw;
QString airframeName; QString airframeName;
...@@ -204,6 +205,7 @@ protected: ...@@ -204,6 +205,7 @@ protected:
bool xPlaneConnected; bool xPlaneConnected;
unsigned int xPlaneVersion; unsigned int xPlaneVersion;
quint64 simUpdateLast; quint64 simUpdateLast;
quint64 simUpdateFirst;
quint64 simUpdateLastText; quint64 simUpdateLastText;
float simUpdateHz; float simUpdateHz;
bool _sensorHilEnabled; bool _sensorHilEnabled;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment