Commit 8a6998d1 authored by Lorenz Meier's avatar Lorenz Meier

Hil tests

parent 73522dd1
...@@ -42,6 +42,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -42,6 +42,7 @@ This file is part of the QGROUNDCONTROL project
QGCFlightGearLink::QGCFlightGearLink(UASInterface* mav, QString startupArguments, QString remoteHost, QHostAddress host, quint16 port) : QGCFlightGearLink::QGCFlightGearLink(UASInterface* mav, QString startupArguments, QString remoteHost, QHostAddress host, quint16 port) :
process(NULL), process(NULL),
terraSync(NULL), terraSync(NULL),
socket(NULL),
startupArguments(startupArguments), startupArguments(startupArguments),
flightGearVersion(0) flightGearVersion(0)
{ {
......
...@@ -99,6 +99,11 @@ public slots: ...@@ -99,6 +99,11 @@ public slots:
Q_UNUSED(version); Q_UNUSED(version);
} }
void selectAirframe(const QString& airframe)
{
Q_UNUSED(airframe);
}
void readBytes(); void readBytes();
/** /**
* @brief Write a number of bytes to the interface. * @brief Write a number of bytes to the interface.
......
...@@ -48,6 +48,8 @@ public slots: ...@@ -48,6 +48,8 @@ public slots:
/** @brief Set the simulator version as text string */ /** @brief Set the simulator version as text string */
virtual void setVersion(const QString& version) = 0; virtual void setVersion(const QString& version) = 0;
virtual void selectAirframe(const QString& airframe) = 0;
virtual void readBytes() = 0; virtual void readBytes() = 0;
/** /**
* @brief Write a number of bytes to the interface. * @brief Write a number of bytes to the interface.
......
...@@ -75,7 +75,7 @@ void QGCXPlaneLink::loadSettings() ...@@ -75,7 +75,7 @@ void QGCXPlaneLink::loadSettings()
settings.beginGroup("QGC_XPLANE_LINK"); settings.beginGroup("QGC_XPLANE_LINK");
setRemoteHost(settings.value("REMOTE_HOST", QString("%1:%2").arg(remoteHost.toString()).arg(remotePort)).toString()); setRemoteHost(settings.value("REMOTE_HOST", QString("%1:%2").arg(remoteHost.toString()).arg(remotePort)).toString());
setVersion(settings.value("XPLANE_VERSION", 10).toInt()); setVersion(settings.value("XPLANE_VERSION", 10).toInt());
selectPlane(settings.value("AIRFRAME", "default").toString()); selectAirframe(settings.value("AIRFRAME", "default").toString());
settings.endGroup(); settings.endGroup();
} }
...@@ -182,7 +182,6 @@ void QGCXPlaneLink::setRemoteHost(const QString& newHost) ...@@ -182,7 +182,6 @@ void QGCXPlaneLink::setRemoteHost(const QString& newHost)
if (newHost.contains(":")) if (newHost.contains(":"))
{ {
//qDebug() << "HOST: " << newHost.split(":").first();
QHostInfo info = QHostInfo::fromName(newHost.split(":").first()); QHostInfo info = QHostInfo::fromName(newHost.split(":").first());
if (info.error() == QHostInfo::NoError) if (info.error() == QHostInfo::NoError)
{ {
...@@ -198,7 +197,6 @@ void QGCXPlaneLink::setRemoteHost(const QString& newHost) ...@@ -198,7 +197,6 @@ void QGCXPlaneLink::setRemoteHost(const QString& newHost)
} }
} }
remoteHost = address; remoteHost = address;
//qDebug() << "Address:" << address.toString();
// Set localPort according to user input // Set localPort according to user input
remotePort = newHost.split(":").last().toInt(); remotePort = newHost.split(":").last().toInt();
} }
...@@ -586,7 +584,7 @@ bool QGCXPlaneLink::disconnectSimulation() ...@@ -586,7 +584,7 @@ bool QGCXPlaneLink::disconnectSimulation()
return !connectState; return !connectState;
} }
void QGCXPlaneLink::selectPlane(const QString& plane) void QGCXPlaneLink::selectAirframe(const QString& plane)
{ {
airframeName = plane; airframeName = plane;
...@@ -718,6 +716,8 @@ void QGCXPlaneLink::setRandomAttitude() ...@@ -718,6 +716,8 @@ void QGCXPlaneLink::setRandomAttitude()
bool QGCXPlaneLink::connectSimulation() bool QGCXPlaneLink::connectSimulation()
{ {
qDebug() << "STARTING X-PLANE LINK, CONNECTING TO" << remoteHost << ":" << remotePort; qDebug() << "STARTING X-PLANE LINK, CONNECTING TO" << remoteHost << ":" << remotePort;
// XXX Hack
storeSettings();
start(LowPriority); start(LowPriority);
...@@ -730,9 +730,6 @@ bool QGCXPlaneLink::connectSimulation() ...@@ -730,9 +730,6 @@ bool QGCXPlaneLink::connectSimulation()
QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes())); QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readBytes()));
//process = new QProcess(this);
//terraSync = new QProcess(this);
connect(mav, SIGNAL(hilControlsChanged(uint64_t, float, float, float, float, uint8_t, uint8_t)), this, SLOT(updateControls(uint64_t,float,float,float,float,uint8_t,uint8_t))); connect(mav, SIGNAL(hilControlsChanged(uint64_t, float, float, float, float, uint8_t, uint8_t)), this, SLOT(updateControls(uint64_t,float,float,float,float,uint8_t,uint8_t)));
connect(mav, SIGNAL(hilActuatorsChanged(uint64_t, float, float, float, float, float, float, float, float)), this, SLOT(updateActuators(uint64_t,float,float,float,float,float,float,float,float))); connect(mav, SIGNAL(hilActuatorsChanged(uint64_t, float, float, float, float, float, float, float, float)), this, SLOT(updateActuators(uint64_t,float,float,float,float,float,float,float,float)));
connect(this, SIGNAL(hilStateChanged(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)), mav, SLOT(sendHilState(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t))); connect(this, SIGNAL(hilStateChanged(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)), mav, SLOT(sendHilState(uint64_t,float,float,float,float,float,float,int32_t,int32_t,int32_t,int16_t,int16_t,int16_t,int16_t,int16_t,int16_t)));
......
...@@ -130,7 +130,7 @@ public slots: ...@@ -130,7 +130,7 @@ public slots:
* @brief Select airplane model * @brief Select airplane model
* @param plane the name of the airplane * @param plane the name of the airplane
*/ */
void selectPlane(const QString& plane); void selectAirframe(const QString& airframe);
/** /**
* @brief Set the airplane position and attitude * @brief Set the airplane position and attitude
* @param lat * @param lat
......
...@@ -97,7 +97,7 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(), ...@@ -97,7 +97,7 @@ UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(),
paramManager(NULL), paramManager(NULL),
attitudeStamped(false), attitudeStamped(false),
lastAttitude(0), lastAttitude(0),
simulation(new QGCXPlaneLink(this)), simulation(0),
isLocalPositionKnown(false), isLocalPositionKnown(false),
isGlobalPositionKnown(false), isGlobalPositionKnown(false),
systemIsArmed(false), systemIsArmed(false),
...@@ -2592,10 +2592,18 @@ bool UAS::emergencyKILL() ...@@ -2592,10 +2592,18 @@ bool UAS::emergencyKILL()
*/ */
void UAS::enableHilFlightGear(bool enable, QString options) void UAS::enableHilFlightGear(bool enable, QString options)
{ {
QGCFlightGearLink* link = dynamic_cast<QGCFlightGearLink*>(simulation);
if (!link || !simulation) {
// Delete wrong sim
if (simulation) {
stopHil();
delete simulation;
}
simulation = new QGCFlightGearLink(this, options);
}
// Connect Flight Gear Link // Connect Flight Gear Link
if (enable) if (enable)
{ {
simulation = new QGCFlightGearLink(this, options);
startHil(); startHil();
} }
else else
...@@ -2609,10 +2617,18 @@ void UAS::enableHilFlightGear(bool enable, QString options) ...@@ -2609,10 +2617,18 @@ void UAS::enableHilFlightGear(bool enable, QString options)
*/ */
void UAS::enableHilXPlane(bool enable) void UAS::enableHilXPlane(bool enable)
{ {
QGCXPlaneLink* link = dynamic_cast<QGCXPlaneLink*>(simulation);
if (!link || !simulation) {
if (simulation) {
stopHil();
delete simulation;
}
qDebug() << "CREATED NEW XPLANE LINK";
simulation = new QGCXPlaneLink(this);
}
// Connect X-Plane Link // Connect X-Plane Link
if (enable) if (enable)
{ {
simulation = new QGCXPlaneLink(this);
startHil(); startHil();
} }
else else
...@@ -2680,7 +2696,7 @@ void UAS::startHil() ...@@ -2680,7 +2696,7 @@ void UAS::startHil()
*/ */
void UAS::stopHil() void UAS::stopHil()
{ {
simulation->disconnectSimulation(); if (simulation) simulation->disconnectSimulation();
mavlink_message_t msg; mavlink_message_t msg;
mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), mode & !MAV_MODE_FLAG_HIL_ENABLED, navMode); mavlink_msg_set_mode_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), mode & !MAV_MODE_FLAG_HIL_ENABLED, navMode);
sendMessage(msg); sendMessage(msg);
......
...@@ -10,12 +10,6 @@ QGCHilConfiguration::QGCHilConfiguration(UAS *mav, QWidget *parent) : ...@@ -10,12 +10,6 @@ QGCHilConfiguration::QGCHilConfiguration(UAS *mav, QWidget *parent) :
ui(new Ui::QGCHilConfiguration) ui(new Ui::QGCHilConfiguration)
{ {
ui->setupUi(this); ui->setupUi(this);
connect(mav->getHILSimulation(), SIGNAL(statusMessage(QString)), this, SLOT(receiveStatusMessage(QString)));
connect(ui->simComboBox, SIGNAL(activated(QString)), mav->getHILSimulation(), SLOT(setVersion(QString)));
//ui->simComboBox->setEditText(mav->getHILSimulation()->getVersion());
// connect(ui->)
} }
void QGCHilConfiguration::receiveStatusMessage(const QString& message) void QGCHilConfiguration::receiveStatusMessage(const QString& message)
...@@ -30,9 +24,10 @@ QGCHilConfiguration::~QGCHilConfiguration() ...@@ -30,9 +24,10 @@ QGCHilConfiguration::~QGCHilConfiguration()
void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index) void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index)
{ {
//XXX make sure here that no other simulator is running
if(1 == index) if(1 == index)
{ {
// Ensure the sim exists and is disabled
mav->enableHilFlightGear(false, "");
QGCHilFlightGearConfiguration* hfgconf = new QGCHilFlightGearConfiguration(mav, this); QGCHilFlightGearConfiguration* hfgconf = new QGCHilFlightGearConfiguration(mav, this);
hfgconf->show(); hfgconf->show();
ui->simulatorConfigurationDockWidget->setWidget(hfgconf); ui->simulatorConfigurationDockWidget->setWidget(hfgconf);
...@@ -40,6 +35,8 @@ void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index) ...@@ -40,6 +35,8 @@ void QGCHilConfiguration::on_simComboBox_currentIndexChanged(int index)
} }
else if(2 == index || 3 == index) else if(2 == index || 3 == index)
{ {
// Ensure the sim exists and is disabled
mav->enableHilXPlane(false);
QGCHilXPlaneConfiguration* hxpconf = new QGCHilXPlaneConfiguration(mav->getHILSimulation(), this); QGCHilXPlaneConfiguration* hxpconf = new QGCHilXPlaneConfiguration(mav->getHILSimulation(), this);
hxpconf->show(); hxpconf->show();
ui->simulatorConfigurationDockWidget->setWidget(hxpconf); ui->simulatorConfigurationDockWidget->setWidget(hxpconf);
......
...@@ -7,11 +7,15 @@ QGCHilXPlaneConfiguration::QGCHilXPlaneConfiguration(QGCHilLink* link, QWidget * ...@@ -7,11 +7,15 @@ QGCHilXPlaneConfiguration::QGCHilXPlaneConfiguration(QGCHilLink* link, QWidget *
ui(new Ui::QGCHilXPlaneConfiguration) ui(new Ui::QGCHilXPlaneConfiguration)
{ {
ui->setupUi(this); ui->setupUi(this);
this->link = link;
connect(ui->startButton, SIGNAL(clicked(bool)), this, SLOT(toggleSimulation(bool))); connect(ui->startButton, SIGNAL(clicked(bool)), this, SLOT(toggleSimulation(bool)));
connect(ui->hostComboBox, SIGNAL(activated(QString)), link, SLOT(setRemoteHost(QString))); connect(ui->hostComboBox, SIGNAL(activated(QString)), link, SLOT(setRemoteHost(QString)));
connect(link, SIGNAL(remoteChanged(QString)), ui->hostComboBox, SLOT(setEditText(QString))); connect(link, SIGNAL(remoteChanged(QString)), ui->hostComboBox, SLOT(setEditText(QString)));
connect(link, SIGNAL(statusMessage(QString)), this, SLOT(receiveStatusMessage(QString))); connect(link, SIGNAL(statusMessage(QString)), parent, SLOT(receiveStatusMessage(QString)));
// connect(mav->getHILSimulation(), SIGNAL(statusMessage(QString)), this, SLOT(receiveStatusMessage(QString)));
// connect(ui->simComboBox, SIGNAL(activated(QString)), mav->getHILSimulation(), SLOT(setVersion(QString)));
ui->startButton->setText(tr("Connect")); ui->startButton->setText(tr("Connect"));
...@@ -21,7 +25,7 @@ QGCHilXPlaneConfiguration::QGCHilXPlaneConfiguration(QGCHilLink* link, QWidget * ...@@ -21,7 +25,7 @@ QGCHilXPlaneConfiguration::QGCHilXPlaneConfiguration(QGCHilLink* link, QWidget *
{ {
connect(ui->randomAttitudeButton, SIGNAL(clicked()), link, SLOT(setRandomAttitude())); connect(ui->randomAttitudeButton, SIGNAL(clicked()), link, SLOT(setRandomAttitude()));
connect(ui->randomPositionButton, SIGNAL(clicked()), link, SLOT(setRandomPosition())); connect(ui->randomPositionButton, SIGNAL(clicked()), link, SLOT(setRandomPosition()));
connect(ui->airframeComboBox, SIGNAL(activated(QString)), link, SLOT(setAirframe(QString))); connect(ui->airframeComboBox, SIGNAL(activated(QString)), link, SLOT(selectAirframe(QString)));
ui->airframeComboBox->setCurrentIndex(link->getAirFrameIndex()); ui->airframeComboBox->setCurrentIndex(link->getAirFrameIndex());
} }
......
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