From 87594174f844fc952811f1456065a06e072f590c Mon Sep 17 00:00:00 2001 From: Thomas Gubler Date: Fri, 14 Feb 2014 12:55:48 +0100 Subject: [PATCH] flightgear: add configurable barometer offset --- src/comm/QGCFlightGearLink.cc | 11 ++++++-- src/comm/QGCFlightGearLink.h | 3 +++ src/uas/UAS.cc | 3 ++- src/uas/UAS.h | 2 +- src/ui/QGCHilConfiguration.cc | 2 +- src/ui/QGCHilFlightGearConfiguration.cc | 8 +++++- src/ui/QGCHilFlightGearConfiguration.h | 4 +++ src/ui/QGCHilFlightGearConfiguration.ui | 36 +++++++++++++++++-------- 8 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/comm/QGCFlightGearLink.cc b/src/comm/QGCFlightGearLink.cc index 72f94e64d..9e9391735 100644 --- a/src/comm/QGCFlightGearLink.cc +++ b/src/comm/QGCFlightGearLink.cc @@ -46,7 +46,8 @@ QGCFlightGearLink::QGCFlightGearLink(UASInterface* mav, QString startupArguments terraSync(NULL), flightGearVersion(0), startupArguments(startupArguments), - _sensorHilEnabled(true) + _sensorHilEnabled(true), + barometerOffsetkPa(0.0) { this->host = host; this->port = port+mav->getUASID(); @@ -279,7 +280,8 @@ void QGCFlightGearLink::readBytes() mag_dip = values.at(18).toFloat(); temperature = values.at(19).toFloat(); - abs_pressure = values.at(20).toFloat()*1e2; //convert to Pa from hPa + abs_pressure = values.at(20).toFloat() * 1e2f; //convert to Pa from hPa + abs_pressure += barometerOffsetkPa * 1e3f; //add offset, convert from kPa to Pa //calculate differential pressure const float air_gas_constant = 287.1f; // J/(kg * K) @@ -736,3 +738,8 @@ void QGCFlightGearLink::setName(QString name) this->name = name; // emit nameChanged(this->name); } + +void QGCFlightGearLink::setBarometerOffset(float barometerOffsetkPa) +{ + this->barometerOffsetkPa = barometerOffsetkPa; +} diff --git a/src/comm/QGCFlightGearLink.h b/src/comm/QGCFlightGearLink.h index 27ba6d2cd..dc074fee0 100644 --- a/src/comm/QGCFlightGearLink.h +++ b/src/comm/QGCFlightGearLink.h @@ -42,6 +42,7 @@ This file is part of the QGROUNDCONTROL project #include #include "UASInterface.h" #include "QGCHilLink.h" +#include class QGCFlightGearLink : public QGCHilLink { @@ -134,6 +135,7 @@ public slots: void printFgfsOutput(); void printFgfsError(); void setStartupArguments(QString startupArguments); + void setBarometerOffset(float barometerOffsetkPa); protected: QString name; @@ -161,6 +163,7 @@ protected: unsigned int flightGearVersion; QString startupArguments; bool _sensorHilEnabled; + float barometerOffsetkPa; void setName(QString name); diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 6aa4258a7..71277ac1b 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -2982,7 +2982,7 @@ bool UAS::emergencyKILL() /** * If enabled, connect the flight gear link. */ -void UAS::enableHilFlightGear(bool enable, QString options, bool sensorHil) +void UAS::enableHilFlightGear(bool enable, QString options, bool sensorHil, QObject * configuration) { QGCFlightGearLink* link = dynamic_cast(simulation); if (!link || !simulation) { @@ -2997,6 +2997,7 @@ void UAS::enableHilFlightGear(bool enable, QString options, bool sensorHil) link = dynamic_cast(simulation); link->setStartupArguments(options); link->sensorHilEnabled(sensorHil); + QObject::connect(configuration, SIGNAL(barometerOffsetChanged(float)), link, SLOT(setBarometerOffset(float))); if (enable) { startHil(); diff --git a/src/uas/UAS.h b/src/uas/UAS.h index 9db1399a7..5f5a77ac0 100644 --- a/src/uas/UAS.h +++ b/src/uas/UAS.h @@ -757,7 +757,7 @@ public slots: void go(); /** @brief Enable / disable HIL */ - void enableHilFlightGear(bool enable, QString options, bool sensorHil); + void enableHilFlightGear(bool enable, QString options, bool sensorHil, QObject * configuration); void enableHilJSBSim(bool enable, QString options); void enableHilXPlane(bool enable); diff --git a/src/ui/QGCHilConfiguration.cc b/src/ui/QGCHilConfiguration.cc index 8d2a52af4..2ea1c7d7f 100644 --- a/src/ui/QGCHilConfiguration.cc +++ b/src/ui/QGCHilConfiguration.cc @@ -64,7 +64,7 @@ void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index) if(1 == index) { // Ensure the sim exists and is disabled - mav->enableHilFlightGear(false, "", true); + mav->enableHilFlightGear(false, "", true, this); QGCHilFlightGearConfiguration* hfgconf = new QGCHilFlightGearConfiguration(mav, this); hfgconf->show(); ui->simulatorConfigurationLayout->addWidget(hfgconf); diff --git a/src/ui/QGCHilFlightGearConfiguration.cc b/src/ui/QGCHilFlightGearConfiguration.cc index ddbccb7c7..67f4eb21d 100644 --- a/src/ui/QGCHilFlightGearConfiguration.cc +++ b/src/ui/QGCHilFlightGearConfiguration.cc @@ -40,10 +40,16 @@ void QGCHilFlightGearConfiguration::on_startButton_clicked() //XXX check validity of inputs QString options = ui->optionsPlainTextEdit->toPlainText(); options.append(" --aircraft=" + ui->aircraftComboBox->currentText()); - mav->enableHilFlightGear(true, options, ui->sensorHilCheckBox->isChecked()); + mav->enableHilFlightGear(true, options, ui->sensorHilCheckBox->isChecked(), this); } void QGCHilFlightGearConfiguration::on_stopButton_clicked() { mav->stopHil(); } + +void QGCHilFlightGearConfiguration::on_barometerOffsetLineEdit_textChanged(const QString& baroOffset) +{ + emit barometerOffsetChanged(baroOffset.toFloat()); +} + diff --git a/src/ui/QGCHilFlightGearConfiguration.h b/src/ui/QGCHilFlightGearConfiguration.h index 9ac353834..7e0e48901 100644 --- a/src/ui/QGCHilFlightGearConfiguration.h +++ b/src/ui/QGCHilFlightGearConfiguration.h @@ -25,9 +25,13 @@ protected: private slots: void on_startButton_clicked(); void on_stopButton_clicked(); + void on_barometerOffsetLineEdit_textChanged(const QString& baroOffset); private: Ui::QGCHilFlightGearConfiguration *ui; + +signals: + void barometerOffsetChanged(float barometerOffsetkPa); }; #endif // QGCHILFLIGHTGEARCONFIGURATION_H diff --git a/src/ui/QGCHilFlightGearConfiguration.ui b/src/ui/QGCHilFlightGearConfiguration.ui index b27ff74a1..fa79fe261 100644 --- a/src/ui/QGCHilFlightGearConfiguration.ui +++ b/src/ui/QGCHilFlightGearConfiguration.ui @@ -32,13 +32,6 @@ 6 - - - - Airframe: - - - @@ -52,14 +45,21 @@ - + <html><head/><body><p>Additional Options:</p></body></html> - + + + + Airframe: + + + + @@ -72,7 +72,7 @@ - + @@ -85,7 +85,7 @@ - + Stop @@ -102,6 +102,20 @@ + + + + Barometer Offset [kPa]: + + + + + + + 0 + + + -- 2.22.0