From 03b9312ba9503ead97c3bcdddd6166004701b99d Mon Sep 17 00:00:00 2001 From: Mariano Lizarraga Date: Fri, 12 Nov 2010 14:53:28 -0600 Subject: [PATCH] Continuing work in HIL Sim for Slugs --- src/comm/SerialLink.cc | 3 +- src/ui/MainWindow.cc | 36 +++++++------- src/ui/MainWindow.h | 2 + src/ui/slugshilsim.cc | 109 +++++++++++++++++++++++++++++++++++++++-- src/ui/slugshilsim.h | 75 +++++++++++++++++++++++++++- src/ui/slugshilsim.ui | 49 +++++++++++++----- 6 files changed, 236 insertions(+), 38 deletions(-) diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index 09d6fa96e..71efcfe33 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -64,7 +64,8 @@ SerialLink::SerialLink(QString portname, BaudRateType baudrate, FlowType flow, P // Set the port name if (porthandle == "") { - name = tr("serial link ") + QString::number(getId()) + tr(" (unconfigured)"); +// name = tr("serial link ") + QString::number(getId()) + tr(" (unconfigured)"); + name = tr("Serial Link ") + QString::number(getId()); } else { diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index e2236c0b9..9902bc457 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -181,6 +181,8 @@ void MainWindow::buildWidgets() slugsDataWidget = new QDockWidget(tr("Slugs Data"), this); slugsDataWidget->setWidget( new SlugsDataSensorView(this)); + slugsHilSimWidget = new QDockWidget(tr("Slugs Hil Sim"), this); + slugsHilSimWidget->setWidget( new SlugsHilSim(this)); } @@ -215,9 +217,14 @@ void MainWindow::connectWidgets() // it notifies that a waypoint global goes to do create and a map graphic too connect(waypointsDockWidget->widget(), SIGNAL(createWaypointAtMap(QPointF)), mapWidget, SLOT(createWaypointGraphAtMap(QPointF))); - // it notifies that a waypoint global change it´s position by spinBox on Widget WaypointView + // it notifies that a waypoint global change itÂ¥s position by spinBox on Widget WaypointView connect(waypointsDockWidget->widget(), SIGNAL(changePositionWPGlobalBySpinBox(int,float,float)), mapWidget, SLOT(changeGlobalWaypointPositionBySpinBox(int,float,float))); } + + if (slugsHilSimWidget->widget()){ + connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), dynamic_cast(slugsHilSimWidget->widget()), SLOT(activeUasSet(UASInterface*)) ); + } + } void MainWindow::arrangeCenterStack() @@ -540,15 +547,13 @@ void MainWindow::UASCreated(UASInterface* uas) // Check which type this UAS is of PxQuadMAV* mav = dynamic_cast(uas); if (mav) loadPixhawkView(); + SlugsMAV* mav2 = dynamic_cast(uas); if (mav2) { - SlugsDataSensorView* slugDataView = dynamic_cast(slugsDataWidget->widget()); - if(slugDataView) - { - slugDataView->addUAS(uas); - } - loadSlugsView(); + dynamic_cast(slugsDataWidget->widget())->addUAS(uas); + loadSlugsView(); + } @@ -639,17 +644,6 @@ void MainWindow::loadSlugsView() infoDockWidget->show(); } - // HORIZONTAL SITUATION INDICATOR - if (hsiDockWidget) - { - HSIDisplay* hsi = dynamic_cast( hsiDockWidget->widget() ); - if (hsi) - { - hsi->start(); - addDockWidget(Qt::LeftDockWidgetArea, hsiDockWidget); - hsiDockWidget->show(); - } - } // WAYPOINT LIST if (waypointsDockWidget) @@ -672,6 +666,12 @@ void MainWindow::loadSlugsView() slugsDataWidget->show(); } + // Slugs Data View + if (slugsHilSimWidget) + { + addDockWidget(Qt::LeftDockWidgetArea, slugsHilSimWidget); + slugsHilSimWidget->show(); + } this->show(); } diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 099bc7e00..092e90363 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -66,6 +66,7 @@ This file is part of the QGROUNDCONTROL project #include "QMap3DWidget.h" #include "SlugsDataSensorView.h" #include "LogCompressor.h" +#include "slugshilsim.h" /** @@ -180,6 +181,7 @@ protected: QPointer hsiDockWidget; QPointer rcViewDockWidget; QPointer slugsDataWidget; + QPointer slugsHilSimWidget; // Popup widgets JoystickWidget* joystickWidget; diff --git a/src/ui/slugshilsim.cc b/src/ui/slugshilsim.cc index 8a8272d1e..08f75b369 100644 --- a/src/ui/slugshilsim.cc +++ b/src/ui/slugshilsim.cc @@ -1,3 +1,33 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Configuration Window for Slugs' HIL Simulator + * @author Mariano Lizarraga + */ + + #include "slugshilsim.h" #include "ui_slugshilsim.h" #include "LinkManager.h" @@ -7,8 +37,15 @@ SlugsHilSim::SlugsHilSim(QWidget *parent) : ui(new Ui::SlugsHilSim) { ui->setupUi(this); - linkAdded(); + rxSocket = new QUdpSocket(this); + txSocket = new QUdpSocket(this); + + connect(LinkManager::instance(), SIGNAL(newLink(LinkInterface*)), this, SLOT(addToCombo(LinkInterface*))); + connect(ui->bt_startHil, SIGNAL(clicked()), this, SLOT(putInHilMode())); + connect(rxSocket, SIGNAL(readyRead()), this, SLOT(readDatagram())); + + linksAvailable.clear(); } SlugsHilSim::~SlugsHilSim() @@ -18,12 +55,74 @@ SlugsHilSim::~SlugsHilSim() void SlugsHilSim::linkAdded(void){ - ui->cb_mavlinkLinks->clear(); +// ui->cb_mavlinkLinks->clear(); + +// QList linkList; +// linkList.append(LinkManager::instance()->getLinks()) ; + +// for (int i = 0; i< linkList.size(); i++){ +// ui->cb_mavlinkLinks->addItem((linkList.takeFirst())->getName()); +// } + +} + +void SlugsHilSim::addToCombo(LinkInterface* theLink){ + + ui->cb_mavlinkLinks->addItem(theLink->getName()); + linksAvailable.insert(ui->cb_mavlinkLinks->count(),theLink); +} - QList linkList = LinkManager::instance()->getLinks() ; +void SlugsHilSim::putInHilMode(void){ - for (int i = 0; i< linkList.size(); i++){ - ui->cb_mavlinkLinks->addItem((linkList.takeFirst())->getName()); + bool sw_enableControls = !(ui->bt_startHil->isChecked()); + QString buttonCaption= ui->bt_startHil->isChecked()? "Stop Slugs HIL Mode": "Set Slugs in HIL Mode"; + + if (ui->bt_startHil->isChecked()){ + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Critical); + msgBox.setText("You are about to put SLUGS in HIL Mode."); + msgBox.setInformativeText("It will stop reading the actual sensor readings. Do you wish to continue?"); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + + if(msgBox.exec() == QMessageBox::Yes) + { + rxSocket->bind(QHostAddress::Any, ui->ed_rxPort->text().toInt()); + txSocket->bind(QHostAddress::Broadcast, ui->ed_txPort->text().toInt()); + + ui->ed_ipAdress->setEnabled(sw_enableControls); + ui->ed_rxPort->setEnabled(sw_enableControls); + ui->ed_txPort->setEnabled(sw_enableControls); + ui->cb_mavlinkLinks->setEnabled(sw_enableControls); + + ui->bt_startHil->setText(buttonCaption); + + + } else { + ui->bt_startHil->setChecked(false); + } + } else { + ui->ed_ipAdress->setEnabled(sw_enableControls); + ui->ed_rxPort->setEnabled(sw_enableControls); + ui->ed_txPort->setEnabled(sw_enableControls); + ui->cb_mavlinkLinks->setEnabled(sw_enableControls); + + ui->bt_startHil->setText(buttonCaption); } + + + +} + +void SlugsHilSim::readDatagram(void){ + +} + + +void SlugsHilSim::activeUasSet(UASInterface* uas){ + + if (uas != NULL) { + activeUas = uas; + } } diff --git a/src/ui/slugshilsim.h b/src/ui/slugshilsim.h index 57c4e56ac..98fab34f4 100644 --- a/src/ui/slugshilsim.h +++ b/src/ui/slugshilsim.h @@ -1,10 +1,42 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009, 2010 QGROUNDCONTROL PROJECT + +This file is part of the QGROUNDCONTROL project + + QGROUNDCONTROL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + QGROUNDCONTROL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QGROUNDCONTROL. If not, see . + +======================================================================*/ + +/** + * @file + * @brief Definition of the configuration Window for Slugs' HIL Simulator + * @author Mariano Lizarraga + */ + #ifndef SLUGSHILSIM_H #define SLUGSHILSIM_H #include #include #include +#include + #include "LinkInterface.h" +#include "UAS.h" namespace Ui { @@ -24,11 +56,52 @@ protected: QHostAddress* simulinkIp; QUdpSocket* txSocket; QUdpSocket* rxSocket; + UAS* activeUas; + +public slots: + void linkAdded (void); + + /** + * @brief Adds a link to the combo box listing so the user can select a link + * + * Populates the Combo box that allows the user to select the link with which Slugs will + * receive the simulated sensor data from Simulink + * + * @param theLink the link that is being added to the combo box + */ + void addToCombo(LinkInterface* theLink); + + /** + * @brief Puts Slugs in HIL Mode + * + * Sends the required messages through the main communication link to set Slugs in HIL Mode + * + */ + void putInHilMode(void); + + /** + * @brief Receives a datagram from Simulink containing the sensor data. + * + * Receives a datagram from Simulink containing the simulated sensor data. This data is then + * forwarded to Slugs to use as input to the attitude estimation and navigation algorithms. + * + */ + void readDatagram(void); + + /** + * @brief Called when the a new UAS is set to active. + * + * Called when the a new UAS is set to active. + * + * @param uas The new active UAS + */ + void activeUasSet(UASInterface* uas); -slots: private: Ui::SlugsHilSim *ui; + QHash linksAvailable; + }; #endif // SLUGSHILSIM_H diff --git a/src/ui/slugshilsim.ui b/src/ui/slugshilsim.ui index 2281b4683..caae1a9aa 100644 --- a/src/ui/slugshilsim.ui +++ b/src/ui/slugshilsim.ui @@ -6,19 +6,19 @@ 0 0 - 256 + 325 191 - 256 + 320 191 - 367 + 450 229 @@ -45,7 +45,7 @@ - Qt::RightToLeft + Qt::LeftToRight IP Address @@ -91,7 +91,7 @@ - Qt::RightToLeft + Qt::LeftToRight Receive Port @@ -124,7 +124,7 @@ - Qt::RightToLeft + Qt::LeftToRight Send Port @@ -132,7 +132,7 @@ - + 60 @@ -165,8 +165,8 @@ - - + + @@ -179,12 +179,32 @@ Qt::RightToLeft - Slugs HIL Sim Serial Link + Slugs HIL Link - - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 171 + 26 + + + @@ -206,7 +226,10 @@ - Set in HIL Mode + Set Slugs in HIL Mode + + + true -- 2.22.0